-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcategory.go
40 lines (33 loc) · 835 Bytes
/
category.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
"strconv"
)
type Category struct {
Id int `redis:"id" json:"id"`
Name string `redis:"name" json:"name"`
}
func getCategoriesMap(redisConn redis.Conn) map[int]Category {
categories := make(map[int]Category, 0)
values, e := getHashAsStringMap(config.KeyCategories, redisConn)
if e != nil {
fmt.Println(e)
}
for categoryId, categoryName := range values {
categoryId, _ := strconv.Atoi(categoryId)
category := Category{
Id: categoryId,
Name: categoryName,
}
categories[categoryId] = category
}
return categories
}
func getCategoryNameById(id int, redisConn redis.Conn) (string, error) {
categoryName, err := redis.String(redisConn.Do("HGET", config.KeyCategories, id))
if err != nil {
return "", err
}
return categoryName, nil
}