Golang net/http.NewServeMux() and ServeMux.Handle() functions example
package net/http
Golang net/http.NewServeMux() and ServeMux.Handle() functions usage example
package main
import (
"net/http"
)
func SayHelloWorld(w http.ResponseWriter, r *http.Request) {
html := "Hello"
html = html + " World"
w.Write([]byte(html))
}
func main() {
mux := http.NewServeMux()
mux.Handle("/", SayHelloWorld)
http.ListenAndServe(":8080", mux)
}
References :
http://golang.org/pkg/net/http/#NewServeMux
http://golang.org/pkg/net/http/#ServeMux.Handle
https://www.socketloop.com/tutorials/golang-http-server-example
Advertisement
Something interesting
Tutorials
+20k Golang : How to run your code only once with sync.Once object
+5.9k Golang : Use NLP to get sentences for each paragraph example
+22.9k Golang : Gorilla mux routing example
+6.8k Golang : Find the longest line of text example
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+8.1k Golang : Multiplexer with net/http and map
+14.6k Golang : Convert(cast) int to float example
+4.7k Linux/MacOSX : How to symlink a file?
+28.6k Get file path of temporary file in Go
+32.4k Golang : Math pow(the power of x^y) example
+6.9k Golang : Pat multiplexer routing example