Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 13db989

Browse files
committed
update config
1 parent 1b096e1 commit 13db989

7 files changed

Lines changed: 523 additions & 12 deletions

File tree

cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package main

conf.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ package main
22

33
import (
44
"fmt"
5+
"github.com/sirupsen/logrus"
6+
"github.com/spf13/viper"
57
"math/rand"
68
"os"
79
"strings"
810
"time"
911
)
1012

13+
type Config struct {
14+
Server struct {
15+
Port int
16+
}
17+
Redis struct {
18+
Host string
19+
Port int
20+
DB int
21+
}
22+
}
23+
24+
var conf Config
25+
1126
var tokenList []string
1227

1328
func GetToken() string {
@@ -34,3 +49,23 @@ func ValidateToken() {
3449
}
3550
logger.Debug(fmt.Sprintf("Found %d available token(s).", len(tokenList)))
3651
}
52+
53+
func ReadToken() {
54+
tokenList = GetTokenFromEnv()
55+
ValidateToken()
56+
}
57+
58+
func ReadConfig() {
59+
_, err := os.Stat("config.yaml")
60+
if err != nil && os.IsNotExist(err) {
61+
logger.Fatal("Config file (config.yaml) not found!")
62+
}
63+
64+
viper.SetConfigFile("config.yaml")
65+
if err := viper.ReadInConfig(); err != nil {
66+
logrus.Fatalf("Failed to read config file: %v", err)
67+
}
68+
if err := viper.Unmarshal(&conf); err != nil {
69+
logrus.Fatalf("Failed to unmarshal config file: %v", err)
70+
}
71+
}

config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
server:
2+
port: 8080
3+
4+
redis:
5+
host: localhost
6+
port: 6379
7+
db: 0

go.mod

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ require (
1010
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect
1111
github.com/andybalholm/brotli v1.0.5 // indirect
1212
github.com/aymerick/douceur v0.2.0 // indirect
13+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
14+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
1315
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect
1416
github.com/fatih/structs v1.1.0 // indirect
1517
github.com/flosch/pongo2/v4 v4.0.2 // indirect
18+
github.com/fsnotify/fsnotify v1.6.0 // indirect
19+
github.com/go-redis/redis/v8 v8.11.5 // indirect
1620
github.com/golang/snappy v0.0.4 // indirect
1721
github.com/google/uuid v1.3.0 // indirect
1822
github.com/gorilla/css v1.0.0 // indirect
23+
github.com/hashicorp/hcl v1.0.0 // indirect
1924
github.com/iris-contrib/schema v0.0.6 // indirect
2025
github.com/josharian/intern v1.0.0 // indirect
2126
github.com/kataras/blocks v0.0.7 // indirect
@@ -25,24 +30,33 @@ require (
2530
github.com/kataras/sitemap v0.0.6 // indirect
2631
github.com/kataras/tunnel v0.0.4 // indirect
2732
github.com/klauspost/compress v1.16.0 // indirect
33+
github.com/magiconair/properties v1.8.7 // indirect
2834
github.com/mailgun/raymond/v2 v2.0.48 // indirect
2935
github.com/mailru/easyjson v0.7.7 // indirect
3036
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
37+
github.com/mitchellh/mapstructure v1.5.0 // indirect
38+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
3139
github.com/russross/blackfriday/v2 v2.1.0 // indirect
3240
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
3341
github.com/sirupsen/logrus v1.9.2 // indirect
42+
github.com/spf13/afero v1.9.5 // indirect
43+
github.com/spf13/cast v1.5.1 // indirect
44+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
45+
github.com/spf13/pflag v1.0.5 // indirect
46+
github.com/spf13/viper v1.16.0 // indirect
47+
github.com/subosito/gotenv v1.4.2 // indirect
3448
github.com/tdewolff/minify/v2 v2.12.4 // indirect
3549
github.com/tdewolff/parse/v2 v2.6.4 // indirect
3650
github.com/valyala/bytebufferpool v1.0.0 // indirect
3751
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
3852
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
3953
github.com/yosssi/ace v0.0.5 // indirect
40-
golang.org/x/crypto v0.7.0 // indirect
41-
golang.org/x/net v0.8.0 // indirect
42-
golang.org/x/sys v0.6.0 // indirect
43-
golang.org/x/text v0.8.0 // indirect
54+
golang.org/x/crypto v0.9.0 // indirect
55+
golang.org/x/net v0.10.0 // indirect
56+
golang.org/x/sys v0.8.0 // indirect
57+
golang.org/x/text v0.9.0 // indirect
4458
golang.org/x/time v0.3.0 // indirect
45-
google.golang.org/protobuf v1.29.0 // indirect
59+
google.golang.org/protobuf v1.30.0 // indirect
4660
gopkg.in/ini.v1 v1.67.0 // indirect
4761
gopkg.in/yaml.v3 v3.0.1 // indirect
4862
)

0 commit comments

Comments
 (0)