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