Last active
December 16, 2015 02:39
-
-
Save grapswiz/5364076 to your computer and use it in GitHub Desktop.
Read config json file sample for gae/go
This file contains hidden or 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
| application: gotwiggle | |
| version: 1 | |
| runtime: go | |
| api_version: go1 | |
| handlers: | |
| - url: /.* | |
| script: _go_app |
This file contains hidden or 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
| { | |
| "Token": "ff", | |
| "Secret": "fff" | |
| } |
This file contains hidden or 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 twitterSample | |
| import ( | |
| "io/ioutil" | |
| "encoding/json" | |
| ) | |
| type Credentials struct { | |
| Token string | |
| Secret string | |
| } | |
| func loadFile(fileName string) ([]byte, error) { | |
| body, err := ioutil.ReadFile(fileName) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return body, nil | |
| } | |
| func loadCredentials() (*Credentials, error) { | |
| body, err := loadFile("config.json") | |
| if err != nil { | |
| return nil, err | |
| } | |
| var c Credentials | |
| err = json.Unmarshal(body, &c) | |
| if err != nil { | |
| return nil, err | |
| } | |
| return &c, nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment