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
// Print out one of our JSON values | |
n, ok := data["name"] | |
if !ok { | |
// access it another way | |
n = "default" | |
} | |
v, ok := n.(string) | |
if !ok { | |
// figure out type another way | |
v = "default" |
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 main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
func main() { | |
// Create a map to parse the JSON | |
var data map[string]interface{} |
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
// Print out the JSON Numbers | |
var nums []int | |
i, ok := data["numbers"].([]interface{}) | |
if ok { | |
for _, v := range i { | |
x, ok := v.(float64) | |
if !ok { | |
// set to default | |
nums = []int{} | |
break |
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 main | |
import ( | |
"encoding/json" | |
"fmt" | |
) | |
// Example is our main data structure used for JSON parsing | |
type Example struct { | |
Name string `json:"name"` |
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
// Example is our main data structure used for JSON parsing | |
type Example struct { | |
Name string `json:"name"` | |
Numbers []int `json:"numbers"` | |
Nested Nested `json:"nested"` | |
} | |
// Nested is an embedded structure within Example | |
type Nested struct { | |
IsIt bool `json:"isit"` |
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
// Print the name | |
fmt.Printf("Name is %s\n", data.Name) | |
// Print the Numbers | |
fmt.Printf("Numbers include") | |
for _, v := range data.Numbers { | |
fmt.Printf(" %d", v) | |
} | |
fmt.Printf("\n") |
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 app | |
import ( | |
"fmt" | |
) | |
var ErrShutdown = fmt.Errorf("application was shutdown gracefully") | |
func Start(...) error { | |
// Application runtime code goes here |
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
// main runs the command-line parsing and validations. This function will also start the application logic execution. | |
func main() { | |
// Parse command-line arguments | |
var opts options | |
args, err := flags.ParseArgs(&opts, os.Args[1:]) | |
if err != nil { | |
os.Exit(1) | |
} | |
// Convert to internal config |
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
$ go get -u github.com/madflojo/efs2 |
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
$ go get -u github.com/madflojo/efs2/cmd/efs2 |