init: first steps
This commit is contained in:
57
router/controller/ping/controller.go
Normal file
57
router/controller/ping/controller.go
Normal file
@@ -0,0 +1,57 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user