Skip to content

Commit

Permalink
fix golint and govet warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeantet committed Feb 29, 2016
1 parent a6054ec commit 176de19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 4 additions & 6 deletions grok.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ func NewWithConfig(config *Config) (*Grok, error) {
if err != nil {
return nil, err
}
return g, nil
}

// Patterns return a map of the loaded patterns.
func (g *Grok) Patterns() map[string]*gPattern {
return g.patterns
return g, nil
}

// AddPattern adds a new pattern to the list of loaded patterns.
Expand All @@ -95,6 +91,7 @@ func (g *Grok) addPattern(name, pattern string) error {
return nil
}

// AddPattern adds a named pattern to grok
func (g *Grok) AddPattern(name, pattern string) error {
g.serviceMu.Lock()
defer g.serviceMu.Unlock()
Expand All @@ -103,6 +100,7 @@ func (g *Grok) AddPattern(name, pattern string) error {
return nil
}

// AddPatternsFromMap loads a map of named patterns
func (g *Grok) AddPatternsFromMap(m map[string]string) error {
g.serviceMu.Lock()
defer g.serviceMu.Unlock()
Expand Down Expand Up @@ -217,7 +215,7 @@ func (g *Grok) Parse(pattern, text string) (map[string]string, error) {
return captures, nil
}

// Parse returns a inteface{} map with captured fields based on provided pattern over the text
// ParseTyped returns a inteface{} map with typed captured fields based on provided pattern over the text
func (g *Grok) ParseTyped(pattern string, text string) (map[string]interface{}, error) {
gr, err := g.compile(pattern)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions grok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import "testing"

func TestNew(t *testing.T) {
g, _ := New()
if len(g.Patterns()) == 0 {
if len(g.patterns) == 0 {
t.Fatal("the Grok object should have some patterns pre loaded")
}

g, _ = NewWithConfig(&Config{NamedCapturesOnly: true})
if len(g.Patterns()) == 0 {
if len(g.patterns) == 0 {
t.Fatal("the Grok object should have some patterns pre loaded")
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestMultiParseWithDefaultCaptureMode(t *testing.T) {

func TestNewWithNoDefaultPatterns(t *testing.T) {
g, _ := NewWithConfig(&Config{SkipDefaultPatterns: true})
if len(g.Patterns()) != 0 {
if len(g.patterns) != 0 {
t.Fatal("Using SkipDefaultPatterns the Grok object should not have any patterns pre loaded")
}
}
Expand Down Expand Up @@ -429,16 +429,16 @@ func TestConcurentParse(t *testing.T) {

func TestPatterns(t *testing.T) {
g, _ := NewWithConfig(&Config{SkipDefaultPatterns: true})
if len(g.Patterns()) != 0 {
t.Fatalf("Patterns should return 0, have '%d'", len(g.Patterns()))
if len(g.patterns) != 0 {
t.Fatalf("Patterns should return 0, have '%d'", len(g.patterns))
}
name := "DAY0"
pattern := "(?:Mon(?:day)?|Tue(?:sday)?|Wed(?:nesday)?|Thu(?:rsday)?|Fri(?:day)?|Sat(?:urday)?|Sun(?:day)?)"

g.AddPattern(name, pattern)
g.AddPattern(name+"1", pattern)
if len(g.Patterns()) != 2 {
t.Fatalf("Patterns should return 2, have '%d'", len(g.Patterns()))
if len(g.patterns) != 2 {
t.Fatalf("Patterns should return 2, have '%d'", len(g.patterns))
}
}

Expand All @@ -454,7 +454,7 @@ func TestParseTypedWithDefaultCaptureMode(t *testing.T) {
t.Fatalf("%s should be '%d' have '%d'", "status", 200, captures["status"])
} else {
if captures["duration"] != 0.8 {
t.Fatalf("%s should be '%d' have '%d'", "duration", 0.8, captures["duration"])
t.Fatalf("%s should be '%f' have '%f'", "duration", 0.8, captures["duration"])
}
}
}
Expand All @@ -470,7 +470,7 @@ func TestParseTypedWithNoTypeInfo(t *testing.T) {
t.Fatalf("%s should be '%s' have '%s'", "timestamp", "23/Apr/2014:22:58:32 +0200", captures["timestamp"])
}
if captures["TIME"] != nil {
t.Fatalf("%s should be '%s' have '%s'", "TIME", nil, captures["TIME"])
t.Fatalf("%s should be nil have '%s'", "TIME", captures["TIME"])
}
}

Expand Down

0 comments on commit 176de19

Please sign in to comment.