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
func Handler(w http.ResponseWriter, r *http.Request) { | |
c := appengine.NewContext(r) | |
u := user.Current(c) | |
//ログインのチェック | |
if u == nil { | |
url, err := user.LoginURL(c, r.URL.String()) | |
if err != nil { | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
return |
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
// ファイルの読み込み | |
rf, err := ioutil.ReadFile("ファイル名") | |
if err != nil { | |
log.Fatal(err) | |
} |
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
c := appengine.NewContext(r) | |
client := urlfetch.Client(c) | |
resp, err := client.Get("https://api.instagram.com/v1/media/popular?client_id=01f47c48216e42d3a9e4d2756cdbc7cb") | |
if err != nil { | |
http.Error(w, err.Error(), http.StatusInternalServerError) | |
return | |
} | |
body, bodyErr := ioutil.ReadAll(resp.Body) | |
if bodyErr != nil { | |
http.Error(w, bodyErr.Error(), http.StatusInternalServerError) |
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
var m Msg | |
b := []byte(`{"message": "とにかく最高!"}`) | |
err2 := json.Unmarshal(b, &m) | |
if err2 != nil { | |
// fmt.Fprintln(os.Stderr, err2) | |
fmt.Fprintf(w, string(m)) | |
} else { | |
fmt.Fprintf(w, string(m)) | |
} |
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
var m Msg | |
b := []byte(`{"message": "とにかく最高!"}`) | |
err2 := json.Unmarshal(b, &m) | |
if err2 != nil { | |
// fmt.Fprintln(os.Stderr, err2) | |
fmt.Fprintf(w, string(m)) | |
} else { | |
fmt.Fprintf(w, string(m)) | |
} |