autotls

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

README

autotls

Support Let's Encrypt for Hertz.

How to start it

  1. Prepare a VM and a domain.
  2. Create a new DNS A record targeting your VM public IP.
  3. Write code and compile it.
  4. Start the binary.
  5. Open your browser with the address of your DNS domain.

Example

func main() {
	h := server.Default(
		server.WithTLS(autotls.NewTlsConfig("your domain")), 
		server.WithHostPorts(":https"),
	)

	// Ping handler
	h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
		ctx.JSON(200, map[string]interface{}{
			"ping": "pong",
		})
	})

	hlog.Fatal(autotls.Run(h))
}

More examples can be found in the examples directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServerWithManagerAndTlsConfig

func NewServerWithManagerAndTlsConfig(m *autocert.Manager, tlsc *tls.Config, opts ...config.Option) *server.Hertz

NewServerWithManagerAndTlsConfig creates Hertz server with autocert manager and TLS config

func NewTlsConfig

func NewTlsConfig(domains ...string) *tls.Config

func Run

func Run(h *server.Hertz) error

Run support 1-line LetsEncrypt HTTPS servers

func RunWithContext

func RunWithContext(ctx context.Context, h *server.Hertz) error

RunWithContext support 1-line LetsEncrypt HTTPS servers with graceful shutdown

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL