This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
49 lines (38 loc) · 1.64 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package server
import (
"net/http"
"github.com/x-ethr/server/logging"
)
type Globals struct {
// Disable determines whether to include [Globals.Middleware] with the caller's handler's own middleware(s). Defaults to false.
//
// - Note that the following field may be subject to breaking change(s) as additional [Globals] attributes may be added.
Disable bool
Logging *logging.Options
// Middleware to wrap all [http.Handler] implementation(s) with.
Middleware []func(http.Handler) http.Handler
}
// Options is the configuration structure optionally mutated via the [Variadic] constructor used throughout the package.
type Options struct {
Globals Globals
// Metadata will enable [Multiplexer] metadata to get added as a context key during route registration. Defaults to true.
Metadata bool
// Middleware to wrap the route's [http.Handler] implementation(s) with. For configuring middleware that should be added to all
// of a [Mux] [http.Handler] implementation(s), see [Options.Globals], [Globals].
Middleware []func(http.Handler) http.Handler
}
// Variadic represents a functional constructor for the [Options] type. Typical callers of Variadic won't need to perform
// nil checks as all implementations first construct an [Options] reference using packaged default(s).
type Variadic func(o *Options)
// options represents a default constructor.
func options() *Options {
return &Options{ // default Options constructor
Globals: Globals{
Disable: false,
Logging: logging.Specification(),
Middleware: make([]func(http.Handler) http.Handler, 0),
},
Metadata: true,
Middleware: make([]func(http.Handler) http.Handler, 0),
}
}