utils

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StructTag

type StructTag struct {
	// Key name which is the first item of a struct tag
	Key string
	// Flags
	OmitEmpty bool
	Default   string
}

StructTag stores information about the struct tags which includes the name of the Key and optional flags like `omitempty` and `default`.

The following string can be parsed as StructTag:

s := "properties:test_key,omitempty,default=test_key_default_value"
st, err := ParseStructTag(s)

And information can be accessed:

st.Key       // returns "test_key"
st.OmitEmpty // return true
st.Default   // returns "test_key_default_value"

func ParseStructTag

func ParseStructTag(s string) (*StructTag, error)

ParseStructTag returns a pointer to a StructTag object holding the information resulted from parsing the s string as a struct tag.

func (StructTag) Skip

func (t StructTag) Skip() bool

Skip method returns true if the Key field of the StructTag is either an empty string or `-` meaning that the struct field should not be considered during marshal/unmarshal.

Calling Skip method for st1 or st2 StructTag object will result false:

s1 := "properties:,omitempty,default=test_key_default_value"
st1, err := ParseStructTag(s1)
st1.Skip()

Or

s2 := "properties:-,omitempty,default=test_key_default_value"
st2, err := ParseStructTag(s2)
st2.Skip()

Jump to

Keyboard shortcuts

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