TechniquesHTTPS/TLS support

HTTPS/TLS Support

To use TLS with GIMBAP, you have to provide the certificate and the key files to the server engine.

The TLS options can be given in two ways:

  1. As path to the certificate and key files.
  2. As a tls.Config object.

Using Certificate and Key file paths

The TLS option can be set as a runtime option upon starting the server.

app.Run(gimbap.RuntimeOptions{
  Port: 8080,
  TLSOption: &gimbap.TLSOption{
    CertFile: "https/server.crt",
    KeyFile:  "https/server.key",
  },
})

The CertFile and KeyFile are the paths to the certificate and key files respectively. The server will use these file paths regardless of the server engine used.

Using tls.Config difectly

The tls.Config object can be used to set the TLS options.

tlsConfig := loadTLSConfig()
 
app.Run(gimbap.RuntimeOptions{
  Port: 8080,
  TLSOption: &gimbap.TLSOption{
    Config: tlsConfig,
  },
})

Check if the server is running with TLS

The app will show a message in the console if the server is running with TLS.

| SampleApp    | 9637   2024-11-22T12:21:23+09:00 LOG    [FiberHttpEngine]    - Starting the http engine with TLS on port 8080

MIT 2024 ©jhseong7