feat: publish v1.0.0-rc.36-custom.1
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
This commit is contained in:
commit
bb7968b612
2381 files changed
+551494
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package cachex
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ValueCodec[V any] interface {
|
||||
Encode(v V) (string, error)
|
||||
Decode(s string) (V, error)
|
||||
}
|
||||
|
||||
type IntCodec struct{}
|
||||
|
||||
func (c IntCodec) Encode(v int) (string, error) {
|
||||
return strconv.Itoa(v), nil
|
||||
}
|
||||
|
||||
func (c IntCodec) Decode(s string) (int, error) {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" {
|
||||
return 0, fmt.Errorf("empty int value")
|
||||
}
|
||||
return strconv.Atoi(s)
|
||||
}
|
||||
|
||||
type StringCodec struct{}
|
||||
|
||||
func (c StringCodec) Encode(v string) (string, error) { return v, nil }
|
||||
func (c StringCodec) Decode(s string) (string, error) { return s, nil }
|
||||
|
||||
type JSONCodec[V any] struct{}
|
||||
|
||||
func (c JSONCodec[V]) Encode(v V) (string, error) {
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
func (c JSONCodec[V]) Decode(s string) (V, error) {
|
||||
var v V
|
||||
if strings.TrimSpace(s) == "" {
|
||||
return v, fmt.Errorf("empty json value")
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil {
|
||||
return v, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
Reference in new issue
Block a user