Skip to content

TonyChouteau/https-restful-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

GO API with SSL

This project show how to make a GO API with HTTPS access. The certificate is made by Let's Encrypt so web browser doesn't send Security warning.

1) Add certbot to the system

git clone https://github.com/certbot/certbot
cd certbot
./certbot-auto --help

OR follow : https://certbot.eff.org/lets-encrypt/ubuntubionic-other

2) Create a SSL Certificate with certbot

./certbot-auto certonly --preferred-challenges http-01 -d www.domain.com

OR (if you followed the installation using the certbot website) :

certbot certonly --preferred-challenges http-01 -d www.domain.com Saving debug log to /var/log/letsencrypt/letsencrypt.log

3) Create you GO API

Using the "net/http" library to server on the desired port.

PORT := "8081"
http.ListenAndServeTLS(":"+PORT, "/etc/letsencrypt/live/www.domain.com/fullchain.pem", "/etc/letsencrypt/live/www.domain.com/privkey.pem", nil)

and (to use gin-gonic) :

PORT := "8081"
router := gin.Default()
http.ListenAndServeTLS(":"+PORT, "/etc/letsencrypt/live/www.domain.com/fullchain.pem", "/etc/letsencrypt/live/www.domain.com/privkey.pem", router)

Have Fun

About

How to secure a Restfull Go API with Let's Encrypt

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages