refactor!: Use gin router instead chi router
- Removed chi dependencies - Updated router registration logic
This commit is contained in:
@@ -5,27 +5,32 @@ import (
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/log"
|
||||
"git.ostiwe.com/ostiwe-com/status/router/controller"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-andiamo/chioas"
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
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) 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) 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +39,7 @@ func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) {
|
||||
"/ping": chioas.Path{
|
||||
Methods: map[string]chioas.Method{
|
||||
http.MethodGet: {
|
||||
Handler: c.PingHandler,
|
||||
Handler: c.Handler(),
|
||||
Responses: chioas.Responses{
|
||||
http.StatusOK: {
|
||||
ContentType: "plain/text",
|
||||
|
||||
Reference in New Issue
Block a user