1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package configs
- import (
- "errors"
- "os"
- "time"
- )
- var Token, BaseURL, Port, UserAgent, ProxyServer, StartingTime, Version, AcceptLanguage string
- func parseEnv(key string) (string, error) {
- value, ok := os.LookupEnv(key)
- if !ok {
- return value, errors.New("Failed to get environment variable" + key)
- }
- return value, nil
- }
- func parseEnvWithDefault(key string, defaultValue string) string {
- value, ok := os.LookupEnv(key)
- if !ok {
- return defaultValue
- }
- return value
- }
- func ParseConfig() error {
- var err error
- Token, err = parseEnv("PIXIVFE_TOKEN")
- if err != nil {
- return err
- }
- BaseURL = parseEnvWithDefault("PIXIVFE_BASEURL", "localhost")
- Port = parseEnvWithDefault("PIXIVFE_PORT", "8282")
- UserAgent = parseEnvWithDefault("PIXIVFE_USERAGENT", "Mozilla/5.0")
- ProxyServer = parseEnvWithDefault("PIXIVFE_IMAGEPROXY", "pximg.cocomi.cf")
- AcceptLanguage = parseEnvWithDefault("PIXIVFE_ACCEPTLANGUAGE", "en-US,en;q=0.5")
- StartingTime = time.Now().UTC().Format("2006-01-02 15:04")
- Version = "v1.0.5"
- return nil
- }
|