lib

package
v0.0.0-...-e7c48a7 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PackLenField = 4

Variables

View Source
var (
	PackKind_name = map[int32]string{
		0:  "PONG",
		1:  "ERR",
		2:  "RES",
		3:  "PUSH",
		4:  "MSG",
		5:  "PING",
		6:  "SIGNUP",
		7:  "SIGNIN",
		8:  "TOKEN",
		9:  "SIGNOUT",
		10: "USERS",
	}
	PackKind_value = map[string]int32{
		"PONG":    0,
		"ERR":     1,
		"RES":     2,
		"PUSH":    3,
		"MSG":     4,
		"PING":    5,
		"SIGNUP":  6,
		"SIGNIN":  7,
		"TOKEN":   8,
		"SIGNOUT": 9,
		"USERS":   10,
	}
)

Enum value maps for PackKind.

View Source
var (
	MsgKind_name = map[int32]string{
		0: "TEXT",
	}
	MsgKind_value = map[string]int32{
		"TEXT": 0,
	}
)

Enum value maps for MsgKind.

View Source
var (
	PushKind_name = map[int32]string{
		0: "ONLINE",
	}
	PushKind_value = map[string]int32{
		"ONLINE": 0,
	}
)

Enum value maps for PushKind.

View Source
var (
	OnlineKind_name = map[int32]string{
		0: "ON",
		1: "OFF",
	}
	OnlineKind_value = map[string]int32{
		"ON":  0,
		"OFF": 1,
	}
)

Enum value maps for OnlineKind.

View Source
var File_packet_proto protoreflect.FileDescriptor
View Source
var HomeDir = getHomeDir()
View Source
var WorkDir = getWorkDir()

Functions

func BytesToUint32

func BytesToUint32(bytes []byte) uint32

func Decrypt

func Decrypt(ciphertext []byte, gcm cipher.AEAD) ([]byte, error)

func Encrypt

func Encrypt(plaintext []byte, gcm cipher.AEAD) []byte

func FatalNotNil

func FatalNotNil(err error)

如果 err != nil,输出错误日志并退出进程

func LogMessage

func LogMessage(msg ...any)

输出日志

func LogNotNil

func LogNotNil(err error)

如果 err != nil,输出错误日志

func Marshal

func Marshal(m proto.Message) (bytes []byte, err error)

func MarshalPack

func MarshalPack(pack proto.Message) (bytes []byte, err error)

func NewEncryptionKey

func NewEncryptionKey() *[32]byte

func NewGCM

func NewGCM(key *[32]byte) (gcm cipher.AEAD, err error)

func PrintErr

func PrintErr(errRes *ErrRes)

打印服务器错误

func PrintMessage

func PrintMessage(msg *Msg)

打印消息

func SplitFunc

func SplitFunc(data []byte, atEOF bool) (advance int, token []byte, err error)

func Uint32ToBytes

func Uint32ToBytes(n uint32) (bytes []byte)

func Unmarshal

func Unmarshal(bytes []byte, m proto.Message) (err error)

Types

type Auth

type Auth struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	Passhash []byte `protobuf:"bytes,2,opt,name=passhash,proto3" json:"passhash,omitempty"`
	// contains filtered or unexported fields
}

func (*Auth) Descriptor deprecated

func (*Auth) Descriptor() ([]byte, []int)

Deprecated: Use Auth.ProtoReflect.Descriptor instead.

func (*Auth) GetPasshash

func (x *Auth) GetPasshash() []byte

func (*Auth) GetUsername

func (x *Auth) GetUsername() string

func (*Auth) ProtoMessage

func (*Auth) ProtoMessage()

func (*Auth) ProtoReflect

func (x *Auth) ProtoReflect() protoreflect.Message

func (*Auth) Reset

func (x *Auth) Reset()

func (*Auth) String

func (x *Auth) String() string

type ErrCode

