Self Signed HTTPS Servers for Go

rocketlaunchr.cloud
Feb 16 · 1 min read

For more than a decade, security experts have been advocating SSL certificates for servers.

For production servers you can use a SSL certificate from a reputable organization like Let’s Encrypt.

For Development (or non-public facing Production) servers, you may want to self-sign your certificates.

I’ve created a package to make it super quick and easy.

package main

import (
"log"
"net/http"
"github.com/rocketlaunchr/https-go"
)
func main() {// Create a simple http hander
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
})
// Configure the port
httpServer, _ := https.Server("443", https.GenerateOptions{Host: "thecucumber.app"})
// Start the server
log.Fatal(httpServer.ListenAndServeTLS("", ""))
}

Just remember to change the url from http to https. Also configure your http client code/application to allow self-signed certificates otherwise they will spit out an error.

You can also call GenerateKeys() function to create a key once and reuse it.

Repository: https://github.com/rocketlaunchr/https-go

Docs: https://godoc.org/github.com/rocketlaunchr/https-go

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade