This repository was archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
83 lines (63 loc) · 1.73 KB
/
config.go
File metadata and controls
83 lines (63 loc) · 1.73 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package caddy
import (
"encoding/json"
"fmt"
)
// Config defines the Caddy configuration structure.
type Config struct {
Admin *AdminConfig `json:"admin,omitempty"`
Logging *Logging `json:"logging,omitempty"`
Storage Module `json:"-"`
StorageRaw json.RawMessage `json:"storage,omitempty"`
Apps map[string]Module `json:"-"`
AppsRaw map[string]json.RawMessage `json:"apps,omitempty"`
}
// rawConfig is a type alias to allow unmarshalling only raw fields and modules.
type rawConfig Config
// UnmarshalJSON implements json.Unmarshaler.
func (c *Config) UnmarshalJSON(buf []byte) error {
// decode only raw modules
if err := json.Unmarshal(buf, (*rawConfig)(c)); err != nil {
return fmt.Errorf("unmarshal config: %w", err)
}
if len(c.StorageRaw) > 0 {
s, err := UnmarshalStorage(c.StorageRaw)
if err != nil {
return err
}
c.Storage = s
}
apps, err := UnmarshalApps(c.AppsRaw)
if err != nil {
return err
}
c.Apps = apps
return nil
}
// MarshalJSON implements json.Marshaler.
func (c Config) MarshalJSON() ([]byte, error) {
if c.Storage != nil {
s, err := json.Marshal(c.Storage)
if err != nil {
return nil, err
}
c.StorageRaw = s
}
rawApps, err := MarshalApps(c.Apps)
if err != nil {
return nil, err
}
c.AppsRaw = rawApps
return json.Marshal((rawConfig)(c))
}
// AdminConfig configures Caddy's API endpoint, which is used to manage Caddy while it is running.
type AdminConfig struct {
ID string `json:"@id,omitempty"`
Disabled bool `json:"disabled"`
Listen string `json:"listen,omitempty"`
}
// Logging configures logging within Caddy.
type Logging struct {
ID string `json:"@id,omitempty"`
//
}