noauth일 때 로컬 아이피를 읽어서 주소를 만듬

This reverts commit 4ae86f0a57.
This commit is contained in:
2023-06-22 16:50:04 +09:00
parent f0f5011e10
commit e65fbafd36

View File

@ -10,6 +10,7 @@ import (
"io"
"math/big"
"math/rand"
"net"
"net/http"
"os"
"strings"
@ -174,24 +175,8 @@ type Maingate struct {
firebaseAppContext context.Context
}
var collectionNameMod = int32(0)
// New :
func New(ctx context.Context) (*Maingate, error) {
if *devflag && atomic.AddInt32(&collectionNameMod, 1) == 1 {
hostname, _ := os.Hostname()
CollectionLink = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionLink)))
CollectionAuth = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAuth)))
CollectionWhitelist = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionWhitelist)))
CollectionService = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionService)))
CollectionAccount = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionAccount)))
CollectionBlock = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionBlock)))
CollectionPlatformLoginToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionPlatformLoginToken)))
CollectionUserToken = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionUserToken)))
CollectionGamepotUserInfo = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionGamepotUserInfo)))
CollectionFirebaseUserInfo = common.CollectionName(fmt.Sprintf("%s-%s", hostname, string(CollectionFirebaseUserInfo)))
}
var config maingateConfig
if err := common.LoadConfig(&config); err != nil {
return nil, err
@ -451,6 +436,19 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
if *noauth {
host, _ := os.Hostname()
addrs, err := net.InterfaceAddrs()
if err != nil {
return err
}
ipaddr := "127.0.0.1"
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ipaddr = ipnet.IP.String()
}
}
}
empty := serviceDescription{
ServiceDescriptionSummary: ServiceDescriptionSummary{
ServiceCode: "000000000000",
@ -461,7 +459,8 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
Priority: 0,
State: DivisionState_FullOpen,
},
Url: fmt.Sprintf("http://%s/warehouse", host),
Url: fmt.Sprintf("http://%s/warehouse", ipaddr),
},
},
}