ipc

package
v0.0.0-...-103f554 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

README

简单IPC(进程间通信)框架的目的很简单,就是封装通信包的编码细节,让使用者可以专 注于业务。我们这里用channel作为模块之间的通信方式。虽然channel可以传递任何数据类型, 甚至包括另外一个channel,但为了让我们的架构更容易分拆,我们还是严格限制了只能用于传递 JSON格式的字符串类型数据。这样如果之后想将这样的单进程示例修改为多进程的分布式架构, 也不需要全部重写,只需替换通信层即可。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client 客户端

func NewIpcClient

func NewIpcClient(server *IpcServer) *Client

func (*Client) Call

func (client *Client) Call(method, params string) (resp *Response, err error)

type IpcServer

type IpcServer struct {
	Server
}

IpcServer ipc结构体

func NewIpcServer

func NewIpcServer(server Server) *IpcServer

NewIpcServer 实例化ipc对象

func (*IpcServer) Connect

func (server *IpcServer) Connect() (conn chan string)

type Request

type Request struct {
	Method string `json:"method"`
	Params string `json:"params"`
}

Request 请求结构体

type Response

type Response struct {
	Code int    `json:"code"`
	Body string `json:"body"`
}

Response 服务处理响应结构体

type Server

type Server interface {
	Name() string
	Handle(method, params string) *Response
}

Server 业务层接口

Jump to

Keyboard shortcuts

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