Created
December 22, 2015 11:04
-
-
Save tbillington/c8cd735c02b11ffe4cac 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" | |
"os" | |
) | |
type parts struct { | |
Parts []part `json:parts` | |
} | |
type part struct { | |
Type string `json:type` | |
Args map[string]string `json:args` | |
Properties map[string]string `json:properties` | |
} | |
type binFunc func(interface{}) | |
func main() { | |
argsWithoutProg := os.Args[1:] | |
fmt.Println(argsWithoutProg) | |
f, err := os.Open(os.Args[1]) | |
if err != nil { | |
panic(err) | |
} | |
var jsonParts parts | |
dec := json.NewDecoder(f) | |
for { | |
//var m map[string]interface{} | |
if err := dec.Decode(&jsonParts); err == io.EOF { | |
break | |
} else if err != nil { | |
panic(err) | |
} | |
fmt.Println(jsonParts) | |
} | |
stuff := map[string]binFunc{} | |
for _, p := range jsonParts.Parts { | |
fmt.Println(p) | |
stuff[p.Type] = func(newPart part) { | |
return func(data interface{}) { | |
fmt.Println(newPart.Args) | |
fmt.Println(newPart.Properties) | |
} | |
}(p) | |
} | |
for k, t := range stuff { | |
fmt.Println(k) | |
t(nil) | |
} | |
} |
dhowden
commented
Dec 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment