forked from crawshaw/httpts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_httpts.go
More file actions
41 lines (35 loc) · 932 Bytes
/
example_httpts.go
File metadata and controls
41 lines (35 loc) · 932 Bytes
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
38
39
40
41
//go:build ignore
// +build ignore
// This example demos serving HTTP on your tailnet.
//
// To run entirely locally use:
//
// go run ./example_httpts.go -devport 8080
//
// This is useful for local development on the bus.
// To run on a tailnet, drop the -devport flag:
//
// go run ./example_httpts.go
//
// The first time, a tailscale login URL will be printed to put it on a tailnet.
// Then it will print out the full URL of this server.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/crawshaw/httpts"
)
func main() {
devPort := flag.Int("devport", 0, "localhost port to run in dev mode, 0 to disable")
flag.Parse()
s := httpts.Server{
Handler: http.HandlerFunc(handler),
InsecureLocalPortOnly: *devPort,
}
log.Fatal(s.Serve("httpts-example"))
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", httpts.WhoFromCtx(r.Context()).LoginName)
}