Files
status/router/controller/ping/controller.go
ostiwe 5a8b53b49d feat: Add documentation generation and serve functionality
- Implement documentation generation
- Replace chi router with gin for documentation server
- Fix issues with docs command execution
2025-11-04 19:20:10 +03:00

54 lines
1.1 KiB
Go

package ping
import (
"net/http"
"git.ostiwe.com/ostiwe-com/status/modules/log"
"git.ostiwe.com/ostiwe-com/status/router/controller"
"github.com/gin-gonic/gin"
"github.com/swaggest/openapi-go"
"github.com/swaggest/openapi-go/openapi3"
)
type Controller struct {
}
func (c *Controller) Method() string {
return http.MethodGet
}
func (c *Controller) Path() string {
return "/api/v1/ping"
}
func (*Controller) New() controller.Controller {
return &Controller{}
}
func (c *Controller) Handler() gin.HandlerFunc {
return func(ginCtx *gin.Context) {
_, err := ginCtx.Writer.Write([]byte("pong"))
if err != nil {
log.Global.Get(log.SERVER).Error(err)
return
}
}
}
func (c *Controller) Documentate(r *openapi3.Reflector) openapi.OperationContext {
op, err := r.NewOperationContext(c.Method(), c.Path())
if err != nil {
return nil
}
op.SetDescription("Route for check service is alive")
op.SetSummary("Server ping")
op.AddRespStructure("pong", func(cu *openapi.ContentUnit) {
cu.ContentType = "plain/text"
cu.HTTPStatus = http.StatusOK
})
return op
}