Skip to content

Instantly share code, notes, and snippets.

@saii9
Created June 12, 2019 19:29
Show Gist options
  • Save saii9/c60970cf747abe36f56d41b0b9ef6f8f to your computer and use it in GitHub Desktop.
Save saii9/c60970cf747abe36f56d41b0b9ef6f8f to your computer and use it in GitHub Desktop.
A simple static https file server
package main
// usage: compile and create static-https-file-server.exe
// set env variables TLSSERVERPORT FILESERVERDIR TLSSERVERCERT TLSSERVERKEY as the names imply
// cmd :
// TLSSERVERPORT=<fill> \
// FILESERVERDIR="<fill>" \
// TLSSERVERCERT="<fill>" \
// TLSSERVERKEY="<fill>" \
// ./static-https-file-server.exe
import (
"net/http"
"log"
"os"
)
func main() {
log.Println("dir" , os.Getenv("FILESERVERDIR"), "cert", os.Getenv("TLSSERVERCERT"), "key", os.Getenv("TLSSERVERKEY"))
http.Handle("/", http.FileServer(http.Dir(os.Getenv("FILESERVERDIR"))))
err := http.ListenAndServeTLS(":"+os.Getenv("TLSSERVERPORT"), os.Getenv("TLSSERVERCERT"), os.Getenv("TLSSERVERKEY"), nil,)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment