"Bloodthirsty go Notes" simple implementation of a go Web application

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

First of all, you need this package: "Net/http" This package is included in the native go, just use it.

Func Checkservice (w http. Responsewriter, R *http. Request) {//This line resolves an incoming parameter, and the default is r that is not resolved. Parseform ()//This will print all incoming parameters in the form of: Map[key:value] to the console FMT. PRINTLN (R.form)//The pathfmt of the request will be printed here. Println ("Path:", R.url. Path)//Here print the defined scheme such as: http, mailto, etc. fmt. PRINTLN ("scheme", R.url. Scheme)//directly print the value of keytest0001 FMT. Println (r.form["keytest0001"])//traverse mapfor k, V: = Range R.form {fmt. Println ("Key:", K) fmt. Println ("Val:", Strings. Join (V, ""))}//if you want to output to the Web page, use the following code (the project needs to be UTF-8 encoded, otherwise error) FMT. fprintf (W, "Background app started successfully")}//the following is the main method: Func main () {//Bind the requested path and method http. Handlefunc ("/", Checkservice)//Listener port 8888err: = http. Listenandserve (": 8888", nil) if err! = Nil {log. Fatal ("Listenandserve:", Err)}}



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.