Skip to content

Instantly share code, notes, and snippets.

@chrissnell
Created February 4, 2014 01:28
Show Gist options
  • Save chrissnell/8795881 to your computer and use it in GitHub Desktop.
Save chrissnell/8795881 to your computer and use it in GitHub Desktop.
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