base

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *sqlx.DB

Functions

func ConfigLoader

func ConfigLoader(
	name string,
	config interface{},
	sql string,
	lifeSpan time.Duration,
	key interface{},
	args ...interface{}) (*gokits.CacheItem, error)

func Handle

func Handle(mux *http.ServeMux) *http.ServeMux

func InitSqlxDB

func InitSqlxDB()

func Load

func Load()

func LoadConfig

func LoadConfig(configFile string, config interface{})

func PublishToClusterNodes

func PublishToClusterNodes(consumer func(address string))

func RegisterHandler

func RegisterHandler(handler Handler)

func RegisterLoader

func RegisterLoader(loader Loader)

func ServerAddr

func ServerAddr() string

func TokenLoader

func TokenLoader(
	name string,
	queryDest UpdatedRecord,
	querySql string,
	queryTokenBuilder func(queryDest UpdatedRecord) interface{},
	createSql string,
	updateSql string,
	requestor func(key interface{}) (map[string]string, error),
	uncompleteSql string,
	completeSql string,
	completeArg func(response map[string]string, lifeSpan time.Duration) map[string]interface{},
	requestTokenBuilder func(response map[string]string) interface{},
	lifeSpan time.Duration,
	lifeSpanTemp time.Duration,
	key interface{},
	args ...interface{}) (*gokits.CacheItem, error)

针对具有刷新过渡期的token 在旧的token即将过期时, 请求获取新的token 在此过程中新旧token同时可用 所以在某一集群节点更新token时 其他节点可临时缓存旧的token保证平滑过渡

func TokenLoaderStrict

func TokenLoaderStrict(
	name string,
	queryDest ExpireTimeRecord,
	querySql string,
	queryTokenBuilder func(queryDest ExpireTimeRecord) interface{},
	requestor func(key interface{}) (map[string]string, error),
	createSql string,
	updateSql string,
	createUpdateArg func(response map[string]string) map[string]interface{},
	expireCriticalSpan time.Duration,
	requestTokenBuilder func(response map[string]string) interface{},
	maxLifeSpan time.Duration,
	key interface{},
	args ...interface{}) (*gokits.CacheItem, error)

针对没有刷新过渡期的token 旧的token固定过期时间, 在有效期内无法获取新的token 超出有效期后, 可请求获取新的token 所以在旧的token即将过期前的一小段时间内, 停止缓存token并请求更新 在某一集群节点更新token后, 其他节点触发入库失败并查询已更新的token进行缓存 由于有效期内token不会更新, 所以重复请求不会覆盖token

func TrimPrefixPath

func TrimPrefixPath(request *http.Request, subPath string) string

Types

type Config

type Config struct {
	gokits.HttpServerConfig

	LogLevel string

	ClusterNodeAddresses []string // notify all cluster node for cache delete event

	DriverName      string
	DataSourceName  string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxIdleTime gokits.Duration
	ConnMaxLifetime gokits.Duration
}

type ExpireTimeRecord

type ExpireTimeRecord interface {
	GetExpireTime() int64
}

type Handler

type Handler func(mux *http.ServeMux)

type HandlerRegistry

type HandlerRegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHandlerRegistry

func NewHandlerRegistry() *HandlerRegistry

func (*HandlerRegistry) Register

func (r *HandlerRegistry) Register(handler Handler)

type Loader

type Loader func(configFile string)

type LoaderRegistry

type LoaderRegistry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLoaderRegistry

func NewLoaderRegistry() *LoaderRegistry

func (*LoaderRegistry) Register

func (r *LoaderRegistry) Register(loader Loader)

type UpdatedRecord

type UpdatedRecord interface {
	ExpireTimeRecord
	GetUpdated() string
}

Jump to

Keyboard shortcuts

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