example: add config flag for TLS key and cert for the server (#4237)

This commit is contained in:
Marten Seemann 2024-01-05 17:21:42 +07:00 committed by GitHub
parent 3ff50295ce
commit 0a922b4e7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -144,6 +144,8 @@ func main() {
flag.Var(&bs, "bind", "bind to")
www := flag.String("www", "", "www data")
tcp := flag.Bool("tcp", false, "also listen on TCP")
key := flag.String("key", "", "TLS key (requires -cert option)")
cert := flag.String("cert", "", "TLS certificate (requires -key option)")
enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)")
flag.Parse()
@ -176,12 +178,18 @@ func main() {
var wg sync.WaitGroup
wg.Add(len(bs))
var certFile, keyFile string
if *key != "" && *cert != "" {
keyFile = *key
certFile = *cert
} else {
certFile, keyFile = testdata.GetCertificatePaths()
}
for _, b := range bs {
bCap := b
go func() {
var err error
if *tcp {
certFile, keyFile := testdata.GetCertificatePaths()
err = http3.ListenAndServe(bCap, certFile, keyFile, handler)
} else {
server := http3.Server{
@ -189,7 +197,7 @@ func main() {
Addr: bCap,
QuicConfig: quicConf,
}
err = server.ListenAndServeTLS(testdata.GetCertificatePaths())
err = server.ListenAndServeTLS(certFile, keyFile)
}
if err != nil {
fmt.Println(err)