dapr

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MPL-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaKeyAppId      = "Hd-App-Id"
	MetaKeyApiVersion = "Hd-Api-Version"
	MetaKeyUserId     = "Hd-User-Id"
	MetaKeyRoleValues = "Hd-Role-Values"
	MetaKeyPermIds    = "Hd-Perm-Ids"
)
View Source
const (
	ModuleKindInvocation moduleKind // dapr调用模块
	ModuleKindEvent                 // dapr事件模块
	ModuleKindDelayEvent            // 延迟事件模块
	ModuleKindHealth                // dapr健康检测模块
)
View Source
const ContentTypeJson = "application/json"

Variables

This section is empty.

Functions

func NewDelayEventModule

func NewDelayEventModule(app string, moduleObject DelayEventModule, functions map[string]DelayEventFunction, options ...DelayEventModuleOption) error

NewDelayEventModule new delay event module

func NewEventModule

func NewEventModule(app, pubsub string, moduleObject EventModule, functions map[string]EventFunction, options ...EventModuleOption) error

NewEventModule 新建事件模块会执行下列操作:

func NewHealthModule

func NewHealthModule(app string, moduleObject HealthModule, fn HealthCheckFunction) error

NewHealthModule 健康模块

func NewInvocationModule

func NewInvocationModule(app string, moduleObject InvocationModule, functions map[string]InvocationFunction) error

NewInvocationModule 新建服务调用模块会执行下列操作: 1. 实例化invocation module 2. 注册invocation functions 3. 注册module

Types

type APIer

type APIer interface {
	Invoke(appId string, moduleVersion int, module, method string, data any, args ...string) ([]byte, error)
	Lock(lockStore, lockOwner, resource string, expiryInSeconds int) error
	Unlock(lockStore, lockOwner, resource string) error
	Publish(pubSubName, topic string, data interface{}, args ...bool) error
	SaveState(storeName, key string, value interface{}) error
	GetState(storeName, key string) ([]byte, error)
	DeleteState(storeName, key string) error
}

func Api

func Api() APIer

type DelayEventFunction

type DelayEventFunction func(message []byte) (retry bool, err error)

type DelayEventModule

type DelayEventModule interface {
	RegisterHandlers(functions map[string]DelayEventFunction) error // 注册Handlers
	GetHandlers() []delayEventHandler                               // 获取handlers
	GetAckTimeout() time.Duration
	GetBackOffPolicy() backoff.BackOff
	// contains filtered or unexported methods
}

func AsDelayEventModule

func AsDelayEventModule(app string, moduleObject any, options ...DelayEventModuleOption) (DelayEventModule, error)

AsDelayEventModule 将一个any类型的结构体转换成DelayEventModule

e,g:

	type v1_test struct {
	  DelayEventModule
	}

	 v := &v1_test{}
	 im, err := AsDelayEventModule("app",v)
     if err != nil {
      ...
     }
     im.DiscoverHandlers()

type DelayEventModuleOption

type DelayEventModuleOption func(*delayEventModuleImpl)

func WithBackOff

func WithBackOff(backoff backoff.BackOff) DelayEventModuleOption

type EventFunction

type EventFunction func(ctx context.Context, event *common.TopicEvent) (retry bool, err error)

type EventModule

type EventModule interface {
	RegisterHandlers(functions map[string]EventFunction) error // 注册Handlers
	GetHandlers() []eventHandler                               // 获取handlers
	GetPubSub() string
	GetAckTimeout() time.Duration
	// contains filtered or unexported methods
}

func AsEventModule

func AsEventModule(app, pubsub string, moduleObject any, options ...EventModuleOption) (EventModule, error)

AsEventModule 将一个any类型的结构体转换成EventModule

e,g:

	type v1_test struct {
	  InvocationModule
	}

	 v := &v1_test{}
	 im, err := AsEventModule("app",v)
     if err != nil {
      ...
     }
     im.DiscoverHandlers()

type EventModuleOption

type EventModuleOption func(*eventModuleImpl)

func WithConsumerTimeout

func WithConsumerTimeout(duration time.Duration) EventModuleOption

type HandlerNameMatcher

type HandlerNameMatcher func(methodName string) (string, bool) // 传入receiver.methodName, 判断是否匹配,然后取出处理后的handlerName

type HealthCheckFunction

type HealthCheckFunction func(context.Context) error

type HealthModule

type HealthModule interface {
	GetHandler() common.HealthCheckHandler
	// contains filtered or unexported methods
}

func AsHealthModule

func AsHealthModule(app string, moduleObject any, fn HealthCheckFunction) (HealthModule, error)

AsHealthModule 将一个any类型的结构体转换成HealthModule

e,g:

	type v1_test struct {
	  HealthModule
	}

	 v := &v1_test{}
	 im, err := AsHealthModule("app",v)
     if err != nil {
      ...
     }

type InvocationFunction

type InvocationFunction func(ctx context.Context, event *common.InvocationEvent) (any, error)

type InvocationModule

type InvocationModule interface {
	DiscoverHandlers(args ...HandlerNameMatcher) ([]invocationHandler, error)                   // 通过反射发现Handlers
	RegisterHandlers(functions map[string]InvocationFunction) error                             // 注册Handlers
	GetHandlers() []invocationHandler                                                           // 获取handlers
	GetRouteAnnotations(srcPath string, args ...HandlerNameMatcher) ([]*routeAnnotation, error) // 从源代码获取路由注解
	// contains filtered or unexported methods
}

func AsInvocationModule

func AsInvocationModule(app string, moduleObject any) (InvocationModule, error)

AsInvocationModule 将一个any类型的结构体转换成InvocationModule

e,g:

	type v1_test struct {
	  InvocationModule
	}

	 v := &v1_test{}
	 im, err := AsInvocationModule("app",v)
     if err != nil {
      ...
     }
     im.DiscoverHandlers()

type MetaManager

type MetaManager interface {
	GetHttpHeaderKeys() []string
	GetValue(ctx context.Context, key string) string
	GetValues(ctx context.Context, key string) []string
	GetAppId(ctx context.Context) string
	GetApiVersion(ctx context.Context) string
	GetUserId(ctx context.Context) int64
	GetRoleValues(ctx context.Context) []*RoleValue
	GetPermIds(ctx context.Context) []int64
}

func Meta

func Meta() MetaManager

type RoleValue

type RoleValue struct {
	Id    int64
	Level int
}

type Server

type Server interface {
	Start() error
	Stop() error
	GracefulStop() error
	GetInvocationHandlers() map[string]common.ServiceInvocationHandler
	GetBindingHandlers() map[string]common.BindingInvocationHandler
	GetEvents() []daprEvent
}

func NewGrpcServer

func NewGrpcServer(logger intf.LoggerProvider, address string) (Server, error)

func NewHttpServer

func NewHttpServer(logger intf.LoggerProvider, address string) (Server, error)

type SourceCodeHandler

type SourceCodeHandler interface {
	Discover(skipDirs ...string) (*SourceCodeInfo, error)                                                                // 查找源代码信息
	Patch(sourceCodeInfo *SourceCodeInfo) error                                                                          // 给源代码文件打补丁,加入导入匿名import模块路径
	FindRoutes(sourceCodeInfo *SourceCodeInfo, handlerNameMatchers ...HandlerNameMatcher) ([]*protobuf.RouteItem, error) // 找路由,必须在patch完成后重启一个进程来执行该方法,否则patch内容不生效
}

func NewSourceCodeHandler

func NewSourceCodeHandler(baseDir string) SourceCodeHandler

NewSourceCodeHandler 获取模块源代码处理器

type SourceCodeInfo

type SourceCodeInfo struct {
	ModulePaths map[moduleKind]string // 模块的路径
	ServerEntry string                // 服务的入口文件即dapr.NewGrpcServer所在的go文件
}

SourceCodeInfo 模块源代码信息

Jump to

Keyboard shortcuts

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