Created
February 4, 2014 01:28
-
-
Save chrissnell/8795881 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" | |
) | |
/* | |
JSON looks like this: | |
{ | |
"response": "ok", | |
"host": { | |
"logs": [ | |
], | |
"c": 1391473736982, | |
"name": "testhost-01", | |
"distver": "", | |
"hostname": "testhost-01 prod", | |
"object": "host", | |
"distname": "", | |
"key": "somekeyhere" | |
}, | |
"host_key": "somehostkeyhere", | |
"worker": "a3", | |
"agent_key": "someagentkeyhere" | |
} | |
*/ | |
type LogentriesEntity struct { | |
response string | |
host map[string]Host | |
host_key string | |
worker string | |
agent_key string | |
} | |
type Host struct { | |
c float64 | |
name string | |
distver string | |
hostname string | |
object string | |
distname string | |
key string | |
} | |
func main() { | |
var jsonBlob = []byte(`{"response":"ok","host":{"logs":[],"c":1391473736982,"name":"testhost-01","distver":"","hostname":"testhost-01 prod","object":"host","distname":"","key":"somekeyhere"},"host_key":"somehostkeyhere","worker":"a3","agent_key":"someagentkeyhere"}`) | |
// var entity map[string]interface{} | |
var entity LogentriesEntity | |
err := json.Unmarshal(jsonBlob, &entity) | |
if err != nil { | |
fmt.Println("error:", err) | |
} | |
fmt.Printf("%+v\n", entity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment