Untitled

mail@pastecode.io avatar
unknown
golang
2 months ago
608 B
1
Indexable
Never
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)
}
Leave a Comment