douchui3933 2014-07-13 14:02
浏览 59
已采纳

在这种简单情况下如何解决缺少泛型的问题

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?

  • 写回答

1条回答 默认 最新

  • dpaal28266 2014-07-13 14:07
    关注

    Use interface{} for this:

    type SqlColumn struct {
        name string
        columnType interface{}
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?