Skip to content

Instantly share code, notes, and snippets.

@Aaron-Macneill
Created March 28, 2018 21:21
Show Gist options
  • Save Aaron-Macneill/9945b4e9aab690cce762643fd964b00f to your computer and use it in GitHub Desktop.
Save Aaron-Macneill/9945b4e9aab690cce762643fd964b00f to your computer and use it in GitHub Desktop.
Quick listing thing for gokrazy
package main
import (
"fmt"
"github.com/gokrazy/gokrazy"
"log"
"net/http"
"path/filepath"
)
type listHandler struct{}
func (h listHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
files, err := fPrintDir(r.URL.Path)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(w, "%s", files)
}
func fPrintDir(dir string) ([]string, error) {
files, err := filepath.Glob(dir + "*")
if err != nil {
return nil, err
}
fmt.Println(files)
return files, nil
}
func main() {
gokrazy.DontStartOnBoot()
err := http.ListenAndServe(":9999", listHandler{})
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment