Gweb Summary of the opening

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
gweb not a web framework, but a web scaffolding that you organize yourself? Also do not know how to call more appropriate, so the main purpose is to summarize the relevant knowledge. The third-party packages that are used are available in the project's vendor folder. I also want to make a web framework, while summing up and moving in this direction.

Project background

At first I used to Python write Web services, as for Python to write code is what kind of experience, everyone has experience, when you are accustomed to using Python form resolution check, and then use Golang to do the same thing, for the first touch Golang of the program Ape, It fell from heaven to hell. The premise, of course, is to perform a form check gracefully. And not like the following example:

func Foo(w http.ResponseWriter req *http.Request) {    req.ParseForm()    bar := req.FormValue("bar")    if bar == "" {        // do some work        io.WriteString(w, "param invalid")    }}

Above is just a simple example (handwritten code, please forgive the mistake).

So what we want is: just write the business logic, define the form and the response body. Other work is offered to the other modules for unified processing. The final effect is posted here:

// 定义表单type HelloGetForm struct {    Name string `schema:"name" valid:"Required" json:"name"`    Age  int    `schema:"age" valid:"Required;Min(18)" json:"age"`}var PoolHelloGetForm = &sync.Pool{New: func() interface{} { return &HelloGetForm{} }}// 定义响应体type HelloGetResp struct {    CodeInfo    Tip string `json:"tip"`}var PoolHelloGetResp = &sync.Pool{New: func() interface{} { return &HelloGetResp{} }}// 业务逻辑处理func HelloGet(req *HelloGetForm) *HelloGetResp {    resp := PoolHelloGetResp.Get().(*HelloGetResp)    defer PoolHelloGetResp.Put(resp)    resp.Tip = fmt.Sprintf("Get Hello, %s! your age[%d] is valid to access", req.Name, req.Age)    // TODO: sleep over 10 *time.Second, test Response TimeOut    time.Sleep(10 * time.Second)    Response(resp, NewCodeInfo(CodeOk, ""))    return resp}

Official opening

Put it on the demo, which includes the method of the RESTful API, the parsing of JSON-formatted data, and examples of file processing:

    1. Get
    2. Post
    3. Put
    4. Delete [No example at the moment]
    5. Jsonbody
    6. Files

Subsequent

I will put in gweb the various modules recently such as:

    • Router/middleware/* & Router/router Implements a unified parsing, checksum response module, and the most important part
    • Models is basically the use of ORM
    • Mainc/servers Http Server & RPC Server
    • The processing function of controller's business logic
    • Logger's own web logger
    • Sh/makefile Deploying Golang programs through Makefile

Welcome Fork

Github.com/yeqown/gweb

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.