api

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// UpdateTokenTime 更新token时间
	UpdateTokenTime = (60 * 60 * 24 / 2)
)

Variables

This section is empty.

Functions

func ConvertLocalAddr

func ConvertLocalAddr(addr string) string

ConvertLocalAddr 转换成本地IP 格式 IP:PORT

func GenToken

func GenToken(playerID int64) string

GenToken 生成token

func HTTPPost

func HTTPPost(url string, contentType string, body io.Reader) ([]byte, error)

HTTPPost 发送httpPost请求(不认证服务端证书)

func HTTPPostToken

func HTTPPostToken(url string, playerID int64, contentType string, body io.Reader) ([]byte, error)

HTTPPostToken 发送httpPost请求(不认证服务端证书)

func NewUUID

func NewUUID() uuid.UUID

NewUUID 生成UUID

Types

type Conf

type Conf struct {
	Addr          string          //服务器监听地址
	Name          string          //服务器名称
	Type          ServerType      //服务器类型
	ConnRedis     bool            //连接redis		//默认不连接
	RedisServer   RedisServerInfo //redis服务器信息
	ConnMQ        bool            //连接MQ // 默认不连接
	MQServer      MQServerInfo    //MQ服务器信息
	ConnDB        bool            //连接数据库		//默认不连接
	DBServer      DBServerInfo    //数据库信息
	OrderTestMode bool            //支付测试模式开关 打开情况下只支付最小额度
	ConsulAddr    string          //服务注册地址
	CertFile      string
	Keyfile       string
	Version       string
	StdConf       StConfig
}

Conf 服务器配置信息

func (*Conf) GetIPAddr

func (c *Conf) GetIPAddr() string

GetIPAddr 获取服务器ip地址

func (*Conf) GetIPPort

func (c *Conf) GetIPPort() int

GetIPPort 获取服务器端口

type Cookie struct {
	Token string `json:"Token"`
}

Cookie 请求头信息

func (*Cookie) Decode

func (c *Cookie) Decode(str string) bool

Decode 解码

func (*Cookie) Encode

func (c *Cookie) Encode() string

Encode 编码

type DBServerInfo

type DBServerInfo struct {
	Addr     string
	Account  string
	Password string
	DBName   string
}

DBServerInfo 数据库信息

type MQServerInfo

type MQServerInfo struct {
	Addr     string
	Account  string
	Password string
}

MQServerInfo Mq服务器信息

type RedisServerInfo

type RedisServerInfo struct {
	Addr     string
	DataBase int
}

RedisServerInfo Redis服务器信息

type ServerType

type ServerType string

ServerType 服务器类型

var (
	//AuthServer 认证服
	AuthServer ServerType = "auth"
	//RechargeServer 支付服务器
	RechargeServer ServerType = "recharge_xzy"
	//PushServer 推送服务器
	PushServer ServerType = "push"
)

func (ServerType) String

func (t ServerType) String() string

String 获得服务器类型名称

type Service

type Service interface {

	// Init is called before the program/service is started
	// This method must be non-blocking.
	Init(s *Conf) error

	// Start is called after Init. This method must be non-blocking.
	Start() error

	// Stop is called in response to syscall.SIGINT, syscall.SIGTERM, or when a
	// Service is stopped.
	Stop() error
}

Service interface contains Start and Stop methods which are called when the service is started and stopped. The Init method is called before the service is started.

The Start and Init methods must be non-blocking.

Implement this interface and pass it to the Run function to start your program.

type StConfig

type StConfig struct {
	Name         string          `json:"Name"`
	Listen       string          `json:"Listen"`
	RPCPort      string          `json:"RPCPort"`
	CertFile     string          `json:"CertFile"`
	KeyFile      string          `json:"KeyFile"`
	RedisServer  RedisServerInfo `json:"RedisServer"`
	MQServer     MQServerInfo    `json:"MQServer"`
	DBServer     DBServerInfo    `json:"DBServer"`
	ConsulAddr   string          `json:"ConsulAddr"`
	AuthAddr     string          `json:"AuthAddr"`
	RechargeAddr string          `json:"RechargeAddr"`
	Language     string          `json:"Language"`
}

StConfig 配置文件

type Token

type Token struct {
	PlayerID   int64
	CreateTime int64
}

Token 结构

func ParseToken

func ParseToken(token string) (*Token, error)

ParseToken 解析Token

func (*Token) IsExpire

func (t *Token) IsExpire() bool

IsExpire 是否过期

func (*Token) RemainingTime

func (t *Token) RemainingTime() int64

RemainingTime 剩余过期时间单位秒

Jump to

Keyboard shortcuts

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