package server import ( "fes/modules/config" "fes/modules/ui" "fmt" "log" "net/http" "os" "path/filepath" "strings" ) var routes map[string]string func Start(dir string) { if err := os.Chdir(dir); err != nil { ui.Error(fmt.Sprintf("failed to change directory to %s", dir), err) } ui.Log("running root=%s, port=%d.", filepath.Clean(dir), *config.Port) routes := loadDirs() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { route, ok := routes[r.URL.Path] var err error = nil /* defer won't update paramaters unless we do this. */ defer func() { ui.Path(route, err) }() if !ok { err = config.ErrRouteMiss route = r.URL.Path if strings.HasPrefix(route, "/archive") { err = readArchive(w, route) } else { w.WriteHeader(http.StatusNotFound) w.Write([]byte(`