refactor routes,
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 30s

use json encoding for route body parameters,
implement modify user/group/pool operations,
simplify schema by using comon lib struct tags and RequireAll and AtLeastOne helper functions,
properly implement locadb as Backend interface
This commit is contained in:
alu
2026-08-21 20:49:15 +00:00
parent 670f7d4999
commit 4783d79523
13 changed files with 959 additions and 606 deletions
+6 -1
View File
@@ -25,6 +25,10 @@ type LDAPConfig struct {
Verify bool
}
type LocalDBConfig struct {
Path string `json:"path"`
}
type Config struct {
ListenPort int `json:"listenPort"`
SessionCookieName string `json:"sessionCookieName"`
@@ -34,7 +38,8 @@ type Config struct {
Secure bool `json:"secure"`
MaxAge int `json:"maxAge"`
}
PVE PVEConfig `json:"pve"`
PVE PVEConfig `json:"pve"`
LocalDB LocalDBConfig `json:"localdb"`
}
func GetConfig(configPath string) Config {
+2 -16
View File
@@ -1,21 +1,7 @@
package app
type Login struct { // login body struct
UsernameRaw string `form:"username" binding:"required"`
UsernameRaw string `json:"username" binding:"required"`
Username Username
Password string `form:"password" binding:"required"`
}
type UserFormRequired struct { // add user body struct
CN string `form:"cn" binding:"required"`
SN string `form:"sn" binding:"required"`
Mail string `form:"mail" binding:"required"`
Password string `form:"password" binding:"required"`
}
type UserFormOptional struct { // modify user body struct
CN string `form:"cn"`
SN string `form:"sn"`
Mail string `form:"mail"`
Password string `form:"password"`
Password string `json:"password" binding:"required"`
}
+5 -2
View File
@@ -3,15 +3,18 @@ package app
import paas "proxmoxaas-common-lib"
type Backend interface {
NewPool(poolname string) (int, error)
NewPool(poolname string, pool Pool) (int, error)
ModPool(poolname string, pool Pool) (int, error)
GetPool(poolname string) (Pool, []string, int, error) // []string members
DelPool(poolname string) (int, error)
NewGroup(groupname Groupname) (int, error)
NewGroup(groupname Groupname, group Group) (int, error)
ModGroup(groupname Groupname, group Group) (int, error)
GetGroup(groupname Groupname) (Group, []string, int, error) // []string members
DelGroup(groupname Groupname) (int, error)
AddGroupToPool(groupname Groupname, poolname string) (int, error)
DelGroupFromPool(groupname Groupname, poolname string) (int, error)
NewUser(username Username, user User) (int, error)
ModUser(username Username, user User) (int, error)
GetUser(username Username) (User, int, error)
DelUser(username Username) (int, error)
AddUserToGroup(username Username, groupname Groupname) (int, error)
+55
View File
@@ -0,0 +1,55 @@
package app
import (
"reflect"
)
// RequireAll ensures that EVERY non-excluded exported field in the struct is non-zero.
func RequireAll(v any, excludes ...string) bool {
val := reflect.ValueOf(v)
if val.Kind() == reflect.Pointer {
val = val.Elem()
}
typ := val.Type()
excludeMap := make(map[string]bool)
for _, ex := range excludes {
excludeMap[ex] = true
}
for i := 0; i < val.NumField(); i++ {
fieldName := typ.Field(i).Name
if excludeMap[fieldName] {
continue
}
if val.Field(i).IsZero() {
return false
}
}
return true
}
// AtLeastOne ensures that AT LEAST ONE non-excluded exported field is non-zero.
func AtLeastOne(v any, excludes ...string) bool {
val := reflect.ValueOf(v)
if val.Kind() == reflect.Pointer {
val = val.Elem()
}
typ := val.Type()
excludeMap := make(map[string]bool)
for _, ex := range excludes {
excludeMap[ex] = true
}
for i := 0; i < val.NumField(); i++ {
fieldName := typ.Field(i).Name
if excludeMap[fieldName] {
continue
}
if !val.Field(i).IsZero() {
return true
}
}
return false
}