bi

package
v0.0.0-...-012d1c6 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInit    = errors.New("not init")
	ErrHasInit    = errors.New("has init")
	ErrTooManyMsg = errors.New("too many msg")
	ErrBadOption  = errors.New("bad option")
	ErrBadEvent   = errors.New("bad event")
)

Functions

func DefaultEncode

func DefaultEncode(events []*Message) []byte

默认使用json编码,且字段名固定

func Init

func Init(opts *Options) error

初始化数据

func Send

func Send(event string, params M) error

func Sendx

func Sendx(s interface{}) error

通过反射类发送

func Stop

func Stop()

Types

type Client

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

BI统计 一:需要统计的数据 全局ID:可用于重发排重 事件ID:用于区分参数含义 时间戳:标识发送时间 参数: 任意kv结构

二:支持的特性 1.异步发送 2.缓存一定数量,超过则会丢失 3.可批量发送 4.json编码 5.默认http发送,可扩展

三:一些注意 1.虽然会缓存数据,但是超过上限后依然会丢弃数据,防止占用内存过大导致宕机 2.默认实现了http协议,效率可能没有那么高,可考虑使用MQ

func (*Client) Init

func (r *Client) Init(opts *Options) error

func (*Client) Send

func (r *Client) Send(event string, params M) error

func (*Client) Stat

func (r *Client) Stat() Stat

func (*Client) Stop

func (r *Client) Stop()

type Encode

type Encode func(events []*Message) []byte

编码器,默认json编码,并且自动名固定

type HttpTransport

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

func (*HttpTransport) Init

func (t *HttpTransport) Init()

func (*HttpTransport) Send

func (t *HttpTransport) Send(opts *Options, datas []byte) error

type M

type M = map[string]interface{}

func Reflect

func Reflect(s interface{}) (string, M, error)

默认key使用小写snake形式输出 通过反射获取要发送的内容

type Message

type Message struct {
	ID     string
	Time   time.Time
	Event  string
	Params M
	// contains filtered or unexported fields
}

type Options

type Options struct {
	Tran   Transport     // 默认http
	URL    string        // 发送地址
	Batch  int           // 批量发送大小
	Retry  int           // 尝试重发次数
	Max    int           // 最大缓存数,超出则丢弃
	Wait   time.Duration // 最大等待时间,超过此时间,则强制退出
	Encode Encode        // 编码器
}

配置信息,通常只需要设置URL,其他使用默认值

type Queue

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

单向非循环队列

func (*Queue) Empty

func (q *Queue) Empty() bool

func (*Queue) Len

func (q *Queue) Len() int

func (*Queue) Pop

func (q *Queue) Pop(records []*Message) []*Message

返回N个数据

func (*Queue) Push

func (q *Queue) Push(m *Message)

type Stat

type Stat struct {
	Success int   // 成功次数
	Fail    int   // 失败次数
	Err     error // 最后一次错误
}

type Transport

type Transport interface {
	Send(opts *Options, events []byte) error
}

用于编码并发送消息

func NewHttp

func NewHttp() Transport

Jump to

Keyboard shortcuts

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