lib

package
v0.0.0-...-9de2c1c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package lib is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error, code int) error

Wraps an error with an error code.

func CreateHttpClient

func CreateHttpClient(conn redis.Conn) *http.Client

CreateHttpClient creates a http.Client instance which will cache responses inside our Redis database

func Error

func Error(code int, s string) error

Returns an error with the given message and status code.

func Errorf

func Errorf(code int, s string, args ...interface{}) error

Returns an error with the given message format and status code.

func GenSnowflake

func GenSnowflake() snowflake.ID

GenSnowflake generates a snowflake ID.

func GenToken

func GenToken() (string, error)

Generates a random, 64-bit token, encoded as base62.

func GetDB

func GetDB(ctx context.Context) *gorm.DB

GetDB returns the DB associated with the context, or nil.

func GetHttpClient

func GetHttpClient(ctx context.Context) *http.Client

GetHttpClient returns the Http client associated with the context, or nil

func GetLogger

func GetLogger(ctx context.Context) *zap.Logger

GetLogger returns the logger associated with the context, or the global logger if none is set.

func GetRedis

func GetRedis(ctx context.Context) *redis.Client

GetRedis returns the Redis client associated with the context, or nil.

func NormalizeURL

func NormalizeURL(u url.URL) url.URL

func Report

func Report(ctx context.Context, err error, msg string)

Report logs an error to the global logger. Useful for `defer conn.Close()`-type constructs, where there's not really anything useful to do with the error, but you still want to log it.

func RootURL

func RootURL(url url.URL) url.URL

func WithDB

func WithDB(ctx context.Context, db *gorm.DB) context.Context

WithDB associates a DB with a context.

func WithHttpClient

func WithHttpClient(ctx context.Context, cli *http.Client) context.Context

WithHttpClient associates the HttpClient with a context

func WithLogger

func WithLogger(ctx context.Context, l *zap.Logger) context.Context

WithLogger associates a logger with a context.

func WithLoggerFields

func WithLoggerFields(ctx context.Context, f ...zap.Field) context.Context

func WithNamedLogger

func WithNamedLogger(ctx context.Context, name string) context.Context

WithLogger is a shorthand for associating a named sub-logger with a context.

func WithRedis

func WithRedis(ctx context.Context, r *redis.Client) context.Context

WithRedis associates a Redis connection with a context.

func Wrap

func Wrap(err error, code int, s string) error

Wraps an error with an error code and message.

func Wrapf

func Wrapf(err error, code int, s string, args ...interface{}) error

Wraps an error with an error code and message.

Types

type Err

type Err struct {
	Err        error
	StatusCode int
}

Error attaches a status code to an error.

func (Err) Cause

func (err Err) Cause() error

Satisfies errors.causer.

func (Err) Error

func (err Err) Error() string

Satisfies error.

type MockSnowflakeGenerator

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

MockSnowflakeGenerator is a mock of SnowflakeGenerator interface

func NewMockSnowflakeGenerator

func NewMockSnowflakeGenerator(ctrl *gomock.Controller) *MockSnowflakeGenerator

NewMockSnowflakeGenerator creates a new mock instance

func (*MockSnowflakeGenerator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockSnowflakeGenerator) Generate

func (m *MockSnowflakeGenerator) Generate() snowflake.ID

Generate mocks base method

type MockSnowflakeGeneratorMockRecorder

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

MockSnowflakeGeneratorMockRecorder is the mock recorder for MockSnowflakeGenerator

func (*MockSnowflakeGeneratorMockRecorder) Generate

Generate indicates an expected call of Generate

type SnowflakeGenerator

type SnowflakeGenerator interface {
	Generate() snowflake.ID
}
var DefaultSnowflakeGenerator SnowflakeGenerator

Directories

Path Synopsis
Package redis provides a redis interface for http caching.
Package redis provides a redis interface for http caching.

Jump to

Keyboard shortcuts

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