Main.gopackage mainimport ("FMT")//Note://?channel does not need to be shut down as often as a file. Only if you really don't have any data to send, or do you want to explicitly end the range loop or something like this before you close channel;//? After the channel is closed, data cannot be sent to the channel (resulting in a panic error that causes the receive to immediately return a value of 0);/? After the channel is closed, the data can continue to be received from the channel;//for nil ch
The program can be used to perform some tasks on a regular basis, and it can also do the appropriate warning and cleanup when the force is interrupted by the semaphore processing.Package main//semaphore and timer//author:xiong Chuan liang//date:2015-2-25import "FMT" import "OS" import "os/signal" import "Time" Func Main () {sigs: = Make (chan os. Signal, 1) Done: = Make (chan bool, 1) Signal. Notify (sigs, OS. Interrupt, OS. Kill) go func () {sig: = If you press CTRL-C, the result is as follows:
"Transfer from http://www.01happy.com/golang-http-client-get-and-post/"GET requestGet requests can be directly HTTP. The Get method is very simple.
1234567891011121314
func httpGet() {resp, err := http.Get("http://www.01happy.com/demo/accept.php?id=1")if err != nil {// handle error}defer resp.Body.Close()body, err := ioutil.ReadAll(resp.Body)if err != nil {// handle error}fmt.Println(string(body))}
One of the post requests is
This example describes how Golang uses the sort interface to implement sorting. Share to everyone for your reference, specific as follows:
See the group today to discuss sorted sort again. The realization of interface, there are children's shoes have been uncertain, I started a bit, oh yes, the code is here.
Actually very simple sort. Interface three ways to implement these three methods for your own stru
The example in this article describes the Golang method for implementing HTTP server processing static files. Share to everyone for your reference, specific as follows:
The new version is more streamlined:
Copy Code code as follows:
Package Main
Import (
"Flag"
"Log"
"Net/http"
"OS"
"IO"
"Path"
"StrConv"
)
var dir string
var Port int
var Statichandler http. Handler
Initialization pa
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.