Skip to content

Commit

Permalink
Go loves tabulations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Martin committed Nov 30, 2018
1 parent 820d01a commit 025f7c7
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions scripts/template.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
package main

import (
"fmt"
"os"
"path/filepath"
"fmt"
"os"
"path/filepath"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/template"
"github.com/elastic/go-ucfg/yaml"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/template"
"github.com/elastic/go-ucfg/yaml"
)

func main() {

// For the path to be correct, the execution must be from the top directory
paths, err := filepath.Glob("./schemas/*.yml")
if err != nil {
fmt.Printf("Error: %s \n", err)
os.Exit(1)
}
// For the path to be correct, the execution must be from the top directory
paths, err := filepath.Glob("./schemas/*.yml")
if err != nil {
fmt.Printf("Error: %s \n", err)
os.Exit(1)
}

fields := common.Fields{}
fields := common.Fields{}

for _, path := range paths {
f := common.Fields{}
for _, path := range paths {
f := common.Fields{}

cfg, err := yaml.NewConfigWithFile(path)
if err != nil {
fmt.Printf("Error: %s \n", err)
os.Exit(1)
}
cfg.Unpack(&f)
cfg, err := yaml.NewConfigWithFile(path)
if err != nil {
fmt.Printf("Error: %s \n", err)
os.Exit(1)
}
cfg.Unpack(&f)

for key, f2 := range f {
// The definitions don't have the type group in and the template
// generator assumes otherwise keyword as default
f[key].Type = "group"
for key, f2 := range f {
// The definitions don't have the type group in and the template
// generator assumes otherwise keyword as default
f[key].Type = "group"

// Moves the docs under base to the top level
if f2.Name == "base" {
f = f2.Fields
}
}
// Moves the docs under base to the top level
if f2.Name == "base" {
f = f2.Fields
}
}

fields = append(fields, f...)
}
fields = append(fields, f...)
}

// If getting a failure on the following instantiation, check out / update Beats master
version := common.MustNewVersion("6.0.0")
Expand All @@ -53,14 +53,14 @@ func main() {
os.Exit(1)
}

// Start processing at the root
properties := common.MapStr{}
processor := template.Processor{}
if err := processor.Process(fields, "", properties); err != nil {
fmt.Printf("Error: %s \n", err)
os.Exit(1)
}
output := t.Generate(properties, nil)
// Start processing at the root
properties := common.MapStr{}
processor := template.Processor{}
if err := processor.Process(fields, "", properties); err != nil {
fmt.Printf("Error: %s \n", err)
os.Exit(1)
}
output := t.Generate(properties, nil)

fmt.Printf("%s", output.StringToPrint())
fmt.Printf("%s", output.StringToPrint())
}

0 comments on commit 025f7c7

Please sign in to comment.