Skip to content

Commit ccd967b

Browse files
committed
Moved all non-net/http related code to the new Engine struct
1 parent 17ded45 commit ccd967b

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

engine.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fuego
2+
3+
func NewEngine() *Engine {
4+
return &Engine{
5+
OpenAPI: NewOpenAPI(),
6+
ErrorHandler: ErrorHandler,
7+
}
8+
}
9+
10+
// The Engine is the main struct of the framework.
11+
type Engine struct {
12+
OpenAPI *OpenAPI
13+
ErrorHandler func(error) error
14+
15+
acceptedContentTypes []string
16+
}

server.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,22 @@ type Server struct {
5656
disableAutoGroupTags bool
5757
basePath string // Base path of the group
5858

59-
// Points to the server OpenAPI struct.
60-
OpenAPI *OpenAPI
59+
*Engine
6160

6261
Security Security
6362

6463
autoAuth AutoAuthConfig
6564
fs fs.FS
6665
template *template.Template // TODO: use preparsed templates
6766

68-
acceptedContentTypes []string
69-
7067
DisallowUnknownFields bool // If true, the server will return an error if the request body contains unknown fields. Useful for quick debugging in development.
7168
DisableOpenapi bool // If true, the routes within the server will not generate an OpenAPI spec.
7269
maxBodySize int64
7370

74-
Serialize Sender // Custom serializer that overrides the default one.
75-
SerializeError ErrorSender // Used to serialize the error response. Defaults to [SendError].
76-
ErrorHandler func(err error) error // Used to transform any error into a unified error type structure with status code. Defaults to [ErrorHandler]
77-
startTime time.Time
71+
Serialize Sender // Custom serializer that overrides the default one.
72+
SerializeError ErrorSender // Used to serialize the error response. Defaults to [SendError].
73+
74+
startTime time.Time
7875

7976
OpenAPIConfig OpenAPIConfig
8077

@@ -99,8 +96,8 @@ func NewServer(options ...func(*Server)) *Server {
9996
WriteTimeout: 30 * time.Second,
10097
IdleTimeout: 30 * time.Second,
10198
},
102-
Mux: http.NewServeMux(),
103-
OpenAPI: NewOpenAPI(),
99+
Mux: http.NewServeMux(),
100+
Engine: NewEngine(),
104101

105102
OpenAPIConfig: defaultOpenAPIConfig,
106103

@@ -113,7 +110,6 @@ func NewServer(options ...func(*Server)) *Server {
113110
WithDisallowUnknownFields(true),
114111
WithSerializer(Send),
115112
WithErrorSerializer(SendError),
116-
WithErrorHandler(ErrorHandler),
117113
WithRouteOptions(
118114
OptionAddResponse(http.StatusBadRequest, "Bad Request _(validation or deserialization error)_", Response{Type: HTTPError{}}),
119115
OptionAddResponse(http.StatusInternalServerError, "Internal Server Error _(panics)_", Response{Type: HTTPError{}}),

0 commit comments

Comments
 (0)