https

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: Unlicense Imports: 5 Imported by: 0

README

golang-https

Easy way to add https to your go application with automatic Let's Encrypt certificate getting and updating

Example

The simplest way to start your https server looks like this:

srv := https.New("./data", "my@email.com", "my.site.com")

err := srv.ListenHTTPS(":443", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("Hello, world!"))
}))
if err != nil {
    log.Fatal(err)
}

Additional functions

  • ListenHTTPRedirect starts server which redirects all http requests to the corresponding https url.
    • http://some.site.com/path/to/handler?param1=value1 -> https://some.site.com/path/to/handler?param1=value1
  • GetHTTPSServer returns https server ready to be started. You should use this function if you want to manually tweak some params of the server.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(cacheDir string, email string, hosts ...string) *Service

New creates autocert service cacheDir should be a path to the folder when you want to store your certificates (to save them when the app stops) email is used only for Let's Encrypt registration purposes hosts is the list of domain names of your site (could be just one)

func (*Service) GetHTTPSServer

func (s *Service) GetHTTPSServer(hostPort string, mux http.Handler) *http.Server

GetHTTPSServer should be used when you want some manual control over created https server after getting the server and applying your settings just call .ListenAndServeTLS("", "")

func (*Service) ListenHTTPRedirect

func (s *Service) ListenHTTPRedirect(listenHostPort string) error

ListenHTTPRedirect listens plain http and redirects all requests to https version of the site works only when your https server listens at 443 port

func (*Service) ListenHTTPS

func (s *Service) ListenHTTPS(hostPort string, mux http.Handler) error

ListenHTTPS is the easiest way to start your https server hostPort may look like :443 (listens all interfaces) or 1.2.3.4:443 (listens only provided ip) mux should be a router of your choice (for example github.com/julienschmidt/httprouter)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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