tube/pkg/app/config.go

58 lines
1.2 KiB
Go
Raw Normal View History

2019-06-27 23:09:17 +03:00
package app
import (
"encoding/json"
"os"
)
2019-06-30 01:02:05 +03:00
// Config settings for main App.
2019-06-27 23:09:17 +03:00
type Config struct {
LibraryPath string `json:"library"`
Server *ServerConfig `json:"server"`
2019-06-29 06:50:59 +03:00
Feed *FeedConfig `json:"feed"`
2019-06-27 23:09:17 +03:00
}
2019-06-30 01:02:05 +03:00
// ServerConfig settings for App Server.
2019-06-27 23:09:17 +03:00
type ServerConfig struct {
Host string `json:"host"`
Port int `json:"port"`
}
2019-06-30 01:02:05 +03:00
// FeedConfig settings for App Feed.
2019-06-29 06:50:59 +03:00
type FeedConfig struct {
ExternalURL string `json:"external_url"`
Title string `json:"title"`
Link string `json:"link"`
Description string `json:"description"`
Author struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"author"`
Copyright string `json:"copyright"`
}
2019-06-30 01:02:05 +03:00
// DefaultConfig returns Config initialized with default values.
2019-06-27 23:09:17 +03:00
func DefaultConfig() *Config {
return &Config{
LibraryPath: "videos",
Server: &ServerConfig{
Host: "127.0.0.1",
Port: 0,
},
2019-06-29 06:50:59 +03:00
Feed: &FeedConfig{
ExternalURL: "http://localhost",
},
2019-06-27 23:09:17 +03:00
}
}
2019-06-30 01:02:05 +03:00
// ReadFile reads a JSON file into Config.
2019-06-27 23:09:17 +03:00
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)
}