Created
July 31, 2021 03:52
-
-
Save madflojo/78e999d855769d734bfcec1908ab7aa8 to your computer and use it in GitHub Desktop.
httprouter Article - Basic HTTP Example (w/httprouter)
This file contains hidden or 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 ( | |
"fmt" | |
"github.com/julienschmidt/httprouter" | |
"log" | |
"net/http" | |
) | |
// handler is a basic HTTP handler that prints hello world. | |
func handler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
fmt.Fprintf(w, "Hello World") | |
} | |
func main() { | |
// Create Router | |
router := httprouter.New() | |
router.GET("/hello", handler) | |
// Start HTTP Listener | |
err := http.ListenAndServe(":8080", router) | |
if err != nil { | |
log.Printf("HTTP Server stopped - %s", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment