Skip to content

Instantly share code, notes, and snippets.

@bmcculley
Created March 1, 2021 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmcculley/c8d6d5590a17c0c63389ac412875bab7 to your computer and use it in GitHub Desktop.
Save bmcculley/c8d6d5590a17c0c63389ac412875bab7 to your computer and use it in GitHub Desktop.
Golang HTTP/3 fileserver example
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