stdlib

package module
v0.2.3-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MEMORY_CACHE_TYPE = "Memory"
	REDIS_CACHE_TYPE  = "Redis"
)
View Source
const (
	INVALID_VALUE_COUNT     = "invalid number of values"
	VERSION_INVALID_LENGTH  = "invalid version length"
	TRACEID_INVALID_LENGTH  = "invalid traceid length"
	PARENTID_INVALID_LENGTH = "invalid parentid length"
	FLAG_INVALID_LENGTH     = "invalid flag length"
	TRACEID_IS_ZERO         = "error traceid value is zero"
	PARENTID_IS_ZERO        = "error parentid value is zero"
)

Variables

View Source
var (
	Err_KEY_NOT_FOUND = fmt.Errorf("key not found")
)

Functions

func ConsoleLogger

func ConsoleLogger(args ...string) *zap.SugaredLogger

func GenerateNewTraceparent

func GenerateNewTraceparent(sampled bool) (string, error)

func GenerateParentId

func GenerateParentId() (string, error)

Counting on go compiler to inline these plsplspls :)

func GenerateParentIdRaw

func GenerateParentIdRaw() ([]byte, error)

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

func GenerateTraceId

func GenerateTraceId() (string, error)

func GenerateTraceIdRaw

func GenerateTraceIdRaw() ([]byte, error)

func NewContextWithCancel

func NewContextWithCancel() (Context, Cancel)

func NewContextWithDeadline

func NewContextWithDeadline(deadline time.Time) (Context, Cancel)

func ParseTraceparent

func ParseTraceparent(
	traceparent string,
) (string, string, string, string, error)

func ParseTraceparentRaw

func ParseTraceparentRaw(
	traceparent string,
) ([]byte, []byte, []byte, []byte, error)

func ValidateParentIdValue

func ValidateParentIdValue(parentId []byte) error

func ValidateTraceIdValue

func ValidateTraceIdValue(traceId []byte) error

Types

type AuthProvider

type AuthProvider interface {
	GetAuthHeader() string
}

type Cache

type Cache interface {
	Get(key string) (interface{}, error)
	Set(key string, value interface{}) error
	SetWithExpiration(key string, value interface{}, expiration time.Duration) error
	GetCtx(ctx context.Context, key string) (interface{}, error)
	SetCtx(ctx context.Context, key string, value interface{}) error
	SetWithExpirationCtx(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	Delete(key string) error
	DeleteCtx(ctx context.Context, key string) error
	Keys(pattern string) ([]string, error)
	KeysCtx(ctx context.Context, pattern string) ([]string, error)
	WithLogger(l *zap.Logger) Cache
	WithTracer(t *tracer.AppInsightsCore) Cache
	WithName(name string) Cache
}

func CreateFailedMockCacher

func CreateFailedMockCacher() Cache

func CreateSuccessMockCacher

func CreateSuccessMockCacher() Cache

func InitMemoryCache

func InitMemoryCache(
	expiration time.Duration,
	cleanupInterval time.Duration,
) Cache

func InitRedisCache

func InitRedisCache(
	url string,
) (Cache, error)

type Cancel

type Cancel func()

type Client

type Client interface {
	Get(ctx Context, baseUrl string, query string, opt *ClientOptions, dest interface{}) (int, error)
	Put(ctx Context, baseUrl string, query string, opt *ClientOptions, body interface{}, dest interface{}) (int, error)
	Del(ctx Context, baseUrl string, query string, opt *ClientOptions, dest interface{}) (int, error)
	Post(ctx Context, baseUrl string, query string, opt *ClientOptions, body interface{}, dest interface{}) (int, error)
	Patch(ctx Context, baseUrl string, query string, opt *ClientOptions, body interface{}, dest interface{}) (int, error)
	// contains filtered or unexported methods
}

func ClientProvider

func ClientProvider() Client

type ClientOptions

type ClientOptions struct {
	Authorization string             `json:"authorization"`
	ContentType   string             `json:"content_type"`
	Query         string             `json:"query"`
	Headers       *map[string]string `json:"headers"`
	Timeout       *time.Time         `json:"timeout"`
	RequestType   string             `json:"request_type"`
	// contains filtered or unexported fields
}

type Context

type Context struct {
	context.Context
	Res  chan interface{}
	Code int
	// contains filtered or unexported fields
}

func NewContext

func NewContext() Context

func WrapContext

func WrapContext(ctx context.Context) Context

func (*Context) AddDeadline

func (r *Context) AddDeadline(deadline time.Time) Cancel

func (*Context) Cancel

func (r *Context) Cancel()

func (*Context) CompletionHandler

func (r *Context) CompletionHandler(code int, result interface{})

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Error

func (c *Context) Error() error

func (*Context) OnCancel

func (c *Context) OnCancel() <-chan struct{}

func (*Context) Value

func (r *Context) Value(key string) interface{}

func (*Context) WithValue

func (r *Context) WithValue(key, val interface{})

type NativeDatabase

type NativeDatabase interface {
	Begin() (*TracedNativeTx, error)
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*TracedNativeTx, error)
	Close() error
	Conn(ctx context.Context) (*sql.Conn, error)
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Ping() error
	PingContext(ctx context.Context) error
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
	SetConnMaxIdleTime(d time.Duration)
	SetConnMaxLifetime(d time.Duration)
	Stats() sql.DBStats
	WithLogger(l *zap.Logger) NativeDatabase
}

