forked from lazada/swgui
/
handler.go
50 lines (40 loc) · 1.32 KB
/
handler.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
50
// Package v4emb provides Swagger UI v4 with Go embed.
package v4emb
import (
"net/http"
"github.com/swaggest/swgui"
"github.com/swaggest/swgui/internal"
)
// Handler handles swagger UI request.
type Handler = internal.Handler
// NewWithConfig creates configurable handler constructor.
func NewWithConfig(config swgui.Config) func(title, swaggerJSONPath string, basePath string) http.Handler {
return func(title, swaggerJSONPath string, basePath string) http.Handler {
if config.Title == "" {
config.Title = title
}
if config.SwaggerJSON == "" {
config.SwaggerJSON = swaggerJSONPath
}
if config.BasePath == "" {
config.BasePath = basePath
}
return NewHandlerWithConfig(config)
}
}
// New creates HTTP handler for Swagger UI.
func New(title, swaggerJSONPath string, basePath string) http.Handler {
return NewHandler(title, swaggerJSONPath, basePath)
}
// NewHandler creates HTTP handler for Swagger UI.
func NewHandler(title, swaggerJSONPath string, basePath string) *Handler {
return NewHandlerWithConfig(swgui.Config{
Title: title,
SwaggerJSON: swaggerJSONPath,
BasePath: basePath,
})
}
// NewHandlerWithConfig creates HTTP handler for Swagger UI.
func NewHandlerWithConfig(config swgui.Config) *Handler {
return internal.NewHandlerWithConfig(config, assetsBase, faviconBase, staticServer)
}