Created
July 4, 2019 12:22
-
-
Save vkorbes/277304a0959ae5221e041dc4c6398737 to your computer and use it in GitHub Desktop.
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" | |
| "io/ioutil" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { | |
| http.HandleFunc("/", webserver) | |
| http.ListenAndServe(":8080", nil) | |
| message := get() | |
| fmt.Println("The webserver said:", message) | |
| } | |
| func webserver(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Howdy!") | |
| } | |
| func get() string { | |
| response, err := http.Get("http://localhost:8080/") | |
| if err != nil { | |
| log.Fatalln(err) | |
| } | |
| message, err := ioutil.ReadAll(response.Body) | |
| if err != nil { | |
| log.Fatalln(err) | |
| } | |
| return string(message) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment