Andreas Mieke
0a69d4a9f2
Implemented getters for: * Snapchat * Twitter * Instagram Also implemented config and database modules.
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type Config struct {
|
|
DatabaseConnection string
|
|
BindAddress string
|
|
AssetsDirectory string
|
|
TemplatesDirectory string
|
|
ContentDirectory string
|
|
ContentWebDirectory string
|
|
Snapchat Snapchat
|
|
Twitter Twitter
|
|
Instagram Instagram
|
|
}
|
|
|
|
type Instagram struct {
|
|
Tag string
|
|
}
|
|
|
|
type Twitter struct {
|
|
ConsumerKey string
|
|
ConsumerSecret string
|
|
OAuthToken string
|
|
OAuthTokenSecret string
|
|
Filter []string
|
|
}
|
|
|
|
type Snapchat struct {
|
|
ApiBase string
|
|
UserAgent string
|
|
UserName string
|
|
GetConversations SnapchatEndpoint
|
|
GetBlob SnapchatEndpoint
|
|
MarkAsSeen SnapchatEndpoint
|
|
}
|
|
|
|
type SnapchatEndpoint struct {
|
|
Uuid string
|
|
ClientAuthToken string
|
|
RequestToken string
|
|
Timestamp string
|
|
}
|
|
|
|
var C Config
|
|
|
|
func LoadConfig(path string) error {
|
|
_, e := toml.DecodeFile(path, &C)
|
|
return e
|
|
}
|
|
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
|
|
}
|