added docs and container (podman + docker) setup

This commit is contained in:
2025-10-13 01:28:52 +02:00
parent 67cca9854f
commit 1cccb4e603
16 changed files with 1918 additions and 5 deletions

37
main.go
View File

@@ -6,13 +6,18 @@ import (
"io/fs"
"log"
"net/http"
"os"
"strings"
"text/template"
)
//go:embed static/* templates/*
var content embed.FS
var content embed.FS // Environment configuration
type Config struct {
Port string
LogLevel string
}
type Argument struct {
Params string `json:"params"`
Command string `json:"command"`
@@ -36,11 +41,34 @@ type GenerateRequestV2 struct {
Subcommands []Subcommand `json:"subcommands"`
}
func loadConfig() Config {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
return Config{
Port: port,
LogLevel: os.Getenv("LOG_LEVEL"),
}
}
// Add health check endpoint
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{
"status": "healthy",
"version": "1.0.0",
})
}
func main() {
staticFS, err := fs.Sub(content, "static")
if err != nil {
log.Fatal(err)
}
config := loadConfig()
templatesFS, err := fs.Sub(content, "templates")
if err != nil {
@@ -49,6 +77,7 @@ func main() {
tmpl := template.Must(template.ParseFS(templatesFS, "*.html"))
http.HandleFunc("/health", healthHandler)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@@ -97,8 +126,9 @@ func main() {
w.Write([]byte(bashCode))
})
log.Println("Server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
addr := ":" + config.Port
log.Printf("Server starting on %s", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}
func generateBashScript(req GenerateRequest) string {
@@ -222,6 +252,7 @@ func generateBashScript(req GenerateRequest) string {
return sb.String()
}
func generateBashScriptV2(req GenerateRequestV2) string {
// If no subcommands, use flat generation
if len(req.Subcommands) == 0 {