// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
|
|
|
|
package container
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// 基本组件信息
|
|
// @Implement LAPP_GAAS_GFrame_BACKEND/container/ComponentInformation
|
|
type ElementInformation struct {
|
|
// 实例工厂
|
|
factory Factory
|
|
// 接口类型
|
|
interfaceType Interface
|
|
}
|
|
|
|
// 创建服务组件信息
|
|
// 参数
|
|
// 1.工厂方法
|
|
// 返回值:
|
|
// 1.服务组件信息
|
|
// 2.错误
|
|
func NewElementInformation(factory interface{}) (*ElementInformation, error) {
|
|
|
|
valueOfFactory, interfaceType, err := parseFactory(factory)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &ElementInformation{valueOfFactory, interfaceType}, nil
|
|
}
|
|
|
|
// @Reference LAPP_GAAS_GFrame_BACKEND/container/ComponentInformation.Interface
|
|
func (info *ElementInformation) Interface() Interface {
|
|
return info.interfaceType
|
|
}
|
|
|
|
// @Reference LAPP_GAAS_GFrame_BACKEND/container/ComponentInformation.BuildHandler
|
|
func (info *ElementInformation) BuildHandler(session *Session) (ComponentHandler, error) {
|
|
|
|
if session == nil {
|
|
return nil, errors.New(fmt.Sprintf("会话不能为空!"))
|
|
}
|
|
instance, err := info.factory.Create(&session.SessionContext)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return NewElementHandler(instance), nil
|
|
}
|