package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
)
func main() {
port := flag.Int("port", 3000, "Port to listen on")
flag.Parse()
addr := fmt.Sprintf(":%d", *port)
username := os.Getenv("APP_USER_NAME")
userID := os.Getenv("APP_USER_ID")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, `
My App Instance
Instance Info
Port%d
User%s
User ID%s
StatusRunning
`, *port, username, userID)
})
http.HandleFunc("/admin", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, `
Admin Panel
Admin Settings
Instance Port%d
Managed User%s
User ID%s
Actions
This is a private admin area. Only authenticated users should access this page.
`, *port, username, userID)
})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, `{"status":"ok","port":%d,"user":"%s"}`, *port, username)
})
log.Printf("Test app starting on %s (user=%s)", addr, username)
log.Fatal(http.ListenAndServe(addr, nil))
}