63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/mattn/go-mastodon"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type KikiSettings struct {
|
|
Instance string `yaml:"instance,omitempty"`
|
|
RSSUri string `yaml:"rss_url,omitempty"`
|
|
Redis struct {
|
|
Address string `yaml:"address"`
|
|
} `yaml:"redis"`
|
|
}
|
|
|
|
type MastodonClientData struct {
|
|
ClientID string `yaml:"clientID,omitempty"`
|
|
ClientSecret string `yaml:"clientSecret,omitempty"`
|
|
AccessToken string `yaml:"accessToken,omitempty"`
|
|
Instance string `yaml:"instance,omitempty"`
|
|
}
|
|
|
|
func GetKikiConfig(path string) KikiSettings {
|
|
var kikiSettings KikiSettings
|
|
|
|
kikiConfigFile, err := os.ReadFile(path)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
err = yaml.Unmarshal(kikiConfigFile, &kikiSettings)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
return kikiSettings
|
|
}
|
|
|
|
func GetSecrets(path string) *mastodon.Config {
|
|
var clientData MastodonClientData
|
|
|
|
secretConfig, err := os.ReadFile(path)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
err = yaml.Unmarshal(secretConfig, &clientData)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
config := &mastodon.Config{
|
|
Server: clientData.Instance,
|
|
ClientID: clientData.ClientID,
|
|
ClientSecret: clientData.ClientSecret,
|
|
AccessToken: clientData.AccessToken,
|
|
}
|
|
|
|
return config
|
|
}
|