How to make an HTTPS server with Go / Gin

I found a way to make it an HTTPS server with Go / Gin from Gin's Github, so I will write it instead of a memo.

[environment] go version go1.15.2 darwin/amd64

[Reference URL] https://github.com/gin-gonic/gin README.md

For HTTP server

httpd.go


r := gin.Default()
r.GET("/", func(c *gin.Context) {
    c.String(200, "Hello Gin!!")
})
r.Run()

For HTTPS server

httpd.go


r := gin.Default()
r.GET("/", func(c *gin.Context) {
    c.String(200, "Hello Gin!!")
})
r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key")

As described above, If you change "r.Run" to "r.RunTLS", it becomes an https server. The first argument of r.RunTLS is the port number, and the second and third arguments are the certificate path.

that's all.

Recommended Posts

How to make an HTTPS server with Go / Gin
How to make an artificial intelligence LINE bot with Flask + LINE Messaging API
How to make an embedded Linux device driver (11)
How to make an embedded Linux device driver (8)
How to make an embedded Linux device driver (1)
How to make an embedded Linux device driver (4)
How to make a dictionary with a hierarchical structure.
How to make an embedded Linux device driver (7)
How to make an embedded Linux device driver (2)
How to crop an image with Python + OpenCV
How to make an embedded Linux device driver (3)
How to read an array with Python's ConfigParser
[Blender x Python] How to make an animation
How to make an embedded Linux device driver (6)
How to make an embedded Linux device driver (5)
How to make an embedded Linux device driver (10)
How to make Linux compatible with Japanese keyboard
How to make an embedded Linux device driver (9)
Explain in detail how to make sounds with python
How to make a shooting game with toio (Part 1)
How to make an interactive CLI tool in Golang
How to deploy a Go application to an ECS instance
How to make an embedded Linux device driver (12) (Complete)
I tried to make an OCR application with PySimpleGUI
[https proxy with squid] How to represent https whitelist with url_regex
How to make an arbitrary DictCursor with PyMySQL and not return None when NULL
[Learning memo] How to make an application with Django ~ Until Hello World is displayed ~
[Learning memo] How to make an application with Django ~ From virtual environment to pushing to github ~
Connect to Postgresql with GO
Easy to make with syntax
How to update with SQLAlchemy?
How to cast with Theano
How to define Go variables
[Go] How to use "... (3 periods)"
How to Alter with SQLAlchemy?
How to separate strings with','
How to RDP with Fedora31
How to Delete with SQLAlchemy?
[Python] How to make an adjacency matrix / adjacency list [Graph theory]
How to convert an array to a dictionary with Python [Application]
How to make a Python package (written for an intern)
How to manipulate the DOM in an iframe with Selenium
How to make a simple Flappy Bird game with pygame
How to run an app built with Python + py2app built with Anaconda
[Python Kivy] How to create an exe file with pyinstaller
How to read an Excel file (.xlsx) with Pandas [Python]
How to cancel RT with tweepy
Python: How to use async with
Make it possible to output a log to a file with go echo
How to make a string into an array or an array into a string in Python
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install python-pip with ubuntu20.04LTS
How to make a slack bot
How to make a command to read the configuration file with pyramid
How to deal with imbalanced data
How to make a surveillance camera (Security Camera) with Opencv and Python
How to create an email user
How to make a crawler --Advanced
How to make a recursive function
How to get started with Scrapy