From b1a2abf41b9d57197bf9e5dd5af7accf16810d4a Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 21 Sep 2021 22:17:45 -0700 Subject: [PATCH] client/tailscale/example/servetls: add demo program for docs Updates #1235 Signed-off-by: Brad Fitzpatrick --- client/tailscale/example/servetls/servetls.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 client/tailscale/example/servetls/servetls.go diff --git a/client/tailscale/example/servetls/servetls.go b/client/tailscale/example/servetls/servetls.go new file mode 100644 index 000000000..bfa2cc9ed --- /dev/null +++ b/client/tailscale/example/servetls/servetls.go @@ -0,0 +1,29 @@ +// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The servetls program shows how to run an HTTPS server +// using a Tailscale cert via LetsEncrypt. +package main + +import ( + "crypto/tls" + "io" + "log" + "net/http" + + "tailscale.com/client/tailscale" +) + +func main() { + s := &http.Server{ + TLSConfig: &tls.Config{ + GetCertificate: tailscale.GetCertificate, + }, + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "

Hello from Tailscale!

It works.") + }), + } + log.Printf("Running TLS server on :443 ...") + log.Fatal(s.ListenAndServeTLS("", "")) +}