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)
}

 

posted @ 2019-05-22 17:47  ma_fighting  阅读(518)  评论(0编辑  收藏  举报
历史天气查