本文整理匯總了Golang中github.com/fatih/structs.Name函數的典型用法代碼示例。如果您正苦於以下問題:Golang Name函數的具體用法?Golang Name怎麽用?Golang Name使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Name函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestENV
func TestENV(t *testing.T) {
m := EnvironmentLoader{}
s := &Server{}
structName := structs.Name(s)
// set env variables
setEnvVars(t, structName, "")
if err := m.Load(s); err != nil {
t.Error(err)
}
testStruct(t, s, getDefaultServer())
}
示例2: TestCamelCaseEnv
func TestCamelCaseEnv(t *testing.T) {
m := EnvironmentLoader{
CamelCase: true,
}
s := &CamelCaseServer{}
structName := structs.Name(s)
// set env variables
setEnvVars(t, structName, "")
if err := m.Load(s); err != nil {
t.Error(err)
}
testCamelcaseStruct(t, s, getDefaultCamelCaseServer())
}
示例3: TestTagFlags
func TestTagFlags(t *testing.T) {
m := FlagLoader{}
s := &TestFlagTagServer{}
structName := structs.Name(s)
// get flags
args := getFlags(t, structName, "")
m.Args = args[1:]
if err := m.Load(s); err != nil {
t.Error(err)
}
testFlagTagStruct(t, s, getDefaultFlagTagServer())
}
示例4: TestFlagWithPrefix
func TestFlagWithPrefix(t *testing.T) {
const prefix = "Prefix"
m := FlagLoader{Prefix: prefix}
s := &TestFlagServer{}
structName := structs.Name(s)
// get flags
args := getFlags(t, structName, prefix)
m.Args = args[1:]
if err := m.Load(s); err != nil {
t.Error(err)
}
testFlagStruct(t, s, getDefaultFlagServer())
}
示例5: TestCamelcaseFlags
func TestCamelcaseFlags(t *testing.T) {
m := FlagLoader{
CamelCase: true,
}
s := &CamelCaseServer{}
structName := structs.Name(s)
// get flags
args := getFlags(t, structName, "")
m.Args = args[1:]
if err := m.Load(s); err != nil {
t.Error(err)
}
testCamelcaseStruct(t, s, getDefaultCamelCaseServer())
}
示例6: otherReflect
func otherReflect(ui IEntity) {
structName := structs.Name(ui)
log.Println("structName", structName)
fieldNames := structs.Names(ui)
structInfo := structs.New(ui)
values := make([]interface{}, 0)
sqlFieldStr := ""
sqlFieldPre := ""
i := 0
for _, fieldName := range fieldNames {
field := structInfo.Field(fieldName)
if field.IsExported() {
tags := strings.Split(strings.Trim(field.Tag("db"), " "), ",")
isPk := false
if len(tags) == 2 && tags[1] == "pk" {
isPk = true
}
tag := tags[0]
if !isPk {
values = append(values, field.Value())
if i == 0 {
sqlFieldStr += "(" + strings.ToLower(tag)
sqlFieldPre += "(?"
} else {
sqlFieldStr += "," + strings.ToLower(tag)
sqlFieldPre += ",?"
}
i++
}
}
}
if len(values) > 1 {
sqlFieldStr += ")"
sqlFieldPre += ")"
}
sql := fmt.Sprintf("INSERT INTO %s %s VALUES %s", ui.TableName(), sqlFieldStr, sqlFieldPre)
fmt.Println(sql)
fmt.Println(values)
}