period.go 915 字节
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
package goku_log

import (
	"fmt"
	"strings"
)

type LogPeriod interface {
	String() string
	FormatLayout()string
}
type LogPeriodType int

func ParsePeriod(v string)(LogPeriod,error)  {
	switch strings.ToLower(v) {
	case "month":
		return PeriodMonth,nil
	case "day":
		return PeriodDay,nil
	case "hour":
		return PeriodHour,nil
	}

	return nil, fmt.Errorf("not a valid period: %q", v)
}
func (period LogPeriodType) String() string {
	switch period {
	case PeriodMonth:
		return "month"
	case PeriodDay:
		return "day"
	case PeriodHour:
		return "hour"
	default:
		return "unknown"
	}
}

const (
	PeriodMonth LogPeriodType = iota
	PeriodDay
	PeriodHour
)


func (period LogPeriodType) FormatLayout() string {
	switch period {
	case PeriodHour:
		{
			return  "2006-01-02-15"
		}
	case PeriodDay:
		{
			return "2006-01-02"
		}
	case PeriodMonth:
		{
			return "2006-01"
		}
	default:
		return "2006-01-02-15"
	}
}