Go语言中文网 为您找到相关结果 5

go struct 自定义标签获取

想获取 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) ...阅读全文

博文 2016-08-10 23:00:00 liangguangchuan

关于Go内置的http 包的Post数据的问题

postform 这个玩意里面有个url.value 这个,他里面的东西只支持String,怎么办?我要放一个int进去 他给我报了个cannot use 25423901 (type int) as type string in array or slice literal 代码如下 respDomainRecord,err := http.PostForm("http://dnsapi.cn/Record.List",url.Values{"login_email":{login_email},"login_password":{login_password},"format":{"json"},"domain_id":{25423901}}) if err !=nil{ ...阅读全文