webtoy_base

package module
v0.0.0-...-b1e5a9d Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: MIT Imports: 26 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ERROR_OK       = 0
	ERROR_COMMON   = -1  // 通用错误
	ERROR_INTERNAL = 501 // 内部错误
	ERROR_AUTH     = 502 // 认证错误(无法获取session, token过期等)
	ERROR_BAD_REQ  = 503 // 客户端错误的请求
	ERROR_CAPTCHA  = 504 // 验证码错误
)
View Source
const (
	SESSION_USER  = "uid"
	SESSION_ID    = "session"
	SESSION_TOKEN = "token"
)
View Source
const (
	ServiceStatus_Pass           = 1
	ServiceStatus_ReadyToOffline = 2
)

Variables

This section is empty.

Functions

func BCryptMatchPasswd

func BCryptMatchPasswd(hashPasswd, passwd string) bool

func BcryptHashPasswd

func BcryptHashPasswd(passwd string) (string, error)

func HttpClientPost

func HttpClientPost(url string, transport http.RoundTripper, req interface{}) ([]byte, error)

func HttpClientPostBytes

func HttpClientPostBytes(url string, transport http.RoundTripper, b []byte) ([]byte, error)

func HttpResponse

func HttpResponse(w http.ResponseWriter, res *MessageRsp) error

func HttpTransportGet

func HttpTransportGet(url string, transport http.RoundTripper, w http.ResponseWriter) ([]byte, error)

func HttpTransportPost

func HttpTransportPost(url string, transport http.RoundTripper, obj interface{}, w http.ResponseWriter) ([]byte, error)

func HttpTransportPostBytes

func HttpTransportPostBytes(url string, transport http.RoundTripper, body []byte, w http.ResponseWriter) ([]byte, error)

func InitLog

func InitLog(logLevel, logFile string, enableConsole bool) error

func MiddlewareTimeElapsed

func MiddlewareTimeElapsed(next http.Handler) http.Handler

Types

type DBComponent

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

func GetDBComponent

func GetDBComponent() *DBComponent

func (*DBComponent) AddDBMysql

func (this *DBComponent) AddDBMysql(name string, cfg DBConfig) error

func (*DBComponent) GetEngine

func (this *DBComponent) GetEngine(name string) (*xorm.Engine, error)

func (*DBComponent) InitEngines

func (this *DBComponent) InitEngines(dbMap map[string]DBConfig) error

type DBConfig

type DBConfig struct {
	Driver string
	Net    string
	Addr   string
	Params string
	Db     string
	User   string
	Passwd string
}

type LogFormat

type LogFormat struct{}

func (*LogFormat) Format

func (this *LogFormat) Format(entry *log.Entry) ([]byte, error)

func (*LogFormat) Goid

func (this *LogFormat) Goid() int

type MessageRsp

type MessageRsp struct {
	Code   int         `json:"code,omitempty"`
	ErrMsg string      `json:"msg,omitempty"`
	Data   interface{} `json:"data,omitempty"`
}

func HttpSRPost

func HttpSRPost(serviceName, urlPath string, transport http.RoundTripper, req interface{}, rspData interface{}) (*MessageRsp, error)

http service registry post

type RedisComponent

type RedisComponent struct {
	Client *redis.Client
}

func GetRedisComponent

func GetRedisComponent() *RedisComponent

func (*RedisComponent) Init

func (this *RedisComponent) Init(host string, port uint, passwd string, db int) error

type SRClient

type SRClient struct {
	ClientSD      *srd.ServiceDiscoveryClient
	ClientLB      *clb.ClientLoadBalancer
	ServiceStatus int
}

func NewSRClient

func NewSRClient(args *SRClientArgs) (*SRClient, error)

func (*SRClient) Check

func (this *SRClient) Check() (bool, error)

type SRClientArgs

type SRClientArgs struct {
	SrAddr        string
	SrServiceID   string
	SrServiceName string
	SrServiceHost string
	SrServicePort uint
	SrServiceTag  string
	SrServiceTTL  time.Duration
}

type Session

type Session struct {
	UserID  string `json:"uid"`
	Session string `json:"session"`
	Token   string `json:"token"`
}

type SessionComponent

type SessionComponent struct {
	Handler *SessionHandler
}

func GetSessionComponent

func GetSessionComponent() *SessionComponent

type SessionHandler

type SessionHandler struct {
	RedisClient         *redis.Client
	SessionExpireSecond int
}

func NewSessionHandler

func NewSessionHandler(redisClient *redis.Client, sessionExpireSecond int) *SessionHandler

func (*SessionHandler) GenSession

func (this *SessionHandler) GenSession(userID string) (*Session, error)

generate and save user session

func (*SessionHandler) GenSessionID

func (this *SessionHandler) GenSessionID() (string, error)

func (*SessionHandler) GenToken

func (this *SessionHandler) GenToken(plainText string) (string, error)

func (*SessionHandler) GenerateRandomBytes

func (this *SessionHandler) GenerateRandomBytes(n int) ([]byte, error)

func (*SessionHandler) MiddlewareSessionCheck

func (this *SessionHandler) MiddlewareSessionCheck(next http.Handler) http.Handler

func (*SessionHandler) SaveSession

func (this *SessionHandler) SaveSession(session *Session) error

func (*SessionHandler) UpdateSession

func (this *SessionHandler) UpdateSession(session *Session) error

refresh session

type SrClientComponent

type SrClientComponent struct {
	Client *SRClient
}

func GetSrClientComponent

func GetSrClientComponent() *SrClientComponent

func (*SrClientComponent) Init

func (this *SrClientComponent) Init(args *SRClientArgs) error

Jump to

Keyboard shortcuts

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