generate-a-self-signed-certificate-for-go.webp

Generate a self-signed certificate for Go

Use OpenSSL generate a self-signed certificate for Golang. In this code snippet I created a certificate with validity of 15 years. openssl genrsa -out server.key 2048 openssl req -new -x509 -sha256 -key server.key -out server.crt -days 5475 Once you create the certificate and key you can use it in your Golang HTTP like this 1package main 2 3import ( 4 "log" 5 "net/http" 6 "time" 7 8 "github.com/julienschmidt/httprouter" 9) 10 11func main() { 12 router := httprouter.New() 13 router.HandlerFunc(http.MethodGet, "/", func(w http.ResponseWriter, r *http.Request) { 14 w.WriteHeader(200) 15 w.Write([]byte("Hello in TLS")) 16 }) 17 18 httpServer := &http.Server{ 19 Addr: ":8080", 20 Handler: router, 21 ReadTimeout: 120 * time.Second, 22 WriteTimeout: 120 * time.Second, 23 } 24 25 log.Fatal(httpServer.ListenAndServeTLS("server.crt", "server.key")) // <- Listen and serve with TLS 26}

December 27, 2025 · John Pili
create-a-linux-systemd-entry-for-your-application.webp

Create a Linux systemd entry for your application

Systemd is a Linux software suite that handles system services (daemon) and timers; it enables you to start, stop and restart your application using systemctl command. It can also start your application during operating systems boot-up sequence. Note that you will need to have root or sudo privileges for this operation. To create a systemd unit file, create a service file inside the directory /etc/systemd/system/. The filename must end with .service for example: ...

January 4, 2021 · John Pili