slackutil

package
v0.0.0-...-c6ea6ab Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: LGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSlackAuthTestFailed = errutil.NewFactory("slack client auth test failed")
	ErrSlackFormatFailed1  = errutil.NewFactory("format slack message failed %q")
)

errors

View Source
var (
	ErrorSlackUnexpectedResponseBody1   = errutil.NewFactory("unexpected slack response body: %v")
	ErrorSlackUnexpectedResponseStatus1 = errutil.NewFactory("unexpected slack response status: %v")
)

errors

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	// show error position with short filename
	ShortFile bool
	// hide error position with line number
	HideLine bool
	// show customized user name for slack message
	UserName string
	// filter runtime caller
	CallerFilter []runtimecaller.Filter
	// replace package name for securify
	ReplacePackages map[string]string
}

Formatter used to format error object to slack message

type IncomingWebHook

type IncomingWebHook struct {
	WebHookURL string `json:"webhookurl,omitempty"`
	Channel    string `json:"channel,omitempty"`
	IconEmoji  string `json:"icon_emoji,omitempty"`
}

func (*IncomingWebHook) SendMessage

func (t *IncomingWebHook) SendMessage(message IncomingWebHookMessage) (err error)

type IncomingWebHookMessage

type IncomingWebHookMessage struct {
	Channel   string `json:"channel,omitempty"`
	Username  string `json:"username,omitempty"`
	Text      string `json:"text,omitempty"`
	IconEmoji string `json:"icon_emoji,omitempty"`
}

func (*IncomingWebHookMessage) FillEmptyFieldWithDefaultValue

func (t *IncomingWebHookMessage) FillEmptyFieldWithDefaultValue(config IncomingWebHook)

type LoggerOptions

type LoggerOptions struct {
	// default log channel, default: "#general"
	ChannelDefault string
	// channel for debug, fallback to Default channel if empty
	ChannelDebug string
	// channel for error, fallback to Default channel if empty
	ChannelError string

	// format log
	Formatter Formatter

	// fallback logger when slack log failed, default: errutil.Logger()
	FallbackLogger errutil.LoggerType

	// context for async api call, default: context.Background()
	Context context.Context
	// message queue size for async api call, default: 10
	MessageQueueSize int64
	// worker count for async api call, default: 1
	Worker int
	// do not use async api call
	Sync bool
	// flush timeout before close, default 3 seconds
	FlushTimeout time.Duration
}

LoggerOptions options for create logger

type LoggerType

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

LoggerType logger main type

func NewLogger

func NewLogger(token string, opt LoggerOptions) (instance *LoggerType, err error)

NewLogger create new Logger instance

func (*LoggerType) Close

func (t *LoggerType) Close() (err error)

Close cancel slack context and wait for worker loop done

func (LoggerType) Debug

func (t LoggerType) Debug(v ...interface{})

Debug output message to slack debug channel

func (LoggerType) Debugf

func (t LoggerType) Debugf(format string, a ...interface{})

Debugf output message to slack debug channel

func (LoggerType) Error

func (t LoggerType) Error(v ...interface{})

Error output message to slack error channel

func (LoggerType) Errorf

func (t LoggerType) Errorf(format string, a ...interface{})

Errorf output message to slack error channel

func (LoggerType) Print

func (t LoggerType) Print(v ...interface{})

Print output message to slack default channel

func (LoggerType) Printf

func (t LoggerType) Printf(format string, a ...interface{})

Printf output message to slack default channel

func (LoggerType) Trace

func (t LoggerType) Trace(errin error)

Trace output message to slack error channel if errin is not nil

Jump to

Keyboard shortcuts

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