Code Snippets-golang implement a simple Web server

Source: Internet
Author: User
Tags sqlite database linux mint

------------------------------the following piece of code to implement the simplest Web Server: compiled environment: Linux Mint Cinnamon 64-bit Golang 1.7------------------- -----------//main.gopackage mainimport ("fmt" "log" "net/http")//processing home page request Func index (w HTTP. responsewriter, R *HTTP. Request) {//writes The content to the client Fmt. fprintf (w, "Hello world!")} Func main () {http. Handlefunc ("/", index)//set access to the route err: = Http. Listenandserve (": 9090", Nil)//set The listening port if err! = Nil {log. Fatal ("listenandserve:", Err)}}------------------------------after Executing the above program, open the Web browser and enter in the address Bar: 127.0.0.1:9090 You will be able to access this server.  It only implements the simplest single-page Output.  Next we have the server accept the data entered by the client and then feed it back to the Client. first, We write a form page to the client so that the client has a place to fill in the data and submit the Data. You will then need to add a page handler function on the server to handle the data submitted by the User. The following is the beginning of the implementation of this Feature. ------------------------------//main.gopackage mainimport ("fmt" "log" "net/http")//write This data to the client so that the client can fill in the text and commit Var indexhtml = ' 

Code Snippets-golang Implementing a simple Web server

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.