Created
June 12, 2019 19:29
-
-
Save saii9/c60970cf747abe36f56d41b0b9ef6f8f to your computer and use it in GitHub Desktop.
A simple static https file server
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 | |
// 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