fedilogue/fedilogger/config.go

72 lines
1.8 KiB
Go
Raw Normal View History

2020-12-05 23:59:32 -05:00
package main
import (
"encoding/json"
2020-12-17 04:23:25 +00:00
"io/ioutil"
2022-01-01 02:26:39 +00:00
2020-12-17 04:23:25 +00:00
"muzzammil.xyz/jsonc"
2020-12-05 23:59:32 -05:00
)
2020-12-17 04:23:25 +00:00
// MassFollower - Mass follower configuration used by config.go
2020-12-05 23:59:32 -05:00
type MassFollower struct {
2020-12-17 04:23:25 +00:00
Acct string `"json:acct"`
Name string `"json:name"`
Summary string `"json:summary"`
FollowingCount int `"json:followingcount"`
FollowLimit int `"json:followlimit"`
2020-12-05 23:59:32 -05:00
}
2020-12-17 04:23:25 +00:00
// ExtAccount - External account configuration used by config.go
2020-12-05 23:59:32 -05:00
type ExtAccount struct {
2020-12-17 04:23:25 +00:00
Username string `"json:username"`
Password string `"json:password"`
Endpoint string `"json:endpoint"`
Followlimit int `"json:followlimit"`
2020-12-05 23:59:32 -05:00
}
2020-12-17 04:23:25 +00:00
// Proxy - Configuration file proxy settings
2020-12-05 23:59:32 -05:00
type Proxy struct {
2020-12-17 04:23:25 +00:00
Host string `"json:host"`
Port int `"json:port"`
Username string `"json:username'`
Password string `"json:password"`
2020-12-05 23:59:32 -05:00
}
2020-12-17 04:23:25 +00:00
// Settings - Configuration file structure
2020-12-05 23:59:32 -05:00
type Settings struct {
2020-12-17 04:23:25 +00:00
Crawl bool `"json:crawl"`
Proxies []Proxy `"json:proxies"`
Externalaccounts []ExtAccount `"json:externalaccounts"`
MassFollowers []MassFollower `"json:massfollowers"`
2022-01-01 02:26:39 +00:00
LogLevel int `"json:loglevel"`
Hostname string `"json:hostname"`
2020-12-05 23:59:32 -05:00
}
var settings Settings
2021-09-29 06:43:06 +00:00
/* Test: TestStringexists */
2020-12-17 04:23:25 +00:00
func stringexists(needle string, haystack []string) bool {
2020-12-05 23:59:32 -05:00
for _, check := range haystack {
if check == needle {
return true
}
}
return false
}
func getSettings() {
c, err := ioutil.ReadFile("config.jsonc")
2020-12-17 04:23:25 +00:00
if err != nil {
logFatal("Unable to open config.jsonc, exiting: ", err)
2020-12-05 23:59:32 -05:00
}
jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON
if jsonc.Valid(jsoncbin) == false {
logFatal("Invalid jsonc, exiting.")
2020-12-05 23:59:32 -05:00
}
err = json.Unmarshal(jsoncbin, &settings)
if err != nil {
logFatal("Unable to parse config.jsonc, exiting: ", err)
2020-12-05 23:59:32 -05:00
}
}