generated from Lerking/golang-repo-template
Updated. /JL
This commit is contained in:
6
go.mod
6
go.mod
@@ -1,5 +1,3 @@
|
||||
module template
|
||||
module test-web-app
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/webview/webview v0.0.0-20240422163931-93be13a101e5 // indirect
|
||||
go 1.22
|
||||
|
2
go.sum
2
go.sum
@@ -1,2 +0,0 @@
|
||||
github.com/webview/webview v0.0.0-20240422163931-93be13a101e5 h1:YeAdzszxZAIYebts/ZGyJjEXCpQWv+XCJm/4F3QNQDE=
|
||||
github.com/webview/webview v0.0.0-20240422163931-93be13a101e5/go.mod h1:Zk81X+8/mp/MNoeJXXK4Noydn8pcea09e00dFfAwrxg=
|
||||
|
27
main.go
27
main.go
@@ -6,10 +6,24 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/webview/webview"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func openBrowser(url string) bool {
|
||||
var args []string
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
args = []string{"open"}
|
||||
case "windows":
|
||||
args = []string{"cmd", "/c", "start", "chrome"}
|
||||
default:
|
||||
args = []string{"xdg-open"}
|
||||
}
|
||||
cmd := exec.Command(args[0], append(args[1:], url)...)
|
||||
return cmd.Start() == nil
|
||||
}
|
||||
|
||||
func getRoot(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("got / request\n")
|
||||
io.WriteString(w, "Welcome to TimeCard!\n")
|
||||
@@ -20,6 +34,8 @@ func getHello(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
openBrowser("127.0.0.10:3333")
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", getRoot)
|
||||
mux.HandleFunc("/hello", getHello)
|
||||
@@ -31,11 +47,4 @@ func main() {
|
||||
fmt.Printf("error starting server: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
w := webview.New(false)
|
||||
defer w.Destroy()
|
||||
w.SetTitle("Basic Example")
|
||||
w.SetSize(480, 320, webview.HintNone)
|
||||
w.SetHtml("Thanks for using webview!")
|
||||
w.Run()
|
||||
}
|
||||
|
Reference in New Issue
Block a user