go struct 自定义标签获取

package main

import (
"fmt"
"reflect"
)

type Test struct {
Id int `json:"user_id"`
Name string "this is name"
}

func main() {
t := Test{Id: 1, Name: "xiaochuan"}
r := reflect.TypeOf(t)

fmt.Println()
fmt.Printf("Id Tag is %s \n", r.Field(0).Tag)
fmt.Println()
fmt.Printf("Name Tag is %s \n", r.Field(1).Tag)
}

 

转载于:https://www.cnblogs.com/mafeng/p/10907494.html

你可能感兴趣的:(go struct 自定义标签获取)