utils

package
v0.0.0-...-4a302de Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RESP_SUCCESS_CODE        = 0
	RESP_PARAM_ERROR_CODE    = 1000
	RESP_USER_NOT_FOUND_CODE = 1001
	RESP_USER_EMAIL_ERROR    = 1002
	RESP_USER_PASSWORD_ERROR = 1003
	RESP_USER_EXIST_CODE     = 1004
	RESP_INTERNAL_ERROR_CODE = 1099
)
View Source
const (
	SERVICE_NAME   = "task-monitor-service"
	WEBSOCKET_NAME = "ws://127.0.0.1:9010/ws"
)
View Source
const (
	PASSWORD_SALT       = "sLx2j3SfvE&"
	PASSWORD_MIN_LENGTH = 6
)
View Source
const (
	TOKEN_TIME_LEFT = 3600 * 24 * 7
	TOKEN_KEY       = SERVICE_NAME + ":token:"
)
View Source
const (
	TCP_WRITE_BUFFER_SIZE   = 524288
	TCP_READ_BUFFER_SIZE    = 524288
	CH_WEBSOCKET_WRITE_SIZE = 2000
	TRAFFIC_LIMIT_INTERVAL  = 10
)

Variables

View Source
var DBClient *gorm.DB
View Source
var RESPONSE_TEXT = map[int]string{
	0:    "success",
	1000: "param error",
	1001: "invalid username or password",
	1002: "invalid email",
	1003: "invalid password",
	1004: "user exist",
	1099: "internal error",
}
View Source
var RedisClient *redis.Client

Functions

func CheckEmailFormat

func CheckEmailFormat(email string) bool

func GetPasswordHash

func GetPasswordHash(password string) string

func GetTimeNow

func GetTimeNow() time.Time

func LoadConfig

func LoadConfig(config string) (*anyvalue.AnyValue, error)

func RandomString

func RandomString(n int) string

func Response200

func Response200(c *gin.Context, data interface{})

func Response400

func Response400(c *gin.Context, code int)

func Response500

func Response500(c *gin.Context, code int)

Types

type Conn

type Conn interface {
	Id() string
	Send([]byte)
	Close(bool) error
	IsClosed() bool
	String() string
	Read()
	Write()
}

type LoginReq

type LoginReq struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

type ProcessHandler

type ProcessHandler interface {
	OnConnected(conn Conn)
	OnRequest(pkg []byte, conn Conn)
	OnClosed(conn Conn, proactive bool)
}

type RegisterReq

type RegisterReq struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
	Email    string `json:"email"`
}

type WebSocketConn

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

func NewWebSocketConn

func NewWebSocketConn(conn *websocket.Conn, handler ProcessHandler) *WebSocketConn

new websocket connection

func (*WebSocketConn) Close

func (wsc *WebSocketConn) Close(flag bool) error

func (*WebSocketConn) Id

func (wsc *WebSocketConn) Id() string

func (*WebSocketConn) IsClosed

func (wsc *WebSocketConn) IsClosed() bool

func (*WebSocketConn) Read

func (wsc *WebSocketConn) Read()

func (*WebSocketConn) Send

func (wsc *WebSocketConn) Send(pkt []byte)

func (*WebSocketConn) String

func (wsc *WebSocketConn) String() string

func (*WebSocketConn) Write

func (wsc *WebSocketConn) Write()

type WsManager

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

func NewConnectionPool

func NewConnectionPool(callback func(av *anyvalue.AnyValue)) (*WsManager, error)

func (*WsManager) OnClosed

func (wsm *WsManager) OnClosed(conn Conn, proactive bool)

func (*WsManager) OnConnected

func (wsm *WsManager) OnConnected(conn Conn)

func (*WsManager) OnRequest

func (wsm *WsManager) OnRequest(pkg []byte, conn Conn)

Jump to

Keyboard shortcuts

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