Golang net/http.Serve() function example
package net/http
Golang net/http.Serve() function usage example
package main
import (
"net/http"
"net"
)
func Hello(w http.ResponseWriter, req *http.Request) {
html := "Hello World!\n"
w.Write([]byte(html))
}
func main() {
http.HandleFunc("/", Hello)
//http.ListenAndServe(":8080", nil)
// break to listen and serve
ln, err := net.Listen("tcp", ":8080")
if err != nil {
panic(err)
}
http.Serve(ln, nil)
}
Reference :
Advertisement
Something interesting
Tutorials
+7.6k Javascript : Push notifications to browser with Push.js
+32.1k Golang : Validate email address with regular expression
+7.4k Golang : Scanf function weird error in Windows
+16.3k Golang : convert string or integer to big.Int type
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+5.5k Golang : If else example and common mistake
+6.2k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+16.3k Golang : Loop each day of the current month example
+9.2k Golang : Write multiple lines or divide string into multiple lines
+17.5k Golang : Linked list example
+21.8k SSL : How to check if current certificate is sha1 or sha2