原文链接:https://www.2cto.com/kf/201712/703563.html 1. 用于判断变量类型 demo如下: switch t := var.(type){ case string: //add your operations case int8: //add your operations case int16: //add your operations default: return errors.New("no this type") } } //空接
先来看一个简单示例: models.gp package main import ( "github.com/astaxie/beego/orm" ) type User struct { Id int Name string Profile *Profile `orm:"rel(one)"` // OneToOne relation Post []*Post `orm:"reverse(many)"` // 设置一对多的反向关系 } type
概述 数据库用来存储数据.只要不是玩具项目,每个项目都需要用到数据库.现在用的最多的还是 MySQL,PostgreSQL的使用也在快速增长中. 在 Web 开发中,数据库也是必须的.本文将介绍如何在 Go 语言中操作数据库,基于 MySQL.本文假定大家已经掌握了数据库和 MySQL 的基础知识. 关于 MySQL 有一个非常详细的免费教程我放在参考中了,需要的自取. Go 语言标准库database/sql只是提供了一组查询和操作数据库的接口,没有提供任何实现.在 Go 中操作数据库只能使用