jsontogo

package module
v0.0.0-...-85da603 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Abbreviation = map[string]bool{
	"API":   true,
	"ASCII": true,
	"CPU":   true,
	"CSS":   true,
	"DNS":   true,
	"EOF":   true,
	"GUID":  true,
	"HTML":  true,
	"HTTP":  true,
	"HTTPS": true,
	"ID":    true,
	"IP":    true,
	"JSON":  true,
	"LHS":   true,
	"QPS":   true,
	"RAM":   true,
	"RHS":   true,
	"RPC":   true,
	"SLA":   true,
	"SMTP":  true,
	"SSH":   true,
	"TCP":   true,
	"TLS":   true,
	"TTL":   true,
	"UDP":   true,
	"UI":    true,
	"UID":   true,
	"UUID":  true,
	"URI":   true,
	"URL":   true,
	"UTF8":  true,
	"VM":    true,
	"XML":   true,
	"XSRF":  true,
	"XSS":   true,
}

Abbreviation 是需要保持全大写的缩写词的映射,值为真时生效

View Source
var DefaultConverter = &Converter{}
View Source
var ErrInvalidDelim = errors.New("jsontogo: invalid delim")
View Source
var ErrInvalidToken = errors.New("jsontogo: invalid token")

Functions

func CompareNumberType

func CompareNumberType(type1, type2 string) string

CompareNumberType 用于比较两个类型名,当任一类型不为浮点数或整数时返回 `any` ,否则返回范围更大的类型名

func ParseType

func ParseType(t json.Token) (string, string)

ParseType 用于解析词元类型,返回其类型名和值的字符串形式

func Regularize

func Regularize(name string) string

Regularize 将字符串规范化为合法字段名

func Replace

func Replace(s string, pattern *regexp.Regexp, fn func(match string, submatch []string) string) string

Replace 用正则表达式对字符串匹配和替换,用法与 JavaScript 中的替换函数类似

func ToPascalCase

func ToPascalCase(name string) string

ToPascalCase 将字段名称转换为驼峰命名,会保持缩写词全大写并且移除所有非字母数字的字符

func Unmarshal

func Unmarshal(data []byte, name string) ([]byte, error)

func UnmarshalAPI

func UnmarshalAPI(api req.API) error

Types

type Converter

type Converter struct {
	// 是否使用 interface{}
	UseInterface bool

	// 是否在字段后加注释
	AddComment bool
	// contains filtered or unexported fields
}

Converter 转换器,用于将 JSON 文本转换为能接收其值的结构体

func (*Converter) String

func (c *Converter) String() string

String 已解析内容

func (*Converter) Struct

func (c *Converter) Struct(name string) ([]byte, error)

Struct 输出格式化结构体

func (*Converter) Unmarshal

func (c *Converter) Unmarshal(data []byte, name string) ([]byte, error)

Unmarshal 将 JSON 转换成结构体字符串

参数 name 为最外层结构体名字(会进行正规化)

func (*Converter) UnmarshalAPI

func (c *Converter) UnmarshalAPI(api req.API) error

func (*Converter) UnmarshalJSON

func (c *Converter) UnmarshalJSON(data []byte) error

UnmarshalJSON 反序列化 JSON

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL