Skip to content

Commit

Permalink
update: export module (vesoft-inc#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
huaxiabuluo authored and veeding committed Jun 14, 2022
1 parent 3238a0e commit ca56f2f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 45 deletions.
39 changes: 0 additions & 39 deletions server-v2/api/studio/internal/common/utils.go

This file was deleted.

4 changes: 2 additions & 2 deletions server-v2/api/studio/internal/svc/servicecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/vesoft-inc/go-pkg/httpclient"
"github.com/vesoft-inc/go-pkg/response"
"github.com/vesoft-inc/go-pkg/validator"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/common"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/config"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/pkg/ecode"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/pkg/utils"
"github.com/zeromicro/go-zero/core/logx"
)

Expand Down Expand Up @@ -51,7 +51,7 @@ func createResponseHandler(c config.Config) response.Handler { // nolint:gocriti
Errorf: logx.Errorf,
DebugInfo: c.Debug.Enable,
CheckBodyType: func(r *http.Request) response.StandardHandlerBodyType {
if common.PathMatchPattern(r.URL.Path, common.IgnoreHandlerBodyPatterns) {
if utils.PathMatchPattern(r.URL.Path, utils.IgnoreHandlerBodyPatterns) {
return response.StandardHandlerBodyNone
}
return response.StandardHandlerBodyJson
Expand Down
18 changes: 18 additions & 0 deletions server-v2/api/studio/pkg/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package server

import (
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/config"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/service/importer"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/svc"
)

type (
ServiceContext = svc.ServiceContext
Config = config.Config
)

var NewServiceContext = svc.NewServiceContext

func InitDB(dbFilePath string) {
importer.InitDB(dbFilePath)
}
25 changes: 24 additions & 1 deletion server-v2/api/studio/pkg/utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ import (
"io"
"io/ioutil"
"net/http"
"regexp"
"strings"
)

const MIMEOctetStream = "application/octet-stream"
var (
ReserveRequestRoutes = []string{
"/api-nebula/db/",
"/api/files",
"/api/import-tasks",
}
ReserveResponseRoutes = []string{
"/api-nebula/db/",
"/api/import-tasks",
}
IgnoreHandlerBodyPatterns = []*regexp.Regexp{
regexp.MustCompile(`^/api/import-tasks/\d+/download`),
}
)

func CopyHttpRequest(r *http.Request) *http.Request {
reqCopy := new(http.Request)
Expand Down Expand Up @@ -64,3 +78,12 @@ func PathHasPrefix(path string, routes []string) bool {
}
return false
}

func PathMatchPattern(path string, patterns []*regexp.Regexp) bool {
for _, pattern := range patterns {
if pattern.MatchString(path) {
return true
}
}
return false
}
6 changes: 3 additions & 3 deletions server-v2/api/studio/studio.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"fmt"
"net/http"

"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/common"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/config"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/handler"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/service/importer"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/internal/svc"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/pkg/auth"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/pkg/logging"
"github.com/vesoft-inc/nebula-studio/server-v2/api/studio/pkg/utils"

"github.com/vesoft-inc/go-pkg/middleware"
"github.com/zeromicro/go-zero/core/conf"
Expand Down Expand Up @@ -56,12 +56,12 @@ func main() {
server.Use(auth.AuthMiddlewareWithCtx(svcCtx))
server.Use(rest.ToMiddleware(middleware.ReserveRequest(middleware.ReserveRequestConfig{
Skipper: func(r *http.Request) bool {
return !common.PathHasPrefix(r.URL.Path, common.ReserveRequestRoutes)
return !utils.PathHasPrefix(r.URL.Path, utils.ReserveRequestRoutes)
},
})))
server.Use(rest.ToMiddleware(middleware.ReserveResponseWriter(middleware.ReserveResponseWriterConfig{
Skipper: func(r *http.Request) bool {
return !common.PathHasPrefix(r.URL.Path, common.ReserveResponseRoutes)
return !utils.PathHasPrefix(r.URL.Path, utils.ReserveResponseRoutes)
},
})))

Expand Down

0 comments on commit ca56f2f

Please sign in to comment.