-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconfig.go
More file actions
57 lines (49 loc) · 1.3 KB
/
config.go
File metadata and controls
57 lines (49 loc) · 1.3 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 astra
// Config is the configuration for the generator.
// It matches very closely to the OpenAPI specification.
type Config struct {
Title string `json:"title"`
Description string `json:"description"`
Version string `json:"version"`
Contact Contact `json:"contact"`
License License `json:"license"`
Secure bool `json:"secure"`
Host string `json:"host"`
BasePath string `json:"basePath"`
Port int `json:"port"`
}
type Contact struct {
Name string `json:"name"`
URL string `json:"url"`
Email string `json:"email"`
}
type License struct {
Name string `json:"name"`
URL string `json:"url"`
}
// Validate validates the configuration.
// It will also set default values for some fields.
func (c *Config) Validate() error {
// For now, only the port is required, the rest are set to default values.
if c.Host == "" {
c.Host = "localhost"
}
if c.Port == 0 {
return ErrConfigPortRequired
}
if c.BasePath == "" {
c.BasePath = "/"
}
return nil
}
// SetConfig sets the configuration for the generator.
func (s *Service) SetConfig(config *Config) *Service {
s.Config = config
return s
}
// WithConfig sets the configuration for the generator in option pattern.
func WithConfig(config *Config) Option {
return func(s *Service) {
s.SetConfig(config)
}
}