logger

package
v0.0.0-...-c13ee6f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	APICounter = APICallCounter{}

	DefaultCountValidSpan = 30 * time.Second
	DefaultCountSpanDays  = 30
)
View Source
var LogOptionPattern = DefaultLogPattern()

Functions

func CleanupUpdateDBTask

func CleanupUpdateDBTask(kill, finish chan bool)

func UpdateDBRoutine

func UpdateDBRoutine(ctx context.Context, appender Appender, interval time.Duration, kill, finish chan bool)

Types

type APICallCounter

type APICallCounter struct {
	sync.Map
}

func (*APICallCounter) GetCount

func (ac *APICallCounter) GetCount(ctx context.Context, apikey string, path model.URITemplate) (int, error)

type Appender

type Appender interface {
	UpdateDB(ctx context.Context)
	Do(key, path string, r *http.Request,
		apiResp *http.Response, calcBillingStatus func(resp *http.Response) BillingStatus) error
}

type BillingStatus

type BillingStatus int
const (
	NotBilling BillingStatus = iota
	Billing
)

func (BillingStatus) String

func (bs BillingStatus) String() string

type CSVAppender

type CSVAppender struct {
	Writer *csv.Writer

	LogItems LogItems
}

func NewCSVAppender

func NewCSVAppender(writer *csv.Writer) CSVAppender

func (*CSVAppender) Do

func (a *CSVAppender) Do(key, path string, r *http.Request,
	apiResp *http.Response, calcBillingStatus func(resp *http.Response) BillingStatus) error

func (*CSVAppender) UpdateDB

func (a *CSVAppender) UpdateDB(ctx context.Context)

type DefaultAppender

type DefaultAppender struct {
	Writer   io.Writer
	LogItems LogItems
}

func (*DefaultAppender) Do

func (a *DefaultAppender) Do(key, path string, r *http.Request,
	apiResp *http.Response, calcBillingStatus func(resp *http.Response) BillingStatus) error

func (*DefaultAppender) UpdateDB

func (a *DefaultAppender) UpdateDB(ctx context.Context)

type LogItem

type LogItem struct {
	TimeStamp     string        `dynamo:"timestamp"`
	Key           string        `dynamo:"api_key"`
	Path          string        `dynamo:"path"`
	StatusCode    int           `dynamo:"status_code"`
	BillingStatus BillingStatus `dynamo:"billing_status"`
}

func NewLogItem

func NewLogItem(key, path string, apiResp *http.Response, calcBillingStatus func(resp *http.Response) BillingStatus) (LogItem, error)

type LogItems

type LogItems struct {
	sync.Mutex
	Items []LogItem
}

func NewLogItems

func NewLogItems() LogItems

func (*LogItems) Append

func (li *LogItems) Append(item LogItem)

func (*LogItems) ReadAndDeleteAll

func (li *LogItems) ReadAndDeleteAll() []LogItem

type LogOption

type LogOption func(record *[]string, logItem *LogItem, r *http.Request)

func DefaultLogPattern

func DefaultLogPattern() []LogOption

func HeaderElement

func HeaderElement(name string) LogOption

func WithBillingStatus

func WithBillingStatus() LogOption

func WithKey

func WithKey() LogOption

func WithPath

func WithPath() LogOption

func WithResponseStatus

func WithResponseStatus() LogOption

func WithTime

func WithTime() LogOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL