utils

package
v0.0.0-...-8588863 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinUserId       = int64(0)
	MaxUserId       = int64(math.MaxInt32)
	DoNotChangeHash = 512
	DoNotChangeStep = 10 * 10000
	RegSectNum      = 5
	RoutingSectNum  = 6
)
View Source
const (
	MaxRetryNum   = 3
	RetryInterval = time.Millisecond * 250
)

Variables

View Source
var (
	ErrInvalidParameter = errors.New("invalid parameter")
	ErrNoRoutingFound   = errors.New("no routing found")
	ErrSectionNotReady  = errors.New("section not ready")
	ErrAllocExists      = errors.New("alloc exists")
	ErrUnexpectedRules  = errors.New("unexpected rules")
	ErrAllocNotReady    = errors.New("alloc not ready")
)

Functions

func DELETE

func DELETE(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func GET

func GET(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func POST

func POST(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func PUT

func PUT(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func Sign

func Sign(secret string, timestamp int64) (string, error)

Types

type Config

type Config struct {
	Server   *ServerConfig   `json:"server,omitempty" yaml:"server"`
	Storage  *StorageConfig  `json:"storage,omitempty" yaml:"storage"`
	Reporter *ReporterConfig `json:"reporter,omitempty" yaml:"reporter"`
}

func NewConfig

func NewConfig(ctx context.Context, path string) (*Config, error)

func NewTestConfig

func NewTestConfig() *Config

func (*Config) Check

func (c *Config) Check() bool

func (*Config) GetEtcdId

func (c *Config) GetEtcdId() string

func (*Config) GetMySQLSource

func (c *Config) GetMySQLSource() string

func (*Config) GetTable

func (c *Config) GetTable() string

func (*Config) GetType

func (c *Config) GetType() StorageType

type Content

type Content struct {
	Text string `json:"text"`
}

type EtcdConfig

type EtcdConfig struct {
	Endpoints string `json:"endpoints,omitempty" yaml:"endpoints"`
	Identity  string `json:"identity,omitempty" yaml:"identity"`
}

type Hash

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

func NewHash

func NewHash(ctx context.Context, nodes []string) *Hash

func (*Hash) Get

func (h *Hash) Get(ctx context.Context, name string) string

type LarkBot

type LarkBot struct {
	*RestyClient
	// contains filtered or unexported fields
}

func NewLarkBot

func NewLarkBot(ctx context.Context, config *Config) (*LarkBot, error)

func (*LarkBot) SendMsg

func (l *LarkBot) SendMsg(ctx context.Context, format string, args ...interface{})

type MySQLConfig

type MySQLConfig struct {
	Host         string `json:"host,omitempty" yaml:"host"`
	Port         int    `json:"port,omitempty" yaml:"port"`
	Protocol     string `json:"protocol,omitempty" yaml:"protocol"`
	Database     string `json:"database,omitempty" yaml:"database"`
	Username     string `json:"username,omitempty" yaml:"username"`
	Password     string `json:"password,omitempty" yaml:"password"`
	Charset      string `json:"charset,omitempty" yaml:"charset"`
	PingInterval int    `json:"ping_interval,omitempty" yaml:"ping_interval"`
	MaxIdleConn  int    `json:"max_idle_conn,omitempty" yaml:"max_idle_conn"`
	MaxOpenConn  int    `json:"max_open_conn,omitempty" yaml:"max_open_conn"`
}

type RedisConfig

type RedisConfig struct {
	Network   string `json:"network,omitempty" yaml:"network"`
	Addr      string `json:"addr,omitempty" yaml:"addr"`
	Username  string `json:"username,omitempty" yaml:"username"`
	Password  string `json:"password,omitempty" yaml:"password"`
	Database  int    `json:"database,omitempty" yaml:"database"`
	KeyPrefix string `json:"key_prefix,omitempty" yaml:"key_prefix"`
}

type ReporterConfig

type ReporterConfig struct {
	Webhook string `json:"webhook,omitempty" yaml:"webhook"`
	Secret  string `json:"secret,omitempty" yaml:"secret"`
}

type Response

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

type RestyClient

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

func NewRestyClient

func NewRestyClient(hc *http.Client) (*RestyClient, error)

func (*RestyClient) DELETE

func (r *RestyClient) DELETE(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func (*RestyClient) GET

func (r *RestyClient) GET(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func (*RestyClient) POST

func (r *RestyClient) POST(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

func (*RestyClient) PUT

func (r *RestyClient) PUT(ctx context.Context, url, token string, body interface{}, timeout time.Duration) ([]byte, error)

type ServerConfig

type ServerConfig struct {
	Addr     string `json:"addr,omitempty" yaml:"addr"`
	Name     string `json:"name,omitempty" yaml:"name"`
	LogLevel string `json:"log_level,omitempty" yaml:"log_level"`
	Table    string `json:"table,omitempty" yaml:"table"`
}

type StorageConfig

type StorageConfig struct {
	Type  StorageType  `json:"type,omitempty" yaml:"type"`
	Redis *RedisConfig `json:"redis,omitempty" yaml:"redis"`
	MySQL *MySQLConfig `json:"mysql,omitempty" yaml:"mysql"`
	Etcd  *EtcdConfig  `json:"etcd,omitempty" yaml:"etcd"`
}

type StorageType

type StorageType int
const (
	TypeRedis StorageType = 1
	TypeMysql StorageType = 2
)

type TextMessage

type TextMessage struct {
	Timestamp string   `json:"timestamp,omitempty"`
	Sign      string   `json:"sign,omitempty"`
	MsgType   string   `json:"msg_type,omitempty"`
	Content   *Content `json:"content,omitempty"`
}

Jump to

Keyboard shortcuts

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