-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
44 lines (36 loc) · 922 Bytes
/
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
38
39
40
41
42
43
44
package main
import (
"embed"
"flag"
"fmt"
"io/fs"
"log"
"net/http"
"os/exec"
"github.com/vifon/yeetlight/api"
)
//go:embed public/*
var content embed.FS
// Browse launches a web browser (as defined by xdg-open) with the
// launched service open.
func Browse(iface string) {
exec.Command("xdg-open", "http://" + iface).Run()
}
func main() {
browse := flag.Bool("browse", false, "Launch a browser.")
iface := flag.String("iface", "0.0.0.0:8080", "Network interface to bind to.")
config := flag.String("config", "", "Path to the config.")
flag.Parse()
static, err := fs.Sub(content, "public")
if err != nil {
log.Panic(
"The embedded FS has no 'public' directory; it should never happen, please report!",
)
}
api.Handle(static, *config)
fmt.Printf("Serving at http://%v\n", *iface)
if browse != nil && *browse == true {
go Browse(*iface)
}
log.Fatal(http.ListenAndServe(*iface, nil))
}