Created
March 1, 2021 22:52
-
-
Save bmcculley/c8d6d5590a17c0c63389ac412875bab7 to your computer and use it in GitHub Desktop.
Golang HTTP/3 fileserver example
This file contains hidden or 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 ( | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"path" | |
"github.com/lucas-clemente/quic-go/http3" | |
) | |
func main() { | |
listenPort := flag.String("port", "3000", "port to listen on") | |
wwwDir := flag.String("wwwDir", "public", "directory with html to be served") | |
certPath := flag.String("certPath", "cert", "path to the ca cert pem") | |
flag.Parse() | |
fs := http.Handler(http.FileServer(http.Dir(*wwwDir))) | |
certPathName := path.Join(*certPath, "cert.pem") | |
privPathName := path.Join(*certPath, "priv.key") | |
log.Printf("Serving on :%s", *listenPort) | |
log.Fatal(http3.ListenAndServeQUIC(fmt.Sprintf(":%s", *listenPort), | |
fmt.Sprintf("%s", certPathName), | |
fmt.Sprintf("%s", privPathName), fs)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment