File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,14 +9,12 @@ import (
99//
1010// Example:
1111//
12- // http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) })
13- //
14- // opts := GenerateOptions{Host: "domain.com"}
15- // httpServer, _ := Server("8080", opts)
16- // log.Fatal(httpServer.ListenAndServeTLS("", ""))
12+ // http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) })
1713//
14+ // opts := GenerateOptions{Host: "domain.com"}
15+ // httpServer, _ := Server("8080", opts)
16+ // log.Fatal(httpServer.ListenAndServeTLS("", ""))
1817func Server (port string , opts GenerateOptions ) (* http.Server , error ) {
19-
2018 pub , priv , err := GenerateKeys (opts )
2119 if err != nil {
2220 return nil , err
Original file line number Diff line number Diff line change 66// Generate a self-signed X.509 certificate for a TLS server. Outputs to
77// 'cert.pem' and 'key.pem' and will overwrite existing files.
88
9+ //go:build go1.13
910// +build go1.13
1011
1112package https
@@ -21,11 +22,12 @@ import (
2122 "crypto/x509/pkix"
2223 "encoding/pem"
2324 "errors"
24- "golang.org/x/xerrors"
2525 "math/big"
2626 "net"
2727 "strings"
2828 "time"
29+
30+ "golang.org/x/xerrors"
2931)
3032
3133func publicKey (priv interface {}) interface {} {
@@ -45,7 +47,6 @@ func publicKey(priv interface{}) interface{} {
4547//
4648// See https://github.com/denji/golang-tls and https://stackoverflow.com/questions/47857573/passing-certificate-and-key-as-string-to-listenandservetls/47857805
4749func GenerateKeys (opts GenerateOptions ) ([]byte , []byte , error ) {
48-
4950 // Validate Options
5051 if opts .Host == "" {
5152 return nil , nil , errors .New ("missing required Host parameter" )
Original file line number Diff line number Diff line change 66// Generate a self-signed X.509 certificate for a TLS server. Outputs to
77// 'cert.pem' and 'key.pem' and will overwrite existing files.
88
9+ //go:build !go1.13
910// +build !go1.13
1011
1112package https
@@ -20,11 +21,12 @@ import (
2021 "crypto/x509/pkix"
2122 "encoding/pem"
2223 "errors"
23- "golang.org/x/xerrors"
2424 "math/big"
2525 "net"
2626 "strings"
2727 "time"
28+
29+ "golang.org/x/xerrors"
2830)
2931
3032func publicKey (priv interface {}) interface {} {
@@ -42,7 +44,6 @@ func publicKey(priv interface{}) interface{} {
4244//
4345// See https://github.com/denji/golang-tls and https://stackoverflow.com/questions/47857573/passing-certificate-and-key-as-string-to-listenandservetls/47857805
4446func GenerateKeys (opts GenerateOptions ) ([]byte , []byte , error ) {
45-
4647 // Validate Options
4748 if opts .Host == "" {
4849 return nil , nil , errors .New ("missing required Host parameter" )
You can’t perform that action at this time.
0 commit comments