Skip to content

Commit

Permalink
Added -c|--config
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuchiki committed Oct 29, 2015
1 parent a4933d8 commit 44892be
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 117 deletions.
106 changes: 106 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package main

import (
"strings"
)

type Config struct {
File string `yaml:"file"`
Sort string `yaml:"sort"`
Reverse bool `yaml:"reverse"`
QueryString bool `yaml:"query_string"`
Tsv bool `yaml:"tsv"`
ApptimeLabel string `yaml:"apptime_label"`
SizeLabel string `yaml:"size_label"`
MethodLabel string `yaml:"method_label"`
UriLabel string `yaml:"uri_label"`
TimeLabel string `yaml:"time_label"`
Limit int `yaml:"limit"`
Includes []string `yaml:"includes"`
Excludes []string `yaml:"excludes"`
NoHeaders bool `yaml:no_headers`
Aggregates []string `yaml:"aggregates"`
StartTime string `yaml:"start_time"`
EndTime string `yaml:"end_time"`
StartTimeDuration string `yaml:"start_time_duration"`
EndTimeDuration string `yaml:"end_time_duration"`
IncludesStr string
ExcludesStr string
AggregatesStr string
}

func SetConfig(config Config, arg Config) Config {
if arg.File != "" {
config.File = arg.File
}

if arg.Reverse {
config.Reverse = arg.Reverse
}

if arg.QueryString {
config.QueryString = arg.QueryString
}

if arg.Tsv {
config.Tsv = arg.Tsv
}

if config.ApptimeLabel == "" {
config.ApptimeLabel = arg.ApptimeLabel
}

if config.SizeLabel == "" {
config.SizeLabel = arg.SizeLabel
}

if config.MethodLabel == "" {
config.MethodLabel = arg.MethodLabel
}

if config.UriLabel == "" {
config.UriLabel = arg.UriLabel
}

if config.TimeLabel == "" {
config.TimeLabel = arg.TimeLabel
}

if config.Limit == 0 {
config.Limit = arg.Limit
}

if arg.IncludesStr != "" {
config.Includes = strings.Split(arg.IncludesStr, ",")
}

if arg.ExcludesStr != "" {
config.Excludes = strings.Split(arg.ExcludesStr, ",")
}

if arg.NoHeaders {
config.NoHeaders = arg.NoHeaders
}

if arg.AggregatesStr != "" {
config.Aggregates = strings.Split(arg.AggregatesStr, ",")
}

if arg.StartTime != "" {
config.StartTime = arg.StartTime
}

if arg.EndTime != "" {
config.EndTime = arg.EndTime
}

if arg.StartTimeDuration != "" {
config.StartTimeDuration = arg.StartTimeDuration
}

if arg.EndTimeDuration != "" {
config.EndTimeDuration = arg.EndTimeDuration
}

return config
}
20 changes: 20 additions & 0 deletions example/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
file: # access.log
sort: # max|min|avg|sum|cnt|uri|method|max-body|min-body|avg-body|sum-body
reverse: # boolean
query_string: # boolean
tsv: # boolean
apptime_label: # apptime
size_label: # size
method_label: # method
uri_label: # uri
time_label: # time
limit: # 5000
includes: # array
excludes: # array
no_headers: # boolean
aggregates: # array
start_time: # 2006-01-02T15:04:05
end_time: # 2006-01-02 15:04:05
start_time_duration: # 1m
end_time_duration: # 1h
Loading

0 comments on commit 44892be

Please sign in to comment.