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.
Open-IM-Server/cmd/api/main.go

52 lines
1.3 KiB

4 years ago
package main
import (
2 years ago
"OpenIM/internal/api"
2 years ago
"OpenIM/pkg/common/cmd"
2 years ago
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/log"
2 years ago
"OpenIM/pkg/common/mw"
3 years ago
"fmt"
2 years ago
"github.com/OpenIMSDK/openKeeper"
2 years ago
"os"
4 years ago
"strconv"
2 years ago
"OpenIM/pkg/common/constant"
4 years ago
)
2 years ago
func main() {
2 years ago
apiCmd := cmd.NewApiCmd()
apiCmd.AddPortFlag()
apiCmd.AddApi(run)
if err := apiCmd.Execute(); err != nil {
2 years ago
fmt.Println(err)
os.Exit(1)
}
2 years ago
}
2 years ago
func run(port int) error {
2 years ago
if port == 0 {
port = config.Config.Api.GinPort[0]
}
2 years ago
zk, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, 10, config.Config.Zookeeper.UserName, config.Config.Zookeeper.Password)
2 years ago
if err != nil {
return err
}
2 years ago
log.NewPrivateLog(constant.LogFileName)
2 years ago
zk.AddOption(mw.GrpcClient())
router := api.NewGinRouter(zk)
2 years ago
address := constant.LocalHost + ":" + strconv.Itoa(port)
if config.Config.Api.ListenIP != "" {
2 years ago
address = config.Config.Api.ListenIP + ":" + strconv.Itoa(port)
}
2 years ago
fmt.Println("start api server, address: ", address, ", OpenIM version: ", config.Version)
2 years ago
//log2.Info(context.Background(), "start server success", "address", address, "version", config.Version)
2 years ago
log.Info("s", "start server")
2 years ago
err = router.Run(address)
3 years ago
if err != nil {
2 years ago
log.Error("", "api run failed ", address, err.Error())
2 years ago
return err
}
return nil
}