address golint warnings
This commit is contained in:
parent
cd6b409971
commit
f3dc89699d
|
@ -24,17 +24,17 @@ import (
|
||||||
|
|
||||||
const Name = "flexiblego"
|
const Name = "flexiblego"
|
||||||
|
|
||||||
type FlexibleGoDateTimeParser struct {
|
type DateTimeParser struct {
|
||||||
layouts []string
|
layouts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFlexibleGoDateTimeParser(layouts []string) *FlexibleGoDateTimeParser {
|
func New(layouts []string) *DateTimeParser {
|
||||||
return &FlexibleGoDateTimeParser{
|
return &DateTimeParser{
|
||||||
layouts: layouts,
|
layouts: layouts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FlexibleGoDateTimeParser) ParseDateTime(input string) (time.Time, error) {
|
func (p *DateTimeParser) ParseDateTime(input string) (time.Time, error) {
|
||||||
for _, layout := range p.layouts {
|
for _, layout := range p.layouts {
|
||||||
rv, err := time.Parse(layout, input)
|
rv, err := time.Parse(layout, input)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -44,21 +44,21 @@ func (p *FlexibleGoDateTimeParser) ParseDateTime(input string) (time.Time, error
|
||||||
return time.Time{}, analysis.ErrInvalidDateTime
|
return time.Time{}, analysis.ErrInvalidDateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
func FlexibleGoDateTimeParserConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.DateTimeParser, error) {
|
func DateTimeParserConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.DateTimeParser, error) {
|
||||||
layouts, ok := config["layouts"].([]interface{})
|
layouts, ok := config["layouts"].([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("must specify layouts")
|
return nil, fmt.Errorf("must specify layouts")
|
||||||
}
|
}
|
||||||
layoutStrs := make([]string, 0)
|
var layoutStrs []string
|
||||||
for _, layout := range layouts {
|
for _, layout := range layouts {
|
||||||
layoutStr, ok := layout.(string)
|
layoutStr, ok := layout.(string)
|
||||||
if ok {
|
if ok {
|
||||||
layoutStrs = append(layoutStrs, layoutStr)
|
layoutStrs = append(layoutStrs, layoutStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NewFlexibleGoDateTimeParser(layoutStrs), nil
|
return New(layoutStrs), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.RegisterDateTimeParser(Name, FlexibleGoDateTimeParserConstructor)
|
registry.RegisterDateTimeParser(Name, DateTimeParserConstructor)
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestFlexibleDateTimeParser(t *testing.T) {
|
||||||
rfc3339NoTimezoneNoT := "2006-01-02 15:04:05"
|
rfc3339NoTimezoneNoT := "2006-01-02 15:04:05"
|
||||||
rfc3339NoTime := "2006-01-02"
|
rfc3339NoTime := "2006-01-02"
|
||||||
|
|
||||||
dateOptionalTimeParser := NewFlexibleGoDateTimeParser(
|
dateOptionalTimeParser := New(
|
||||||
[]string{
|
[]string{
|
||||||
time.RFC3339Nano,
|
time.RFC3339Nano,
|
||||||
time.RFC3339,
|
time.RFC3339,
|
||||||
|
|
|
@ -37,7 +37,7 @@ var layouts = []string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func DateTimeParserConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.DateTimeParser, error) {
|
func DateTimeParserConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.DateTimeParser, error) {
|
||||||
return flexible.NewFlexibleGoDateTimeParser(layouts), nil
|
return flexible.New(layouts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Reference in New Issue