plugin

package module
v0.0.0-...-a453172 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 18 Imported by: 4

README

Golang SDK 说明

生成 *.pb.go 文件

基于 .proto 文件生成 .pb.go 文件,需要以下几个步骤

步骤1

安装 Protocol Buffers 编译器 protoc:

访问 Protocol Buffers 的 GitHub 仓库 下载 最新的编译器版本

解压缩下载的文件,并将 protoc 可执行文件添加到系统的可执行文件路径中

步骤2

安装 Go 的 Protobuf 插件 protoc-gen-go:

打开终端并运行以下命令来安装 protoc-gen-go 插件:

go get google.golang.org/protobuf/cmd/protoc-gen-go

步骤3

使用 protoc 编译器生成Go代码文件。在终端中,使用以下命令

protoc --proto_path=../proto driver.proto --go_out=plugins=grpc:. 
  • protoc: Protocol Buffers 编译器的命令
  • --proto_path=../proto: 指定了 proto 文件的搜索路径。在这里,../proto 是 proto 文件的相对路径,表示 proto 文件位于当前目录的两级父目录下的 proto 目录中。编译器将在这个路径下查找 driver.proto 文件
  • driver.proto: 要编译的具体 protobuf 文件的名称。在这个例子中,它是 driver.proto
  • --go_out=plugins=grpc:.: 这是生成 Go 语言代码的选项。它告诉编译器使用 gRPC 插件生成 Go 语言的代码,并将生成的文件放在当前目录 ./ 中

综合起来,此命令通知 Protocol Buffers 编译器在指定的 ../../proto 目录下查找 driver.proto 文件,然后使用 gRPC 插件生成 Go 语言的代码,并将生成的代码文件放在当前目录。这些生成的文件通常包括用于与 gRPC 通信的 Go 语言结构和函数

Documentation

Index

Constants

View Source
const PluginName = "driver"
View Source
const (
	ProgramEntryYaml = "program.yml" // in program package to specify entry
)

Variables

View Source
var Handshake = plugin.HandshakeConfig{

	ProtocolVersion:  1,
	MagicCookieKey:   "DRIVER_PLUGIN",
	MagicCookieValue: "ON",
}

Handshake is a common handshake that is shared by plugin and host.

View Source
var PluginFactories = make(map[string]*Client)
View Source
var PluginLock sync.Mutex
View Source
var PluginMap = map[string]plugin.Plugin{
	PluginName: &DriverGRPCPlugin{},
}

PluginMap is the map of plugins we can dispense.

Functions

func ClosePlugin

func ClosePlugin(name string) error

func Serve

func Serve(opts *ServeOpts) error

Types

type BackendConfig

type BackendConfig struct {
	DriverName string
	ReportSvc  Report
	Log        log.Logger
}

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func GetPlugin

func GetPlugin(name string) (*Client, error)

func NewClient

func NewClient(name, path string) (*Client, error)

func RegisterPlugin

func RegisterPlugin(driver DriverConfig) (*Client, error)

func (*Client) Check

func (c *Client) Check() error

func (*Client) Disable

func (c *Client) Disable() error

func (*Client) Get

func (c *Client) Get(req *Request) (*Response, error)

func (*Client) GetDriverInfo

func (c *Client) GetDriverInfo(req *Request) (*Response, error)

func (*Client) Open

func (c *Client) Open() error

func (*Client) Restart

func (c *Client) Restart(req *Request) (*Response, error)

func (*Client) Set

func (c *Client) Set(req *Request) (*Response, error)

func (*Client) SetConfig

func (c *Client) SetConfig(req *Request) (*Response, error)

func (*Client) Setup

func (c *Client) Setup(config *BackendConfig) (*Response, error)

func (*Client) Start

func (c *Client) Start(req *Request) (*Response, error)

func (*Client) Status

func (c *Client) Status() (enable, on bool)

func (*Client) Stop

func (c *Client) Stop(req *Request) (*Response, error)

type Driver

type Driver interface {
	// GetDriverInfo 获取驱动信息
	GetDriverInfo(req *Request) (*Response, error)
	// SetConfig 配置驱动,目前只配置了驱动的配置文件路径
	SetConfig(req *Request) (*Response, error)
	// Setup 宿主进程上报接口传递,必须调用下述逻辑,其余可用户自定义
	Setup(config *BackendConfig) (*Response, error)
	// Start 驱动采集启动,用户自定义实现
	Start(req *Request) (*Response, error)
	// Restart 驱动重启,用户自定义实现
	Restart(req *Request) (*Response, error)
	// Stop 驱动停止,用户自定义实现
	Stop(req *Request) (*Response, error)

	// Get 召测,用户自定义实现
	Get(req *Request) (*Response, error)
	// Set 置数,用户自定义实现
	Set(req *Request) (*Response, error)
}

type DriverConfig

type DriverConfig struct {
	Name       string `yaml:"name" json:"name"`
	BinPath    string `yaml:"binPath" json:"binPath"`
	ConfigPath string `yaml:"configPath" json:"configPath"`
}

type DriverGRPCPlugin

type DriverGRPCPlugin struct {
	plugin.NetRPCUnsupportedPlugin
	Factory Factory
	Log     log.Logger
}

func (*DriverGRPCPlugin) GRPCClient

func (p *DriverGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (any, error)

func (*DriverGRPCPlugin) GRPCServer

func (p *DriverGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error

type Entry

type Entry struct {
	Entry string `yaml:"entry" json:"entry" validate:"nonzero"`
}

type Factory

type Factory func(context.Context, *BackendConfig) (Driver, error)

Factory is the factory function to create a logical driver backend.

type Report

type Report interface {
	Post(req *Request) (*Response, error)
	State(req *Request) (*Response, error)
}

Report 驱动 --> 宿主

type Request

type Request struct {
	BrokerID  uint32 `json:"brokerID"`
	Req       string `json:"req"`
	RequestID string `json:"requestID"`
}

type Response

type Response struct {
	Data      string `json:"data"`
	RequestID string `json:"requestID"`
}

type ServeOpts

type ServeOpts struct {
	FactoryFunc     Factory
	TLSProviderFunc TLSProviderFunc
	Logger          log.Logger
}

type TLSProviderFunc

type TLSProviderFunc func() (*tls.Config, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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