Gorose orm+dotweb Framework Quick Build Go Web site Combat (V)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Controllers and Models

Here we take the news list as an example, do a complete controller processing business, database model to obtain data

Create GetNewsById a way to get a piece of news in the controller

func GetNewsById(ctx dotweb.Context) error {    res := model.GetNewsById(ctx)    ctx.WriteJson(utils.SuccessReturn(res))    return nil}

Description

    • ctxContent of the request
    • ctx.WriteJsonReturn json Format data
    • utils.SuccessReturnSuccessful return function encapsulated in the toolkit
    • modelThe introduction of the model directory, the contents are as follows:

      // 根据主键id获取一条数据func GetNewsById(ctx dotweb.Context) interface{} {    res, err := DB.Table("news").        Where("id", ctx.FormValue("id")).        First()    if err != nil {        return ""    }    return res}
      This is a basic to get the corresponding data according to the parameters, through the import of the database driver, we call the final first method to obtain a data, more usage can refer to the source code

Here, we just take one of the methods to do the example, the other usage is similar, we just need to view the source code, all the source code is in the Https://github.com/gohouse/kuaixinwenz

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.