add some debugging

This commit is contained in:
Aaron Bieber 2022-11-17 11:23:12 -07:00
parent 671019ff26
commit 06ff140507
No known key found for this signature in database
2 changed files with 15 additions and 12 deletions

View File

@ -15,7 +15,7 @@
in { in {
tsvnstat = pkgs.buildGoModule { tsvnstat = pkgs.buildGoModule {
pname = "tsvnstat"; pname = "tsvnstat";
version = "v0.0.3"; version = "v0.0.4";
src = ./.; src = ./.;
vendorSha256 = "sha256-RNhu1gQ62Hg8Fhiw9uIS+b4YaAHtZMaqbelMKv+oZjM="; vendorSha256 = "sha256-RNhu1gQ62Hg8Fhiw9uIS+b4YaAHtZMaqbelMKv+oZjM=";

21
main.go
View File

@ -54,14 +54,16 @@ func main() {
key := flag.String("key", "", "path to file containing the api key") key := flag.String("key", "", "path to file containing the api key")
flag.Parse() flag.Parse()
s := &tsnet.Server{
Hostname: *name,
}
if *key != "" {
keyData, err := os.ReadFile(*key) keyData, err := os.ReadFile(*key)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
s.AuthKey = string(keyData)
s := &tsnet.Server{
Hostname: *name,
AuthKey: string(keyData),
} }
ln, err := s.Listen("tcp", ":80") ln, err := s.Listen("tcp", ":80")
@ -77,11 +79,12 @@ func main() {
go func() { go func() {
for { for {
time.Sleep(10 * time.Second)
log.Printf("running %q in %q", tmpFile.Name(), tmpDir) log.Printf("running %q in %q", tmpFile.Name(), tmpDir)
ifaces, err := net.Interfaces() ifaces, err := net.Interfaces()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal("can't get interfaces...", err)
} }
var ifNames []string var ifNames []string
@ -93,10 +96,10 @@ func main() {
genCmd.Dir = *dir genCmd.Dir = *dir
out, err := genCmd.Output() out, err := genCmd.Output()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal("can't run generation script", err)
} }
log.Println(out) log.Println(string(out))
time.Sleep(5 * time.Minute) time.Sleep(5 * time.Minute)
} }
@ -108,7 +111,7 @@ func main() {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fileServer.ServeHTTP(w, r) fileServer.ServeHTTP(w, r)
}) })
mux.HandleFunc("/index.html", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/index.html", func(w http.ResponseWriter, r *http.Request) {
images, err := os.ReadDir(*dir) images, err := os.ReadDir(*dir)
if err != nil { if err != nil {
http.Error(w, err.Error(), 500) http.Error(w, err.Error(), 500)
@ -146,7 +149,7 @@ func main() {
fmt.Fprintf(w, "<img src=%q /><br />", in) fmt.Fprintf(w, "<img src=%q /><br />", in)
} }
} }
})) })
hs := &http.Server{ hs := &http.Server{
Handler: mux, Handler: mux,