Skip to content

Instantly share code, notes, and snippets.

@hagen1778
Last active November 29, 2020 14:35
Show Gist options
  • Save hagen1778/ee1d43cc5d78e2ac5e9bbae79d46199c to your computer and use it in GitHub Desktop.
Save hagen1778/ee1d43cc5d78e2ac5e9bbae79d46199c to your computer and use it in GitHub Desktop.
Simple go web app
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