arpc

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT Imports: 19 Imported by: 0

README

arpc

A RPC Framework for api and rtc signal

Documentation

Index

Constants

View Source
const (
	AuthOK = iota
	AuthTimestampError
	AuthExpireError
	AuthSignatureError
)
View Source
const (
	ParseRequestError = 20000
)

Variables

View Source
var (
	Debug  = GetLogger().Debug
	Debugf = GetLogger().Debugf
	Debugv = GetLogger().Debugv
	Debugw = GetLogger().Debugw
	Error  = GetLogger().Error
	Errorf = GetLogger().Errorf
	Errorv = GetLogger().Errorv
	Errorw = GetLogger().Errorw
	Info   = GetLogger().Info
	Infof  = GetLogger().Infof
	Infov  = GetLogger().Infov
	Infow  = GetLogger().Infow
	Slow   = GetLogger().Slow
	Slowf  = GetLogger().Slowf
	Slowv  = GetLogger().Slowv
	Sloww  = GetLogger().Sloww
)

Functions

func CheckAuth added in v1.0.2

func CheckAuth(timeout int64, signature, key, cid, id, ts, userdata string) int

func CloseLogger

func CloseLogger()

func FillDefault

func FillDefault(v any) error

func GenSignature

func GenSignature(key, cid, id, userdata string) (string, string)

func MustInitLog

func MustInitLog(conf *LogConf)

func MustLoad

func MustLoad(path string, v any)

Types

type APIContext

type APIContext interface {
	SetLogger(log Logger)           // 设置 logger
	SetContext(ctx context.Context) // 设置请求 Context

	Request() any                     // 获取请求结构体,用于收到 HTTP 请求时做请求参数校验时调用
	Handler(l *APILogic) (any, error) // API 处理函数
}

APIContext 接口,每个 HTTP 请求会对应一个 APIContext 实例

type APILogic

type APILogic struct {
	Context       any // 业务 Context
	Uri           string
	NewAPIContext NewAPIContextFunc // 收到 HTTP 请求后,创建请求的 APIContext 回调函数
}

API 业务逻辑,每个接口对应一个该类的实例

func NewAPILogic

func NewAPILogic(f NewAPIContextFunc, ctx any) *APILogic

用于创建 APILogic 使用 f 为收到 HTTP 请求后,创建请求的 APIContext 回调函数 ctx 为业务自定义内容

type APIServer

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

APIServer 结构

func CreateAPIServerWithConf

func CreateAPIServerWithConf(c *RestConf) *APIServer

使用已初始化的配置创建 APIServer

func (*APIServer) RegisteHandler

func (s *APIServer) RegisteHandler(prefix string, method string, path string, l *APILogic)

注册 API 路由 prefix 为请求 path 中的版本,如 /v1,/v2 method 为 HTTP 请求方法,如 http.MethodGet path 为访问路径 l 为请求处理的 APILogic 实例

func (*APIServer) RegisteUserHandler

func (s *APIServer) RegisteUserHandler(prefix string, method string, path string, f http.HandlerFunc)

注册用户 HTTPHandler prefix 为请求 path 中的版本,如 /v1,/v2 method 为 HTTP 请求方法,如 http.MethodGet path 为访问路径 f 为用户 HTTP 请求处理函数

func (*APIServer) Run

func (s *APIServer) Run(wg *sync.WaitGroup)

启动 APIServer

type CommonConf added in v1.0.2

type CommonConf struct {
	ClusterId  string `json:",default=test-cluster"`
	InstanceId string `json:",default=test-instance"`
	AuthKey    string `json:",optional"`
}

func (*CommonConf) ReplaceEnv added in v1.0.2

func (c *CommonConf) ReplaceEnv()

type EncryptionType

type EncryptionType int
const (
	SHA_256 EncryptionType = 1
)

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type FloatCmd

type FloatCmd = red.FloatCmd

FloatCmd is an alias of redis.FloatCmd.

type FloatPair

type FloatPair struct {
	Key   string
	Score float64
}

A FloatPair is a key/pair for float set used in redis zet.

type GeoLocation

type GeoLocation = red.GeoLocation

GeoLocation is used with GeoAdd to add geospatial location.

type GeoPos

type GeoPos = red.GeoPos

GeoPos is used to represent a geo position.

type GeoRadiusQuery

type GeoRadiusQuery = red.GeoRadiusQuery

GeoRadiusQuery is used with GeoRadius to query geospatial index.

type HttpClient

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

func NewHttpClient

func NewHttpClient(ctx context.Context, method string, url string, req any) *HttpClient

func (*HttpClient) Body

func (hc *HttpClient) Body() ([]byte, error)

func (*HttpClient) Close

func (hc *HttpClient) Close()

func (*HttpClient) Do

func (hc *HttpClient) Do() error

func (*HttpClient) Parse

func (hc *HttpClient) Parse(val any) error

func (*HttpClient) StatusCode

func (hc *HttpClient) StatusCode() int

type IntCmd

type IntCmd = red.IntCmd

IntCmd is an alias of redis.IntCmd.

type LogConf

type LogConf = logx.LogConf

type Logger

type Logger logx.Logger

func GetLogger

func GetLogger() Logger

func GetLoggerWithContext

func GetLoggerWithContext(ctx context.Context) Logger

type NewAPIContextFunc

type NewAPIContextFunc func() APIContext

type OptParser added in v1.0.2

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

func NewOptParser added in v1.0.2

func NewOptParser() *OptParser

New Option Parser

func (*OptParser) GetOpt added in v1.0.2

func (opt *OptParser) GetOpt(optstring string) bool

Parse Opt, the option string optstring may contain the following elements: individual characters, and characters followed by a colon to indicate an option argument is to follow. For example, an option string "x" recognizes an option “-x”, and an option string "x:" recognizes an option and argument “-x argument”. It does not matter to getopt() if a following argument has leading white space.

func (*OptParser) Opt added in v1.0.2

func (opt *OptParser) Opt() byte

Get Option Key, if GetOpt parse option string error, Opt will get '?'

func (*OptParser) OptVal added in v1.0.2

func (opt *OptParser) OptVal() string

Get Option Value

type Option

type Option func(r *Redis)

Option defines the method to customize a Redis.

type Pair

type Pair struct {
	Key   string
	Score int64
}

A Pair is a key/pair set used in redis zset.

type Pipeliner

type Pipeliner = red.Pipeliner

Pipeliner is an alias of redis.Pipeliner.

type Pool

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

func NewPool

func NewPool(new func() any) *Pool

func (*Pool) Get

func (p *Pool) Get() any

func (*Pool) Put

func (p *Pool) Put(x any)

func (*Pool) Resource

func (p *Pool) Resource() (int32, int32)

type Redis

type Redis = red.Redis

func NewRedisClient

func NewRedisClient(conf *RedisConf) *Redis

type RedisConf

type RedisConf = redis.RedisConf

type RedisLock

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

func NewRedisLock

func NewRedisLock(rds *Redis, key string, seconds int) *RedisLock

func (*RedisLock) Acquire

func (rl *RedisLock) Acquire() (bool, error)

func (*RedisLock) BlockAcquire

func (rl *RedisLock) BlockAcquire() (bool, error)

func (*RedisLock) Release

func (rl *RedisLock) Release() (bool, error)

type RedisNode

type RedisNode interface {
	red.RedisNode
}

RedisNode interface represents a redis node.

type RestConf

type RestConf = rest.RestConf

type Script

type Script = red.Script

Script is an alias of redis.Script.

func NewScript

func NewScript(script string) *Script

type ServiceError

type ServiceError struct {
	StatusCode int
	Code       int
	Message    string
}

func (*ServiceError) Error

func (se *ServiceError) Error() string

func (*ServiceError) GenResponse

func (se *ServiceError) GenResponse(w http.ResponseWriter, err error)

type StringCmd

type StringCmd = red.StringCmd

StringCmd is an alias of redis.StringCmd.

type Z

type Z = red.Z

Z represents sorted set member.

type ZStore

type ZStore = red.ZStore

ZStore is an alias of redis.ZStore.

Directories

Path Synopsis
from gozero logx.rotatelogger.go
from gozero logx.rotatelogger.go

Jump to

Keyboard shortcuts

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