implement pool group and user get routes,
improvements to http return codes, add localdb backend handler
This commit is contained in:
+2
-27
@@ -1,15 +1,13 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
common "user-manager-api/app/common"
|
||||
localdb "user-manager-api/app/localdb"
|
||||
pve "user-manager-api/app/pve"
|
||||
)
|
||||
|
||||
@@ -24,6 +22,7 @@ type UserSession struct {
|
||||
Name string
|
||||
Handler any
|
||||
}
|
||||
DB *localdb.DB
|
||||
}
|
||||
|
||||
func GetUserSessionFromContext(c *gin.Context) (*UserSession, int, error) {
|
||||
@@ -36,27 +35,3 @@ func GetUserSessionFromContext(c *gin.Context) (*UserSession, int, error) {
|
||||
usersession := UserSessions[uuid]
|
||||
return usersession, http.StatusOK, nil
|
||||
}
|
||||
|
||||
func LoadLocaldb(dbPath string) (map[string]common.User, error) {
|
||||
users := map[string]common.User{}
|
||||
content, err := os.ReadFile(dbPath)
|
||||
if err != nil {
|
||||
//log.Fatal("Error when opening file: ", err)
|
||||
return users, err
|
||||
}
|
||||
err = json.Unmarshal(content, &users)
|
||||
if err != nil {
|
||||
//log.Fatal("Error during Unmarshal(): ", err)
|
||||
return users, err
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func SaveLocaldb(configPath string, users map[string]common.User) error {
|
||||
json, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile(configPath, []byte(json), 0644)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user