Added different formatting for telegram bot
This commit is contained in:
parent
35f8fa5a57
commit
89623f5f6a
18 changed files with 233 additions and 173 deletions
|
|
@ -1,9 +1,12 @@
|
|||
package caching
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/flygrounder/go-mtg-vk/internal/cardsinfo"
|
||||
)
|
||||
|
||||
type CacheClient struct {
|
||||
|
|
@ -22,10 +25,17 @@ func NewClient(addr string, passwd string, expiration time.Duration, db int) *Ca
|
|||
}
|
||||
}
|
||||
|
||||
func (client *CacheClient) Set(key string, value string) {
|
||||
func (client *CacheClient) Set(key string, prices []cardsinfo.ScgCardPrice) {
|
||||
value, _ := json.Marshal(prices)
|
||||
client.Storage.Set(key, value, client.Expiration)
|
||||
}
|
||||
|
||||
func (client *CacheClient) Get(key string) (string, error) {
|
||||
return client.Storage.Get(key).Result()
|
||||
func (client *CacheClient) Get(key string) ([]cardsinfo.ScgCardPrice, error) {
|
||||
c, err := client.Storage.Get(key).Result()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "No such key in cache")
|
||||
}
|
||||
var prices []cardsinfo.ScgCardPrice
|
||||
json.Unmarshal([]byte(c), &prices)
|
||||
return prices, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue