httpsvr

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: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SignKey 签名Key
	SignKey = "EE7a1c5bc548e542GBFc340c531657F4"
)

Variables

View Source
var (
	Conf = Config{
		Port: 15001,
		Test: true,
	}

	Flags = []cli.Flag{
		&cli.IntFlag{
			Name:        "HTTP_PORT",
			Value:       5001,
			Usage:       "-HTTP_PORT 7001",
			EnvVars:     []string{"HTTP_PORT"},
			Destination: &Conf.Port,
		},
		&cli.BoolFlag{
			Name:        "HTTP_TEST",
			Value:       true,
			Usage:       "-HTTP_TEST true",
			EnvVars:     []string{"HTTP_TEST"},
			Destination: &Conf.Test,
		},
	}
)

Functions

func BlackList

func BlackList(playerid int64) (bool, error)

BlackList 黑名单策略

func CreateHTTPServer

func CreateHTTPServer()

func GenSign

func GenSign(vals ...string) string

GenSign 生成签名

func GetLocalServer

func GetLocalServer() string

func GetServerID

func GetServerID() string

func GetVersion

func GetVersion() int

GetVersion 版本号

func HandlePbReplyTs added in v0.0.6

func HandlePbReplyTs(paths map[string]PbReplyTs, check bool)

func Listen

func Listen(server *api.Conf, svc api.Service)

Listen 监听HTTP

func Makesign

func Makesign(r *http.Request, path string) string

Makesign 设置请求签名

func PostPb added in v0.0.6

func PostPb(path string, handle PbReply, check bool)

func Register

func Register(paths map[string]PbReply, check bool)

func RegisterContent

func RegisterContent(paths map[string]ByteReply)

RegisterContent 注册函数

func RegisterGetHandle

func RegisterGetHandle(subPath string, handle Handle)

RegisterGetHandle 注册http get handle

func RegisterGetHandleNoUserID

func RegisterGetHandleNoUserID(subPath string, handle Handle)

RegisterGetHandleNoUserID 注册http post handle

func RegisterJSON

func RegisterJSON(paths map[string]JsonReply)

RegisterJSON 注册函数

func RegisterPostHandle

func RegisterPostHandle(subPath string, handle Handle)

RegisterPostHandle 注册http post handle

func RegisterPostHandleNoUserID

func RegisterPostHandleNoUserID(subPath string, handle Handle)

RegisterPostHandleNoUserID 注册http post handle

func RegisterString

func RegisterString(paths map[string]StrReply)

RegisterString 注册函数

func Run

func Run(cfg *api.Conf, service api.Service)

Run 启动服务

func Start

func Start(addr string)

Types

type ByteReply

type ByteReply func(r *Request) []byte

type Config

type Config struct {
	Port int  `csv:"noHolidaysTime"`
	Test bool `csv:"holidaysTime"`
}

type Context

type Context struct {
	Rds       redis.Conn
	Db        *xorm.Engine
	MqChannel *mqwrap.MqChannel
	UserID    string
	Query     url.Values
	Params    httprouter.Params
	Body      []byte

	W   http.ResponseWriter
	Ctx context.Context
	// contains filtered or unexported fields
}

func (*Context) GetHTTPRequest

func (ctx *Context) GetHTTPRequest() *http.Request

GetHTTPRequest 获取请求信息

func (*Context) WriteRsp

func (ctx *Context) WriteRsp(m *pb.HttpReply)

WriteRsp send protobuf messsage to peer

type Handle

type Handle func(*Context)

type HttpReply

type HttpReply struct {
	Err  int    `json:"err"`
	Msg  string `json:"msg"`
	Data []byte `json:"data"`
}

type JsonReply

type JsonReply func(r *Request) (int, interface{})

type PbReply

type PbReply func(r *Request) (proto.Message, int32)

type PbReplyTs added in v0.0.6

type PbReplyTs func(r *Request) proto.Message

type Request

type Request struct {
	Path   string
	Method string
	Log    *mlog.Logger
	// contains filtered or unexported fields
}

Request 请求结构

func NewRequest

func NewRequest(w http.ResponseWriter, r *http.Request) *Request

NewRequest 创建请求对象

func (*Request) AllStringParam

func (r *Request) AllStringParam() string

AllStringParam 获得所有参数字符串

func (*Request) Body

func (r *Request) Body() []byte

Body request body

func (*Request) GetCookie

func (r *Request) GetCookie() *api.Cookie

GetCookie get cookie header

func (*Request) GetHTTPRequest

func (r *Request) GetHTTPRequest() *http.Request

GetHTTPRequest 获取http请求结构体

func (*Request) GetRemoteAddr

func (r *Request) GetRemoteAddr() string

GetRemoteAddr 获得远端地址

func (*Request) GetRequest

func (r *Request) GetRequest() *http.Request

GetRequest 获得http请求

func (*Request) GetVals

func (r *Request) GetVals() url.Values

GetVals 获取http请求结构体

func (*Request) GetXForwardedFor

func (r *Request) GetXForwardedFor() string

GetXForwardedFor 获得远端地址

func (*Request) Int32Param

func (r *Request) Int32Param(key string) (int32, bool)

Int32Param 获得int32参数

func (*Request) Int64Param

func (r *Request) Int64Param(key string) (int64, bool)

Int64Param 获得int64参数

func (*Request) IntParam

func (r *Request) IntParam(key string) (int, bool)

IntParam 获得int参数

func (*Request) SendCode

func (r *Request) SendCode(data []byte)

SendCode qq回调返回

func (*Request) SendNotFind

func (r *Request) SendNotFind()

SendNotFind 发送没有找到

func (*Request) SendSUCCESS

func (r *Request) SendSUCCESS()

SendSUCCESS 发送没有找到

func (*Request) SetCookie

func (r *Request) SetCookie(cookie *api.Cookie)

SetCookie set cookie header

func (*Request) StringParam

func (r *Request) StringParam(key string) (string, bool)

StringParam 获得字符串参数

func (*Request) Token

func (r *Request) Token() *api.Token

Token 获得请求token

func (*Request) VerifyToken

func (r *Request) VerifyToken() bool

VerifyToken 验证token

type StrReply

type StrReply func(r *Request) string

Jump to

Keyboard shortcuts

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