gokit

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MPL-2.0 Imports: 16 Imported by: 22

README

Build Status

About go kit

Frequently used by spot max team

Coverage

  1. logging
  2. formatting
  3. tool
  4. typically structure

Principle

  1. easy to use
  2. easy to maintain
  3. respect the open source author

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrESCreateIndex     = fmt.Errorf("es: create elasticsearch index error")
	ErrConsulKeyNotExist = fmt.Errorf("consul: key not exist")
)
View Source
var FileLineFormatter = &logrus.TextFormatter{
	CallerPrettyfier: func(f *runtime.Frame) (string, string) {
		filename := path.Base(f.File)
		return fmt.Sprintf("%s()", f.Function), fmt.Sprintf("%s:%d", filename, f.Line)
	},
}

Functions

func NewLogrusBufferHook added in v1.0.6

func NewLogrusBufferHook(levels []logrus.Level, size int) (*LogrusBufferHook, *RingBuffer)

return hook: for logrus buffer: for reading data

func Prettify

func Prettify(i interface{}) string

Prettify returns the string representation of a value.

func PrettifyJson

func PrettifyJson(i interface{}, indent bool) string

Only for normal logging purpose, 4 space indent

func PrettifyYaml added in v1.0.9

func PrettifyYaml(i interface{}) string

Only for normal logging purpose, 4 space indent

func Realpath added in v1.0.2

func Realpath(path string) string

Get file's real path, for example, go test issue

func String

func String(v string) *string

String returns a pointer to the string value passed in.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

Types

type Consul

type Consul struct {
	// contains filtered or unexported fields
}

func NewConsul

func NewConsul(address string) *Consul

func NewConsulToken added in v1.0.8

func NewConsulToken(address string, token string) *Consul

func (*Consul) GetKey

func (c *Consul) GetKey(key string) ([]byte, error)

func (*Consul) GetList added in v1.0.4

func (c *Consul) GetList(key string) (api.KVPairs, error)

func (*Consul) GetService

func (c *Consul) GetService(service string) ([]*api.ServiceEntry, error)

func (*Consul) PutKey

func (c *Consul) PutKey(key string, value []byte) error

type ESIndexRotate

type ESIndexRotate int
const (
	RotateNon ESIndexRotate = iota
	RotateDay
	RotateMonth
)

type ElasticHook

type ElasticHook struct {
	// contains filtered or unexported fields
}

func NewElasticHook

func NewElasticHook(client *elastic.Client, host string, level logrus.Level, index string, rotate ESIndexRotate) (*ElasticHook, error)

func (*ElasticHook) Cancel

func (hook *ElasticHook) Cancel()

func (*ElasticHook) Fire

func (hook *ElasticHook) Fire(entry *logrus.Entry) error

func (*ElasticHook) Levels

func (hook *ElasticHook) Levels() []logrus.Level

type Iterator

type Iterator struct {
	C <-chan interface{}
	// contains filtered or unexported fields
}

Iterator defines an iterator over a Set, its C channel can be used to range over the Set's elements.

func (*Iterator) Stop

func (i *Iterator) Stop()

Stop stops the Iterator, no further elements will be received on C, C will be closed.

type LogrusBufferHook added in v1.0.6

type LogrusBufferHook struct {
	// contains filtered or unexported fields
}

func (*LogrusBufferHook) Cancel added in v1.0.6

func (hook *LogrusBufferHook) Cancel()

func (*LogrusBufferHook) Fire added in v1.0.6

func (hook *LogrusBufferHook) Fire(entry *logrus.Entry) error

func (*LogrusBufferHook) Levels added in v1.0.6

func (hook *LogrusBufferHook) Levels() []logrus.Level

type RingBuffer added in v1.0.6

type RingBuffer struct {
	// contains filtered or unexported fields
}

func NewRingBuffer added in v1.0.6

func NewRingBuffer(size int) *RingBuffer

func (*RingBuffer) Read added in v1.0.6

func (r *RingBuffer) Read() []*RingBufferData

func (*RingBuffer) Write added in v1.0.6

func (r *RingBuffer) Write(p *RingBufferData)

type RingBufferData added in v1.0.7

type RingBufferData struct {
	Timestamp string `json:"timestamp"`
	Message   string `json:"message"`
	Level     string `json:"level"`
}

type Set

type Set interface {
	// Adds an element to the set. Returns whether
	// the item was added.
	Add(i interface{}) bool

	// Returns the number of elements in the set.
	Cardinality() int

	// Removes all elements from the set, leaving
	// the empty set.
	Clear()

	// Returns a clone of the set using the same
	// implementation, duplicating all keys.
	Clone() Set

	// Returns whether the given items
	// are all in the set.
	Contains(i ...interface{}) bool

	// Returns the difference between this set
	// and other. The returned set will contain
	// all elements of this set that are not also
	// elements of other.
	//
	// Note that the argument to Difference
	// must be of the same type as the receiver
	// of the method. Otherwise, Difference will
	// panic.
	Difference(other Set) Set

	// Determines if two sets are equal to each
	// other. If they have the same cardinality
	// and contain the same elements, they are
	// considered equal. The order in which
	// the elements were added is irrelevant.
	//
	// Note that the argument to Equal must be
	// of the same type as the receiver of the
	// method. Otherwise, Equal will panic.
	Equal(other Set) bool

	// Returns a new set containing only the elements
	// that exist only in both sets.
	//
	// Note that the argument to Intersect
	// must be of the same type as the receiver
	// of the method. Otherwise, Intersect will
	// panic.
	Intersect(other Set) Set

	// Iterates over elements and executes the passed func against each element.
	// If passed func returns true, stop iteration at the time.
	Each(func(interface{}) bool)

	// Returns a channel of elements that you can
	// range over.
	Iter() <-chan interface{}

	// Returns an Iterator object that you can
	// use to range over the set.
	Iterator() *Iterator

	// Remove a single element from the set.
	Remove(i interface{})

	// Provides a convenient string representation
	// of the current state of the set.
	String() string

	// same type as the receiver of the method.
	// Otherwise, IsSuperset will panic.
	Union(other Set) Set

	// Pop removes and returns an arbitrary item from the set.
	Pop() interface{}

	// Returns the members of the set as a slice.
	ToSlice() []interface{}
}

func NewSet

func NewSet(s ...interface{}) Set

func NewSetFromSlice

func NewSetFromSlice(s []interface{}) Set

type SimpleTimer

type SimpleTimer struct {
	// contains filtered or unexported fields
}

func NewSimpleTimer

func NewSimpleTimer(duration time.Duration) *SimpleTimer

func (*SimpleTimer) Checkpoint

func (t *SimpleTimer) Checkpoint() bool

if timeout, reset it automatically

func (*SimpleTimer) Reset

func (t *SimpleTimer) Reset()

reset timer to now

func (*SimpleTimer) Timeout

func (t *SimpleTimer) Timeout() bool

if time duration past

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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