This commit is contained in:
Leufolium 2023-12-24 13:35:01 +08:00
commit 3669f868de
4 changed files with 60 additions and 5 deletions

View File

@ -64,6 +64,8 @@ const PackageRootPath = "/app/wishpal-ironfan"
const MainConfigPath = PackageRootPath + "/etc/mix/mix-test.yaml"
const ProductionConfigPath = PackageRootPath + "/etc/mix/mix-prod.yaml"
const LocalConfigPath = "/Users/erwin/wishpal/wishpal-ironfan/etc/mix/mix-local.yaml"
const ReservedUserIdRegexesConfig = PackageRootPath + "/etc/mix/resource/reg_reserved_user_id_config.xml"

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"net"
"net/http"
"os"
"runtime"
@ -21,13 +22,18 @@ import (
"service/library/redis"
"service/library/sms"
"service/library/validator"
"strings"
"time"
)
func main() {
// 加载配置
// 1.默认配置
configPath := consts.MainConfigPath
configPath := consts.ProductionConfigPath
//if os.Getenv("PROJECT_ENV") == "production" {
// configPath = consts.ProductionConfigPath
//}
cfg := new(conf.ConfigSt)
err := configcenter.LoadConfig(configPath, cfg)
if err != nil {
@ -91,7 +97,7 @@ func main() {
validator.InitDefaultNotNullValidator()
controller.Init(router)
srv := &http.Server{
Addr: fmt.Sprintf("%s:%d", cfg.App.Ip, cfg.App.Port),
Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.App.Port),
Handler: router,
}
httpserver.StartHttpServer(srv, cfg.DefaultConfig)
@ -103,3 +109,25 @@ func PrintAndExit(msg string) {
time.Sleep(1) //wait logger flush
os.Exit(1)
}
func GetIp() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
PrintAndExit("get ip fail")
return "127.0.0.1"
}
retIp := ""
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ip := ipnet.IP.String()
if strings.HasPrefix(ip, "172.") {
retIp = ip
break
}
}
}
}
return retIp
}

View File

@ -12,7 +12,7 @@ app:
port: 9999
mix_mongo:
uri: "mongodb://root:Tbuy!vj@24vq@dds-bp1628b447c242e41.mongodb.rds.aliyuncs.com:3717,dds-bp1628b447c242e42.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-74245203"
uri: "mongodb://root:Wishpal2024@dds-bp1628b447c242e41.mongodb.rds.aliyuncs.com:3717,dds-bp1628b447c242e42.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-74245203"
username: ""
password: ""
max_pool_size: 16
@ -50,7 +50,7 @@ alipay:
apollo:
app_id: "wishpal_live_service"
cluster: "dev"
ip: "http://localhost:8080"
ip: "http://172.16.0.174:8080"
namespace_name: "application,tag,account_init,platform,support_wx_id,version"
secret: ""
is_back_up_config: true
@ -82,7 +82,7 @@ media:
expire_time: 1800
redis:
uri: "r-bp1slashewonusih6h.redis.rds.aliyuncs.com"
uri: "r-bp1slashewonusih6h.redis.rds.aliyuncs.com:6379"
password: "SWEbaxdt6aM@"
max_active: 0
max_idle: 0

25
main.go
View File

@ -4,10 +4,12 @@ import (
"fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/bwmarrin/snowflake"
"net"
"os"
"service/library/configcenter"
"service/library/redis"
"strconv"
"strings"
)
func main() {
@ -18,8 +20,31 @@ func main() {
n, _ := snowflake.NewNode(6)
fmt.Println(n.Generate().Time())
fmt.Println(GetIp())
}
func GetIp() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
fmt.Println(err)
return "127.0.0.1"
}
retIp := ""
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ip := ipnet.IP.String()
if strings.HasPrefix(ip, "172.") {
retIp = ip
break
}
}
}
}
return retIp
}
func UploadImage() {
// yourEndpoint填写Bucket对应的Endpoint以华东1杭州为例填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
// yourAccessKeyId以及yourAccessKeySecret分别填写从STS服务获取的临时访问密钥AccessKey ID和AccessKey Secret