mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
Adding src/helpers.go
This commit is contained in:
parent
da28a68943
commit
704965b9cc
2 changed files with 49 additions and 0 deletions
20
src/helpers.go
Normal file
20
src/helpers.go
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/inconshreveable/log15"
|
||||||
|
)
|
||||||
|
|
||||||
|
func parseLogFormatter(name string) log.Format {
|
||||||
|
|
||||||
|
switch name {
|
||||||
|
case "logfmt" :
|
||||||
|
return log.LogfmtFormat()
|
||||||
|
case "json" :
|
||||||
|
return log.JsonFormat()
|
||||||
|
case "json-pretty" :
|
||||||
|
return log.JsonFormatEx(true, true)
|
||||||
|
default :
|
||||||
|
return log.TerminalFormat()
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/helpers_test.go
Normal file
29
src/helpers_test.go
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
log "github.com/inconshreveable/log15"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_parseLogFormatter(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
arg string
|
||||||
|
want log.Format
|
||||||
|
}{
|
||||||
|
{ "Default", "", log.TerminalFormat() },
|
||||||
|
{ "LogFmt", "logfmt", log.LogfmtFormat() },
|
||||||
|
{ "Json", "json", log.JsonFormat() },
|
||||||
|
{ "JsonPretty", "json-pretty", log.JsonFormat() },
|
||||||
|
{ "Unknown", "unknown", log.TerminalFormat() },
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := parseLogFormatter(tt.arg); reflect.ValueOf(got).Pointer() != reflect.ValueOf(tt.want).Pointer() {
|
||||||
|
t.Errorf("parseLogFormatter() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue