-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (55 loc) · 988 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"bufio"
"embed"
"errors"
"fmt"
"io"
"log"
"os"
"github.com/discoverkl/gots/ui"
)
//go:embed index.html
var www embed.FS
func add(a, b int) int {
return a + b
}
func main() {
app := ui.New(
ui.Mode(promptRunMod()),
ui.Root(www),
ui.OnlineAddr(":8000"),
)
app.BindFunc("add", add)
app.Run()
}
func promptRunMod() string {
for {
fmt.Print(promptText)
ch, _, err := bufio.NewReader(os.Stdin).ReadRune()
if err != nil {
if errors.Is(err, io.EOF) {
fmt.Println()
os.Exit(0)
}
log.Fatal(err)
}
switch ch {
case '1', 10:
return "app"
case '2':
return "page"
case '3':
return "online"
case 'q':
os.Exit(0)
default:
}
}
}
const promptText = `
*** Commands ***
1: LocalApp - start a local web server, open its' serving url within a native app
2: LocalPage - start a local web server, open its' serving url with your default web browser
3: Online - run a online web server
Please enter (1-3)? `