fedilogue/restapi/config.go

82 lines
2.2 KiB
Go
Raw Permalink Normal View History

2021-02-13 02:49:36 +00:00
package main
import (
"encoding/json"
"io/ioutil"
"muzzammil.xyz/jsonc"
)
// Database - Database configuration used by config.go
type Database struct {
Host string `"json:host"`
Port int `"json:port"`
Username string `"json:username"`
Password string `"json:password"`
Workers int `"json:workers"`
}
// MassFollower - Mass follower configuration used by config.go
type MassFollower struct {
Acct string `"json:acct"`
Name string `"json:name"`
Summary string `"json:summary"`
FollowingCount int `"json:followingcount"`
FollowLimit int `"json:followlimit"`
}
// ExtAccount - External account configuration used by config.go
type ExtAccount struct {
Username string `"json:username"`
Password string `"json:password"`
Endpoint string `"json:endpoint"`
Followlimit int `"json:followlimit"`
}
// Proxy - Configuration file proxy settings
type Proxy struct {
Host string `"json:host"`
Port int `"json:port"`
Username string `"json:username'`
Password string `"json:password"`
}
// Settings - Configuration file structure
type Settings struct {
Autostart []string `"json:autostart"`
Crawl bool `"json:crawl"`
Banned []string `"json:banned"`
Alwaysbot []string `"json:alwaysbot"`
Proxies []Proxy `"json:proxies"`
Externalaccounts []ExtAccount `"json:externalaccounts"`
MassFollowers []MassFollower `"json:massfollowers"`
Database Database `"json:database"`
LogLevel int `"json:loglevel"`
}
var settings Settings
func stringexists(needle string, haystack []string) bool {
for _, check := range haystack {
if check == needle {
return true
}
}
return false
}
func getSettings() {
c, err := ioutil.ReadFile("config.jsonc")
if err != nil {
logFatal.Fatal("Unable to open config.jsonc, exiting: ", err)
}
jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON
if jsonc.Valid(jsoncbin) == false {
logFatal.Fatal("Invalid jsonc, exiting.")
}
err = json.Unmarshal(jsoncbin, &settings)
if err != nil {
logFatal.Fatal("Unable to parse config.jsonc, exiting: ", err)
}
}