GO語言"reflect"包中"StructTag"類型的用法及代碼示例。
StructTag 是結構字段中的標記字符串。
按照慣例,標記字符串是可選用空格分隔的鍵:"value" 對的串聯。每個鍵都是一個非空字符串,由除空格 (U+0020 ' ')、引號 (U+0022 '"') 和冒號 (U+003A ':') 以外的非控製字符組成。每個值都使用 U+0022 '"' 字符和 Go 字符串文字語法進行引用。
用法:
type StructTag string
例子:
package main
import (
"fmt"
"reflect"
)
func main() {
type S struct {
F string `species:"gopher" color:"blue"`
}
s := S{}
st := reflect.TypeOf(s)
field := st.Field(0)
fmt.Println(field.Tag.Get("color"), field.Tag.Get("species"))
}
輸出:
blue gopher
相關用法
- GO StructTag.Lookup用法及代碼示例
- GO StructOf用法及代碼示例
- GO StreamWriter用法及代碼示例
- GO Strings用法及代碼示例
- GO Stringer用法及代碼示例
- GO StripPrefix用法及代碼示例
- GO StreamReader用法及代碼示例
- GO Stmt用法及代碼示例
- GO Stmt.QueryRowContext用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO Split用法及代碼示例
- GO Server.Shutdown用法及代碼示例
- GO Slice用法及代碼示例
- GO SplitAfter用法及代碼示例
- GO Sum256用法及代碼示例
- GO SectionReader用法及代碼示例
- GO Sin用法及代碼示例
- GO Sprintf用法及代碼示例
- GO SendMail用法及代碼示例
- GO Sprint用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 StructTag。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。