Golang net/http.Server.ListenAndServe() function and Server type example
package net/http
Golang net/http.Server.ListenAndServe() function and Server type usage example
package main
import (
"fmt"
"net/http"
)
func home(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", home)
// type Server http://golang.org/pkg/net/http/#Server
server := &http.Server{Handler: mux}
server.Addr = ":8080"
fmt.Println("Listening to TCP address : ", server.Addr)
// http.ListenAndServe(":8080", mux)
err := server.ListenAndServe()
if err != nil {
fmt.Println(err)
}
}
References :
Advertisement
Something interesting
Tutorials
+13.6k Golang : Qt progress dialog example
+10.6k Golang : Bubble sort example
+29.9k Golang : Get and Set User-Agent examples
+13.6k Golang : Get user input until a command or receive a word to stop
+7.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+12.3k Golang : Display list of countries and ISO codes
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+10.5k Swift : Convert (cast) String to Integer
+16.3k Golang : Find out mime type from bytes in buffer
+14.3k Golang : Recombine chunked files example
+5.7k Linux/Unix/PHP : Restart PHP-FPM