Building webserver with golang


How to build a simple webserver with Go

Code:

package main
import ( "fmt" "net/http")
func main() {    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Golang webserver.")    })
    http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World!")    })
    fs := http.FileServer(http.Dir("static/"))    http.Handle("/static/", http.StripPrefix("/static/", fs))
    http.ListenAndServe(":3000", nil)}

Comments system

[blogger][disqus][facebook]
Powered by Blogger.