package main import ( "Medical_ERP/common/global" _ "Medical_ERP/common/initialize" "Medical_ERP/conf" "Medical_ERP/controllers" _ "Medical_ERP/models" _ "Medical_ERP/routers" "fmt" beego "github.com/beego/beego/v2/server/web" "github.com/go-resty/resty/v2" "github.com/tidwall/gjson" "gogs.baozhida.cn/zoie/OAuth-core/pkg" _ "image/jpeg" _ "image/png" "log" "net/http" "os" ) //go:generate swag init --parseDependency --parseDepth=6 // @title 药品进销存管理系统 // @version 1.0 // @description 药品进销存管理系统 // @Host 192.168.11.77:8110 // @BasePath /api // @Schemes http // @securityDefinitions.apikey Bearer // @in header // @name Authorization func main() { if beego.BConfig.RunMode == "dev" { //beego.BConfig.WebConfig.DirectoryIndex = true //beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.SetStaticPath("/swagger", "docs") } // 错误处理 beego.ErrorController(&controllers.ErrorController{}) // 从 panic 中恢复 beego.BConfig.RecoverPanic = true //go func() { // // 初始化服务发现 // InitServiceDiscovery() //}() go InitServiceDiscovery() //models.BatchAlterMedicineTemplateTable() // 批量修改表结构 //models.SyncMedicineInfoToMedicineImg() fmt.Println(pkg.Green("Server run at:")) fmt.Printf("- Local: http://127.0.0.1:%d/ \r\n", conf.Httpport) fmt.Printf("- Network: http://%s:%d/ \r\n", pkg.GetLocalHost(), conf.Httpport) fmt.Println(pkg.Green("Swagger run at:")) fmt.Printf("- Local: http://127.0.0.1:%d/swagger/index.html \r\n", conf.Httpport) fmt.Printf("- Network: http://%s:%d/swagger/index.html \r\n", pkg.GetLocalHost(), conf.Httpport) beego.Run() } // 初始化服务发现 func InitServiceDiscovery() { AuthCode, _ := beego.AppConfig.String("Service_authCode") Host, _ := beego.AppConfig.String("Service_host") Name, _ := beego.AppConfig.String("Service_name") RoleApiUrl, _ := beego.AppConfig.String("Service_roleApiUrl") reqPath := "/api/service-disco" url := conf.OAuthBaseUrl + reqPath r, reqError := resty.New().R().SetBody(map[string]string{ "authCode": AuthCode, "host": Host, "name": Name, "roleApiUrl": RoleApiUrl, }).Post(url) if reqError != nil { log.Fatal("初始化服务发现失败", reqError) os.Exit(-1) } code := gjson.GetBytes(r.Body(), "code").Int() id := gjson.GetBytes(r.Body(), "data").Int() if code != http.StatusOK { log.Fatal("初始化服务发现失败", string(r.Body())) os.Exit(-1) } global.ServiceId = int(id) }