Files
gitea/routers/api/actions/ping/ping.go
T
silverwind 68c5cb4a0c refactor(actions): migrate the runner API to connect-go v2
Pin https://gitea.com/gitea/actionslib/pulls/28, which generates
connect-go v2 code. v2 hides plain error messages from clients and caps
messages at 4 MiB. Keep v1's behaviour for runners: they show the messages,
and send all pending log rows in one UpdateLog.

Assisted-by: Claude Code:claude-opus-5-5
2026-10-19 03:49:15 +02:00

43 lines
1.0 KiB
Go

// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package ping
import (
"context"
"fmt"
"net/http"
pingv1 "gitea.dev/actionslib/ping/v1"
"gitea.dev/actionslib/ping/v1/pingv1connect"
"gitea.dev/modules/log"
"connectrpc.com/connect/v2"
"connectrpc.com/connect/v2/connecthttp"
)
func NewPingServiceHandler() (string, http.Handler) {
server := connect.NewServer()
pingv1connect.RegisterPingServiceHandler(server, &Service{})
mux := http.NewServeMux()
connecthttp.Mount(mux, server)
return "/" + pingv1connect.PingServiceName + "/", mux
}
var _ pingv1connect.PingServiceHandler = (*Service)(nil)
type Service struct{}
func (s *Service) Ping(
ctx context.Context,
req *pingv1.PingRequest,
) (*pingv1.PingResponse, error) {
info, _ := connect.CallInfoForServerContext(ctx)
log.Trace("Content-Type: %s", info.RequestHeader().Get("Content-Type"))
log.Trace("User-Agent: %s", info.RequestHeader().Get("User-Agent"))
res := &pingv1.PingResponse{
Data: fmt.Sprintf("Hello, %s!", req.Data),
}
return res, nil
}