Last active
August 30, 2020 17:59
-
-
Save jimbo8098/dd006db6f8dcf5b4460318e578a7737a to your computer and use it in GitHub Desktop.
Go HTTP Server
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
// Using this Gist, you can kick off a web server and start receiving and sending data when you visit localhost:5000/foo or /bar | |
package main | |
import ( | |
"net/http" | |
) | |
type fooHandler struct { | |
Message string | |
} | |
func main() { | |
http.Handle("/foo",&fooHandler{Message: "foo called"}) | |
http.HandleFunc("/bar",barHandler) | |
http.ListenAndServe(":5000",nil) | |
} | |
func (f *fooHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte(f.Message)); | |
} | |
func barHandler(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("bar called")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment