You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1.5 KiB

// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
package container
import (
"errors"
"fmt"
)
// 服务组件句柄
// @Implement LAPP_LF_MOM_BACKEND/container/ComponentHandler
type ServiceHandler struct {
// @Inherit LAPP_LF_MOM_BACKEND/container/ElementHandler
ElementHandler
// 方法句柄映射: map[方法名]方法句柄
methodMapping map[string]*ServiceMethodHandler
}
// 创建服务组件句柄
// 参数
// 1.服务组件实例
// 2.方法句柄映射: map[方法名]方法句柄
// 返回值:
// 1.服务组件句柄
// 2.错误
func NewServiceHandler(instance Instance, methodMapping map[string]*ServiceMethodHandler) (*ServiceHandler, error) {
if methodMapping == nil {
return nil, errors.New(fmt.Sprintf("方法句柄映射不能为空!"))
}
if len(methodMapping) > 0 {
for methodName, methodHandler := range methodMapping {
if methodName == "" {
return nil, errors.New(fmt.Sprintf("方法名不能为空!"))
}
if methodHandler == nil {
return nil, errors.New(fmt.Sprintf("方法句柄不能为空!"))
}
}
}
return &ServiceHandler{ElementHandler{instance}, methodMapping}, nil
}
// 创建获取方法句柄
// 参数
// 1.方法名
// 返回值:
// 1.方法句柄
func (handler *ServiceHandler) Method(methodName string) *ServiceMethodHandler {
if methodName == "" {
return nil
}
serviceMethodHandler, ok := handler.methodMapping[methodName]
if !ok {
return nil
}
return serviceMethodHandler
}