go-gemini/examples/cert.go

38 lines
651 B
Go
Raw Normal View History

2020-10-12 14:34:52 -06:00
// +build ignore
2020-09-27 11:50:48 -06:00
package main
import (
2020-10-28 11:47:52 -06:00
"fmt"
2020-09-27 11:50:48 -06:00
"log"
2020-10-13 14:50:59 -06:00
"os"
2020-09-27 21:49:41 -06:00
"time"
2020-09-27 11:50:48 -06:00
2020-10-27 21:35:22 -06:00
"git.sr.ht/~adnano/go-gemini"
2020-09-27 11:50:48 -06:00
)
func main() {
2020-10-28 11:47:52 -06:00
if len(os.Args) < 3 {
fmt.Printf("usage: %s [hostname] [duration]\n", os.Args[0])
os.Exit(1)
}
host := os.Args[1]
duration, err := time.ParseDuration(os.Args[2])
if err != nil {
log.Fatal(err)
}
options := gemini.CertificateOptions{
DNSNames: []string{host},
Duration: duration,
}
cert, err := gemini.CreateCertificate(options)
2020-09-27 11:50:48 -06:00
if err != nil {
log.Fatal(err)
}
2020-11-01 12:19:18 -07:00
certPath := host + ".crt"
keyPath := host + ".key"
if err := gemini.WriteCertificate(cert, certPath, keyPath); err != nil {
2020-09-27 11:50:48 -06:00
log.Fatal(err)
}
}