type ErrCode int32
const (
	Err_Unmarshal ErrCode = -(iota + 10000)
	Err_Bcrypt_Gen
	Err_Acc_Exist
	Err_Parse_Token
	Err_Token_Expired
	Err_Acc_Not_Exist
	Err_Gen_Token
	Err_Base64_Decode
	Err_Bcrypt_Compare
	Err_Forbidden
	Err_Get_Users
)

func (ErrCode) Val

func (ec ErrCode) Val() int32

type ErrRes

type ErrRes struct {
	Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	// contains filtered or unexported fields
}

func (*ErrRes) Descriptor deprecated

func (*ErrRes) Descriptor() ([]byte, []int)

Deprecated: Use ErrRes.ProtoReflect.Descriptor instead.

func (*ErrRes) GetCode

func (x *ErrRes) GetCode() int32

func (*ErrRes) ProtoMessage

func (*ErrRes) ProtoMessage()

func (*ErrRes) ProtoReflect

func (x *ErrRes) ProtoReflect() protoreflect.Message

func (*ErrRes) Reset

func (x *ErrRes) Reset()

func (*ErrRes) String

func (x *ErrRes) String() string

type Msg

type Msg struct {
	Id   int64   `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
	Kind MsgKind `protobuf:"varint,2,opt,name=kind,proto3,enum=lib.MsgKind" json:"kind,omitempty"`
	From string  `protobuf:"bytes,3,opt,name=from,proto3" json:"from,omitempty"`
	To   string  `protobuf:"bytes,4,opt,name=to,proto3" json:"to,omitempty"`
	Data []byte  `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*Msg) Descriptor deprecated

func (*Msg) Descriptor() ([]byte, []int)

Deprecated: Use Msg.ProtoReflect.Descriptor instead.

func (*Msg) GetData

func (x *Msg) GetData() []byte

func (*Msg) GetFrom

func (x *Msg) GetFrom() string

func (*Msg) GetId

func (x *Msg) GetId() int64

func (*Msg) GetKind

func (x *Msg) GetKind() MsgKind

func (*Msg) GetTo

func (x *Msg) GetTo() string

func (*Msg) ProtoMessage

func (*Msg) ProtoMessage()

func (*Msg) ProtoReflect

func (x *Msg) ProtoReflect() protoreflect.Message

func (*Msg) Reset

func (x *Msg) Reset()

func (*Msg) String

func (x *Msg) String() string

type MsgKind

type MsgKind int32
const (
	MsgKind_TEXT MsgKind = 0
)

func (MsgKind) Descriptor

func (MsgKind) Descriptor() protoreflect.EnumDescriptor

func (MsgKind) Enum

func (x MsgKind) Enum() *MsgKind

func (MsgKind) EnumDescriptor deprecated

func (MsgKind) EnumDescriptor() ([]byte, []int)

Deprecated: Use MsgKind.Descriptor instead.

func (MsgKind) Number

func (x MsgKind) Number() protoreflect.EnumNumber

func (MsgKind) String

func (x MsgKind) String() string

func (MsgKind) Type

func (MsgKind) Type() protoreflect.EnumType

type Online

type Online struct {
	Kind     OnlineKind `protobuf:"varint,1,opt,name=kind,proto3,enum=lib.OnlineKind" json:"kind,omitempty"`
	Username string     `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
	// contains filtered or unexported fields
}

func (*Online) Descriptor deprecated

func (*Online) Descriptor() ([]byte, []int)

Deprecated: Use Online.ProtoReflect.Descriptor instead.

func (*Online) GetKind

func (x *Online) GetKind() OnlineKind

func (*Online) GetUsername

func (x *Online) GetUsername() string

func (*Online) ProtoMessage

func (*Online) ProtoMessage()

func (*Online) ProtoReflect

func (x *Online) ProtoReflect() protoreflect.Message

func (*Online) Reset

func (x *Online) Reset()

func (*Online) String

func (x *Online) String() string

type OnlineKind

type OnlineKind int32
const (
	OnlineKind_ON  OnlineKind = 0
	OnlineKind_OFF OnlineKind = 1
)

func (OnlineKind) Descriptor

func (OnlineKind) Descriptor() protoreflect.EnumDescriptor

func (OnlineKind) Enum

func (x OnlineKind) Enum() *OnlineKind

func (OnlineKind) EnumDescriptor deprecated

func (OnlineKind) EnumDescriptor() ([]byte, []int)

Deprecated: Use OnlineKind.Descriptor instead.

func (OnlineKind) Number

func (x OnlineKind) Number() protoreflect.EnumNumber

func (OnlineKind) String

func (x OnlineKind) String() string

func (OnlineKind) Type

type PackKind

type PackKind int32
const (
	// Server
	PackKind_PONG PackKind = 0
	PackKind_ERR  PackKind = 1
	PackKind_RES  PackKind = 2
	PackKind_PUSH PackKind = 3
	// All
	PackKind_MSG PackKind = 4
	// Client
	PackKind_PING    PackKind = 5
	PackKind_SIGNUP  PackKind = 6
	PackKind_SIGNIN  PackKind = 7
	PackKind_TOKEN   PackKind = 8
	PackKind_SIGNOUT PackKind = 9
	PackKind_USERS   PackKind = 10
)

func (PackKind) Descriptor

func (PackKind) Descriptor() protoreflect.EnumDescriptor

func (PackKind) Enum

func (x PackKind) Enum() *PackKind

func (PackKind) EnumDescriptor deprecated

func (PackKind) EnumDescriptor() ([]byte, []int)

Deprecated: Use PackKind.Descriptor instead.

func (PackKind) Number

func (x PackKind) Number() protoreflect.EnumNumber

func (PackKind) String

func (x PackKind) String() string

func (PackKind) Type

type Packet

type Packet struct {
	Kind PackKind `protobuf:"varint,1,opt,name=kind,proto3,enum=lib.PackKind" json:"kind,omitempty"`
	Id   uint64   `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
	Data []byte   `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*Packet) Descriptor deprecated

func (*Packet) Descriptor() ([]byte, []int)

Deprecated: Use Packet.ProtoReflect.Descriptor instead.

func (*Packet) GetData

func (x *Packet) GetData() []byte

func (*Packet) GetId

func (x *Packet) GetId() uint64

func (*Packet) GetKind

func (x *Packet) GetKind() PackKind

func (*Packet) ProtoMessage

func (*Packet) ProtoMessage()

func (*Packet) ProtoReflect

func (x *Packet) ProtoReflect() protoreflect.Message

func (*Packet) Reset

func (x *Packet) Reset()

func (*Packet) String

func (x *Packet) String() string

type Ping

type Ping struct {
	Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`
	// contains filtered or unexported fields
}

func (*Ping) Descriptor deprecated

func (*Ping) Descriptor() ([]byte, []int)

Deprecated: Use Ping.ProtoReflect.Descriptor instead.

func (*Ping) GetPayload

func (x *Ping) GetPayload() []byte

func (*Ping) ProtoMessage

func (*Ping) ProtoMessage()

func (*Ping) ProtoReflect

func (x *Ping) ProtoReflect() protoreflect.Message

func (*Ping) Reset

func (x *Ping) Reset()

func (*Ping) String

func (x *Ping) String() string

type Pong

type Pong struct {
	Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"`
	// contains filtered or unexported fields
}

func (*Pong) Descriptor deprecated

func (*Pong) Descriptor() ([]byte, []int)

Deprecated: Use Pong.ProtoReflect.Descriptor instead.

func (*Pong) GetPayload

func (x *Pong) GetPayload() []byte

func (*Pong) ProtoMessage

func (*Pong) ProtoMessage()

func (*Pong) ProtoReflect

func (x *Pong) ProtoReflect() protoreflect.Message

func (*Pong) Reset

func (x *Pong) Reset()

func (*Pong) String

func (x *Pong) String() string

type Post

type Post interface {
	// 处理同步请求
	Handle(req, res proto.Message) error

	// 发送非同步请求
	Send(req proto.Message) error

	// 关闭并清理资源
	Close()
}

定义处理 packet 接口

type Push

type Push struct {
	Kind PushKind `protobuf:"varint,1,opt,name=kind,proto3,enum=lib.PushKind" json:"kind,omitempty"`
	Data []byte   `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*Push) Descriptor deprecated

func (*Push) Descriptor() ([]byte, []int)

Deprecated: Use Push.ProtoReflect.Descriptor instead.

func (*Push) GetData

func (x *Push) GetData() []byte

func (*Push) GetKind

func (x *Push) GetKind() PushKind

func (*Push) ProtoMessage

func (*Push) ProtoMessage()

func (*Push) ProtoReflect

func (x *Push) ProtoReflect() protoreflect.Message

func (*Push) Reset

func (x *Push) Reset()

func (*Push) String

func (x *Push) String() string

type PushKind

type PushKind int32
const (
	PushKind_ONLINE PushKind = 0
)

func (PushKind) Descriptor

func (PushKind) Descriptor() protoreflect.EnumDescriptor

func (PushKind) Enum

func (x PushKind) Enum() *PushKind

func (PushKind) EnumDescriptor deprecated

func (PushKind) EnumDescriptor() ([]byte, []int)

Deprecated: Use PushKind.Descriptor instead.

func (PushKind) Number

func (x PushKind) Number() protoreflect.EnumNumber

func (PushKind) String

func (x PushKind) String() string

func (PushKind) Type

type Signin

type Signin struct {
	Auth *Auth `protobuf:"bytes,1,opt,name=auth,proto3" json:"auth,omitempty"`
	// contains filtered or unexported fields
}

func (*Signin) Descriptor deprecated

func (*Signin) Descriptor() ([]byte, []int)

Deprecated: Use Signin.ProtoReflect.Descriptor instead.

func (*Signin) GetAuth

func (x *Signin) GetAuth() *Auth

func (*Signin) ProtoMessage

func (*Signin) ProtoMessage()

func (*Signin) ProtoReflect

func (x *Signin) ProtoReflect() protoreflect.Message

func (*Signin) Reset

func (x *Signin) Reset()

func (*Signin) String

func (x *Signin) String() string

type Signout

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

func (*Signout) Descriptor deprecated

func (*Signout) Descriptor() ([]byte, []int)

Deprecated: Use Signout.ProtoReflect.Descriptor instead.

func (*Signout) ProtoMessage

func (*Signout) ProtoMessage()

func (*Signout) ProtoReflect

func (x *Signout) ProtoReflect() protoreflect.Message

func (*Signout) Reset

func (x *Signout) Reset()

func (*Signout) String

func (x *Signout) String() string

type SignoutRes

type SignoutRes struct {
	Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	// contains filtered or unexported fields
}

func (*SignoutRes) Descriptor deprecated

func (*SignoutRes) Descriptor() ([]byte, []int)

Deprecated: Use SignoutRes.ProtoReflect.Descriptor instead.

func (*SignoutRes) GetCode

func (x *SignoutRes) GetCode() int32

func (*SignoutRes) ProtoMessage

func (*SignoutRes) ProtoMessage()

func (*SignoutRes) ProtoReflect

func (x *SignoutRes) ProtoReflect() protoreflect.Message

func (*SignoutRes) Reset

func (x *SignoutRes) Reset()

func (*SignoutRes) String

func (x *SignoutRes) String() string

type Signup

type Signup struct {
	Auth *Auth `protobuf:"bytes,1,opt,name=auth,proto3" json:"auth,omitempty"`
	// contains filtered or unexported fields
}

func (*Signup) Descriptor deprecated

func (*Signup) Descriptor() ([]byte, []int)

Deprecated: Use Signup.ProtoReflect.Descriptor instead.

func (*Signup) GetAuth

func (x *Signup) GetAuth() *Auth

func (*Signup) ProtoMessage

func (*Signup) ProtoMessage()

func (*Signup) ProtoReflect

func (x *Signup) ProtoReflect() protoreflect.Message

func (*Signup) Reset

func (x *Signup) Reset()

func (*Signup) String

func (x *Signup) String() string

type Token

type Token struct {
	Token []byte `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
	// contains filtered or unexported fields
}

