diff --git a/go.mod b/go.mod index a2f39dca..3e2d1426 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/go-fuego/fuego -go 1.21.3 +go 1.22.0 require ( github.com/getkin/kin-openapi v0.122.0 diff --git a/go.work b/go.work index b0ba841b..f8199051 100644 --- a/go.work +++ b/go.work @@ -1,7 +1,7 @@ -go 1.21.5 +go 1.22.0 use ( . - ./examples/full-app-gourmet ./examples/basic + ./examples/full-app-gourmet ) diff --git a/mux.go b/mux.go index fcc82e30..f43116bc 100644 --- a/mux.go +++ b/mux.go @@ -43,11 +43,12 @@ type Route[ResponseBody any, RequestBody any] struct { operation *openapi3.Operation } -const MethodAll = "ALL" - // Capture all methods (GET, POST, PUT, PATCH, DELETE) and register a controller. func All[T any, B any, Contexted ctx[B]](s *Server, path string, controller func(Contexted) (T, error), middlewares ...func(http.Handler) http.Handler) Route[T, B] { - return Register[T](s, MethodAll, path, controller, middlewares...) + for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete} { + Register[T](s, method, path, controller, middlewares...) + } + return Register[T](s, http.MethodGet, path, controller, middlewares...) } func Get[T any, B any, Contexted ctx[B]](s *Server, path string, controller func(Contexted) (T, error), middlewares ...func(http.Handler) http.Handler) Route[T, B] { @@ -72,10 +73,8 @@ func Patch[T any, B any, Contexted ctx[B]](s *Server, path string, controller fu // Registers route into the default mux. func Register[T any, B any, Contexted ctx[B]](s *Server, method string, path string, controller func(Contexted) (T, error), middlewares ...func(http.Handler) http.Handler) Route[T, B] { - fullPath := s.basePath + path - if isGo1_22 { - fullPath = method + " " + path - } + fullPath := method + " " + s.basePath + path + slog.Debug("registering openapi controller " + fullPath) route := register[T, B](s, method, path, httpHandler[T, B](s, controller), middlewares...) @@ -88,10 +87,7 @@ func Register[T any, B any, Contexted ctx[B]](s *Server, method string, path str } func register[T any, B any](s *Server, method string, path string, controller http.Handler, middlewares ...func(http.Handler) http.Handler) Route[T, B] { - fullPath := s.basePath + path - if isGo1_22 && method != MethodAll { - fullPath = method + " " + fullPath - } + fullPath := method + " " + s.basePath + path allMiddlewares := append(middlewares, s.middlewares...) s.Mux.Handle(fullPath, withMiddlewares(controller, allMiddlewares...)) @@ -187,10 +183,8 @@ func PatchStd(s *Server, path string, controller func(http.ResponseWriter, *http // RegisterStd registers a standard http handler into the default mux. func RegisterStd(s *Server, method string, path string, controller func(http.ResponseWriter, *http.Request), middlewares ...func(http.Handler) http.Handler) Route[any, any] { - fullPath := s.basePath + path - if isGo1_22 { - fullPath = method + " " + path - } + fullPath := method + " " + s.basePath + path + slog.Debug("registering standard controller " + fullPath) route := register[any, any](s, method, path, http.HandlerFunc(controller), middlewares...) diff --git a/openapi.go b/openapi.go index 07d0504f..58e6e56f 100644 --- a/openapi.go +++ b/openapi.go @@ -192,9 +192,6 @@ func RegisterOpenAPIOperation[T any, B any](s *Server, method, path string) (*op operation.AddParameter(parameter) } - if method == MethodAll { - method = http.MethodGet - } s.OpenApiSpec.AddOperation(path, method, operation) return operation, nil diff --git a/options.go b/options.go index 1c28aefa..c3f65185 100644 --- a/options.go +++ b/options.go @@ -7,16 +7,12 @@ import ( "log/slog" "net/http" "os" - "runtime" - "strings" "time" "github.com/getkin/kin-openapi/openapi3" "github.com/golang-jwt/jwt/v5" ) -var isGo1_22 = strings.TrimPrefix(runtime.Version(), "devel ") >= "go1.22" - type OpenapiConfig struct { DisableSwagger bool DisableLocalSave bool @@ -100,13 +96,6 @@ func NewServer(options ...func(*Server)) *Server { option(s) } - if !isGo1_22 { - slog.Warn( - "Please upgrade to Go >= 1.22. " + - "You are running " + runtime.Version() + ": " + - "you cannot use path params nor register routes with the same path but different methods. ") - } - s.startTime = time.Now() if s.autoAuth.Enabled {