本文整理汇总了Golang中edu/models.Data类的典型用法代码示例。如果您正苦于以下问题:Golang Data类的具体用法?Golang Data怎么用?Golang Data使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Data类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetAll
// @Title Get All
// @Description get Users
// @Param query query string false "Filter. e.g. col1:v1,col2:v2 ..."
// @Param fields query string false "Fields returned. e.g. col1,col2 ..."
// @Param sortby query string false "Sorted-by fields. e.g. col1,col2 ..."
// @Param order query string false "Order corresponding to each sortby field, if single value, apply to all sortby fields. e.g. desc,asc ..."
// @Param limit query string false "Limit the size of result set. Must be an integer"
// @Param offset query string false "Start position of result set. Must be an integer"
// @Success 200 {object} models.Users
// @Failure 403
// @router / [get]
func (this *UsersController) GetAll() {
var fields []string
var sortby []string
var order []string
var query map[string]string = make(map[string]string)
var limit int64 = 10
var offset int64 = 0
// fields: col1,col2,entity.col3
if v := this.GetString("fields"); v != "" {
fields = strings.Split(v, ",")
}
// limit: 10 (default is 10)
if v, err := this.GetInt("limit"); err == nil {
limit = v
}
// offset: 0 (default is 0)
if v, err := this.GetInt("offset"); err == nil {
offset = v
}
// sortby: col1,col2
if v := this.GetString("sortby"); v != "" {
sortby = strings.Split(v, ",")
}
// order: desc,asc
if v := this.GetString("order"); v != "" {
order = strings.Split(v, ",")
}
// query: k:v,k:v
if v := this.GetString("query"); v != "" {
for _, cond := range strings.Split(v, ",") {
kv := strings.Split(cond, ":")
if len(kv) != 2 {
this.Data["json"] = errors.New("Error: invalid query key/value pair")
this.ServeJson()
return
}
k, v := kv[0], kv[1]
query[k] = v
}
}
l, err := models.GetAllUsers(query, fields, sortby, order, offset, limit)
var data models.Data
if err != nil {
data.Error = 1
data.Result = err.Error()
this.Data["json"] = data
} else {
data.Error = 0
data.Result = l
this.Data["json"] = data
}
this.ServeJson()
}
开发者ID:justinyaoqi,项目名称:edu,代码行数:66,代码来源:users.go
示例2: Delete
// @Title Delete
// @Description delete the Users
// @Param id path string true "The id you want to delete"
// @Success 200 {string} delete success!
// @Failure 403 id is empty
// @router /:id [delete]
func (this *UsersController) Delete() {
idStr := this.Ctx.Input.Params[":id"]
id, _ := strconv.Atoi(idStr)
var data models.Data
if err := models.DeleteUsers(id); err == nil {
data.Error = 0
data.Result = "OK"
this.Data["json"] = data
} else {
data.Error = 1
data.Result = err.Error()
this.Data["json"] = data
}
this.ServeJson()
}
开发者ID:justinyaoqi,项目名称:edu,代码行数:21,代码来源:users.go
示例3: Post
// @Title Post
// @Description create Course
// @Param body body models.Course true "body for Course content"
// @Success 200 {int} models.Course.Id
// @Failure 403 body is empty
// @router / [post]
func (this *CourseController) Post() {
var v models.Course
json.Unmarshal(this.Ctx.Input.RequestBody, &v)
var data models.Data
if id, err := models.AddCourse(&v); err == nil {
data.Error = 0
data.Result = map[string]int64{"id": id}
this.Data["json"] = data
} else {
data.Error = 1
data.Result = err.Error()
this.Data["json"] = data
}
this.ServeJson()
}
开发者ID:justinyaoqi,项目名称:edu,代码行数:21,代码来源:course.go
示例4: GetOne
// @Title Get
// @Description get Course by id
// @Param id path string true "The key for staticblock"
// @Success 200 {object} models.Course
// @Failure 403 :id is empty
// @router /:id [get]
func (this *CourseController) GetOne() {
idStr := this.Ctx.Input.Params[":id"]
id, _ := strconv.Atoi(idStr)
v, err := models.GetCourseById(id)
var data models.Data
if err != nil {
data.Error = 1
data.Result = err.Error()
this.Data["json"] = data
} else {
data.Error = 0
data.Result = v
this.Data["json"] = data
}
this.ServeJson()
}
开发者ID:justinyaoqi,项目名称:edu,代码行数:22,代码来源:course.go
示例5: Put
// @Title Update
// @Description update the Users
// @Param id path string true "The id you want to update"
// @Param body body models.Users true "body for Users content"
// @Success 200 {object} models.Users
// @Failure 403 :id is not int
// @router /:id [put]
func (this *UsersController) Put() {
idStr := this.Ctx.Input.Params[":id"]
id, _ := strconv.Atoi(idStr)
v := models.Users{Id: id}
json.Unmarshal(this.Ctx.Input.RequestBody, &v)
var data models.Data
if err := models.UpdateUsersById(&v); err == nil {
data.Error = 0
data.Result = "OK"
this.Data["json"] = "OK"
} else {
data.Error = 1
data.Result = err.Error()
this.Data["json"] = data
}
this.ServeJson()
}
开发者ID:justinyaoqi,项目名称:edu,代码行数:24,代码来源:users.go
注:本文中的edu/models.Data类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论