forked from foomo/simplecert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (31 loc) · 1.2 KB
/
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
//
// simplecert
//
// Created by Philipp Mieden
// Contact: dreadl0ck@protonmail.ch
// Copyright © 2018 bestbytes. All rights reserved.
//
package main
import (
http "github.com/Noooste/fhttp"
"log"
"github.com/Noooste/simplecert"
)
// This example demonstrates how spin up a simple HTTPS webserver for local development, with a locally trusted certificate.
// The mkcert (https://github.com/FiloSottile/mkcert) util must be installed for this to work, the generated certificates will be valid for 10 years.
// Caution: simplecert will automatically add an entry to your /etc/hosts to point the specified domain(s) to localhost!
func main() {
// handle incoming HTTP request via the
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello"))
})
// start the server and log the error if it crashes
log.Fatal(simplecert.ListenAndServeTLSLocal(
":443",
nil, // <- passing a nil handler will use the http.DefaultServeMux, analogous to the standard library API
nil, // <- passing nil for the cleanup function will cause your program to exit when receiving an interrupt signal
"myawesomewebsite.com",
"sub.myawesomewebsite.com",
))
}