Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen.go: allow to customise the URL when generating #17

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions certifi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import (
"log"
"net/http"
"os"
"strings"
"text/template"
"time"
)

func main() {
const url = "https://mkcert.org/generate/"
if len(os.Args) != 2 || !strings.HasPrefix(os.Args[1], "https://") {
log.Fatal("usage: go run gen.go <url>")
}
url := os.Args[1]

resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -53,17 +58,17 @@ var tmpl = template.Must(template.New("").Parse(`// Code generated by go generat

package gocertifi

//go:generate go run gen.go
//go:generate go run gen.go "{{ .URL }}"

import "crypto/x509"

const pemcerts string = ` + "`" + `
{{ .Bundle }}
` + "`" + `

// CACerts builds an X.509 certificate pool containing the Mozilla CA
// Certificate bundle. Returns nil on error along with an appropriate error
// code.
// CACerts builds an X.509 certificate pool containing the
// certificate bundle from {{ .URL }} fetch on {{ .Timestamp }}.
// Returns nil on error along with an appropriate error code.
func CACerts() (*x509.CertPool, error) {
pool := x509.NewCertPool()
pool.AppendCertsFromPEM([]byte(pemcerts))
Expand Down