复制项目
This commit is contained in:
41
pkg/common/cmd/chat_api.go
Normal file
41
pkg/common/cmd/chat_api.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.imall.cloud/openim/chat/internal/api/chat"
|
||||
"git.imall.cloud/openim/chat/pkg/common/config"
|
||||
"github.com/openimsdk/tools/system/program"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type ChatApiCmd struct {
|
||||
*RootCmd
|
||||
ctx context.Context
|
||||
configMap map[string]any
|
||||
apiConfig chat.Config
|
||||
}
|
||||
|
||||
func NewChatApiCmd() *ChatApiCmd {
|
||||
var ret ChatApiCmd
|
||||
ret.configMap = map[string]any{
|
||||
config.ShareFileName: &ret.apiConfig.Share,
|
||||
config.ChatAPIChatCfgFileName: &ret.apiConfig.ApiConfig,
|
||||
config.DiscoveryConfigFileName: &ret.apiConfig.Discovery,
|
||||
config.RedisConfigFileName: &ret.apiConfig.Redis,
|
||||
}
|
||||
ret.RootCmd = NewRootCmd(program.GetProcessName(), WithConfigMap(ret.configMap))
|
||||
ret.ctx = context.WithValue(context.Background(), "version", config.Version)
|
||||
ret.Command.RunE = func(cmd *cobra.Command, args []string) error {
|
||||
return ret.runE()
|
||||
}
|
||||
return &ret
|
||||
}
|
||||
|
||||
func (a *ChatApiCmd) Exec() error {
|
||||
return a.Execute()
|
||||
}
|
||||
|
||||
func (a *ChatApiCmd) runE() error {
|
||||
return chat.Start(a.ctx, a.Index(), &a.apiConfig)
|
||||
}
|
||||
Reference in New Issue
Block a user