-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigBuilder.go
67 lines (54 loc) · 1.46 KB
/
configBuilder.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
package astra
// ConfigBuilder is a builder for the Config struct
// It has methods to set the fields of the Config struct
// It also has a Build method that returns the Config struct and an error, allowing for easy chaining and basic validation
type ConfigBuilder struct {
config *Config
}
func NewConfigBuilder() *ConfigBuilder {
return &ConfigBuilder{
config: &Config{},
}
}
func (c *ConfigBuilder) SetTitle(title string) *ConfigBuilder {
c.config.Title = title
return c
}
func (c *ConfigBuilder) SetDescription(description string) *ConfigBuilder {
c.config.Description = description
return c
}
func (c *ConfigBuilder) SetVersion(version string) *ConfigBuilder {
c.config.Version = version
return c
}
func (c *ConfigBuilder) SetContact(contact Contact) *ConfigBuilder {
c.config.Contact = contact
return c
}
func (c *ConfigBuilder) SetLicense(license License) *ConfigBuilder {
c.config.License = license
return c
}
func (c *ConfigBuilder) SetSecure(secure bool) *ConfigBuilder {
c.config.Secure = secure
return c
}
func (c *ConfigBuilder) SetHost(host string) *ConfigBuilder {
c.config.Host = host
return c
}
func (c *ConfigBuilder) SetBasePath(basePath string) *ConfigBuilder {
c.config.BasePath = basePath
return c
}
func (c *ConfigBuilder) SetPort(port int) *ConfigBuilder {
c.config.Port = port
return c
}
func (c *ConfigBuilder) Build() (*Config, error) {
if err := c.config.Validate(); err != nil {
return nil, err
}
return c.config, nil
}