Untitled
unknown
golang
a year ago
608 B
4
Indexable
package main import( "fmt" "net/http" ) func HelloWorldPage(w http.ResponseWriter, r *http.Request){ fmt.Fprint(w, "Hello World") switch r.URL.Path{ case "/": fmt.Fprint(w, "Hello World") case "/profile": fmt.Fprint(w, "Profile") default: fmt.Fprint(w, "Error!") } fmt.Printf("Handling function with %s request\n", r.Method) } func htmlVsPlain(w http.ResponseWriter, r *http.Request) { fmt.Println("htmlVsPlain") w.Header().Set("Content-Type", "text/plain") fmt.Fprint(w, "<h1>Hello World</h1>") } func main(){ http.HandleFunc("/", HelloWorldPage) http.ListenAndServe(":8080", nil) }
Editor is loading...
Leave a Comment