diff --git a/engine.go b/engine.go new file mode 100644 index 00000000..acb89568 --- /dev/null +++ b/engine.go @@ -0,0 +1,16 @@ +package fuego + +func NewEngine() *Engine { + return &Engine{ + OpenAPI: NewOpenAPI(), + ErrorHandler: ErrorHandler, + } +} + +// The Engine is the main struct of the framework. +type Engine struct { + OpenAPI *OpenAPI + ErrorHandler func(error) error + + acceptedContentTypes []string +} diff --git a/server.go b/server.go index ad146ede..a573c4e2 100644 --- a/server.go +++ b/server.go @@ -56,8 +56,7 @@ type Server struct { disableAutoGroupTags bool basePath string // Base path of the group - // Points to the server OpenAPI struct. - OpenAPI *OpenAPI + *Engine Security Security @@ -65,16 +64,16 @@ type Server struct { fs fs.FS template *template.Template // TODO: use preparsed templates - acceptedContentTypes []string - DisallowUnknownFields bool // If true, the server will return an error if the request body contains unknown fields. Useful for quick debugging in development. DisableOpenapi bool // If true, the routes within the server will not generate an OpenAPI spec. maxBodySize int64 - Serialize Sender // Custom serializer that overrides the default one. - SerializeError ErrorSender // Used to serialize the error response. Defaults to [SendError]. - ErrorHandler func(err error) error // Used to transform any error into a unified error type structure with status code. Defaults to [ErrorHandler] - startTime time.Time + // Custom serializer that overrides the default one. + Serialize Sender + // Used to serialize the error response. Defaults to [SendError]. + SerializeError ErrorSender + + startTime time.Time OpenAPIConfig OpenAPIConfig @@ -99,8 +98,8 @@ func NewServer(options ...func(*Server)) *Server { WriteTimeout: 30 * time.Second, IdleTimeout: 30 * time.Second, }, - Mux: http.NewServeMux(), - OpenAPI: NewOpenAPI(), + Mux: http.NewServeMux(), + Engine: NewEngine(), OpenAPIConfig: defaultOpenAPIConfig, @@ -113,7 +112,6 @@ func NewServer(options ...func(*Server)) *Server { WithDisallowUnknownFields(true), WithSerializer(Send), WithErrorSerializer(SendError), - WithErrorHandler(ErrorHandler), WithRouteOptions( OptionAddResponse(http.StatusBadRequest, "Bad Request _(validation or deserialization error)_", Response{Type: HTTPError{}}), OptionAddResponse(http.StatusInternalServerError, "Internal Server Error _(panics)_", Response{Type: HTTPError{}}),