go-cert-generator

module
v0.0.0-...-ec46ac4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2022 License: GPL-3.0

README

📝 Go SSL Certificate Generator 📝

A utility package for generating self-signed SSL certificates within your Go application. No third-party tools required. Self-signed certs will be generated in the "etc/ssl/" directory of your application. As of now, this path is not changeable. I will likely change this in the future to be configurable but defaulting to "etc/ssl" to ensure backwards compatibility.

[ your-awesome-go-app ]
 |_ cmd
 |_ pkg
 |_ internal
 |_ etc
 |   |_ssl
 |  	|_ server.key   <- Generated key
 |	|_ server.pem   <- Generated pem
 |
 |_ README.md

Install Instructions:

go install https://github.com/KeithAlt/go-cert-generator


Example Implementation:

// An example of package usage with Gin ...

func main() {
	cert, err := gencert.Generate()
	if err != nil {
		log.Fatal(err)
	}

	r := gin.Default()
	r.GET("/", func(c *gin.Context) {
		c.String(http.StatusOK, "Hello World")
	})

	r.RunTLS(":8080", cert.PemPath, cert.KeyPath)
}

Accessible Fields:

type Cert struct {
	PemPath   string `binding:"required"`
	KeyPath   string `binding:"required"`
	PemBytes  []byte `binding:"required"`
	KeyBytes  []byte `binding:"required"`
	CertBytes []byte `binding:"required"`
}
  cert, err := gencert.Generate()
  if err != nil {
    log.Fatal(err)
  }
  
  fmt.Println(cert.PemPath) // -> String path to the generated .pem file
  fmt.Println(cert.KeyPath) // -> String path to the generated .key file
  fmt.Println(cert.PemBytes) // -> []Byte field containing the pem file contents
  fmt.Println(cert.KeyBytes) // -> []Byte field containing the key file contents
  fmt.Println(cert.CertBytes) // -> []Byte field containing the cert contents

If you are checking out this package for usage in an internally communicating API, consider GRPC

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL