y

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

README

y

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidDataError    = fmt.Errorf("invalid data error")
	InvalidServiceError = fmt.Errorf("invalid service error")
)
View Source
var (
	DefaultIDGenerator = NewUint64IDGenerator()
)
View Source
var (
	Logger = LogFunc(Info)
)

Functions

func Debug

func Debug(v ...interface{})

Debug formats message using the default formats for its operands and writes to default logger with ylog level = Debug

func Debugf

func Debugf(format string, params ...interface{})

Debugf formats message according to format specifier and writes to default logger with ylog level = Debug.

func Error

func Error(v ...interface{}) error

Error formats message using the default formats for its operands and writes to default logger with ylog level = Error

func Errorf

func Errorf(format string, params ...interface{}) error

Errorf formats message according to format specifier and writes to default logger with ylog level = Error

func FlushLog

func FlushLog()

func GenUUID5

func GenUUID5(name string) string

func Get

func Get(url string) ([]byte, error)

func GetJSON

func GetJSON(url string) (map[string]interface{}, error)

func GetJSONArray

func GetJSONArray(url string) ([]interface{}, error)

func GoForever

func GoForever(f func() bool)

func HttpClientIP

func HttpClientIP(r *http.Request) string

func Info

func Info(v ...interface{})

Info formats message using the default formats for its operands and writes to default logger with ylog level = Info

func Infof

func Infof(format string, params ...interface{})

Infof formats message according to format specifier and writes to default logger with ylog level = Info.

func InitLog

func InitLog(fileName string) error

func InitLogDefault

func InitLogDefault() error

func InitLogDefaultWithConsole added in v0.0.6

func InitLogDefaultWithConsole() error

func LoadXml

func LoadXml(fileName string, cfg interface{}) error

func Panic

func Panic(err interface{})

func Post added in v0.0.3

func Post(url string, form url.Values, headers map[string]string) ([]byte, http.Header, error)

func PostJSONArray added in v0.0.3

func PostJSONArray(url string, form url.Values, headers map[string]string) ([]interface{}, http.Header, error)

func PostJson added in v0.0.3

func PostJson(url string, form url.Values, headers map[string]string) (map[string]interface{}, http.Header, error)

func RecoverError

func RecoverError()

func ReplyError

func ReplyError(w http.ResponseWriter, res string, err error)

func ReplyMap

func ReplyMap(w http.ResponseWriter, v map[string]interface{})

func ReplyRawText

func ReplyRawText(w http.ResponseWriter, text string)

func ReplyString

func ReplyString(w http.ResponseWriter, res string)

func SaveXml

func SaveXml(fileName string, cfg interface{}) error

func Ternary

func Ternary(cond bool, trueValue, falseValue interface{}) interface{}

Types

type DB

type DB struct {
	*gorm.DB
}

func NewDB

func NewDB(config *DBConfig) (db *DB, err error)

func NewDBFromConfigFile

func NewDBFromConfigFile(fileName string) (db *DB, err error)

func (*DB) InitTable

func (db *DB) InitTable(values ...interface{})

type DBConfig

type DBConfig struct {
	Type string

	Username string
	Password string
	Protocol string
	Address  string
	Port     int
	Database string
	Charset  string

	EnableLog   bool
	MaxIdle     int
	MaxOpen     int
	MaxConnLife int
}

type DefaultParser

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

func NewDefaultParser

func NewDefaultParser(handler IHandler, maxLength int) *DefaultParser

func (*DefaultParser) OnNewData

func (p *DefaultParser) OnNewData(client IClient, buf []byte) error

func (*DefaultParser) PackData

func (p *DefaultParser) PackData(data interface{}) []byte

type FileWatcher

type FileWatcher struct {
	*fsnotify.Watcher
}

func NewFileWatcher

func NewFileWatcher(f func(fileName string, mode string)) (fileWatcher *FileWatcher, err error)

type HttpServer

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

func NewHttpServer

func NewHttpServer(ctx context.Context, config *HttpServerConfig) (server *HttpServer, err error)

func NewHttpServerFromConfigFile

func NewHttpServerFromConfigFile(ctx context.Context, fileName string) (server *HttpServer, err error)

func (*HttpServer) Close

func (s *HttpServer) Close()

func (*HttpServer) Handle

func (s *HttpServer) Handle(pattern string, handler http.Handler)

func (*HttpServer) HandleFunc

