blob: c4ea1708231cf0ffb6b55945d00c25261537d57f (
plain)
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
|
package app
import (
"encoding/json"
"os"
)
type Config struct {
LibraryPath string `json:"library"`
Server *ServerConfig `json:"server"`
}
type ServerConfig struct {
Host string `json:"host"`
Port int `json:"port"`
}
func DefaultConfig() *Config {
return &Config{
LibraryPath: "videos",
Server: &ServerConfig{
Host: "127.0.0.1",
Port: 0,
},
}
}
func (c *Config) ReadFile(path string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
d := json.NewDecoder(f)
return d.Decode(c)
}
|