Documentation
¶
Index ¶
- Variables
- func Bytes2str(b []byte) string
- func Decode(m interface{}, rawVal interface{}) error
- func DecodePath(m map[string]interface{}, rawVal interface{}) error
- func DecodeSegment(seg string) ([]byte, error)
- func DecodeSlicePath(ms []map[string]interface{}, rawSlice interface{}) error
- func EncodeSegment(seg []byte) string
- func FistIsLower(str string) bool
- func FistToLower(str string) string
- func FormatCode(code, separate string) string
- func GetMethodName(method interface{}) string
- func GetStructModAndName(s any) (mod, name string)
- func GetUrlParam(s, param string) string
- func HS256Sign(signing []byte, key interface{}) (string, error)
- func HS256Verify(signingString, signature string, key interface{}) error
- func Hide(str string, length int) string
- func HideCompare(hideStr, source string) bool
- func IntToCode(code int, length int32) string
- func LastName(path string) string
- func MapToAssciiSortJson(m map[string]interface{}) string
- func ParseInt(number string) int64
- func PrintJson(js interface{})
- func RemoveSpecialCharacters(str string) string
- func Sha1(data string) string
- func SplitAreaCode(code string) []string
- func SplitCode(code, separate string) []string
- func Str2bytes(s string) []byte
- func StrLimit(str, suffix string, length int32) string
- func ToCamelCase(s string) string
- func ToCamelFirstLowerCase(s string) string
- func ToI32(numStr string) int32
- func ToI64(numStr string) int64
- func ToInt(i interface{}) int
- func ToInt32[T ~int | ~int32 | ~int64](i T) int32
- func ToInt64[T ~int | ~int32 | ~int64](i T) int64
- func ToJsonString(js interface{}) string
- func ToSnakeCase(s string) string
- type DecodeHookFunc
- type Decoder
- type DecoderConfig
- type Error
- type Metadata
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidKey = errors.New("key is invalid") ErrInvalidKeyType = errors.New("key is of invalid type") ErrSignatureInvalid = errors.New("signature is invalid") )
Error constants
var DecodePaddingAllowed bool
Functions ¶
func Decode ¶
func Decode(m interface{}, rawVal interface{}) error
Decode takes a map and uses reflection to convert it into the given Go native structure. val must be a pointer to a struct.
func DecodePath ¶
DecodePath takes a map and uses reflection to convert it into the given Go native structure. Tags are used to specify the mapping between fields in the map and structure
func DecodeSegment ¶ added in v1.3.2
DecodeSegment decodes a JWT specific base64url encoding with padding stripped should only be used internally
func DecodeSlicePath ¶
DecodeSlicePath decodes a slice of maps against a slice of structures that contain specified tags
func EncodeSegment ¶ added in v1.3.2
EncodeSegment encodes a JWT specific base64url encoding with padding stripped should only be used internally
func FistIsLower ¶ added in v1.3.2
func FistToLower ¶
func FormatCode ¶
func GetMethodName ¶ added in v1.3.21
func GetMethodName(method interface{}) string
func GetStructModAndName ¶ added in v1.3.2
func GetUrlParam ¶ added in v1.3.22
func HS256Sign ¶ added in v1.3.2
HS256Sign implements token signing for the SigningMethod. Key must be []byte
func HS256Verify ¶ added in v1.3.2
HS256Verify implements token verification for the SigningMethod. Returns nil if the signature is valid.
func HideCompare ¶
func MapToAssciiSortJson ¶
func RemoveSpecialCharacters ¶
func SplitAreaCode ¶
func ToCamelCase ¶
*
- 蛇形转驼峰
- @description xx_yy to XxYx xx_y_y to XxYY
- @date 2020/7/30
- @param s要转换的字符串
- @return string *
func ToCamelFirstLowerCase ¶
*
- 蛇形转驼峰
- @description xx_yy to XxYx xx_y_y to XxYY
- @date 2020/7/30
- @param s要转换的字符串
- @return string *
func ToJsonString ¶
func ToJsonString(js interface{}) string
func ToSnakeCase ¶
*
- 驼峰转蛇形 snake string
- @description XxYy to xx_yy , XxYY to xx_y_y
- @param s 需要转换的字符串
- @return string *
Types ¶
type DecodeHookFunc ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder takes a raw interface value and turns it into structured data, keeping track of rich error information along the way in case anything goes wrong. Unlike the basic top-level Decode method, you can more finely control how the Decoder behaves using the DecoderConfig structure. The top-level Decode method is just a convenience that sets up the most basic Decoder.
func NewDecoder ¶
func NewDecoder(config *DecoderConfig) (*Decoder, error)
NewDecoder returns a new decoder for the given configuration. Once a decoder has been returned, the same configuration must not be used again.
func NewPathDecoder ¶
func NewPathDecoder(config *DecoderConfig) (*Decoder, error)
NewPathDecoder returns a new decoder for the given configuration. This is used to decode path specific structures
type DecoderConfig ¶
type DecoderConfig struct {
// DecodeHook, if set, will be called before any decoding and any
// type conversion (if WeaklyTypedInput is on). This lets you modify
// the values before they're set down onto the resulting struct.
//
// If an error is returned, the entire decode will fail with that
// error.
DecodeHook DecodeHookFunc
// If ErrorUnused is true, then it is an error for there to exist
// keys in the original map that were unused in the decoding process
// (extra keys).
ErrorUnused bool
// If WeaklyTypedInput is true, the decoder will make the following
// "weak" conversions:
//
// - bools to string (true = "1", false = "0")
// - numbers to string (base 10)
// - bools to int/uint (true = 1, false = 0)
// - strings to int/uint (base implied by prefix)
// - int to bool (true if value != 0)
// - string to bool (accepts: 1, t, T, TRUE, true, True, 0, f, F,
// FALSE, false, False. Anything else is an error)
// - empty array = empty map and vice versa
//
WeaklyTypedInput bool
// Metadata is the struct that will contain extra metadata about
// the decoding. If this is nil, then no metadata will be tracked.
Metadata *Metadata
// Result is a pointer to the struct that will contain the decoded
// value.
Result interface{}
// The tag name that mapstructure reads for field names. This
// defaults to "mapstructure"
TagName string
}
DecoderConfig is the configuration that is used to create a new decoder and allows customization of various aspects of decoding.
type Metadata ¶
type Metadata struct {
// Keys are the keys of the structure which were successfully decoded
Keys []string
// Unused is a slice of keys that were found in the raw value but
// weren't decoded since there was no matching field in the result interface
Unused []string
}
Metadata contains information about decoding a structure that is tedious or difficult to get otherwise.