func (s *HttpServer) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*HttpServer) Start

func (s *HttpServer) Start()

type HttpServerConfig

type HttpServerConfig struct {
	ListenPort   int
	ReadTimeout  int
	WriteTimeout int
	CaFile       string
	CertFile     string
	KeyFile      string
}

type IAuth

type IAuth interface {
	OnAuth(r *http.Request) interface{}
}

type IClient

type IClient interface {
	Close()
	Send([]byte)
	ConnId() uint64
	UserId() interface{}
	LastTime() time.Time
}

type IClientChanged

type IClientChanged interface {
	OnAdded(connId uint64, userId interface{})
	OnRemoved(connId uint64, userId interface{}, beKickedClient IClient)
}

在同一协程中调用

type IDGenerator

type IDGenerator interface {
	Next() interface{}
}

func NewUint64IDGenerator

func NewUint64IDGenerator() IDGenerator

type IHandler

type IHandler interface {
	HandleNewData(client IClient, data interface{}) error
	PackData(data interface{}) []byte
}

type IParser

type IParser interface {
	OnNewData(client IClient, buf []byte) error
	PackData(data interface{}) []byte
}

type IState

type IState interface {
	OnOpen(client IClient)
	OnClose(client IClient)
}

type JsonMsg

type JsonMsg struct {
	Client IClient
	MsgMap map[string]interface{}
}

type JsonMsgHandler

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

json format data

func NewJsonMsgHandler

func NewJsonMsgHandler(router map[string]func(jsonMsg *JsonMsg)) *JsonMsgHandler

func (*JsonMsgHandler) HandleNewData

func (h *JsonMsgHandler) HandleNewData(client IClient, data interface{}) error

func (*JsonMsgHandler) PackData

func (h *JsonMsgHandler) PackData(data interface{}) []byte

type LogFunc

type LogFunc func(keyvals ...interface{})

func (LogFunc) Log

func (l LogFunc) Log(keyvals ...interface{}) error

type MultiThreadHandler

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

func NewMultiThreadHandler

func NewMultiThreadHandler(ctx context.Context, handler IHandler, threadCount int) *MultiThreadHandler

func (*MultiThreadHandler) HandleNewData

func (h *MultiThreadHandler) HandleNewData(client IClient, data interface{}) error

func (*MultiThreadHandler) PackData

func (h *MultiThreadHandler) PackData(data interface{}) []byte

type Uint64IDGenerator

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

func (*Uint64IDGenerator) Next

func (g *Uint64IDGenerator) Next() interface{}

type WSClient

type WSClient struct {
	Parser IParser
	State  IState
	// contains filtered or unexported fields
}

func (*WSClient) Close

func (c *WSClient) Close()

func (*WSClient) ConnId

func (c *WSClient) ConnId() uint64

func (*WSClient) LastTime

func (c *WSClient) LastTime() time.Time

func (*WSClient) Send

func (c *WSClient) Send(data []byte)

func (*WSClient) UserId

func (c *WSClient) UserId() interface{}

type WSClientDialer

type WSClientDialer struct {
	*websocket.Dialer
	Heartbeat time.Duration
}

func (*WSClientDialer) Dial

func (d *WSClientDialer) Dial(ctx context.Context, connection string, id uint64) (client *WSClient, err error)

type WSServer

type WSServer struct {
	Auth          IAuth
	Parser        IParser
	ClientChanged IClientChanged
	// contains filtered or unexported fields
}

func NewWSServer

func NewWSServer(ctx context.Context, config *WSServerConfig) (*WSServer, error)

func NewWSServerFromConfigFile

func NewWSServerFromConfigFile(ctx context.Context, fileName string) (*WSServer, error)

func (*WSServer) Close

func (ws *WSServer) Close()

func (*WSServer) IClientById

func (ws *WSServer) IClientById(id uint64) IClient

func (*WSServer) IClientByUserId

func (ws *WSServer) IClientByUserId(userId interface{}) IClient

func (*WSServer) IsTls

func (ws *WSServer) IsTls() bool

func (*WSServer) Start

func (ws *WSServer) Start(forceNoSSL bool)

type WSServerConfig

type WSServerConfig struct {
	AccessPath     string
	ListenPort     int
	Auth           IAuth
	Parser         IParser
	ClientCallback IClientChanged

	CaFile   string
	CertFile string
	KeyFile  string
}

Jump to

Keyboard shortcuts

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