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]
results, err := mongo.GetAll()
if checkErr(err, "get keys from db") {
if checkErr(err, "get documents from db") {
if retry == 5 {
time.Sleep(500 * time.Millisecond)
cache(retry + 1)

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ func Server() {
api.ApplyRoutes(router)
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)
}
}