-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuff.go
More file actions
57 lines (49 loc) · 1.59 KB
/
puff.go
File metadata and controls
57 lines (49 loc) · 1.59 KB
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
50
51
52
53
54
55
56
57
// Package puff provides primitives for implementing a Puff Server
package puff
import "log/slog"
type HandlerFunc func(*Context)
type Middleware func(next HandlerFunc) HandlerFunc
// AppConfig defines PuffApp parameters.
type AppConfig struct {
// Name is the application name
Name string
// Version is the application version.
Version string
// DocsURL is the Router prefix for Swagger documentation. Can be "" to disable Swagger documentation.
DocsURL string
// TLSPublicCertFile specifies the file for the TLS certificate (usually .pem or .crt).
TLSPublicCertFile string
// TLSPrivateKeyFile specifies the file for the TLS private key (usually .key).
TLSPrivateKeyFile string
// OpenAPI configuration. Gives users access to the OpenAPI spec generated. Can be manipulated by the user.
OpenAPI *OpenAPI
// SwaggerUIConfig is the UI specific configuration.
SwaggerUIConfig *SwaggerUIConfig
// LoggerConfig is the application logger config.
LoggerConfig *LoggerConfig
// DisableOpenAPIGeneration controls whether an OpenAPI schema will be generated.
DisableOpenAPIGeneration bool
}
func App(c *AppConfig) *PuffApp {
r := &Router{Name: "Default", Tag: "Default", Description: "Default Router"}
a := &PuffApp{
Config: c,
RootRouter: r,
}
if a.Config.LoggerConfig == nil {
a.Config.LoggerConfig = &LoggerConfig{}
}
l := NewLogger(a.Config.LoggerConfig)
slog.SetDefault(l)
a.RootRouter.puff = a
a.RootRouter.Responses = Responses{}
return a
}
func DefaultApp(name string) *PuffApp {
app := App(&AppConfig{
Version: "0.0.0",
Name: name,
DocsURL: "/docs",
})
return app
}