HTTPS with TLS Example
This project demonstrates how to set up an HTTPS server with TLS in a Go application using the Fiber framework.
Prerequisites
Ensure you have the following installed:
- Golang
- Fiber package
- TLS certificates (self-signed or from a trusted CA)
Setup
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git
cd recipes/https-tls -
Install dependencies:
go get
-
Place your TLS certificate (
cert.pem
) and private key (key.pem
) in the project directory.
Running the Application
-
Start the application:
go run main.go
-
Access the application at
https://localhost:3000
.
Example
Here is an example of how to set up an HTTPS server with TLS in a Fiber application:
package main
import (
"log"
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, HTTPS with TLS!")
})
// Start server with TLS
log.Fatal(app.ListenTLS(":3000", "cert.pem", "key.pem"))
}