Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7341e3d9e | ||
|
|
8b73652c9b | ||
|
|
35ecaf84e0 | ||
|
|
01c1f0389a | ||
|
|
8284ffbc43 | ||
|
|
f4deeb1ab6 |
No files matched your search
@@ -49,10 +49,3 @@ type VMID struct {
|
|||||||
Min int `json:"min" mapstructure:"min"`
|
Min int `json:"min" mapstructure:"min"`
|
||||||
Max int `json:"max" mapstructure:"max"`
|
Max int `json:"max" mapstructure:"max"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Templates struct {
|
|
||||||
Instances struct {
|
|
||||||
LXC map[string]ResourceTemplate `json:"lxc" mapstructure:"lxc"`
|
|
||||||
QEMU map[string]ResourceTemplate `json:"qemu" mapstructure:"qemu"`
|
|
||||||
} `json:"instances"`
|
|
||||||
}
|
|
||||||
+1
-1
@@ -14,7 +14,7 @@ func (g Groupname) ToString() string {
|
|||||||
// Converts input username object to string representation.
|
// Converts input username object to string representation.
|
||||||
// Uses the format uid@realm.
|
// Uses the format uid@realm.
|
||||||
func (u Username) ToString() string {
|
func (u Username) ToString() string {
|
||||||
return fmt.Sprintf("%s-%s", u.UserID, u.Realm)
|
return fmt.Sprintf("%s@%s", u.UserID, u.Realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses input groupname string to gid and realm.
|
// Parses input groupname string to gid and realm.
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package proxmoxaas_common_lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HTTPExecuteHTMLTemplate(w http.ResponseWriter, t *template.Template, name string, d any) {
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
body := bytes.Buffer{}
|
||||||
|
err := t.ExecuteTemplate(&body, name, d)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Write(body.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func HTTPExecuteHTMLFragmentTemplate(w http.ResponseWriter, t *template.Template, name string, d any) {
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
|
body := bytes.Buffer{}
|
||||||
|
err := t.ExecuteTemplate(&body, name, d)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Write(body.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func HTTPWriteJson(w http.ResponseWriter, code int, obj any) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json, err := json.Marshal(obj)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(code)
|
||||||
|
w.Write(json)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoggingMiddleware(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
start := time.Now()
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
log.Printf("%s %s %s", r.Method, r.URL.Path, time.Since(start))
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -56,6 +56,13 @@ type ListResource struct {
|
|||||||
Category string
|
Category string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Templates struct {
|
||||||
|
Instances struct {
|
||||||
|
LXC map[string]ResourceTemplate `json:"lxc" mapstructure:"lxc"`
|
||||||
|
QEMU map[string]ResourceTemplate `json:"qemu" mapstructure:"qemu"`
|
||||||
|
} `json:"instances"`
|
||||||
|
}
|
||||||
|
|
||||||
type ResourceTemplate struct {
|
type ResourceTemplate struct {
|
||||||
Value string `json:"value" mapstructure:"value"`
|
Value string `json:"value" mapstructure:"value"`
|
||||||
Resource struct {
|
Resource struct {
|
||||||
|
|||||||
Reference in new issue
Block a user