plugins

package
v0.0.0-...-d28bcca Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

travel 项目 第三发 插件包 插件包括 ffmpeg (用于音视频处理的工具) nats,pusher (简单站内消息通知工具,简单rpc服务) qrcode (二维码处理工具插件) qinniu (oss 七牛云服务)

Index

Constants

View Source
const (
	EtcdProvider        = "etcd"
	EtcdEndpointsEnvKey = "ETCD_ENDPOINTS"
)
View Source
const (
	LimiterPlugin         = "limiter"
	LimiterTokenPolicy    = "token"
	PolicyKey             = "policy"
	GlobalPolicyEnvKey    = "LIMIT_POLICY"
	TokenCtxValueKey      = "token"
	MacCtxValueKey        = "mac"
	MinAccessTimeInterval = 100 * time.Microsecond // api 访问时间间隔
	MaxAccessTimes        = 10                     // api 最大访问次数
)
View Source
const (
	NatsUserKey  = "NATS_USER"
	NatsName     = "NATS_NAME"
	NatsPassword = "NATS_PASSWORD"
	NatsConnUrl  = "NATS_CONN_URL"
	NatsNkey     = "NATS_NKEY"
	NatsSeedKey  = "NATS_SEED_KEY"
	NatsTokenKey = "NATS_TOKEN"
)
View Source
const (
	OssPluginName     = "oss"
	QinNiuPrefixKey   = "QINNIU_PREFIX"
	QinNiuAccessKey   = "AK"
	QinNiuSecretKey   = "SK"
	QinNiuBucketImg   = "IMG"
	QinNiuBucketVideo = "VIDEO"
	QinNiuReturnBody  = "RETURN_BODY"
	QinNiuCallbackUrl = "CALLBACK_URL"
	OssProviderQinNiu = "QinNiu"
	OssDefaultExpires = 1800
)
View Source
const (
	QrcodePluginName = "qrcode"
)

Variables

This section is empty.

Functions

func AppendCertificate

func AppendCertificate(Url string, expire int64) string

func GetConfigureCentreRepositoryMangerInstance

func GetConfigureCentreRepositoryMangerInstance() *configureCentreRepositoryMangerImpl

func GetEtcdClient

func GetEtcdClient() (*clientv3.Client, error)

func GetOssAccessUrl

func GetOssAccessUrl(key string, ossName string, bucket string) string

func GetQinNiuProperties

func GetQinNiuProperties() map[string]string

func GetQinNiuPropertiesKeys

func GetQinNiuPropertiesKeys() []string

func GetQinNiuProperty

func GetQinNiuProperty(key string, defaults ...string) string

func NewErrorResponse

func NewErrorResponse() []byte

func NewWatchHandler

func NewWatchHandler(handler EtcdWatcherHandler) func(watchChan clientv3.WatchChan)

func ScreenShot

func ScreenShot(filename string, storage string, services ...FFmpegPluginInterface) bool

截图

Types

type CContext

type CContext struct {
	TimeoutFn context.CancelFunc
	Cancel    context.CancelFunc
}

type ConfigBootStrap

type ConfigBootStrap interface {
	Boot()
}

type ConfigureCentreRepository

type ConfigureCentreRepository interface {
	Del(keys []string, appId ...string) int
	Put(key string, value interface{}, appId ...string) error
	Get(key string, appId ...string) (map[string]string, error)
	Pull(appId string) (map[string]string, error)
}

func EtcdConfigureCentreRepositoryOf

func EtcdConfigureCentreRepositoryOf() ConfigureCentreRepository

type ContextLimit

type ContextLimit interface {
	GetPolicy() string
	Ctx() context.Context
	SetPolicy(name string) ContextLimit
	SetValue(name string, value interface{}) ContextLimit
}

func NewContextLimit

func NewContextLimit() ContextLimit

type EtcdConfigureCentreRepository

type EtcdConfigureCentreRepository interface {
	ConfigureCentreRepository
	Watch(args WatchArgs)
	Count(key string) (int64, error)
	Keys(key ...string) ([]string, error)
}

type EtcdWatcherHandler

type EtcdWatcherHandler func(eventType mvccpb.Event_EventType, kv mvccpb.KeyValue, event *clientv3.Event)

type FFmpegPluginInterface

type FFmpegPluginInterface interface {
	GetScreenShotAt() string
	SetScreenShotAt(at time.Duration)
	SetBinary(bin string) FFmpegPluginInterface
	SaveScreenShot(file string, storage ...string) string
}

截图

func GetFfmpeg

func GetFfmpeg() FFmpegPluginInterface

type LimitResult

type LimitResult struct {
	Ok  bool   `json:"ok"`
	Msg string `json:"msg"`
}

type Limiter

type Limiter interface {
	Get(name string, ctx ContextLimit) func() *LimitResult
	New(ContextLimit) func(ctx ContextLimit) *LimitResult
	SetProvider(name string, provider func(ctx ContextLimit) *LimitResult)
	PluginInterface
}

Limiter 限流器

func GetLimiter

func GetLimiter() Limiter

type MapperDecoder

type MapperDecoder interface {
	M(...func(beego.M)) beego.M
}

type MsgRpc

type MsgRpc interface {
	Close()
	GetTimeOut() time.Duration
	SetTimeOut(duration time.Duration) MsgRpc
	Worker(handler interface{}) (*nats.Subscription, error)
	RpcCall(method string, data interface{}, responsePtr interface{}, timeOut ...time.Duration) error
	RpcService(method string, handler func(string, []byte) (interface{}, error)) (*nats.Subscription, error)
}

func GetMsgRpc

func GetMsgRpc() MsgRpc

type NatsConfig

type NatsConfig struct {
	Name     string `json:"name"`
	ConnUrl  string `json:"connUrl"`
	Nkey     string `json:"nkey,omitempty"`
	User     string `json:"user,omitempty"`
	NkeySeed string `json:"nkeySeed,omitempty"`
	Password string `json:"password,omitempty"`
	Token    string `json:"token,omitempty"`
}

配置

func NewNatsConfig

func NewNatsConfig() *NatsConfig

func NewNatsConfigByFile

func NewNatsConfigByFile(file string) *NatsConfig

type NatsPlugin

type NatsPlugin struct {
	Name   string      `json:"name"`
	Config *NatsConfig `json:"config"`
	// contains filtered or unexported fields
}

插件

func GetNatsPlugin

func GetNatsPlugin() *NatsPlugin

func (*NatsPlugin) GetConn

func (this *NatsPlugin) GetConn() *nats.Conn

获取conn

func (*NatsPlugin) Init

func (this *NatsPlugin) Init()

func (*NatsPlugin) PluginName

func (this *NatsPlugin) PluginName() string

func (*NatsPlugin) Register

func (this *NatsPlugin) Register()

type Options

type Options struct {
	Size            int                  `json:"size"`            // 二维码 (宽 X 高)
	FileName        string               `json:"filename"`        // 文件保存名路径
	BackgroundColor color.Color          `json:"backgroundColor"` // 背景色
	ForegroundColor color.Color          `json:"foregroundColor"` // 颜色
	Level           qrcode.RecoveryLevel `json:"level"`           // 质量
	Auto            bool                 `json:"auto"`            // 是否自动扩展 减少白边
}

func (*Options) GetLevel

func (this *Options) GetLevel() qr.ErrorCorrectionLevel

func (*Options) GetStorage

func (this *Options) GetStorage() string

func (*Options) Init

func (this *Options) Init()

type Oss

type Oss interface {
	CreateUploader(params OssParams, configures ...func(*storage.Config)) func(
		context.Context, ...func(*storage.PutExtra)) (interface{}, error)
}

type OssParams

type OssParams struct {
	Provider  string             `json:"provider"`          // 服务提供
	TypeName  string             `json:"type"`              // 图片 | 视频类型 IMG , VIDEO 按类型自动获取 bucket
	Token     string             `json:"token,omitempty"`   // 上传令牌
	Bucket    string             `json:"bucket,omitempty"`  // 存储桶 ,有对应类型时可选
	Storage   storage.Config     `json:"storage"`           // 存储配置 [ 区域,https, cdn加速域名]
	Result    interface{}        `json:"result"`            // 上传结果对象
	Reader    io.Reader          `json:",omitempty"`        // 上传io流
	Size      int64              `json:"size,omitempty"`    // 流大小
	File      string             `json:"file,omitempty"`    // 上传本地文件地址
	Key       string             `json:"key"`               // 上传文件保存名字
	Expires   uint64             `json:"expires,omitempty"` // token 有效时间
	Extras    *storage.PutExtra  `json:"extras"`            // 上传扩展信息
	PutPolicy *storage.PutPolicy `json:"put_policy"`        // 上传策略
}

type OssPlugin

type OssPlugin struct {
	Policy *storage.PutPolicy
	// contains filtered or unexported fields
}

func GetOSS

func GetOSS() *OssPlugin

func OSS

func OSS() *OssPlugin

func (*OssPlugin) Auth

func (this *OssPlugin) Auth() error

授权

func (*OssPlugin) CreatePolicy

func (this *OssPlugin) CreatePolicy(jsonData ...string) *OssPlugin

func (*OssPlugin) CreateUploader

func (this *OssPlugin) CreateUploader(params *OssParams, configures ...func(*storage.Config)) func(
	context.Context, ...func(*storage.PutExtra)) (interface{}, error)

CreateUploader 构建上传函数

func (*OssPlugin) GetAccessKey

func (this *OssPlugin) GetAccessKey() string

func (*OssPlugin) GetBucket

func (this *OssPlugin) GetBucket(typ string) string

func (*OssPlugin) GetPolicy

func (this *OssPlugin) GetPolicy() *storage.PutPolicy

func (*OssPlugin) GetSecretKey

func (this *OssPlugin) GetSecretKey() string

func (*OssPlugin) Lock

func (this *OssPlugin) Lock()

Lock 获取锁

func (*OssPlugin) PluginName

func (this *OssPlugin) PluginName() string

func (*OssPlugin) Register

func (this *OssPlugin) Register()

func (*OssPlugin) UnLock

func (this *OssPlugin) UnLock()

UnLock 解锁

type PluginInterface

type PluginInterface interface {
	Register()
	PluginName() string
}

func Plugin

func Plugin(name string, plugins ...PluginInterface) PluginInterface

插件

type Pusher

type Pusher struct {
	Client *NatsPlugin

	Timeout time.Duration
	// contains filtered or unexported fields
}

func (*Pusher) Close

func (this *Pusher) Close()

func (*Pusher) GetChannel

func (this *Pusher) GetChannel() string

func (*Pusher) GetTimeOut

func (this *Pusher) GetTimeOut() time.Duration

func (*Pusher) Init

func (this *Pusher) Init()

func (*Pusher) Push

func (this *Pusher) Push(channel string, data interface{}) error

func (*Pusher) Queue

func (this *Pusher) Queue(channel, queue string, cb interface{}) (*nats.Subscription, error)

队列订阅

func (*Pusher) QueueSubscribe

func (this *Pusher) QueueSubscribe(channel, queue string, cb interface{}) (*nats.Subscription, error)

队列订阅

func (*Pusher) RpcCall

func (this *Pusher) RpcCall(method string, data interface{}, responsePtr interface{}, timeOut ...time.Duration) error

远程调用

func (*Pusher) RpcService

func (this *Pusher) RpcService(method string, handler func(string, []byte) (interface{}, error)) (*nats.Subscription, error)

调用远程服务

func (*Pusher) Send

func (this *Pusher) Send(data []byte) error

func (*Pusher) SetChannel

func (this *Pusher) SetChannel(channel string) PusherInterface

func (*Pusher) SetTimeOut

func (this *Pusher) SetTimeOut(duration time.Duration) MsgRpc

func (*Pusher) Subscribe

func (this *Pusher) Subscribe(channel string, handler interface{}) (*nats.Subscription, error)

订阅

func (*Pusher) Worker

func (this *Pusher) Worker(handler interface{}) (*nats.Subscription, error)

worker

type PusherInterface

type PusherInterface interface {
	GetChannel() string
	Push(string, interface{}) error
	SetChannel(string) PusherInterface
	Subscribe(string, interface{}) (*nats.Subscription, error)
	Close()
}

func GetPusher

func GetPusher() PusherInterface

type Qrcode

type Qrcode struct {
	Storage string  `json:"storage"`
	Config  beego.M `json:"config"`
}

func GetQrcode

func GetQrcode() *Qrcode

func (*Qrcode) Create

func (this *Qrcode) Create(content string, options ...int) ([]byte, error)

func (*Qrcode) Decode

func (this *Qrcode) Decode(filename string) (*qrcode2.Matrix, error)

func (*Qrcode) GetLevels

func (this *Qrcode) GetLevels() []int

func (*Qrcode) GetSizes

func (this *Qrcode) GetSizes() []int

func (*Qrcode) PluginName

func (this *Qrcode) PluginName() string

func (*Qrcode) Register

func (this *Qrcode) Register()

func (*Qrcode) Save

func (this *Qrcode) Save(content string, options *Options) error

type TokenEntry

type TokenEntry struct {
	ExpireAt int64
	Value    string
}

type TokenLimiterProvider

type TokenLimiterProvider interface {
	Handler(ctx ContextLimit) *LimitResult
}

func NewTokenLimiterProvider

func NewTokenLimiterProvider(storage cache.Cache, max int, interval time.Duration) TokenLimiterProvider

type WatchArgs

type WatchArgs struct {
	Key     string
	Ctx     context.Context
	Options []clientv3.OpOption
	Handler func(watchChan clientv3.WatchChan)
}

Jump to

Keyboard shortcuts

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