package main import ( "bytes" "flag" "fmt" "net/http" "strings" "github.com/apex/gateway" ) var ( port = flag.Int("port", -1, "specify a port") ) func main() { flag.Parse() listen := gateway.ListenAndServe addr := "n/a" if *port != -1 { addr = fmt.Sprintf(":%d", *port) listen = http.ListenAndServe } listen(addr, http.HandlerFunc(serve)) } func serve(w http.ResponseWriter, r *http.Request) { parts := strings.Split(r.RequestURI, "/")[1:] w.Header().Set("content-type", "text/html") if len(parts) != 1 { w.Write(notfound()) } else { w.Write(module(parts[0])) } } func notfound() []byte { return []byte(` zestack.dev https://slim.zestack.dev `) } func module(name string) []byte { bts := []byte(` {} - zestack.dev https://slim.zestack.dev `) return bytes.ReplaceAll(bts, []byte("{}"), []byte(name)) }