Skip to content

Commit

Permalink
chore: add docs for WithEngineOptions and NewEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Dec 30, 2024
1 parent 70c7b3d commit 95aff1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
12 changes: 12 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (
"path/filepath"
)

// NewEngine creates a new Engine with the given options.
// For example:
//
// engine := fuego.NewEngin(
// WithOpenAPIConfig(
// OpenAPIConfig{
// PrettyFormatJSON: true,
// },
// ),
// )
//
// Options all begin with `With`.
func NewEngine(options ...func(*Engine)) *Engine {
e := &Engine{
OpenAPI: NewOpenAPI(),
Expand Down
16 changes: 15 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Server struct {
// fuego.WithoutLogger(),
// )
//
// Option all begin with `With`.
// Options all begin with `With`.
// Some default options are set in the function body.
func NewServer(options ...func(*Server)) *Server {
s := &Server{
Expand Down Expand Up @@ -397,6 +397,20 @@ func WithOpenAPIServerConfig(config OpenAPIServerConfig) func(*Server) {
}
}

// WithEngineOptions allows for setting of Engine options
//
// app := fuego.NewServer(
// fuego.WithAddr(":8080"),
// fuego.WithEngineOptions(
// WithOpenAPIConfig(
// OpenAPIConfig{
// PrettyFormatJSON: true,
// },
// ),
// ),
// )
//
// Options all begin with `With`.
func WithEngineOptions(options ...func(*Engine)) func(*Server) {
return func(s *Server) {
for _, option := range options {
Expand Down
13 changes: 7 additions & 6 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func TestWithOpenAPIConfig(t *testing.T) {
SpecURL: "/api/openapi.json",
}),
WithEngineOptions(
WithOpenAPIConfig(OpenAPIConfig{
JSONFilePath: "openapi.json",
DisableLocalSave: true,
PrettyFormatJSON: true,
Disabled: true,
}),
WithOpenAPIConfig(
OpenAPIConfig{
JSONFilePath: "openapi.json",
DisableLocalSave: true,
PrettyFormatJSON: true,
Disabled: true,
}),
),
)

Expand Down

0 comments on commit 95aff1d

Please sign in to comment.