Skip to content

Instantly share code, notes, and snippets.

@miped
Created January 28, 2013 21:03
Show Gist options
  • Save miped/4658969 to your computer and use it in GitHub Desktop.
Save miped/4658969 to your computer and use it in GitHub Desktop.
Splitter in go?!?
package main
import (
"encoding/json"
"fmt"
)
type DatetimeCondition struct {
From *float32
To *float32
}
type Conditions struct {
Device []string
DateTime []DatetimeCondition
OS []string
}
type Split struct {
Redirect string
Conditions Conditions
}
func main() {
b := []byte(`{"redirect": "http://www.apple.com/iphone/", "conditions": {"device": ["iPhone"], "datetime": [{"to": null, "from": 1359196200.0}]}}`)
var f Split
err := json.Unmarshal(b, &f)
if err != nil {
panic(err)
}
println(f.Redirect)
println(f.Conditions.Device[0])
fmt.Printf("%f\n", *f.Conditions.DateTime[0].From)
println(f.Conditions.DateTime[0].From)
if f.Conditions.DateTime[0].To == nil {
println("No to datetime")
}
if f.Conditions.OS == nil {
println("No OS")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment