An open API service indexing awesome lists of open source software.

https://github.com/tonychouteau/https-restful-api

How to secure a Restfull Go API with Let's Encrypt
https://github.com/tonychouteau/https-restful-api

go https letsencrypt

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

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

```bash
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

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

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

```bash
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.

```go
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) :

```go
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