SocialDragon/config/config.go

87 lines
1.8 KiB
Go
Raw Permalink Normal View History

package config
import (
"bytes"
"io/ioutil"
"github.com/BurntSushi/toml"
)
2017-05-21 22:53:22 +00:00
// Config defines config fields
type Config struct {
DatabaseConnection string
BindAddress string
AssetsDirectory string
TemplatesDirectory string
ContentDirectory string
ContentWebDirectory string
Snapchat Snapchat
Twitter Twitter
Instagram Instagram
2020-01-15 22:10:20 +00:00
Tumblr Tumblr
Folder Folder
}
2017-05-21 22:53:22 +00:00
// Folder defines fields for Folder configuration
type Folder struct {
Folder string
}
2020-01-15 22:10:20 +00:00
// Tumblr defines fields for Tumblr configuration
type Tumblr struct {
Tag string
APIKey string
}
2017-05-21 22:53:22 +00:00
// Instagram defines fields for Instagram configuration
type Instagram struct {
Tag string
}
2017-05-21 22:53:22 +00:00
// Twitter defines fields for Twitter configuration
type Twitter struct {
ConsumerKey string
ConsumerSecret string
OAuthToken string
OAuthTokenSecret string
Filter []string
}
2017-05-21 22:53:22 +00:00
// Snapchat defines fields for Snapchat configuration
type Snapchat struct {
2017-05-21 22:53:22 +00:00
APIBase string
UserAgent string
UserName string
GetConversations SnapchatEndpoint
GetBlob SnapchatEndpoint
MarkAsSeen SnapchatEndpoint
}
2017-05-21 22:53:22 +00:00
// SnapchatEndpoint defines fields for Snapchat endpoint configuration
type SnapchatEndpoint struct {
2017-05-21 22:53:22 +00:00
UUID string
ClientAuthToken string
RequestToken string
Timestamp string
}
2017-05-21 22:53:22 +00:00
// C is the config handler
var C Config
2017-05-21 22:53:22 +00:00
// LoadConfig loads the configuration from given path
func LoadConfig(path string) error {
_, e := toml.DecodeFile(path, &C)
return e
}
2017-05-21 22:53:22 +00:00
// WriteConfig writes the configuration to the given path
func WriteConfig(path string) error {
buf := new(bytes.Buffer)
err := toml.NewEncoder(buf).Encode(C)
if err != nil {
return err
}
err = ioutil.WriteFile(path, buf.Bytes(), 0644)
return err
}