dapr

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

README

lib-dapr

dapr library

New Invocation Module

type exampleModule struct {
    module.InvocationModule
}

when the suffix of module struct name is module, hd will take example as module name

Initialize module

func init() {
    v := &exampleModule{}
    err := module.NewInvocationModule(v, g.App, map[string]module.InvocationFunction{
        "hello": v.helloHandler, // handler adds here
	})
    if err != nil {
        panic(err)
    }
}

Add Invocation Handler

func (*exampleModule) helloHandler(ctx biz.Context, data []byte) (any, error) {
	var req ExampleRequest
	if err := json.Unmarshal(data, &req); err != nil {
		return nil, err
	}

	err := xxx.New().Hello(req.Name)
	if err != nil {
		return nil, errors.Wrapf(err, "hello world", "req", req)
	}

	return &pb.SimpleMessage{"Message": "ok"}, nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInvocationModules

func GetInvocationModules() []module.InvocationModule

func LoadStoredExposedHandlers

func LoadStoredExposedHandlers(fs embed.FS) ([]*protobuf.DaprHandler, error)

LoadStoredExposedHandlers 从embed.FS中加载ast解析后保存的DaprHandlers

func NewGrpcServer

func NewGrpcServer(app, address string, options ...ServerOption) (types.AppServer, error)

func NewHttpServer

func NewHttpServer(app, address string, options ...ServerOption) (types.AppServer, error)

Types

type RegisterFunction

type RegisterFunction func(string, []*protobuf.DaprHandler) error

RegisterFunction app向gateway注册的函数

type ServerOption

type ServerOption func(impl *daprServerImpl)

func WithAssets

func WithAssets(fs embed.FS) ServerOption

func WithDebug

func WithDebug(debug bool) ServerOption

func WithProviders

func WithProviders(providers ...types.Provider) ServerOption

WithProviders 提供的providers

func WithRegisterFunction

func WithRegisterFunction(fn RegisterFunction) ServerOption

func WithRegisterHandlers

func WithRegisterHandlers(handlers []*protobuf.DaprHandler) ServerOption

func WithSkipRegister

func WithSkipRegister() ServerOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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