-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooked.go
63 lines (51 loc) · 1.07 KB
/
booked.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
//go:generate go run -tags=dev internal/assets/generate.go
//go:generate go run -tags=dev internal/templates/generate.go
import (
"flag"
"fmt"
"log"
"net"
"net/http"
"net/url"
"os"
"go.tmthrgd.dev/booked/browser"
)
func init() {
log.SetFlags(0)
flag.Usage = func() {
out := flag.CommandLine.Output()
fmt.Fprintf(out, "usage: %s [flags] facebook-json.zip\n", os.Args[0])
flag.PrintDefaults()
}
}
func main() {
addr := flag.String("addr", ":8080", "the address to listen on")
noLaunch := flag.Bool("no-launch", false, "skip launching a browser window")
flag.Parse()
if flag.NArg() < 1 {
flag.Usage()
os.Exit(1)
}
h, err := open(flag.Args()...)
if err != nil {
log.Fatal(err)
}
if !*noLaunch {
go launch(*addr)
}
log.Printf("listening on %s", *addr)
log.Fatal(http.ListenAndServe(*addr, h))
}
func launch(addr string) {
u := &url.URL{
Scheme: "http",
Host: addr,
}
if u.Hostname() == "" {
u.Host = net.JoinHostPort("localhost", u.Port())
}
if !browser.Open(u.String()) {
log.Printf("navigate to %s in your browser", u)
}
}