maintenance 링크를 잘못 만들던 문제 수정
This commit is contained in:
10
core/api.go
10
core/api.go
@ -18,7 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
common "repositories.action2quare.com/ayo/gocommon"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -66,9 +66,9 @@ func (fd *FileDocumentDesc) Save() error {
|
|||||||
if fd.Extract {
|
if fd.Extract {
|
||||||
switch path.Ext(destFile) {
|
switch path.Ext(destFile) {
|
||||||
case ".zip":
|
case ".zip":
|
||||||
err = common.Unzip(destFile)
|
err = gocommon.Unzip(destFile)
|
||||||
case ".tar":
|
case ".tar":
|
||||||
err = common.Untar(destFile)
|
err = gocommon.Untar(destFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -431,9 +431,9 @@ func (mg *Maingate) api(w http.ResponseWriter, r *http.Request) {
|
|||||||
ptr := atomic.LoadPointer(&mg.admins)
|
ptr := atomic.LoadPointer(&mg.admins)
|
||||||
adminsptr := (*globalAdmins)(ptr)
|
adminsptr := (*globalAdmins)(ptr)
|
||||||
|
|
||||||
if adminsptr.modtime != common.ConfigModTime() {
|
if adminsptr.modtime != gocommon.ConfigModTime() {
|
||||||
var config globalAdmins
|
var config globalAdmins
|
||||||
if err := common.LoadConfig(&config); err == nil {
|
if err := gocommon.LoadConfig(&config); err == nil {
|
||||||
config.parse()
|
config.parse()
|
||||||
adminsptr = &config
|
adminsptr = &config
|
||||||
atomic.StorePointer(&mg.admins, unsafe.Pointer(adminsptr))
|
atomic.StorePointer(&mg.admins, unsafe.Pointer(adminsptr))
|
||||||
|
|||||||
@ -2,20 +2,18 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
common "repositories.action2quare.com/ayo/gocommon"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -139,9 +137,9 @@ type serviceDescription struct {
|
|||||||
ServerApiTokens []primitive.ObjectID `bson:"api_tokens" json:"api_tokens"`
|
ServerApiTokens []primitive.ObjectID `bson:"api_tokens" json:"api_tokens"`
|
||||||
Admins []string `bson:"admins" json:"admins"`
|
Admins []string `bson:"admins" json:"admins"`
|
||||||
|
|
||||||
auths *common.AuthCollection
|
auths *gocommon.AuthCollection
|
||||||
wl *whitelist
|
wl *whitelist
|
||||||
mongoClient common.MongoClient
|
mongoClient gocommon.MongoClient
|
||||||
sessionTTL time.Duration
|
sessionTTL time.Duration
|
||||||
MaximumNumLinkAccount int64
|
MaximumNumLinkAccount int64
|
||||||
|
|
||||||
@ -238,11 +236,16 @@ func (sh *serviceDescription) prepare(mg *Maingate) error {
|
|||||||
} else if strings.HasPrefix(div.Maintenance.Notice, "http") {
|
} else if strings.HasPrefix(div.Maintenance.Notice, "http") {
|
||||||
div.Maintenance.link = div.Maintenance.Notice
|
div.Maintenance.link = div.Maintenance.Notice
|
||||||
} else {
|
} else {
|
||||||
hasher := md5.New()
|
var fd FileDocumentDesc
|
||||||
hasher.Write(sh.Id[:])
|
if err := sh.mongoClient.FindOneAs(CollectionFile, bson.M{
|
||||||
subfolder := hex.EncodeToString(hasher.Sum(nil))[:8]
|
"key": div.Maintenance.Notice,
|
||||||
|
}, &fd, options.FindOne().SetProjection(bson.M{"link": 1})); err != nil {
|
||||||
|
logger.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
div.Maintenance.link = path.Join("static", subfolder, div.Maintenance.Notice)
|
div.Maintenance.link = fd.Link
|
||||||
|
logger.Println("div.Maintenance.link :", fd.Link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -687,7 +690,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
newsession := primitive.NewObjectID()
|
newsession := primitive.NewObjectID()
|
||||||
expired := primitive.NewDateTimeFromTime(time.Now().UTC().Add(sh.sessionTTL))
|
expired := primitive.NewDateTimeFromTime(time.Now().UTC().Add(sh.sessionTTL))
|
||||||
newauth := common.Authinfo{
|
newauth := gocommon.Authinfo{
|
||||||
Accid: accid,
|
Accid: accid,
|
||||||
ServiceCode: sh.ServiceCode,
|
ServiceCode: sh.ServiceCode,
|
||||||
Platform: authtype,
|
Platform: authtype,
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
common "repositories.action2quare.com/ayo/gocommon"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -24,7 +24,7 @@ type authPipelineDocument struct {
|
|||||||
DocumentKey struct {
|
DocumentKey struct {
|
||||||
Id primitive.ObjectID `bson:"_id"`
|
Id primitive.ObjectID `bson:"_id"`
|
||||||
} `bson:"documentKey"`
|
} `bson:"documentKey"`
|
||||||
Authinfo *common.Authinfo `bson:"fullDocument"`
|
Authinfo *gocommon.Authinfo `bson:"fullDocument"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type servicePipelineDocument struct {
|
type servicePipelineDocument struct {
|
||||||
@ -289,7 +289,7 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux *
|
|||||||
logger.Println("service is on the board! :", data.Service)
|
logger.Println("service is on the board! :", data.Service)
|
||||||
atomic.StorePointer(&mg.serviceptr, unsafe.Pointer(data.Service))
|
atomic.StorePointer(&mg.serviceptr, unsafe.Pointer(data.Service))
|
||||||
if !already {
|
if !already {
|
||||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, data.Service.ServiceCode, "/"), mg.service())
|
serveMux.Handle(gocommon.MakeHttpHandlerPattern(prefix, data.Service.ServiceCode, "/"), mg.service())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchAuthCollection(parentctx context.Context, ac *common.AuthCollection, mongoClient common.MongoClient) {
|
func watchAuthCollection(parentctx context.Context, ac *gocommon.AuthCollection, mongoClient gocommon.MongoClient) {
|
||||||
defer func() {
|
defer func() {
|
||||||
s := recover()
|
s := recover()
|
||||||
if s != nil {
|
if s != nil {
|
||||||
|
|||||||
4
main.go
4
main.go
@ -6,7 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
common "repositories.action2quare.com/ayo/gocommon"
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
"repositories.action2quare.com/ayo/gocommon/flagx"
|
"repositories.action2quare.com/ayo/gocommon/flagx"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
"repositories.action2quare.com/ayo/maingate/core"
|
"repositories.action2quare.com/ayo/maingate/core"
|
||||||
@ -36,7 +36,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server := common.NewHTTPServer(serveMux)
|
server := gocommon.NewHTTPServer(serveMux)
|
||||||
logger.Println("maingate is started")
|
logger.Println("maingate is started")
|
||||||
if err := server.Start(); err != nil {
|
if err := server.Start(); err != nil {
|
||||||
logger.Error("maingate is stopped with error :", err)
|
logger.Error("maingate is stopped with error :", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user