在这种简单情况下如何解决缺少泛型的问题
问题描述:
I am creating a simple sql mapper that allows me to create sql mappings at run time because i have no idea how the database schema will be like.
consider the following struct:
type SqlColumn struct {
name string
columnType ? //int float etc...
}
what type should i use for the columnType field?
the only way i could think of is to use strings or a const and handle the rest using reflection, am i on the right path?
我正在创建一个简单的 请考虑以下结构: p>
我唯一想到的方法是使用字符串或const并使用反射来处理其余部分,我在正确的路径上吗? p>
div> sql code>映射器,该映射器允许我在运行时创建sql映射 因为我不知道数据库架构如何。 p>
type SqlColumn结构{
名称 字符串
columnType吗? // int浮点等...
}
code> pre>
columnType code>字段应使用哪种类型? p> \ n
答
Use interface{} for this:
type SqlColumn struct {
name string
columnType interface{}
}