-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgophig.go
37 lines (30 loc) · 836 Bytes
/
gophig.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
package gophig
import (
"io/fs"
)
// Gophig is a struct that contains the name, extension, and permission of a configuration file.
type Gophig[T any] struct {
ctx *RawContext
name string
marshaler Marshaler
perm fs.FileMode
}
// NewGophig returns a new Gophig struct.
func NewGophig[T any](name string, marshaler Marshaler, perm fs.FileMode) *Gophig[T] {
g := &Gophig[T]{
name: name,
marshaler: marshaler,
perm: perm,
ctx: newRawContext(name, marshaler, perm, nil),
}
return g
}
// SaveConf saves the given interface to the configuration file.
func (g *Gophig[T]) SaveConf(v T) error {
g.ctx.values["value"] = v
return SaveConfContext(g.ctx)
}
// LoadConf loads the configuration file into the given interface.
func (g *Gophig[T]) LoadConf() (T, error) {
return LoadConfContext[T](g.ctx)
}