Created
January 26, 2019 11:59
-
-
Save oscartbeaumont/5c552ec1a62cc74eb6742428eb79a143 to your computer and use it in GitHub Desktop.
A Basic Go Webserver Using Certmagic listening on the ports 8443 and 8080.
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 ( | |
"log" | |
"net/http" | |
"github.com/mholt/certmagic" | |
) | |
func main() { | |
mux := http.NewServeMux() | |
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
w.Write([]byte("Hello World")) | |
}) | |
magic := certmagic.New(certmagic.Config{ | |
CA: certmagic.LetsEncryptStagingCA, | |
Email: "[email protected]", | |
Agreed: true, | |
//AltHTTPPort: 8080, | |
AltTLSALPNPort: 8443, | |
}) | |
err := magic.Manage([]string{"example.com"}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
s := http.Server{ | |
Addr: "8443", | |
Handler: mux, | |
TLSConfig: magic.TLSConfig(), | |
} | |
log.Println("listening...") | |
go log.Fatal(http.ListenAndServe(":8080", magic.HTTPChallengeHandler(mux))) | |
log.Fatal(s.ListenAndServeTLS("", "")) | |
} |
You are correct. I assume certmagic have changed their api since I wrote this sample.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not sure how this works given that
certmagic.New
has an arity of two