fix: add omitempty to types fields, change error message

This commit is contained in:
Medzik 2021-08-12 21:13:10 +00:00
parent 35298bacfc
commit 0ba1c8a2c0
5 changed files with 7 additions and 9 deletions

View File

@ -12,7 +12,7 @@ func cache(retry int) {
cacheURL = cacheURL[:0] cacheURL = cacheURL[:0]
results, err := mongo.GetAll() results, err := mongo.GetAll()
if checkErr(err, "get keys from db") { if checkErr(err, "get documents from db") {
if retry == 5 { if retry == 5 {
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)
cache(retry + 1) cache(retry + 1)

View File

@ -20,7 +20,7 @@ func Connect(retry ...int8) {
retry = append(retry, 0) retry = append(retry, 0)
} }
if retry[0] == 2 { if retry[0] == 5 {
os.Exit(1) os.Exit(1)
} }

View File

@ -13,8 +13,8 @@ func GetAll() ([]URL, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()
cursor, err := Coll.Find(ctx, json{ cursor, err := Coll.Find(ctx, URL{
"cluster": config.Toml.Cluster.ID, Cluster: config.Toml.Cluster.ID,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1,8 +1,6 @@
package mongo package mongo
type URL struct { type URL struct {
URL string `bson:"_id"` URL string `bson:"_id,omitempty" json:"url,omitempty"`
Cluster int `bson:"cluster"` Cluster int `bson:"cluster,omitempty" json:"cluster,omitempty"`
} }
type json map[string]interface{}

View File

@ -28,7 +28,7 @@ func Server() {
api.ApplyRoutes(router) api.ApplyRoutes(router)
err := router.Run(":" + strconv.Itoa(config.Toml.HTTP.Port)) err := router.Run(":" + strconv.Itoa(config.Toml.HTTP.Port))
if common.CheckErr(err, "gin start") { if common.CheckErr(err, "gin server run") {
os.Exit(1) os.Exit(1)
} }
} }