Skip to content

Commit

Permalink
Add readme (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh authored Sep 16, 2023
1 parent 886ceb7 commit 6162f5c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# go-ecs

go-ecs is a library for querying [ECS][ecs] fields by name to obtain the fields
definition (e.g. Elasticsearch field data type, description, etc).

The library includes data from tagged released of [elastic/ecs][ecs_repo].

[ecs]: https://www.elastic.co/guide/en/ecs/current/index.html
[ecs_repo]: https://github.com/elastic/ecs

## Install

`go get github.com/andrewkroh/go-ecs@main`

## Usage

```go
package main

import (
"fmt"

"github.com/andrewkroh/go-ecs"
)

func main() {
field, err := ecs.Lookup("host.os.name", "8.10")
if err != nil {
return err
}

fmt.Println("data_type", field.DataType)
fmt.Println("is array", field.Array)
fmt.Println("pattern", field.Pattern)
fmt.Println("description", field.Description)
}
```
23 changes: 22 additions & 1 deletion ecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

package ecs

import "testing"
import (
"encoding/json"
"fmt"
"testing"
)

func TestLookup(t *testing.T) {
testCases := []struct {
Expand Down Expand Up @@ -65,3 +69,20 @@ func BenchmarkLookup(b *testing.B) {
}
}
}

func ExampleLookup() {
field, err := Lookup("host.os.name", "8.10")
if err != nil {
fmt.Println(err)
return
}

data, _ := json.MarshalIndent(field, "", " ")
fmt.Printf("%s", data)
// Output: {
// "name": "host.os.name",
// "data_type": "keyword",
// "array": false,
// "description": "Operating system name, without the version."
// }
}
2 changes: 1 addition & 1 deletion internal/version/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Field struct {
Array bool `json:"array" yaml:"array"`

// Regular expression pattern that can be used to validate the value.
Pattern string `json:"pattern" yaml:"pattern"`
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`

// Short description of the field.
Description string `json:"description" yaml:"description"`
Expand Down

0 comments on commit 6162f5c

Please sign in to comment.