A simple Golang route

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
Package Controllersimport (."Logger"    "Web")//object inherits directly with rest standard interface type login struct {web. Controllerbase}func (This *login) Get () {This. Template["Key"] ="Value"This. WriteString("GET:", this. Template)}func (this *login) Post () {This. WriteString("POST:", this. TemplateThe}//object does not inherit the registration of a method to the route type signout struct {}func (this *signout) signoutget (CTX *web. HttpContext) {CTX. WriteString("Signoutget:", CTX. Template)}func (this *signout) signoutpost (CTX *web. HttpContext) {CTX. WriteString("Signoutpost:", CTX. Template) The}//function directly registers the routing func indexget (ctx *web. HttpContext) {CTX. WriteString("Index Get:", CTX. Template)}func Indexpost (CTX *web. HttpContext) {CTX. WriteString("Index Post:", CTX. Template)}func Printget (CTX *web. HttpContext) {CTX. WriteString(web. Printroute("%v<br>")///Print Data Routing status}//action level interceptor contains get POST put.....func indexactionfilter (ctx *web. HttpContext) {CTX. WriteString("Indexactionfilter:", CTX. Template) CTX. Next()//down pass the registered route}func Globalfilter (CTX *web. HttpContext) {CTX. WriteString("Globalfilter:") Switch CTX. Params["Next"] {case"Yes": CTX. Next()}}func init () {Web. Bringinlog(Logger)//push into a third-party middleware switch//function direct registration route ... Web. Registerroute("/index", Indexget) Web. Registerroute("/index", Indexpost) Web. Registerroute("/print", Printget)//object anonymous inheritance direct with rest standard interface web. Registerroute("/login", &login{})//object does not inherit to register a method to the routing web. Registerroute("/signout", (&signout{}). Signoutget)//Register an action-level interceptor Web. Registeractionfilter("/index", indexactionfilter)//global-level interceptor web. Registerglobalfilter(Globalfilter)}
Related Article

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.