12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package app
- import (
- "fmt"
- "os/exec"
- "pbx-api-gin/internal/app/ami/action"
- "pbx-api-gin/internal/app/mysql"
- "pbx-api-gin/internal/app/stc"
- "pbx-api-gin/internal/app/stc/active"
- "pbx-api-gin/internal/app/stc/socket"
- "pbx-api-gin/pkg/lfshook"
- "strings"
- )
- func StartApp() {
- //init mysql
- mysql.CreateDBInstance()
- //Get cab number acording to IP
- IP, err := getIPByCommand()
- if err != nil {
- lfshook.NewLogger().Infof("Get IP err :%+v", err)
- }
- if IP[len(IP)-2:] == "81" {
- active.CabNum = "8"
- } else {
- active.CabNum = "1"
- }
- lfshook.NewLogger().Infof("=================cab number:%s===========", active.CabNum)
- // 启动带有重连机制的连接管理协程
- go stc.StartStcConnection(socket.Conn)
- // 启动其他服务...
- // 启动 AMI
- go func() {
- action.StartAMI(func() {
- lfshook.NewLogger().Info("ami callback")
- }, []func(event map[string]string){})
- }()
- }
- func getIPByCommand() (string, error) {
- cmd := "ifconfig eth0 | grep 'inet addr:' | awk '{print $2}' | cut -d: -f2"
- out, err := exec.Command("bash", "-c", cmd).CombinedOutput()
- if err != nil {
- return "", err
- }
- ip := strings.TrimSpace(string(out))
- if ip == "" {
- return "", fmt.Errorf("no IP address found")
- }
- return ip, nil
- }
|