From ef01f99df7dafc61c11203e879e997c15dea98ca Mon Sep 17 00:00:00 2001 From: davy Date: Thu, 27 Jun 2019 15:09:17 -0500 Subject: added config.json --- pkg/app/config.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pkg/app/config.go (limited to 'pkg/app/config.go') diff --git a/pkg/app/config.go b/pkg/app/config.go new file mode 100644 index 0000000..c4ea170 --- /dev/null +++ b/pkg/app/config.go @@ -0,0 +1,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) +} -- cgit v1.2.3