转载请注明来源-作者@loongshawn:http://blog.csdn.net/loongshawn/article/details/54114606,建议读者阅读原文,确保获得完整的信息
1.工程创建
本文介绍利用beego框架快速构建web api服务,可以通过beego提供的命令来创建API工程。beego命令更详细的使用说明可以参考官方文档
bee api apiproject
工程创建后,主要包含如图中的conf、controllers、models模块
conf文件夹中包含默认文件app.conf,在models中创建user.go文件,controllers中创建user.go文件,具体如下:
models文件夹中的user.go
package models
import (
"github.com/astaxie/beego/orm"
"fmt"
)
type User struct {
Id int
User_name string
Age int
Email string
Staff_id string
Position string
Extension_number string
Telephone_number string
Office_location string
}
func init() {
// 需要在init中注册定义的model
orm.RegisterModel(new(User))
}