Skip to content

Instantly share code, notes, and snippets.

@bpowell
Created February 18, 2016 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpowell/83dd1394ea2b452cfd87 to your computer and use it in GitHub Desktop.
Save bpowell/83dd1394ea2b452cfd87 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Layout struct {
User string
}
func get_html() {
//HTML page
url := "http://google.com"
page, err := http.Get(url)
if err != nil {
fmt.Println(err)
return
}
defer page.Body.Close()
body, err := ioutil.ReadAll(page.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
func get_json() {
//JSON feed
url := "https://mysail.oakland.edu/uPortal/layout.json"
page, err := http.Get(url)
if err != nil {
fmt.Println(err)
return
}
defer page.Body.Close()
body, err := ioutil.ReadAll(page.Body)
if err != nil {
fmt.Println(err)
return
}
var layout Layout
if err = json.Unmarshal(body, &layout); err != nil {
fmt.Println(err)
return
}
fmt.Println(layout)
}
func main() {
get_html()
get_json()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment