uds

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package uds

Package uds

Package uds

Package uds

Package uds

Package uds

Package uds

Package uds

Package uds

Index

Constants

View Source
const (
	ErrUnsupportedOperation = "unsupported operation"
	ErrUnresolvedBody       = "unresolved request body"
	ErrUdsListenerNil       = "unix server listener is nil"
	ErrUdsAlreadyListen     = "unix server already listened"
)

Variables

View Source
var AutoCheckOption = Option{
	AutoCheck:         true,
	AutoCheckDuration: 60,
	AutoRecover:       false,
	ResponseFormat:    Res{},
	RequestFormat:     Req{},
	MaxSize:           1 << 10,
	LogTrace:          true,
}
View Source
var BigBodyOption = Option{
	AutoCheck:         false,
	AutoCheckDuration: 60,
	AutoRecover:       false,
	ResponseFormat:    Res{},
	RequestFormat:     Req{},
	MaxSize:           1 << 20,
}
View Source
var DefaultOption = Option{
	AutoCheck:         false,
	AutoCheckDuration: 60,
	AutoRecover:       false,
	ResponseFormat:    Res{},
	RequestFormat:     Req{},
	MaxSize:           1 << 10,
	LogTrace:          true,
}

Functions

func CreateSocket

func CreateSocket(s string) error

CreateSocket 创建socket 默认监听时会创建遇到无权限时调用此方法创建 s app or app.socket

func GetSocket

func GetSocket(s string) string

GetSocket 获取sock文件每次使用前清空之前的连接

func ModuleName

func ModuleName() string

ModuleName 模块名称

func RemoveSocket

func RemoveSocket(s string) error

RemoveSocket 删除socket

func Response

func Response(c net.Conn, res Res) error

Response 响应body数据

func ResponseAny added in v1.0.4

func ResponseAny(c net.Conn, res interface{}) error

ResponseAny 响应任意数据

Types

type Func added in v1.0.4

type Func func(c *UDSContext, req Req)

type FuncRaw added in v1.0.4

type FuncRaw func(c net.Conn, req Req)

type Funcs

type Funcs map[string]Func

type Option

type Option struct {
	AutoCheck         bool // 定时检查连接
	AutoCheckDuration int  // 单位s
	AutoRecover       bool // 出错后自动恢复
	RequestFormat     Req  // 请求的格式
	ResponseFormat    Res  // 响应的格式
	MaxSize           int  // 接收的byte最大字节数 默认1024
	LogTrace          bool // 是否使用内置的日志记录
}

type Req

type Req struct {
	Operation string   `json:"operation"`
	Data      string   `json:"data"`
	From      string   `json:"from,omitempty"`
	To        []string `json:"to,omitempty"` // 可以有多个接收者
}

type Res

type Res struct {
	Error string   `json:"error"`
	Data  string   `json:"data"`
	From  string   `json:"from,omitempty"`
	To    []string `json:"to,omitempty"` // 可以有多个接收者
}

type UDSContext added in v1.0.4

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

UDSContext UDS服务端的上下文

func (*UDSContext) Operation added in v1.0.4

func (uc *UDSContext) Operation() string

Operation 获取注册到此上下文的操作名称

func (*UDSContext) Response added in v1.0.4

func (uc *UDSContext) Response(res Res) error

Response 响应Res

func (*UDSContext) ResponseAny added in v1.0.4

func (uc *UDSContext) ResponseAny(res interface{}) error

ResponseAny 响应任意数据

type UDSServer

type UDSServer struct {
	Name   string              // 注册服务的名称
	Option Option              // 默认使用fushin option
	Logger log.LoggerInterface // 默认使用fushin logger
	// contains filtered or unexported fields
}

func Default

func Default(name string) *UDSServer

Default 返回默认的unix server

func New

func New(name string) *UDSServer

New 返回全新的unix server

func NewWithOption

func NewWithOption(name string, o Option, l log.LoggerInterface) *UDSServer

NewWithOption 返回自定义的unix server

func (*UDSServer) AddFunc

func (u *UDSServer) AddFunc(operation string, f func(c *UDSContext, req Req))

AddFunc 增加uds响应的处理函数 响应会以注册的format格式化 针对不同的处理可以注册多个func处理请求 operation为请求中的操作关键字 用于匹配func

func (*UDSServer) AutoCheck

func (u *UDSServer) AutoCheck()

func (*UDSServer) Close

func (u *UDSServer) Close()

Close 关闭unix的listener 不再接收请求

func (*UDSServer) Listen

func (u *UDSServer) Listen() error

Listen 在协程启动监听

func (*UDSServer) Proxy added in v1.0.7

func (u *UDSServer) Proxy(f Func) error

Proxy 代理转发 只处理基础的报文错误

func (*UDSServer) Run

func (u *UDSServer) Run(c net.Conn)

Run 启动服务监听请求

Jump to

Keyboard shortcuts

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