Add User route and Refactor code
This commit is contained in:
parent
519749fd3a
commit
b311a41dc7
24 changed files with 902 additions and 489 deletions
205
server/server.go
205
server/server.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -12,33 +13,27 @@ import (
|
|||
"path/filepath"
|
||||
"recipe-manager/config"
|
||||
"recipe-manager/data"
|
||||
"recipe-manager/enums/permissions"
|
||||
"recipe-manager/models"
|
||||
"recipe-manager/routers"
|
||||
"recipe-manager/services/logger"
|
||||
"recipe-manager/services/oauth"
|
||||
"recipe-manager/services/recipe"
|
||||
"recipe-manager/services/sheet"
|
||||
"recipe-manager/services/user"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/spf13/viper"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var (
|
||||
Log = logger.GetInstance()
|
||||
python_api_lock sync.Mutex
|
||||
|
||||
upgrader = websocket.Upgrader{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
pythonApiLock sync.Mutex
|
||||
)
|
||||
|
||||
func loadConfig(path string) (*config.ServerConfig, error) {
|
||||
|
|
@ -48,25 +43,27 @@ func loadConfig(path string) (*config.ServerConfig, error) {
|
|||
|
||||
viper.AutomaticEnv()
|
||||
|
||||
var config config.ServerConfig
|
||||
var serverConfig config.ServerConfig
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = viper.Unmarshal(&config)
|
||||
err = viper.Unmarshal(&serverConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
return &serverConfig, nil
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
server *http.Server
|
||||
data *data.Data
|
||||
cfg *config.ServerConfig
|
||||
oauth oauth.OAuthService
|
||||
server *http.Server
|
||||
data *data.Data
|
||||
database *sqlx.DB
|
||||
cfg *config.ServerConfig
|
||||
oauth oauth.OAuthService
|
||||
taoLogger *logger.TaoLogger
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
|
|
@ -77,30 +74,33 @@ func NewServer() *Server {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
taoLogger := logger.NewTaoLogger(serverCfg)
|
||||
|
||||
return &Server{
|
||||
server: &http.Server{Addr: fmt.Sprintf(":%d", serverCfg.ServerPort)},
|
||||
data: data.NewData(),
|
||||
cfg: serverCfg,
|
||||
oauth: oauth.NewOAuthService(serverCfg),
|
||||
server: &http.Server{Addr: fmt.Sprintf(":%d", serverCfg.ServerPort)},
|
||||
data: data.NewData(taoLogger),
|
||||
database: data.NewSqliteDatabase(),
|
||||
cfg: serverCfg,
|
||||
oauth: oauth.NewOAuthService(serverCfg),
|
||||
taoLogger: taoLogger,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Run() error {
|
||||
|
||||
// logger
|
||||
// defer log_inst.Sync()
|
||||
|
||||
if s.cfg.Debug {
|
||||
// logger.SetLevel("DEBUG")
|
||||
Log.Debug("Debug mode", zap.Bool("enable", s.cfg.Debug))
|
||||
logger.EnableDebug(s.cfg.Debug)
|
||||
}
|
||||
|
||||
//go cli.CommandLineListener()
|
||||
|
||||
s.createHandler()
|
||||
// log.Printf("Server running on %s", s.server.Addr)
|
||||
Log.Info("Server running", zap.String("addr", s.server.Addr))
|
||||
s.taoLogger.Log.Info("Server running", zap.String("addr", s.server.Addr))
|
||||
|
||||
defer func(Log *zap.Logger) {
|
||||
err := Log.Sync()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}(s.taoLogger.Log)
|
||||
|
||||
return s.server.ListenAndServe()
|
||||
}
|
||||
|
||||
|
|
@ -115,15 +115,22 @@ func (s *Server) createHandler() {
|
|||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||
}))
|
||||
|
||||
database := data.NewData()
|
||||
// Recipe Service
|
||||
recipeService := recipe.NewRecipeService(s.data)
|
||||
|
||||
// User Service
|
||||
userService := user.NewUserService(s.cfg, s.database, s.taoLogger)
|
||||
|
||||
// Seed
|
||||
_ = userService.CreateNewUser(context.WithValue(context.Background(), "user", &models.User{Email: "system"}), "kenta420", "poomipat.c@forth.co.th", "", permissions.SuperAdmin)
|
||||
|
||||
// Auth Router
|
||||
r.Group(func(r chi.Router) {
|
||||
ar := routers.NewAuthRouter(s.cfg, s.oauth)
|
||||
ar := routers.NewAuthRouter(s.cfg, s.oauth, userService, s.taoLogger)
|
||||
ar.Route(r)
|
||||
})
|
||||
|
||||
// Protect Group
|
||||
// Protected Group
|
||||
r.Group(func(r chi.Router) {
|
||||
|
||||
r.Use(func(next http.Handler) http.Handler {
|
||||
|
|
@ -134,7 +141,7 @@ func (s *Server) createHandler() {
|
|||
token.AccessToken = cookie.Value
|
||||
}
|
||||
|
||||
user, err := s.oauth.GetUserInfo(r.Context(), token)
|
||||
userInfo, err := s.oauth.GetUserInfo(r.Context(), token)
|
||||
|
||||
if err != nil {
|
||||
// if have refresh token, set refresh token to token
|
||||
|
|
@ -149,11 +156,38 @@ func (s *Server) createHandler() {
|
|||
return
|
||||
}
|
||||
|
||||
userInfo, err = s.oauth.GetUserInfo(r.Context(), newToken)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
// set new token to cookie
|
||||
w.Header().Add("set-cookie", fmt.Sprintf("access_token=%s; Path=/; HttpOnly; SameSite=None; Secure; Max-Age=3600", newToken.AccessToken))
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "user", user)
|
||||
if userInfo != nil {
|
||||
userFromDB, err := userService.GetUserByEmail(r.Context(), userInfo.Email)
|
||||
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if userFromDB != nil {
|
||||
userInfo.ID = userFromDB.ID
|
||||
userInfo.Name = userFromDB.Name
|
||||
if userFromDB.Picture != "" {
|
||||
userInfo.Picture = userFromDB.Picture
|
||||
}
|
||||
userInfo.Permissions = userFromDB.Permissions
|
||||
}
|
||||
}
|
||||
|
||||
ctx := context.WithValue(r.Context(), "user", userInfo)
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
|
|
@ -163,18 +197,18 @@ func (s *Server) createHandler() {
|
|||
|
||||
// locking
|
||||
if !pyAPIhandler(w, r) {
|
||||
Log.Warn("Merge - user tried to access while another user is requesting merge",
|
||||
s.taoLogger.Log.Warn("Merge - user tried to access while another user is requesting merge",
|
||||
zap.String("user", r.Context().Value("user").(*models.User).Name))
|
||||
return
|
||||
} else {
|
||||
Log.Debug("Merge - user has access", zap.String("user", r.Context().Value("user").(*models.User).Name))
|
||||
s.taoLogger.Log.Debug("Merge - user has access", zap.String("user", r.Context().Value("user").(*models.User).Name))
|
||||
}
|
||||
|
||||
var targetMap map[string]interface{}
|
||||
err := json.NewDecoder(r.Body).Decode(&targetMap)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
Log.Fatal("Merge request failed", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Merge request failed", zap.Error(err))
|
||||
return
|
||||
}
|
||||
repo_path := "cofffeemachineConfig/coffeethai02_"
|
||||
|
|
@ -187,12 +221,12 @@ func (s *Server) createHandler() {
|
|||
// find target file in the cofffeemachineConfig
|
||||
if _, err := os.Stat(repo_path + master_version + ".json"); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
Log.Fatal("Merge request failed. Master file not found: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Merge request failed. Master file not found: ", zap.Error(err))
|
||||
return
|
||||
}
|
||||
if _, err := os.Stat(repo_path + dev_version + ".json"); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
Log.Fatal("Merge request failed. Dev file not found: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Merge request failed. Dev file not found: ", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -201,59 +235,59 @@ func (s *Server) createHandler() {
|
|||
|
||||
// Get who's requesting
|
||||
user := r.Context().Value("user").(*models.User)
|
||||
Log.Info("Request merge by", zap.String("user", user.Name))
|
||||
s.taoLogger.Log.Info("Request merge by", zap.String("user", user.Name))
|
||||
|
||||
// lookup for python exec
|
||||
py_exec, err := exec.LookPath("python")
|
||||
if err != nil {
|
||||
Log.Fatal("Python error: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Python error: ", zap.Error(err))
|
||||
} else {
|
||||
py_exec, err = filepath.Abs(py_exec)
|
||||
}
|
||||
|
||||
Log.Info("Found python exec: ", zap.String("PythonPath", py_exec))
|
||||
s.taoLogger.Log.Info("Found python exec: ", zap.String("PythonPath", py_exec))
|
||||
// target api file
|
||||
merge_api, api_err := os.Open("./python_api/merge_recipe.py")
|
||||
if api_err != nil {
|
||||
Log.Fatal("Merge request failed. Python api error: ", zap.String("ApiErr", api_err.Error()))
|
||||
s.taoLogger.Log.Fatal("Merge request failed. Python api error: ", zap.String("ApiErr", api_err.Error()))
|
||||
}
|
||||
defer merge_api.Close()
|
||||
// log.Println("Locate python api", merge_api.Name())
|
||||
Log.Info("Locate python api", zap.String("ApiName", merge_api.Name()))
|
||||
s.taoLogger.Log.Info("Locate python api", zap.String("ApiName", merge_api.Name()))
|
||||
cmd := exec.Command(py_exec, merge_api.Name(), "merge", master_path, dev_path, output_path, changelog_path, "", user.Name)
|
||||
|
||||
// log.Println("Run merge command", cmd)
|
||||
Log.Info("Merge", zap.String("master", master_path), zap.String("dev", dev_path), zap.String("output", output_path))
|
||||
Log.Debug("Run merge command", zap.String("Command", cmd.String()))
|
||||
s.taoLogger.Log.Info("Merge", zap.String("master", master_path), zap.String("dev", dev_path), zap.String("output", output_path))
|
||||
s.taoLogger.Log.Debug("Run merge command", zap.String("Command", cmd.String()))
|
||||
out, err := cmd.CombinedOutput()
|
||||
// log.Println(string(out))
|
||||
Log.Debug("Merge output", zap.String("Output", string(out)))
|
||||
s.taoLogger.Log.Debug("Merge output", zap.String("Output", string(out)))
|
||||
if err != nil {
|
||||
// log.Fatalln("Merge request failed. Python merge failed: ", err)
|
||||
Log.Fatal("Merge request failed. Python merge failed", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Merge request failed. Python merge failed", zap.Error(err))
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]string{"message": "Merge success"})
|
||||
Log.Info("Merge success", zap.String("output", "merge success"))
|
||||
s.taoLogger.Log.Info("Merge success", zap.String("output", "merge success"))
|
||||
})
|
||||
|
||||
r.Post("/dllog", func(w http.ResponseWriter, r *http.Request) {
|
||||
Log.Debug("Request uri = ", zap.String("uri", r.RequestURI))
|
||||
s.taoLogger.Log.Debug("Request uri = ", zap.String("uri", r.RequestURI))
|
||||
|
||||
Log.Debug("Query param = ", zap.String("query", r.URL.Query().Get("query")))
|
||||
s.taoLogger.Log.Debug("Query param = ", zap.String("query", r.URL.Query().Get("query")))
|
||||
// param
|
||||
param := r.URL.Query().Get("query")
|
||||
Log.Debug("Param = ", zap.String("param", param))
|
||||
s.taoLogger.Log.Debug("Param = ", zap.String("param", param))
|
||||
|
||||
var postRequest map[string]interface{}
|
||||
err := json.NewDecoder(r.Body).Decode(&postRequest)
|
||||
Log.Debug("Log request: ", zap.String("postRequest", fmt.Sprintf("%+v", postRequest)))
|
||||
s.taoLogger.Log.Debug("Log request: ", zap.String("postRequest", fmt.Sprintf("%+v", postRequest)))
|
||||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
Log.Fatal("Decode in request failed: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Decode in request failed: ", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -269,25 +303,25 @@ func (s *Server) createHandler() {
|
|||
}
|
||||
|
||||
log_name := postRequest["filename"].(string)
|
||||
Log.Warn("Log file name: ", zap.String("filename", log_name))
|
||||
s.taoLogger.Log.Warn("Log file name: ", zap.String("filename", log_name))
|
||||
|
||||
if log_name == "" {
|
||||
Log.Fatal("Empty log file name")
|
||||
s.taoLogger.Log.Fatal("Empty log file name")
|
||||
}
|
||||
|
||||
// log.Println("Log file ext: ", file_ext)
|
||||
default_changelog_path := "cofffeemachineConfig/" + param + "/"
|
||||
Log.Debug("Default changelog path: ", zap.String("default_changelog_path", default_changelog_path))
|
||||
s.taoLogger.Log.Debug("Default changelog path: ", zap.String("default_changelog_path", default_changelog_path))
|
||||
|
||||
changelog_path := default_changelog_path + log_name + file_ext
|
||||
Log.Debug("Changelog path: ", zap.String("changelog_path", changelog_path))
|
||||
s.taoLogger.Log.Debug("Changelog path: ", zap.String("changelog_path", changelog_path))
|
||||
if strings.Contains(log_name, "cofffeemachineConfig") && strings.Contains(log_name, ".json") {
|
||||
changelog_path = log_name
|
||||
}
|
||||
|
||||
logFile, err := os.Open(changelog_path)
|
||||
if err != nil {
|
||||
Log.Fatal("Log request failed: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Log request failed: ", zap.Error(err))
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
|
@ -298,20 +332,20 @@ func (s *Server) createHandler() {
|
|||
var logFileJson map[string]interface{}
|
||||
err = json.NewDecoder(logFile).Decode(&logFileJson)
|
||||
if err != nil {
|
||||
Log.Fatal("Error when decode log file: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Error when decode log file: ", zap.Error(err))
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(logFileJson)
|
||||
Log.Info("Log file: ", zap.String("filename", log_name))
|
||||
s.taoLogger.Log.Info("Log file: ", zap.String("filename", log_name))
|
||||
} else {
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=logfile"+file_ext)
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
|
||||
_, err = io.Copy(w, logFile)
|
||||
if err != nil {
|
||||
Log.Fatal("Could not send blob", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Could not send blob", zap.Error(err))
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
|
@ -324,25 +358,25 @@ func (s *Server) createHandler() {
|
|||
//spl
|
||||
spl_path := strings.Split(r.RequestURI, "/")
|
||||
if len(spl_path) > 3 {
|
||||
Log.Warn("Unexpected depth: ",
|
||||
s.taoLogger.Log.Warn("Unexpected depth: ",
|
||||
zap.String("path", r.RequestURI),
|
||||
zap.String("depth", fmt.Sprintf("%d", len(spl_path))))
|
||||
}
|
||||
|
||||
if spl_path[2] == "" {
|
||||
Log.Error("Empty target dir", zap.String("path", r.RequestURI))
|
||||
s.taoLogger.Log.Error("Empty target dir", zap.String("path", r.RequestURI))
|
||||
}
|
||||
|
||||
Log.Debug("Split path = ", zap.Any("paths", spl_path))
|
||||
s.taoLogger.Log.Debug("Split path = ", zap.Any("paths", spl_path))
|
||||
|
||||
// Log.Info("Target dir: ", zap.String("dir", "cofffeemachineConfig"))
|
||||
// s.taoLogger.Log.Info("Target dir: ", zap.String("dir", "cofffeemachineConfig"))
|
||||
|
||||
main_folder := "cofffeemachineConfig"
|
||||
target_path := main_folder + "/" + spl_path[2]
|
||||
|
||||
dir, err := os.ReadDir(target_path)
|
||||
if err != nil {
|
||||
Log.Error("Error while trying to read dir: ", zap.String("dir", target_path), zap.Error(err))
|
||||
s.taoLogger.Log.Error("Error while trying to read dir: ", zap.String("dir", target_path), zap.Error(err))
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
|
@ -356,12 +390,12 @@ func (s *Server) createHandler() {
|
|||
file_ext = ".json"
|
||||
break
|
||||
}
|
||||
Log.Debug("Set file ext = ", zap.String("file_ext", file_ext))
|
||||
s.taoLogger.Log.Debug("Set file ext = ", zap.String("file_ext", file_ext))
|
||||
|
||||
displayable := make([]string, 0)
|
||||
for _, file := range dir {
|
||||
if strings.Contains(file.Name(), file_ext) {
|
||||
Log.Debug("Found file: ", zap.String("file", file.Name()))
|
||||
s.taoLogger.Log.Debug("Found file: ", zap.String("file", file.Name()))
|
||||
displayable = append(displayable, file.Name()[:len(file.Name())-len(filepath.Ext(file.Name()))])
|
||||
}
|
||||
}
|
||||
|
|
@ -370,7 +404,7 @@ func (s *Server) createHandler() {
|
|||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string][]string{"dirs": displayable})
|
||||
Log.Debug("Scan dir completed < ", zap.String("path", r.RequestURI))
|
||||
s.taoLogger.Log.Debug("Scan dir completed < ", zap.String("path", r.RequestURI))
|
||||
})
|
||||
|
||||
r.Get("/get_log_relation", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -378,27 +412,27 @@ func (s *Server) createHandler() {
|
|||
// Python looker
|
||||
py_exec, err := exec.LookPath("python")
|
||||
if err != nil {
|
||||
Log.Error("Error while trying to find python: ", zap.Error(err))
|
||||
s.taoLogger.Log.Error("Error while trying to find python: ", zap.Error(err))
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
merge_timeline, api_err := os.Open("./python_api/merge_timeline.py")
|
||||
if api_err != nil {
|
||||
Log.Error("Error while trying to open merge_timeline.json: ", zap.Error(api_err))
|
||||
s.taoLogger.Log.Error("Error while trying to open merge_timeline.json: ", zap.Error(api_err))
|
||||
http.Error(w, api_err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
defer merge_timeline.Close()
|
||||
|
||||
cmd := exec.Command(py_exec, merge_timeline.Name(), "get_relate")
|
||||
|
||||
Log.Debug("Command: ", zap.String("command", cmd.String()))
|
||||
s.taoLogger.Log.Debug("Command: ", zap.String("command", cmd.String()))
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
|
||||
Log.Debug("Output: ", zap.String("output", string(out)))
|
||||
s.taoLogger.Log.Debug("Output: ", zap.String("output", string(out)))
|
||||
|
||||
if err != nil {
|
||||
Log.Error("Error while trying to run python: ", zap.Error(err))
|
||||
s.taoLogger.Log.Error("Error while trying to run python: ", zap.Error(err))
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
|
@ -414,28 +448,29 @@ func (s *Server) createHandler() {
|
|||
})
|
||||
|
||||
r.Post("/diffpy/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
Log.Debug("Diffpy: ", zap.String("path", r.RequestURI))
|
||||
s.taoLogger.Log.Debug("Diffpy: ", zap.String("path", r.RequestURI))
|
||||
// TODO: add command exec `python_Exec` `merge_recipe.py` `diff` `master_version` `version-version-version` `debug?` `flatten={true|false}` `out={true|false}`
|
||||
})
|
||||
|
||||
sheetService, err := sheet.NewSheetService(context.Background(), s.cfg)
|
||||
|
||||
if err != nil {
|
||||
Log.Fatal("Error while trying to create sheet service: ", zap.Error(err))
|
||||
s.taoLogger.Log.Fatal("Error while trying to create sheet service: ", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
// Recipe Service
|
||||
rs := recipe.NewRecipeService(database)
|
||||
|
||||
// Recipe Router
|
||||
rr := routers.NewRecipeRouter(database, rs, sheetService)
|
||||
rr := routers.NewRecipeRouter(s.data, recipeService, sheetService, s.taoLogger)
|
||||
rr.Route(r)
|
||||
|
||||
// Material Router
|
||||
mr := routers.NewMaterialRouter(database)
|
||||
mr := routers.NewMaterialRouter(s.data)
|
||||
mr.Route(r)
|
||||
|
||||
// User Router
|
||||
ur := routers.NewUserRouter(s.taoLogger, userService)
|
||||
ur.Route(r)
|
||||
|
||||
})
|
||||
|
||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -454,11 +489,11 @@ func (s *Server) Shutdown(ctx context.Context) error {
|
|||
func pyAPIhandler(w http.ResponseWriter, r *http.Request) bool {
|
||||
timeout := 10 * time.Second
|
||||
|
||||
if !lockThenTimeout(&python_api_lock, timeout) {
|
||||
if !lockThenTimeout(&pythonApiLock, timeout) {
|
||||
http.Error(w, "API is busy", http.StatusServiceUnavailable)
|
||||
return false
|
||||
}
|
||||
defer python_api_lock.Unlock()
|
||||
defer pythonApiLock.Unlock()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue