th7/web/gin.go
2022-11-12 14:20:29 +00:00

37 lines
534 B
Go

package web
import (
"net/http"
"github.com/gin-gonic/gin"
"th7/ports"
)
type GinAdapter struct {
router *gin.Engine
corePort ports.CorePort
}
func (g GinAdapter) registerEndpoints() {
g.router.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, g.corePort.GetAll())
})
}
func NewGinAdapter(corePort ports.CorePort) *GinAdapter {
var adapter GinAdapter
adapter.corePort = corePort
adapter.router = gin.Default()
adapter.registerEndpoints()
return &adapter
}
func (g *GinAdapter) Run() {
g.router.Run()
}