모듈 충돌 해결 및 코드 정리
This commit is contained in:
51
core/api.go
51
core/api.go
@ -13,8 +13,8 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/common"
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
common "repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -114,6 +114,32 @@ func (caller apiCaller) isValidUser(service any, category string) (valid bool, a
|
||||
return svcdesc.isValidAPIUser(category, email), false
|
||||
}
|
||||
|
||||
func (caller apiCaller) uploadAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
// file, header, err := r.FormFile("file")
|
||||
// if err != nil {
|
||||
// logger.Error(err)
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// return
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// contents, err := io.ReadAll(file)
|
||||
// if err != nil {
|
||||
// logger.Error(err)
|
||||
// w.WriteHeader(http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
|
||||
// ext := path.Ext(header.Filename)
|
||||
// if ext == ".zip" {
|
||||
|
||||
// }
|
||||
|
||||
// // deploys 폴더는 파일시스템 서비스이므로 다운로드 가능
|
||||
// filename := path.Join("deploys", name, version, name+ext)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (caller apiCaller) whitelistAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
mg := caller.mg
|
||||
queryvals := r.URL.Query()
|
||||
@ -189,6 +215,25 @@ func (caller apiCaller) whitelistAPI(w http.ResponseWriter, r *http.Request) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (caller apiCaller) divisionAPI(w http.ResponseWriter, r *http.Request, svcid string, divid string) error {
|
||||
// if r.Method == "PUT" {
|
||||
// // svcid, divid에 statemeta 설정
|
||||
// file, header, err := r.FormFile("file")
|
||||
// if err != nil {
|
||||
// logger.Error(err)
|
||||
// w.WriteHeader(http.StatusBadRequest)
|
||||
// return
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// if header.
|
||||
// stateFile, header, err := r.FormFile("file")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func (caller apiCaller) serviceAPI(w http.ResponseWriter, r *http.Request) error {
|
||||
mg := caller.mg
|
||||
queryvals := r.URL.Query()
|
||||
@ -464,6 +509,8 @@ func (mg *Maingate) api(w http.ResponseWriter, r *http.Request) {
|
||||
err = caller.configAPI(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/account") {
|
||||
err = caller.accountAPI(w, r)
|
||||
} else if strings.HasSuffix(r.URL.Path, "/upload") {
|
||||
err = caller.uploadAPI(w, r)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@ -21,8 +21,8 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/common"
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
common "repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -545,9 +545,17 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu
|
||||
w.Write(configraw)
|
||||
})
|
||||
|
||||
if err := os.MkdirAll("static", os.ModePerm); err != nil {
|
||||
// 일반 엔드유저한테 오픈할 static 페이지
|
||||
return err
|
||||
}
|
||||
|
||||
fsx := http.FileServer(http.Dir("./console"))
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "console", "/"), http.StripPrefix("/console/", fsx))
|
||||
|
||||
ssx := http.FileServer(http.Dir("./static"))
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, "static", "/"), http.StripPrefix("/static/", ssx))
|
||||
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "request_login_url", AuthPlatformGoogle), mg.platform_google_get_login_url)
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize", AuthPlatformGoogle), mg.platform_google_authorize)
|
||||
serveMux.HandleFunc(common.MakeHttpHandlerPattern(prefix, "authorize_result", AuthPlatformGoogle), mg.platform_google_authorize_result)
|
||||
@ -767,7 +775,7 @@ func (mg *Maingate) updateUserinfo(info usertokeninfo) (bool, string, string) {
|
||||
|
||||
}
|
||||
|
||||
func (mg *Maingate) getProviderInfo(platform string, uid string) (error, string, string) {
|
||||
func (mg *Maingate) getProviderInfo(platform string, uid string) (string, string, error) {
|
||||
provider := ""
|
||||
providerid := ""
|
||||
|
||||
@ -778,15 +786,15 @@ func (mg *Maingate) getProviderInfo(platform string, uid string) (error, string,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err, "", ""
|
||||
return "", "", err
|
||||
}
|
||||
if found == nil {
|
||||
return errors.New("firebase info not found: " + uid), "", ""
|
||||
return "", "", errors.New("firebase info not found: " + uid)
|
||||
}
|
||||
provider = found["firebaseprovider"].(string)
|
||||
providerid = found["firebaseproviderId"].(string)
|
||||
if provider == "" || providerid == "" {
|
||||
return errors.New("getProviderInfo - firebase info not found: " + provider + " / " + providerid), "", ""
|
||||
return "", "", errors.New("getProviderInfo - firebase info not found: " + provider + " / " + providerid)
|
||||
}
|
||||
default:
|
||||
provider = platform
|
||||
@ -794,10 +802,10 @@ func (mg *Maingate) getProviderInfo(platform string, uid string) (error, string,
|
||||
}
|
||||
|
||||
if provider == "" || providerid == "" {
|
||||
return errors.New("getProviderInfo - provider info not found: " + provider + " / " + providerid), "", ""
|
||||
return "", "", errors.New("getProviderInfo - provider info not found: " + provider + " / " + providerid)
|
||||
}
|
||||
|
||||
return nil, provider, providerid
|
||||
return provider, providerid, nil
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
@ -12,9 +12,8 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/common"
|
||||
common "repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -98,11 +97,30 @@ func (wl *whitelist) isMember(email string, platform string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
DivisionState_Closed = string("closed")
|
||||
DivisionState_Maintenance = string("maintenance")
|
||||
DivisionState_RestrictedOpen = string("restricted")
|
||||
DivisionState_FullOpen = string("open")
|
||||
)
|
||||
|
||||
type maintenance struct {
|
||||
Link string
|
||||
StartTime primitive.Timestamp
|
||||
}
|
||||
|
||||
type division struct {
|
||||
Url string `bson:"url"`
|
||||
Priority int `bson:"priority"`
|
||||
State string `bson:"state"`
|
||||
Maintenance maintenance `bson:"maintenance"`
|
||||
}
|
||||
|
||||
type serviceDescription struct {
|
||||
// sync.Mutex
|
||||
Id primitive.ObjectID `bson:"_id"`
|
||||
ServiceName string `bson:"service"`
|
||||
Divisions map[string]any `bson:"divisions"`
|
||||
Divisions map[string]division `bson:"divisions"`
|
||||
ServiceCode string `bson:"code"`
|
||||
UseWhitelist bool `bson:"use_whitelist"`
|
||||
Closed bool `bson:"closed"`
|
||||
@ -118,7 +136,7 @@ type serviceDescription struct {
|
||||
getUserBrowserInfo func(r *http.Request) (string, error)
|
||||
getUserTokenWithCheck func(platform string, userid string, brinfo string) (usertokeninfo, error)
|
||||
updateUserinfo func(info usertokeninfo) (bool, string, string)
|
||||
getProviderInfo func(platform string, uid string) (error, string, string)
|
||||
getProviderInfo func(platform string, uid string) (string, string, error)
|
||||
|
||||
apiUsers unsafe.Pointer
|
||||
divisionsSerialized unsafe.Pointer
|
||||
@ -305,7 +323,7 @@ func (sh *serviceDescription) link(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err, newType, newId = sh.getProviderInfo(newType, newId)
|
||||
newType, newId, err = sh.getProviderInfo(newType, newId)
|
||||
if err != nil {
|
||||
logger.Error("getProviderInfo failed :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
@ -416,7 +434,7 @@ func (sh *serviceDescription) authorize(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
logger.Println("auth success :", authtype, uid, email, session)
|
||||
|
||||
err, newType, newId := sh.getProviderInfo(authtype, uid)
|
||||
newType, newId, err := sh.getProviderInfo(authtype, uid)
|
||||
if err != nil {
|
||||
logger.Error("getProviderInfo failed :", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
@ -6,9 +6,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/logger"
|
||||
|
||||
"repositories.action2quare.com/ayo/go-ayo/common"
|
||||
common "repositories.action2quare.com/ayo/gocommon"
|
||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
Reference in New Issue
Block a user