-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
71 lines (56 loc) · 1.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package server
import (
"github.com/gookit/slog"
)
type Options func(s *ServerParams) error
type ServerParams struct {
Port string
Host string
Slog *slog.SugaredLogger
}
func newServerParams(opts ...Options) (*ServerParams, error) {
s := &ServerParams{}
for _, opt := range opts {
if err := opt(s); err != nil {
return nil, err
}
}
return s, nil
}
func WithPort(port string) Options {
return func(s *ServerParams) error {
s.Port = port
return nil
}
}
func WithHost(host string) Options {
return func(s *ServerParams) error {
s.Host = host
return nil
}
}
func WithSlog(slog *slog.SugaredLogger) Options {
return func(s *ServerParams) error {
s.Slog = slog
return nil
}
}
// getters and setters ------
func (s *ServerParams) GetPort() string {
return s.Port
}
func (s *ServerParams) GetHost() string {
return s.Host
}
func (s *ServerParams) SetPort(port string) {
s.Port = port
}
func (s *ServerParams) SetHost(host string) {
s.Host = host
}
func (s *ServerParams) GetSlog() *slog.SugaredLogger {
return s.Slog
}
func (s *ServerParams) SetSlog(slog *slog.SugaredLogger) {
s.Slog = slog
}