Skip to content

Commit

Permalink
Remove NewBaseRoute function and use fuego.NewBaseRoute instead
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Dec 17, 2024
1 parent 0ef706b commit daa6f65
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions extra/fuegogin/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fuegogin
import (
"log/slog"

"github.com/getkin/kin-openapi/openapi3"
"github.com/gin-gonic/gin"

"github.com/go-fuego/fuego"
Expand All @@ -26,12 +25,12 @@ func Post[T, B any](s *fuego.OpenAPI, e gin.IRouter, path string, handler func(c
}

func handleFuego[T, B any](openapi *fuego.OpenAPI, e gin.IRouter, method, path string, fuegoHandler func(c ContextWithBody[B]) (T, error), options ...func(*fuego.BaseRoute)) *fuego.Route[T, B] {
baseRoute := NewBaseRoute(method, path, fuegoHandler, openapi, options...)
baseRoute := fuego.NewBaseRoute(method, path, fuegoHandler, openapi, options...)
return handle(openapi, e, &fuego.Route[T, B]{BaseRoute: baseRoute}, GinHandler(fuegoHandler))
}

func handleGin(openapi *fuego.OpenAPI, e gin.IRouter, method, path string, ginHandler gin.HandlerFunc, options ...func(*fuego.BaseRoute)) *fuego.Route[any, any] {
baseRoute := NewBaseRoute(method, path, ginHandler, openapi, options...)
baseRoute := fuego.NewBaseRoute(method, path, ginHandler, openapi, options...)
return handle(openapi, e, &fuego.Route[any, any]{BaseRoute: baseRoute}, ginHandler)
}

Expand All @@ -50,23 +49,6 @@ func handle[T, B any](openapi *fuego.OpenAPI, e gin.IRouter, route *fuego.Route[
return route
}

func NewBaseRoute(method, path string, handler any, openapi *fuego.OpenAPI, options ...func(*fuego.BaseRoute)) fuego.BaseRoute {
baseRoute := fuego.BaseRoute{
Method: method,
Path: path,
Params: make(map[string]fuego.OpenAPIParam),
FullName: fuego.FuncName(handler),
Operation: openapi3.NewOperation(),
OpenAPI: openapi,
}

for _, o := range options {
o(&baseRoute)
}

return baseRoute
}

// Convert a Fuego handler to a Gin handler.
func GinHandler[B, T any](handler func(c ContextWithBody[B]) (T, error)) gin.HandlerFunc {
return func(c *gin.Context) {
Expand Down

0 comments on commit daa6f65

Please sign in to comment.