Last active
November 29, 2020 14:35
-
-
Save hagen1778/ee1d43cc5d78e2ac5e9bbae79d46199c to your computer and use it in GitHub Desktop.
Simple go web app
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 ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", home) | |
http.HandleFunc("/articles", articles) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
func home(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "Welcome!") | |
} | |
func articles(w http.ResponseWriter, r *http.Request) { | |
resp, err := http.DefaultClient.Get("https://www.google.com/search?q=observability+articles") | |
if err != nil { | |
w.WriteHeader(http.StatusInternalServerError) | |
fmt.Fprint(w, err) | |
return | |
} | |
data, _ := ioutil.ReadAll(resp.Body) | |
fmt.Fprint(w, string(data)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment