kv

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT = DynamicValues{
	SessionTTL:      time.Hour,
	LoginTTL:        time.Minute * 15,
	LoginFailures:   5,
	IpLoginFailures: 10,
	IpWhitelist:     []string{},
	IpBlacklist:     []string{},
	PwdStrategy:     1,
	PwdTTL:          time.Hour * 24 * 365,
}
View Source
var Provides = wire.NewSet(
	wire.Struct(new(Controller), "*"),
	wire.Struct(new(Service), "*"),
)
View Source
var SECRET = map[string]bool{
	"tencent_secret_key":        true,
	"feishu_app_secret":         true,
	"feishu_encrypt_key":        true,
	"feishu_verification_token": true,
	"email_password":            true,
	"openapi_secret":            true,
}

Functions

This section is empty.

Types

type Controller

type Controller struct {
	KVService *Service
}

func (*Controller) Get

Get 获取动态配置 @router /values [GET]

func (*Controller) Remove

func (x *Controller) Remove(_ context.Context, c *app.RequestContext)

Remove 移除动态配置 @router /values/:id [DELETE]

func (*Controller) Set

Set 设置动态配置 @router /values [PATCH]

type DSLOption

type DSLOption struct {
	Event bool
	Keys  []string
}

type DynamicValues

type DynamicValues struct {
	// 会话周期(秒)
	// 用户在 1 小时 内没有操作,将结束会话。
	SessionTTL time.Duration `json:"session_ttl"`
	// 登录锁定时间
	// 锁定 15 分钟。
	LoginTTL time.Duration `json:"login_ttl"`
	// 用户最大登录失败次数
	// 有限时间(锁定时间)内连续登录失败 5 次,锁定帐号。
	LoginFailures int64 `json:"login_failures"`
	// IP 最大登录失败次数
	// 同 IP 连续 10 次登录失败后,锁定 IP(周期为锁定时间)。
	IpLoginFailures int64 `json:"ip_login_failures"`
	// IP 白名单
	// 白名单 IP 允许超出最大登录失败次数。
	IpWhitelist []string `json:"ip_whitelist"`
	// GetIpBlacklist IP 黑名单
	// 黑名单 IP 将禁止访问。
	IpBlacklist []string `json:"ip_blacklist"`
	// 密码强度
	// 0:无限制;
	// 1:需要大小写字母;
	// 2:需要大小写字母、数字;
	// 3:需要大小写字母、数字、特殊字符
	PwdStrategy int `json:"pwd_strategy"`
	// 密码有效期(天)
	// 密码过期后强制要求修改密码,0:永久有效
	PwdTTL time.Duration `json:"pwd_ttl"`
	// 云平台
	// tencent:腾讯云;
	Cloud string `json:"cloud"`
	// 腾讯云 API 密钥 Id
	// 建议用子账号分配需要的权限
	TencentSecretId string `json:"tencent_secret_id"`
	// 腾讯云 API 密钥 Key
	TencentSecretKey string `json:"tencent_secret_key,omitempty"`
	// 腾讯云 COS 对象存储 Bucket(存储桶名称)
	TencentCosBucket string `json:"tencent_cos_bucket,omitempty"`
	// 腾讯云 COS 对象存储所属地域,例如:ap-guangzhou
	TencentCosRegion string `json:"tencent_cos_region"`
	// 腾讯云 COS 对象存储预签名有效期,单位:秒
	TencentCosExpired int `json:"tencent_cos_expired"`
	// 腾讯云 COS 对象存储上传大小限制,单位:KB
	TencentCosLimit int64 `json:"tencent_cos_limit"`
	// 办公平台
	// feishu:飞书;
	Office string `json:"office"`
	// 飞书应用 ID
	FeishuAppId string `json:"feishu_app_id"`
	// 飞书应用密钥
	FeishuAppSecret string `json:"feishu_app_secret,omitempty"`
	// 飞书事件订阅安全校验数据密钥
	FeishuEncryptKey string `json:"feishu_encrypt_key,omitempty"`
	// 飞书事件订阅验证令牌
	FeishuVerificationToken string `json:"feishu_verification_token,omitempty"`
	// 第三方免登授权码跳转地址
	RedirectUrl string `json:"redirect_url"`
	// 公共电子邮件服务 SMTP 地址
	EmailHost string `json:"email_host"`
	// SMTP 端口号(SSL)
	EmailPort string `json:"email_port"`
	// 公共邮箱用户
	EmailUsername string `json:"email_username"`
	// 公共邮箱用户
	EmailPassword string `json:"email_password,omitempty"`
	// 开放服务地址
	OpenapiUrl string `json:"openapi_url"`
	// 开放服务应用认证 Key
	// API 网关应用认证方式 https://cloud.tencent.com/document/product/628/55088
	OpenapiKey string `json:"openapi_key"`
	// 开放服务应用认证密钥
	OpenapiSecret string `json:"openapi_secret,omitempty"`
	// DSL 集合控制
	DSL map[string]*DSLOption `json:"dsl,omitempty"`
}

type GetDto

type GetDto struct {
	// 动态配置键
	Keys map[string]int64 `query:"keys" vd:"len($)==0 || range($,regexp('^[a-z_]+$',#k));msg:'key 必须是小写字母与下划线'"`
}

type KV

type KV struct {
	Namespace     string
	KeyValue      nats.KeyValue
	DynamicValues *DynamicValues
}

func New

func New(options ...Option) *KV

type Option

type Option func(x *KV)

func SetDynamicValues

func SetDynamicValues(v *DynamicValues) Option

func SetKeyValue

func SetKeyValue(v nats.KeyValue) Option

func SetNamespace

func SetNamespace(v string) Option

type RemoveDto

type RemoveDto struct {
	Key string `path:"key,required" vd:"regexp('^[a-z_]+$');msg:'key 必须是小写字母与下划线'"`
}

type Service

type Service struct {
	*KV
}

func (*Service) Get

func (x *Service) Get(keys map[string]int64) (values map[string]interface{}, err error)

Get 获取动态配置

func (*Service) Load

func (x *Service) Load() (err error)

Load 载入配置

func (*Service) Remove

func (x *Service) Remove(key string) (err error)

Remove 移除动态配置

func (*Service) Set

func (x *Service) Set(update map[string]interface{}) (err error)

Set 设置动态配置

func (*Service) Sync

func (x *Service) Sync(option *SyncOption) (err error)

Sync 同步节点动态配置

func (*Service) Update

func (x *Service) Update(values map[string]interface{}) (err error)

Update 更新配置

type SetDto

type SetDto struct {
	Data map[string]interface{} `json:"data,required" vd:"len($)>0 && range($,regexp('^[a-z_]+$',#k));msg:'key 必须是小写字母与下划线'"`
}

type SyncOption

type SyncOption struct {
	Updated chan *DynamicValues
	Err     chan error
}

Jump to

Keyboard shortcuts

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