-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
44 lines (37 loc) · 816 Bytes
/
config.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
package fibervhost
import (
"github.com/gofiber/fiber/v2"
)
type Config struct {
Next func(c *fiber.Ctx) bool
Hostname string
Handler func(c *fiber.Ctx) error
HostnameRegexpString string
}
var ConfigDefault = Config{
Next: nil,
Hostname: "vhost.local",
Handler: func(c *fiber.Ctx) error {
return nil
},
HostnameRegexpString: "",
}
func configDefault(config ...Config) Config {
if len(config) < 1 {
return ConfigDefault
}
cfg := config[0]
if cfg.Next == nil {
cfg.Next = ConfigDefault.Next
}
if cfg.Hostname == "" {
cfg.Hostname = ConfigDefault.Hostname
}
if cfg.Handler == nil {
cfg.Handler = ConfigDefault.Handler
}
if cfg.HostnameRegexpString == "" {
cfg.HostnameRegexpString = ConfigDefault.HostnameRegexpString
}
return cfg
}