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

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

Routing planning

Routing is the entry for all requests, where we configure all requests, go to the corresponding name for each request, and request different controllers according to the name to obtain the final data
Here, we have made a simple code example as follows:

Package Routerimport (//Introducing Controller "Github.com/gohouse/kuaixinwen/controller"//Introducing Dotweb "Github.com/devfeel/dot Web "//introduced Dotweb middleware" github.com/devfeel/middleware/cors ") func Run (Route *dotweb. Httpserver) {//sets the Cors option middleware and uses the default cross-domain configuration option: cors. Newconfig (). Usedefault ()//home Test/Route.get ("/", Func (CTX Dotweb. Context) Error {return CTX.    WriteString ("Quick News homepage!") })//JSON return test/json route.get ("/json", func (CTX Dotweb. Context) Error {return CTX. Writejson ("Waves in a wave ...")}). Use (cors. Middleware (option))//Front desk display list/getnewslist route.get ("/getnewslist", controller. Getnewslist). Use (cors. Middleware (option))//Background management admin: = Route.group ("/admin"). Use (cors. Middleware (option))//News list/admin/newsdel Admin. GET ("/getnewslist", controller. getnewslist)//Get a single news message/admin/getnewsbyid Admin. GET ("/getnewsbyid", controller. Getnewsbyid)//news additions or modifications, according to whether the ID to determine, passed the ID on the modification, otherwise add/admin/newsaddoredit admin. POST ("/newsaddoredit", CONtroller. Newsaddoredit)//News Delete/admin/newsdel Admin. POST ("/newsdel", controller. Newsdel)}

Description

Here we use the relevant components of the Dotweb, with HttpServer , Context and cors middleware
They are used for routing, request parameters and other related and middleware (such as cross-domain), etc.

    • Route.GETRepresents the request bit GET request
    • Route.POSTRepresents the request bit POST request
    • Route.GroupThe request is categorized, in the example, all of the background management requests are categorized admin below
    • Route.Group.UseUsing middleware
    • optionMiddleware initialization
    • cors.Middleware(option)Load middleware option
    • controller.xxxxxThe corresponding method of loading controller

Here the routing section is completed, and the controller part is loaded, controller see the next section

The project Source: Https://github.com/gohouse/kuaixinwen

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.