-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
51 lines (46 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
// Copyright 2023 The KCL Authors. All rights reserved.
// KCL playground.
package main
import (
"flag"
"fmt"
"os/exec"
"runtime"
"strings"
"time"
"kcl-lang.io/kcl-playground/pkg/play"
)
func main() {
deploy_mode := flag.Bool("deploy", false, "Whether is deploy mode")
flag.Parse()
opts := play.Options{
PlayMode: true,
AllowShare: true,
}
if *deploy_mode {
play.Run(":80", &opts)
} else {
addr := "localhost:2023"
fmt.Printf("listen at http://%s\n", addr)
go func() {
time.Sleep(time.Second * 2)
openBrowser(addr)
}()
play.Run(addr, &opts)
}
}
func openBrowser(url string) error {
if !strings.HasPrefix(url, "http") {
url = "http://" + url
}
switch runtime.GOOS {
case "linux":
return exec.Command("xdg-open", url).Start()
case "windows":
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
return exec.Command("open", url).Start()
default:
return fmt.Errorf("unsupported platform")
}
}