func (*Token) Descriptor deprecated

func (*Token) Descriptor() ([]byte, []int)

Deprecated: Use Token.ProtoReflect.Descriptor instead.

func (*Token) GetToken

func (x *Token) GetToken() []byte

func (*Token) ProtoMessage

func (*Token) ProtoMessage()

func (*Token) ProtoReflect

func (x *Token) ProtoReflect() protoreflect.Message

func (*Token) Reset

func (x *Token) Reset()

func (*Token) String

func (x *Token) String() string

type TokenRes

type TokenRes struct {
	Code     int32  `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Id       uint64 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
	Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"`
	Token    []byte `protobuf:"bytes,4,opt,name=token,proto3" json:"token,omitempty"`
	// contains filtered or unexported fields
}

func (*TokenRes) Descriptor deprecated

func (*TokenRes) Descriptor() ([]byte, []int)

Deprecated: Use TokenRes.ProtoReflect.Descriptor instead.

func (*TokenRes) GetCode

func (x *TokenRes) GetCode() int32

func (*TokenRes) GetId

func (x *TokenRes) GetId() uint64

func (*TokenRes) GetToken

func (x *TokenRes) GetToken() []byte

func (*TokenRes) GetUsername

func (x *TokenRes) GetUsername() string

func (*TokenRes) ProtoMessage

func (*TokenRes) ProtoMessage()

func (*TokenRes) ProtoReflect

func (x *TokenRes) ProtoReflect() protoreflect.Message

func (*TokenRes) Reset

func (x *TokenRes) Reset()

func (*TokenRes) String

func (x *TokenRes) String() string

type User

type User struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	Online   bool   `protobuf:"varint,2,opt,name=online,proto3" json:"online,omitempty"`
	// contains filtered or unexported fields
}

func (*User) Descriptor deprecated

func (*User) Descriptor() ([]byte, []int)

Deprecated: Use User.ProtoReflect.Descriptor instead.

func (*User) GetOnline

func (x *User) GetOnline() bool

func (*User) GetUsername

func (x *User) GetUsername() string

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) ProtoReflect

func (x *User) ProtoReflect() protoreflect.Message

func (*User) Reset

func (x *User) Reset()

func (*User) String

func (x *User) String() string

type Users

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

func (*Users) Descriptor deprecated

func (*Users) Descriptor() ([]byte, []int)

Deprecated: Use Users.ProtoReflect.Descriptor instead.

func (*Users) ProtoMessage

func (*Users) ProtoMessage()

func (*Users) ProtoReflect

func (x *Users) ProtoReflect() protoreflect.Message

func (*Users) Reset

func (x *Users) Reset()

func (*Users) String

func (x *Users) String() string

type UsersRes

type UsersRes struct {
	Code  int32   `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
	Users []*User `protobuf:"bytes,2,rep,name=users,proto3" json:"users,omitempty"`
	// contains filtered or unexported fields
}

func (*UsersRes) Descriptor deprecated

func (*UsersRes) Descriptor() ([]byte, []int)

Deprecated: Use UsersRes.ProtoReflect.Descriptor instead.

func (*UsersRes) GetCode

func (x *UsersRes) GetCode() int32

func (*UsersRes) GetUsers

func (x *UsersRes) GetUsers() []*User

func (*UsersRes) ProtoMessage

func (*UsersRes) ProtoMessage()

func (*UsersRes) ProtoReflect

func (x *UsersRes) ProtoReflect() protoreflect.Message

func (*UsersRes) Reset

func (x *UsersRes) Reset()

func (*UsersRes) String

func (x *UsersRes) String() string

Jump to

Keyboard shortcuts

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