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
- Host: GitHub
- URL: https://github.com/tonychouteau/https-restful-api
- Owner: TonyChouteau
- Created: 2019-09-02T19:22:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-04T15:24:07.000Z (over 5 years ago)
- Last Synced: 2025-01-31T16:35:58.413Z (4 months ago)
- Topics: go, https, letsencrypt
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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-other2) 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