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
This is a creation in
Article, where the information may have evolved or changed.
Golang mongodb MgO Insert, query a small example, Golang still give me that feeling, than Nodejs write up comfortable. Package main import ("FMT" "Launchpad.net/mgo" "Launchpad.net/mgo/bson") type Mail struct {Id Bson. ObjectId "_id" Name string Email String} func Main () {//Connect
The example in this article describes the use of Golang templates template custom functions. Share to everyone for your reference, specific as follows:
The Golang template is very powerful, and the UNIX pipe style function calls are very much like.
There are a number of built-in templates that can be used to refer to the PKG document
You can also implement cus
An example of this article describes the HTTP Basic authentication mechanism of Golang. Share to everyone for your reference, specific as follows:
Read the
Request Response Process:
Copy Code code as follows:
==>
Get/hello http/1.1
host:127.0.0.1:12345
http/1.1 401 Unauthorized
Www-authenticate:basic realm= "Dotcoo User Login"
==>
Get/hello http/1.1
host:127.0.0.1:12345
Auth
Golang to request a remote Web page, it can be implemented using the method provided by the client in the Net/http package. See the official website There are some examples, there are not too comprehensive examples, so I tidied up a bit.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 {// ha
The example in this article describes the Golang simple TLS protocol usage. Share to everyone for your reference, specific as follows:
Generate private key:
OpenSSL genrsa-out Key.pem 2048
To generate a certificate:
OpenSSL req-new-x509-key key.pem-out cert.pem-days 3650
Https
Copy Code code as follows:
Package Main
Import (
"IO"
"Net/http"
"Log"
)
Fu
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.