Created
March 28, 2018 21:21
-
-
Save Aaron-Macneill/9945b4e9aab690cce762643fd964b00f to your computer and use it in GitHub Desktop.
Quick listing thing for gokrazy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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