Created
December 5, 2018 09:40
-
-
Save sonyarianto/45feb2da543ba038a6ae7413f496666e to your computer and use it in GitHub Desktop.
Web routing with default mux (net/http)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"log" | |
"net/http" | |
) | |
func serviceDefault(w http.ResponseWriter, r *http.Request) { | |
if r.URL.Path != "/" { | |
http.NotFound(w, r) | |
return | |
} | |
io.WriteString(w, "this is the / path") | |
} | |
func service1(w http.ResponseWriter, r *http.Request) { | |
io.WriteString(w, "this is the /service1 path") | |
} | |
func service2(w http.ResponseWriter, r *http.Request) { | |
io.WriteString(w, "this is the /service2 path") | |
} | |
func main() { | |
http.HandleFunc("/", serviceDefault) | |
http.HandleFunc("/service1", service1) | |
http.HandleFunc("/service2", service2) | |
log.Fatal(http.ListenAndServe(":3000", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment