ping API

ping

package

API reference for the ping package.

S
struct

pingResponse

examples/basic/core/modules/ping/endpoint.go:9-11
type pingResponse struct

Fields

Name Type Description
Message []string json:"message"
S
struct

PingEndpoint

PingEndpoint is the declarative endpoint for /api/v1/ping

examples/basic/core/modules/ping/endpoint.go:14-23
type PingEndpoint struct

Methods

OpenAPIMeta
Method

OpenAPIMeta returns metadata for OpenAPI/Swagger generation.

Returns

map[string]any
func (*PingEndpoint) OpenAPIMeta() map[string]any
{
	return map[string]any{
		"summary":     "Ping – returns one or more \"pong\" strings",
		"description": "Optional query-param `times` repeats the reply. Example: `/api/v1/ping?times=3`",
		"parameters": []map[string]any{
			{
				"name":     "times",
				"in":       "query",
				"required": false,
				"schema": map[string]any{
					"type":    "integer",
					"minimum": 1,
				},
			},
		},
		"responses": map[int]any{
			200: "PingResponse",
		},
	}
}
Handle
Method

Handle implements router.Handler

Parameters

Returns

any
error
func (*PingEndpoint) Handle(ctx context.Context) (any, error)
{
	if e.Times < 1 {
		e.Times = 1
	}

	out := make([]string, e.Times)
	for i := range out {
		out[i] = e.PingService.Pong()
	}

	return pingResponse{Message: out}, nil
}

Fields

Name Type Description
Meta core.Pattern method:"GET" path:"/api/v1/ping"
Times int query:"times" default:"1"
PingService PingService
I
interface

PingService

examples/basic/core/modules/ping/service.go:3-3
type PingService interface

Methods

Pong
Method

Returns

string
func Pong(...)
S
struct
Implements: PingService

pingService

examples/basic/core/modules/ping/service.go:5-5
type pingService struct

Methods

Pong
Method

Returns

string
func (pingService) Pong() string
{ return "pong" }
F
function

NewPingService

Returns

examples/basic/core/modules/ping/service.go:9-11
func NewPingService() PingService

{
	return pingService{}
}