struct/

directory
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT

README

PTGU Struct

Import

import (
	PTGUstruct "github.com/parinyapt/golang_utils/struct/v1"
)

Example

Get Struct Tag Value v1
type DemoStruct struct {
	Abc string `json:"abc"`
	Def string `json:"def"`
	Num int `json:"num"`
}

func main() {
	value, err := PTGUstruct.GetStructTagValue(PTGUstruct.GetStructTagValueParam{
		SelectStruct: demostruct{},
		FieldName:    "Abc",
		TagName:      "json",
	})

	if err != nil {
		fmt.Println(err)
		return
	}
	
	fmt.Println(value)
}
Get Struct Tag Value v2
  • The first value that is not empty will be returned
type DemoStruct struct {
	Abc string `json:"abc" form:"abcd" uri:"abce" header:"abcf"`
	Def string `json:"def"`
	Num int `json:"num"`
}

func main() {
	value, err := PTGUstruct.GetStructTagValue(PTGUstruct.GetStructTagValueParam{
		SelectStruct: demostruct{},
		FieldName:    "Abc",
		TagName:      []string{"json", "form", "uri", "header"},
	})

	if err != nil {
		fmt.Println(err)
		return
	}
	
	fmt.Println(value)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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