calmh / ipfix

IPFIX parser package for Go
MIT License
48 stars 26 forks source link

Load export templates #20

Closed asenci closed 6 years ago

asenci commented 6 years ago

Can be used with marshal/unmarshal to implement template caching

Example code:

s := ipfix.NewSession()

fmt.Println("Loading template cache")
trecsJson, _ := ioutil.ReadFile("templates.json")
trecs := make([]ipfix.TemplateRecord, 0)
json.Unmarshal(trecsJson, &trecs)
s.LoadTemplateRecords(trecs)

go func() {
    tik := time.Tick(10 * time.Second)

    for range tik {
        fmt.Println("Exporting template cache")
        trecs := s.ExportTemplateRecords()
        trecsJson, _ := json.Marshal(trecs)
        ioutil.WriteFile("templates.json", trecsJson, 0644)
    }
}()
calmh commented 6 years ago

LGTM. Please gofmt it.

asenci commented 6 years ago

Sorry for that, still getting used to the Go toolchain... 😄 Fmted, veted and tested.

calmh commented 6 years ago

No worries. :)