Created
February 18, 2016 17:28
-
-
Save bpowell/83dd1394ea2b452cfd87 to your computer and use it in GitHub Desktop.
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 ( | |
"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