option

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Overview

antlabs, guonaihong 2023 apache 2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	IsProtobuf      bool
	UsePtr          map[string]bool
	Inline          bool
	Tag             string
	StructName      string
	TypeMap         map[string]string
	GetValue        map[string]string
	GetRawValue     map[string]any
	TagNameFromKey  bool
	OutputFmtBefore io.Writer //需要format之前的数据
}

type OptionFunc

type OptionFunc func(c *Option)

func WithGetRawValue added in v0.0.5

func WithGetRawValue(getValue map[string]any) OptionFunc

目前支持json/yaml/http header/query string

func WithGetValue added in v0.0.4

func WithGetValue(getValue map[string]string) OptionFunc

目前只支持json/yaml

func WithNotInline

func WithNotInline() OptionFunc

控制生成的结构体是否内联

func WithOutputFmtBefore added in v0.0.4

func WithOutputFmtBefore(w io.Writer) OptionFunc

WithOutputFmtBefore(nil) 日志数据打印到控制台 WithOutputFmtBefore(w) 日志数据打印到w里

func WithProtobuf added in v0.0.6

func WithProtobuf() OptionFunc

使用protobuf, 仅限protobuf包有效

func WithSpecifyType added in v0.0.2

func WithSpecifyType(typeMap map[string]string) OptionFunc

指定类型, datal默认转成struct, 这里直接指定生成map[string]string类型 {

	"data" : {
	  "user1": "111"
	}
}

WithSpecifyType(map[string]string{
   ".data": "map[string]string"
})

目前只支持json/yaml

func WithStructName

func WithStructName(name string) OptionFunc

设置最外层结构体的名字,WithStructName("Third")

type Third struct {
	B1 string `json:"b1"`
	B2 string `json:"b2"`
}

func WithTagName

func WithTagName(name string) OptionFunc

设置tag名, 修改third里面的json字段

type Third struct {
	B1 string `json:"b1"`
	B2 string `json:"b2"`
}

func WithTagNameFromKey added in v0.0.3

func WithTagNameFromKey() OptionFunc

tag使用变量名, http header特殊一点 目前仅仅支持http header marshal

func WithUsePtrType added in v0.0.9

func WithUsePtrType(fieldList []string) OptionFunc

传入的字段使用指针类型 入参[]string{".字段名1", ".字段名2"} json/yaml有效

Jump to

Keyboard shortcuts

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