Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateNewTraceparent(sampled bool) (string, error)
- func GenerateParentId() (string, error)
- func GenerateParentIdRaw() ([]byte, error)
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateTraceId() (string, error)
- func GenerateTraceIdRaw() ([]byte, error)
- func ParseTraceparent(traceparent string) (string, string, string, string, error)
- func ParseTraceparentRaw(traceparent string) ([]byte, []byte, []byte, []byte, error)
- func ValidateParentIdValue(parentId []byte) error
- func ValidateTraceIdValue(traceId []byte) error
- type AuthProvider
- type Cache
- type Client
- type ClientOptions
- type NativeDatabase
- type Pooler
- type PoolingOptions
- type TracedClient
- type TracedNativeTx
- func (t *TracedNativeTx) Commit() error
- func (t *TracedNativeTx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (t *TracedNativeTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (t *TracedNativeTx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *TracedNativeTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (t *TracedNativeTx) QueryRow(query string, args ...interface{}) *sql.Row
- func (t *TracedNativeTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (t *TracedNativeTx) Rollback() error
Constants ¶
const ( MEMORY_CACHE_TYPE = "Memory" REDIS_CACHE_TYPE = "Redis" )
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 ¶
var (
Err_KEY_NOT_FOUND = fmt.Errorf("key not found")
)
Functions ¶
func GenerateNewTraceparent ¶
func GenerateParentId ¶
Counting on go compiler to inline these plsplspls :)
func GenerateParentIdRaw ¶
func GenerateRandomBytes ¶
func GenerateTraceId ¶
func GenerateTraceIdRaw ¶
func ParseTraceparent ¶
func ParseTraceparentRaw ¶
func ValidateParentIdValue ¶
func ValidateTraceIdValue ¶
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 ¶
InitMemoryCache initializes cache with in-memory type params:
- expiration: expiration time
- cleanupInterval: cleanup interval
returns:
- Cache: cache instance
func InitRedisCache ¶
InitRedisCache initializes cache with redis type params:
- url: redis url
returns:
- Cache: cache instance
- error: error if any
type Client ¶
type Client 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)
WithLogger(l *zap.Logger) Client
// contains filtered or unexported methods
}
func ClientProvider ¶
ClientProvider returns a new instance of Client This is a constructor function params:
- none
returns:
- Client
- error
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
}
ClientOptions is a struct that contains the options for the http client Parameters:
Authorization: The authorization header ContentType: The content type of the request Query: The query string Headers: The headers to be sent with the request Timeout: The timeout for the request RequestType: The type of request to be made
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
NativeDatabaseProvider returns a NativeDatabase interface for the given driver and DSN WARNING: It will panic if the driver is not supported
func TracedNativeDBWrapper ¶
func TracedNativeDBWrapper( Driver string, DSN string, t *tracer.AppInsightsCore, name string, ) NativeDatabase
TracedNativeDBWrapper returns a NativeDatabase interface for the given driver and DSN WARNING: It will panic if the driver is not supported
type Pooler ¶ added in v0.3.0
func NewPool ¶ added in v0.3.0
func NewPool[T any]( initFunction func() *T, opt *PoolingOptions, ) (Pooler[T], error)
NewPool creates a new pool of entities params:
- initFunction: func() *T => function that returns a new entity<T>
- opt: *PoolingOptions => options for the pool
returns:
- Pooler<T>: pool of entities
- error: error if any
type PoolingOptions ¶ added in v0.3.0
type PoolingOptions struct {
PoolSize int
}
PoolingOptions is the options for the pool params:
- PoolSize: int => size of the pool
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
TracedClientProvider returns a new instance of the TracedClient Params:
- t: The tracer to be used check the tracer package for more details at https://github.com/BetaLixT/appInsightsTrace
- l: The zap logger to be used
Returns:
- TracedClient: The TracedClient instance
func TracedClientProviderWithName ¶
func TracedClientProviderWithName( t *tracer.AppInsightsCore, l *zap.Logger, clientName string, ) TracedClient
TracedClientProviderWithName returns a new instance of the TracedClient Params:
- t: The tracer to be used check the tracer package for more details at
- l: The zap logger to be used
- clientName: The name of the client
Returns:
- TracedClient: The TracedClient instance
type TracedNativeTx ¶
func (*TracedNativeTx) Commit ¶
func (t *TracedNativeTx) Commit() error
Commit commits the transaction. params:
- none
returns:
- error: error if any
func (*TracedNativeTx) Exec ¶
func (t *TracedNativeTx) Exec(query string, args ...interface{}) (sql.Result, error)
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query. params:
- query: query to execute
- args: arguments to pass to query
returns:
- sql.Result: result of query
- error: error if any
func (*TracedNativeTx) ExecContext ¶
func (t *TracedNativeTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query. params:
- query: query to execute
- args: arguments to pass to query
returns:
- sql.Result: result of query
- error: error if any
func (*TracedNativeTx) Query ¶
func (t *TracedNativeTx) Query(query string, args ...interface{}) (*sql.Rows, error)
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query. params:
- query: query to execute
- args: arguments to pass to query
returns:
- sql.Result: result of query
- error: error if any
func (*TracedNativeTx) QueryContext ¶
func (t *TracedNativeTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. params:
- ctx: context
- query: query to execute
- args: arguments to pass to query
returns:
- *sql.Rows: rows returned by query
- error: error if any
func (*TracedNativeTx) QueryRow ¶
func (t *TracedNativeTx) QueryRow(query string, args ...interface{}) *sql.Row
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. params:
- query: query to execute
- args: arguments to pass to query
returns:
- *sql.Row: row returned by query
func (*TracedNativeTx) QueryRowContext ¶
func (t *TracedNativeTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query. params:
- query: query to execute
- args: arguments to pass to query
returns:
- *sql.Row: row returned by query
func (*TracedNativeTx) Rollback ¶
func (t *TracedNativeTx) Rollback() error
Rollback aborts the transaction. params:
- none
returns:
- error: error if any