fix: fix the code

pull/1885/head
luhaoling 2 years ago
parent 4f756c8b29
commit 8ade4677cd

@ -46,7 +46,7 @@ func main() {
apiCmd.AddPortFlag() apiCmd.AddPortFlag()
apiCmd.AddApi(run) apiCmd.AddApi(run)
if err := apiCmd.Execute(); err != nil { if err := apiCmd.Execute(); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -55,6 +55,6 @@ func main() {
// openIM clear msg --clearAll // openIM clear msg --clearAll
msgUtilsCmd.AddCommand(&getCmd.Command, &fixCmd.Command, &clearCmd.Command) msgUtilsCmd.AddCommand(&getCmd.Command, &fixCmd.Command, &clearCmd.Command)
if err := msgUtilsCmd.Execute(); err != nil { if err := msgUtilsCmd.Execute(); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -23,6 +23,6 @@ import (
func main() { func main() {
cronTaskCmd := cmd.NewCronTaskCmd() cronTaskCmd := cmd.NewCronTaskCmd()
if err := cronTaskCmd.Exec(tools.StartTask); err != nil { if err := cronTaskCmd.Exec(tools.StartTask); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -26,6 +26,6 @@ func main() {
msgGatewayCmd.AddPrometheusPortFlag() msgGatewayCmd.AddPrometheusPortFlag()
if err := msgGatewayCmd.Exec(); err != nil { if err := msgGatewayCmd.Exec(); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -24,6 +24,6 @@ func main() {
msgTransferCmd.AddPrometheusPortFlag() msgTransferCmd.AddPrometheusPortFlag()
msgTransferCmd.AddTransferProgressFlag() msgTransferCmd.AddTransferProgressFlag()
if err := msgTransferCmd.Exec(); err != nil { if err := msgTransferCmd.Exec(); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := pushCmd.StartSvr(config.Config.RpcRegisterName.OpenImPushName, push.Start); err != nil { if err := pushCmd.StartSvr(config.Config.RpcRegisterName.OpenImPushName, push.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,7 +29,7 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := authCmd.StartSvr(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil { if err := authCmd.StartSvr(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImConversationName, conversation.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImConversationName, conversation.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImFriendName, friend.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImFriendName, friend.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImGroupName, group.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImGroupName, group.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImMsgName, msg.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImMsgName, msg.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImThirdName, third.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImThirdName, third.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -29,6 +29,6 @@ func main() {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImUserName, user.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImUserName, user.Start); err != nil {
util.ProcessExit(err) util.ExitWithError(err)
} }
} }

@ -17,6 +17,7 @@ package config
import ( import (
_ "embed" _ "embed"
"fmt" "fmt"
"github.com/OpenIMSDK/tools/errs"
"os" "os"
"path/filepath" "path/filepath"
@ -84,24 +85,22 @@ func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
} }
func initConfig(config any, configName, configFolderPath string) error { func initConfig(config any, configName, configFolderPath string) error {
configFolderPath = filepath.Join(configFolderPath, configName) configFullPath := filepath.Join(configFolderPath, configName)
_, err := os.Stat(configFolderPath) _, err := os.Stat(configFullPath)
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
fmt.Println("stat config path error:", err.Error()) return errs.Wrap(err, "IsNotExist "+configFolderPath)
return fmt.Errorf("stat config path error: %w", err)
} }
configFolderPath = filepath.Join(GetProjectRoot(), "config", configName) configFolderPath = filepath.Join(GetProjectRoot(), "config", configName)
fmt.Println("flag's path,enviment's path,default path all is not exist,using project path:", configFolderPath) errs.Wrap(fmt.Errorf("flag's path,enviment's path,default path all is not exist,using project path:%s", configFolderPath))
} }
data, err := os.ReadFile(configFolderPath) data, err := os.ReadFile(configFolderPath)
if err != nil { if err != nil {
return fmt.Errorf("read file error: %w", err) return errs.Wrap(err, "readFile failed, "+configFolderPath)
} }
if err = yaml.Unmarshal(data, config); err != nil { if err = yaml.Unmarshal(data, config); err != nil {
return fmt.Errorf("unmarshal yaml error: %w", err) return errs.Wrap(err, "unmarshal yaml failed, "+configFolderPath)
} }
fmt.Println("use config", configFolderPath)
return nil return nil
} }

@ -40,7 +40,7 @@ func OutDir(path string) (string, error) {
return outDir, nil return outDir, nil
} }
func ProcessExit(err error) { func ExitWithError(err error) {
progName := filepath.Base(os.Args[0]) progName := filepath.Base(os.Args[0])
fmt.Fprintf(os.Stderr, "\n\n%s exit -1: \n%+v\n\n", progName, err) fmt.Fprintf(os.Stderr, "\n\n%s exit -1: \n%+v\n\n", progName, err)
os.Exit(-1) os.Exit(-1)

Loading…
Cancel
Save