Skip to content

Auto generate self signed certificate

Thanatat Tamtan edited this page Jun 9, 2026 · 5 revisions

Hime can help to auto generate self-signed certificate for running https web server while development.

For example, to start https web server on port 8080

package main

import (
	"log"
	"net/http"

	"github.com/moonrhythm/hime"
)

func main() {
	app := hime.New()
	app.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	}))

	app.Address(":8080")
	app.SelfSign(hime.SelfSign{})

	log.Fatal(app.ListenAndServe())
}

TLS profiles

For production, load a real certificate with app.TLS(certFile, keyFile) and pick a cipher-suite profile on the server's tls.Config:

app.Server().TLSConfig = hime.Modern()
app.TLS("cert.pem", "key.pem")
  • hime.Restricted() — TLS 1.2+ with a small set of strong ciphers
  • hime.Modern() — TLS 1.2+ with modern ciphers
  • hime.Compatible() — TLS 1.0+ for broad client compatibility

Redirect HTTP to HTTPS

Run a plain-HTTP server that redirects every request to its HTTPS URL:

go hime.StartHTTPSRedirectServer(":80")

Clone this wiki locally