2018-05-02 15:45:45 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"html"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"path"
|
2018-05-02 17:00:53 -06:00
|
|
|
"strconv"
|
2018-05-02 15:45:45 -06:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var basePath = "."
|
|
|
|
var maintenanceInterval = 20 * time.Second
|
|
|
|
var categories = []string{}
|
|
|
|
|
2018-05-02 17:00:53 -06:00
|
|
|
|
2018-05-02 15:45:45 -06:00
|
|
|
func mooHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
moo := req.FormValue("moo")
|
|
|
|
fmt.Fprintf(w, "Hello, %q. %s", html.EscapeString(req.URL.Path), html.EscapeString(moo))
|
|
|
|
}
|
|
|
|
|
|
|
|
func rootHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
if req.URL.Path != "/" {
|
|
|
|
http.NotFound(w, req)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:00:53 -06:00
|
|
|
func mothPath(parts ...string) string {
|
|
|
|
return path.Join(basePath, parts...)
|
2018-05-02 15:45:45 -06:00
|
|
|
}
|
|
|
|
|
2018-05-02 17:00:53 -06:00
|
|
|
func statePath(parts ...string) string {
|
|
|
|
return path.Join(basePath, "state", parts...)
|
2018-05-02 15:45:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func exists(filename string) bool {
|
|
|
|
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
log.Print("Sup")
|
|
|
|
go maintenance();
|
|
|
|
http.HandleFunc("/", rootHandler)
|
|
|
|
http.HandleFunc("/moo/", mooHandler)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
// docker run --rm -it -p 5880:8080 -v $HOME:$HOME:ro -w $(pwd) golang go run mothd.go
|