One
The HTTP service is developed in Golang and can be provided using the Net/http package. The Net/http package provides a very full functionality, and the HTTP service that is launched is also very stable and efficient , and can be used in production environments entirely.
Package Mainimport ( "FMT" "Log" " net/http")//W represents the Response object, the content returned to the client is processed in the object//R represents the client request object, which contains the request header, Request parameters, etc. func index (w http. Responsewriter, R *http. Request) { //writes content to W, and the FMT is output in the browser . fprintf (W, "Hello Golang http!")} Func Main () { //sets the route, if access/, calls the Index method http. Handlefunc ("/", index) //Start Web service, listen on 9090 port Err: = http. Listenandserve (": 8000", nil) if err! = Nil { log. Fatal ("Listenandserve:", Err) }}
To run the service:
Go Run main.go
You can see the Hello Golang http! output by accessing http://localhost:8000 in the browser.