forked from gofiber/recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (30 loc) · 826 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 🤖 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io
package main
import (
"crypto/tls"
"log"
"github.com/gofiber/fiber/v2"
)
func main() {
// Fiber instance
app := fiber.New()
// Routes
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString(c.Protocol()) // => https
})
// Create tls certificate
cer, err := tls.LoadX509KeyPair("certs/ssl.cert", "certs/ssl.key")
if err != nil {
log.Fatal(err)
}
config := &tls.Config{Certificates: []tls.Certificate{cer}}
// Create custom listener
ln, err := tls.Listen("tcp", ":443", config)
if err != nil {
panic(err)
}
// Start server with https/ssl enabled on http://localhost:443
log.Fatal(app.Listener(ln))
}