Compare commits

..
5 Commits
Author SHA1 Message Date
alu e7341e3d9e remove go mod 2026-10-26 23:12:14 +00:00
alu 8b73652c9b add basic logging middleware
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 28s
2026-10-26 18:28:37 +00:00
alu 35ecaf84e0 add JSON helper to HTTP utils
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 21s
2026-10-23 21:55:27 +00:00
alu 01c1f0389a add http html and html fragment template execute code to common lib
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 22s
2026-10-23 21:52:53 +00:00
alu 8284ffbc43 fix issue in username to string format
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 42s
2026-08-18 23:01:58 +00:00
3 changed files with 58 additions and 4 deletions

No files matched your search

+1 -1
View File
@@ -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.
-3
View File
@@ -1,3 +0,0 @@
module proxmoxaas-common-lib
go 1.26.0
+57
View File
@@ -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))
})
}