58 lines
1.1 KiB
Go
58 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/go-andiamo/chioas"
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
type Controller struct {
|
|
}
|
|
|
|
func (*Controller) New() controller.Controller {
|
|
return &Controller{}
|
|
}
|
|
|
|
func (c *Controller) Group(r chi.Router) {
|
|
|
|
r.Get("/ping", c.PingHandler)
|
|
}
|
|
|
|
func (c *Controller) PingHandler(w http.ResponseWriter, _ *http.Request) {
|
|
_, err := w.Write([]byte("pong"))
|
|
if err != nil {
|
|
log.Global.Get(log.SERVER).Error(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) {
|
|
return &chioas.Paths{
|
|
"/ping": chioas.Path{
|
|
Methods: map[string]chioas.Method{
|
|
http.MethodGet: {
|
|
Handler: c.PingHandler,
|
|
Responses: chioas.Responses{
|
|
http.StatusOK: {
|
|
ContentType: "plain/text",
|
|
Schema: chioas.Schema{Type: "string"},
|
|
Examples: chioas.Examples{
|
|
{
|
|
|
|
Name: "200 OK",
|
|
Value: "pong",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Tag: "service",
|
|
Comment: "Route for check service is alive",
|
|
},
|
|
}, nil
|
|
}
|