admin管理员组

文章数量:1635850

最近刚接触golang,里面基础没有怎么看,只能在项目中边学边看记啦,昨天遇到了结构体报错的问题,今天终于解决了。废话不多说了直接上代码。

 

type Config struct {
    id    int
    key   string
    val   string
    typ   int
}

func regionAll()([]Config,error)  {
   mods  := make([]Config,0)

   error := DB.Select(&mods,"select * from config ")
   fmt.Println(error)
   return mods,error
}

 

运行后请求数据库查询会报错误:

 non-struct dest type struct with >1 columns (4) 问题处理

后来发现结构体(struct)里面的成员变量首字母是区分大小写的,若首字母大写则该成员为公有成员(对外可见),否则是私有成员(对外不可见)。因为我要对外可见,所以把结构体里面的成员变量改成

type Config struct {
    Id    int
    Key   string
    Val   string
    Typ   int
}

执行之后报 missing destination name value in *[]main.Config 异常,然后修改结构体

type Config struct {
    Id    int       `db:"id"`
    Key   string    `db:"key"`
    Val   string    `db:"value"`
    Typ   int          `db:"type"`
}

再执行都解决的帮忙点个赞。

 

本文标签: typegtstructdestdestination