jy2struct

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 14 Imported by: 0

README

jy2struct

一个生成go struct代码库,支持json和yaml。


使用示例

主要设置参数:

type Args struct {
	Format    string // 文档格式,json或yaml
	Data      string // json或yaml内容
	InputFile string // 文件
	Name      string // 结构体名称
	SubStruct bool   // 子结构体是否分开
	Tags      string // 添加额外tag,多个tag用逗号分隔
}

转换示例:

    // json转struct
    code, err := jy2struct.Covert(&jy2struct.Args{
        Format: "json",
        // InputFile: "user.json", // 来源于json文件
        SubStruct: true,
    })

    // json转struct
    code, err := jy2struct.Covert(&jy2struct.Args{
        Format: "yaml",
        // InputFile: "user.yaml", // 来源于yaml文件
        SubStruct: true,
    })

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ForceFloats bool

ForceFloats whether to force a change to float

Functions

func Covert

func Covert(args *Args) (string, error)

Covert json或yaml转go struct

func FmtFieldName

func FmtFieldName(s string) string

FmtFieldName formats a string as a struct key

Example:

FmtFieldName("foo_id")

Output: FooID

func ParseJSON added in v1.4.0

func ParseJSON(input io.Reader) (interface{}, error)

ParseJSON parse json to struct

func ParseYaml

func ParseYaml(input io.Reader) (interface{}, error)

ParseYaml parse yaml to struct

Types

type Args

type Args struct {
	Format    string // 文档格式,json或yaml
	Data      string // json或yaml内容
	InputFile string // 文件
	Name      string // 结构体名称
	SubStruct bool   // 子结构体是否分开
	Tags      string // 字段tag,多个tag用逗号分隔
	// contains filtered or unexported fields
}

Args 参数

type Parser

type Parser func(io.Reader) (interface{}, error)

Parser parser function

Jump to

Keyboard shortcuts

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