mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-12 02:49:38 +08:00
refactor: replace key package with ctxkey for context keys
This commit is contained in:
5
pkg/enums/ctxkey/context_key.go
Normal file
5
pkg/enums/ctxkey/context_key.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package ctxkey
|
||||
|
||||
//go:generate go-enum --values --names --flag --nocase --noprefix
|
||||
// ENUM(content-length)
|
||||
type ContextKey string
|
||||
82
pkg/enums/ctxkey/context_key_enum.go
Normal file
82
pkg/enums/ctxkey/context_key_enum.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// Code generated by go-enum DO NOT EDIT.
|
||||
// Version: 0.6.1
|
||||
// Revision: a6f63bddde05aca4221df9c8e9e6d7d9674b1cb4
|
||||
// Build Date: 2025-03-18T23:42:14Z
|
||||
// Built By: goreleaser
|
||||
|
||||
package ctxkey
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// ContentLength is a ContextKey of type content-length.
|
||||
ContentLength ContextKey = "content-length"
|
||||
)
|
||||
|
||||
var ErrInvalidContextKey = fmt.Errorf("not a valid ContextKey, try [%s]", strings.Join(_ContextKeyNames, ", "))
|
||||
|
||||
var _ContextKeyNames = []string{
|
||||
string(ContentLength),
|
||||
}
|
||||
|
||||
// ContextKeyNames returns a list of possible string values of ContextKey.
|
||||
func ContextKeyNames() []string {
|
||||
tmp := make([]string, len(_ContextKeyNames))
|
||||
copy(tmp, _ContextKeyNames)
|
||||
return tmp
|
||||
}
|
||||
|
||||
// ContextKeyValues returns a list of the values for ContextKey
|
||||
func ContextKeyValues() []ContextKey {
|
||||
return []ContextKey{
|
||||
ContentLength,
|
||||
}
|
||||
}
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (x ContextKey) String() string {
|
||||
return string(x)
|
||||
}
|
||||
|
||||
// IsValid provides a quick way to determine if the typed value is
|
||||
// part of the allowed enumerated values
|
||||
func (x ContextKey) IsValid() bool {
|
||||
_, err := ParseContextKey(string(x))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
var _ContextKeyValue = map[string]ContextKey{
|
||||
"content-length": ContentLength,
|
||||
}
|
||||
|
||||
// ParseContextKey attempts to convert a string to a ContextKey.
|
||||
func ParseContextKey(name string) (ContextKey, error) {
|
||||
if x, ok := _ContextKeyValue[name]; ok {
|
||||
return x, nil
|
||||
}
|
||||
// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
|
||||
if x, ok := _ContextKeyValue[strings.ToLower(name)]; ok {
|
||||
return x, nil
|
||||
}
|
||||
return ContextKey(""), fmt.Errorf("%s is %w", name, ErrInvalidContextKey)
|
||||
}
|
||||
|
||||
// Set implements the Golang flag.Value interface func.
|
||||
func (x *ContextKey) Set(val string) error {
|
||||
v, err := ParseContextKey(val)
|
||||
*x = v
|
||||
return err
|
||||
}
|
||||
|
||||
// Get implements the Golang flag.Getter interface func.
|
||||
func (x *ContextKey) Get() interface{} {
|
||||
return *x
|
||||
}
|
||||
|
||||
// Type implements the github.com/spf13/pFlag Value interface.
|
||||
func (x *ContextKey) Type() string {
|
||||
return "ContextKey"
|
||||
}
|
||||
Reference in New Issue
Block a user