utils

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 17 Imported by: 13

Documentation

Index

Constants

View Source
const ErrorKey = "error"

Variables

View Source
var ErrAlreadyExists = errors.New("already exists")
View Source
var ErrForbidden = errors.New("forbidden")
View Source
var ErrInvalid = errors.New("invalid input")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

func CleanPath

func CleanPath(p string) (string, error)

func CleanStaticURL added in v1.2.0

func CleanStaticURL(got string) (unescaped string, err error)

func CleanURL added in v1.0.0

func CleanURL(got string) (string, error)

func CodeBlock added in v1.0.0

func CodeBlock(in string) string

func FindDir

func FindDir(dir string) (string, bool)

FindDir looks for the given directory in nearby ancestors relative to the current working directory as well as the directory of the executable, falling back to `./` if not found.

func FirstN added in v1.2.1

func FirstN(s string, n int) string

func GetLocale added in v1.0.0

func GetLocale(mm *pluginapi.Client, config *model.Config, userID string) string

func GetLocaleWithUser added in v1.0.0

func GetLocaleWithUser(config *model.Config, user *model.User) string

func JSONBlock added in v1.0.0

func JSONBlock(in interface{}) string

func LastN

func LastN(s string, n int) string

func LoadSession

func LoadSession(mm *pluginapi.Client, sessionID, actingUserID string) (*model.Session, error)

func LogDigest added in v1.1.0

func LogDigest(i interface{}) string

func NewAlreadyExistsError

func NewAlreadyExistsError(args ...interface{}) error

func NewError

func NewError(source error, args ...interface{}) error

func NewForbiddenError

func NewForbiddenError(args ...interface{}) error

func NewInvalidError

func NewInvalidError(args ...interface{}) error

func NewNotFoundError

func NewNotFoundError(args ...interface{}) error

func NewUnauthorizedError

func NewUnauthorizedError(args ...interface{}) error

func Pretty

func Pretty(in interface{}) string

func Remarshal added in v1.0.0

func Remarshal(dst, src interface{})

func ToJSON

func ToJSON(in interface{}) string

Types

type ByteSize

type ByteSize int64

func ParseByteSize

func ParseByteSize(str string) (ByteSize, error)

func (ByteSize) String

func (size ByteSize) String() string

type HasLoggable added in v1.1.0

type HasLoggable interface {
	Loggable() []interface{}
}

type LocError added in v1.0.0

type LocError []*i18n.LocalizeConfig

func NewLocError added in v1.0.0

func NewLocError(err *i18n.LocalizeConfig) LocError

func (LocError) Error added in v1.0.0

func (err LocError) Error(bundle *i18n.Bundle, loc *i18n.Localizer) string

func (LocError) Wrap added in v1.0.0

func (err LocError) Wrap(e *i18n.LocalizeConfig) LocError

type LogConfig added in v1.2.0

type LogConfig struct {
	BotUserID   string
	ChannelID   string
	Level       zapcore.Level
	IncludeJSON bool
}

type LogConfigGetter added in v1.2.0

type LogConfigGetter interface {
	GetLogConfig() LogConfig
}

type Logger added in v1.0.0

type Logger interface {
	// from zap.SugaredLogger
	Debugf(template string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Warnf(template string, args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Infof(template string, args ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Errorf(template string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Fatalf(template string, args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	// implemented here to provide a consistent interface, without using
	// *zap.SugaredLogger
	WithError(error) Logger
	With(args ...interface{}) Logger
}

func MustMakeCommandLogger added in v1.0.0

func MustMakeCommandLogger(level zapcore.Level) Logger

func NewPluginLogger added in v1.0.0

func NewPluginLogger(mmapi *pluginapi.Client, confGetter LogConfigGetter) Logger

func NewTestLogger added in v1.0.0

func NewTestLogger() Logger

type NilLogger added in v1.2.0

type NilLogger struct{}

func (NilLogger) Debugf added in v1.2.0

func (NilLogger) Debugf(string, ...interface{})

func (NilLogger) Debugw added in v1.2.0

func (NilLogger) Debugw(string, ...interface{})

func (NilLogger) Errorf added in v1.2.0

func (NilLogger) Errorf(string, ...interface{})

func (NilLogger) Errorw added in v1.2.0

func (NilLogger) Errorw(string, ...interface{})

func (NilLogger) Fatalf added in v1.2.0

func (NilLogger) Fatalf(string, ...interface{})

func (NilLogger) Fatalw added in v1.2.0

func (NilLogger) Fatalw(string, ...interface{})

func (NilLogger) Infof added in v1.2.0

func (NilLogger) Infof(string, ...interface{})

func (NilLogger) Infow added in v1.2.0

func (NilLogger) Infow(string, ...interface{})

func (NilLogger) Warnf added in v1.2.0

func (NilLogger) Warnf(string, ...interface{})

func (NilLogger) Warnw added in v1.2.0

func (NilLogger) Warnw(string, ...interface{})

func (NilLogger) With added in v1.2.0

func (l NilLogger) With(args ...interface{}) Logger

func (NilLogger) WithError added in v1.2.0

func (l NilLogger) WithError(error) Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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