mirror of
https://github.com/darmiel/yaxc.git
synced 2024-09-20 06:46:13 +08:00
parent
14ea7d3a4a
commit
0c764a737e
|
@ -12,7 +12,7 @@ func printDebugSet(key string, value interface{}) {
|
|||
if !debugEnabled {
|
||||
return
|
||||
}
|
||||
if b, o := value.([]byte); o {
|
||||
if b, o := value.(string); o {
|
||||
fmt.Println(common.StyleCache(),
|
||||
termenv.String("<-").Foreground(common.Profile().Color("#DBAB79")),
|
||||
"Set",
|
||||
|
@ -25,7 +25,7 @@ func printDebugGet(key string, value interface{}) {
|
|||
if !debugEnabled {
|
||||
return
|
||||
}
|
||||
if b, o := value.([]byte); o {
|
||||
if b, o := value.(string); o {
|
||||
fmt.Println(common.StyleCache(),
|
||||
termenv.String("->").Foreground(common.Profile().Color("#66C2CD")),
|
||||
"Get",
|
||||
|
|
|
@ -19,19 +19,19 @@ func (b *CacheBackend) GetHash(key string) (res string, err error) {
|
|||
}
|
||||
|
||||
func (b *CacheBackend) Set(key, value string, ttl time.Duration) error {
|
||||
b.cache.Set("val::"+key, []byte(value), ttl)
|
||||
b.cache.Set("val::"+key, value, ttl)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *CacheBackend) SetHash(key, value string, ttl time.Duration) error {
|
||||
b.cache.Set("hash::"+key, []byte(value), ttl)
|
||||
b.cache.Set("hash::"+key, value, ttl)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *CacheBackend) getString(key string) (res string, err error) {
|
||||
if v, ok := b.cache.Get(key); ok {
|
||||
if r, o := v.([]byte); o {
|
||||
res = string(r)
|
||||
if r, o := v.(string); o {
|
||||
res = r
|
||||
} else {
|
||||
err = b.errCast
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/darmiel/yaxc/internal/common"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
"github.com/muesli/termenv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -13,13 +14,13 @@ import (
|
|||
var errEncryptionNotEnabled = errors.New("encryption not enabled")
|
||||
|
||||
func (s *yAxCServer) handlePostAnywhere(ctx *fiber.Ctx) (err error) {
|
||||
path := strings.TrimSpace(ctx.Params("anywhere"))
|
||||
path := utils.CopyString(strings.TrimSpace(ctx.Params("anywhere")))
|
||||
return s.setAnywhereWithHash(ctx, path, "")
|
||||
}
|
||||
|
||||
func (s *yAxCServer) handlePostAnywhereWithHash(ctx *fiber.Ctx) (err error) {
|
||||
path := strings.TrimSpace(ctx.Params("anywhere"))
|
||||
hash := strings.TrimSpace(ctx.Params("hash"))
|
||||
path := utils.CopyString(strings.TrimSpace(ctx.Params("anywhere")))
|
||||
hash := utils.CopyString(strings.TrimSpace(ctx.Params("hash")))
|
||||
// validate hash
|
||||
if !common.ValidateHex(hash) {
|
||||
return ctx.Status(400).SendString("ERROR: Invalid hash")
|
||||
|
|
Loading…
Reference in a new issue