func NativeDatabaseProvider

func NativeDatabaseProvider(Driver string, DSN string) NativeDatabase

func TracedNativeDBWrapper

func TracedNativeDBWrapper(
	Driver string,
	DSN string,
	t *tracer.AppInsightsCore,
	name string,
) NativeDatabase

type Pooler added in v0.3.0

type Pooler[T any] interface {
	Get() *T
	Clear()
	Size() int
}

func NewPool added in v0.3.0

func NewPool[T any](
	initFunction func() *T,
	opt *PoolingOptions,
) (Pooler[T], error)

type PoolingOptions added in v0.3.0

type PoolingOptions struct {
	PoolSize int
}

type TracedClient

type TracedClient interface {
	Get(ctx context.Context, Url string, opt *ClientOptions, dest interface{}) (int, error)
	Put(ctx context.Context, Url string, opt *ClientOptions, body interface{}, dest interface{}) (int, error)
	Del(ctx context.Context, Url string, opt *ClientOptions, dest interface{}) (int, error)
	Post(ctx context.Context, Url string, opt *ClientOptions, body interface{}, dest interface{}) (int, error)
	Patch(ctx context.Context, Url string, opt *ClientOptions, body interface{}, dest interface{}) (int, error)

	SetAuthHandler(provider AuthProvider)
	WithClientName(clientName string) TracedClient
	// contains filtered or unexported methods
}

func TracedClientProvider

func TracedClientProvider(
	t *tracer.AppInsightsCore,
	l *zap.Logger,
) TracedClient

func TracedClientProviderWithName

func TracedClientProviderWithName(
	t *tracer.AppInsightsCore,
	l *zap.Logger,
	clientName string,
) TracedClient

type TracedNativeTx

type TracedNativeTx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

func (*TracedNativeTx) Commit

func (t *TracedNativeTx) Commit() error

func (*TracedNativeTx) Exec

func (t *TracedNativeTx) Exec(query string, args ...interface{}) (sql.Result, error)

func (*TracedNativeTx) ExecContext

func (t *TracedNativeTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*TracedNativeTx) Query

func (t *TracedNativeTx) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*TracedNativeTx) QueryContext

func (t *TracedNativeTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (*TracedNativeTx) QueryRow

func (t *TracedNativeTx) QueryRow(query string, args ...interface{}) *sql.Row

func (*TracedNativeTx) QueryRowContext

func (t *TracedNativeTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (*TracedNativeTx) Rollback

func (t *TracedNativeTx) Rollback() error

Jump to

Keyboard shortcuts

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