Go 如何链接html

Go 如何链接html,go,Go,我使用这个库创建GUI:github.com/Equanox/gotron 当我点击html按钮运行带有用户名和密码的Go代码时,我需要这个 你知道怎么做吗?我试着用谷歌搜索它,但我没有找到任何与之相关的代码,也许我搜索错了 我的代码: package main import ( "github.com/Equanox/gotron" "log" "os" "text/template&quo

我使用这个库创建GUI:github.com/Equanox/gotron 当我点击html按钮运行带有用户名和密码的Go代码时,我需要这个

你知道怎么做吗?我试着用谷歌搜索它,但我没有找到任何与之相关的代码,也许我搜索错了

我的代码:

package main

import (
    "github.com/Equanox/gotron"
    "log"
    "os"
    "text/template"
)

var tpl *template.Template

func LinkinInit()  {
    tpl = template.Must(template.ParseFiles("tpl.html"))
}

func main() {
    // Create a new browser window instance
    window, err := gotron.New()
    if err != nil {
        panic(err)
    }

    // Alter default window size and window title.
    window.WindowOptions.Width = 720
    window.WindowOptions.Height = 485
    window.WindowOptions.Title = "Login APP"

    // Start the browser window.
    // This will establish a Go <=> nodejs bridge using websockets,
    // to control ElectronBrowserWindow with our window object.
    done, err := window.Start()
    if err != nil {
        panic(err)
    }

    <-done
}
主程序包
进口(
“github.com/Equanox/gotron”
“日志”
“操作系统”
“文本/模板”
)
var tpl*template.template
func LinkinInit(){
tpl=template.Must(template.ParseFiles(“tpl.html”))
}
func main(){
//创建新的浏览器窗口实例
window,err:=gotron.New()
如果错误!=零{
恐慌(错误)
}
//更改默认窗口大小和窗口标题。
window.WindowOptions.Width=720
window.WindowOptions.Height=485
window.WindowOptions.Title=“登录应用程序”
//启动浏览器窗口。
//这将使用WebSocket建立Go-nodejs桥,
//用窗口对象控制ElectronBrowserWindow。
完成,错误:=window.Start()
如果错误!=零{
恐慌(错误)
}

看看Gotron自述文件

后端:处理传入事件

window.On(&gotron.Event{Event: "event-name"}, func(bin []byte) { 
//Handle event here 
}
前端:将事件发送到后端

ws.send(JSON.stringify)({
“事件”:“事件名称”,
“atrnameinfortend”:“你好,世界!”,
}))

我尝试过这个,但它似乎不起作用(我对Javascript不是很在行),它也给了我一个无法解决的错误,正如我所说,我对JS不是很在行。错误是:未捕获的DomeException:未能在“WebSocket”上执行“发送”:仍处于连接状态。在SendEvent单击(文件:/C:/Users/Ur/go/src/main/.gotron/assets/index.html:31:12)位于HTMLButtonElement.onclick(文件:/C:/Users/Ur/go/src/main/.gotron/assets/index.html:23:54)我也不知道我是否正确地使用了它,但我认为是这样的function@Ped也许你应该对那个特定的错误进行一些搜索,在这个网站和其他网站上似乎有很多结果。@Hinos Para Disco谢谢!!我做了,我不太擅长JS,所以我认为这是一些错误g与配置相关,但我在这里看到它没有加载,并且在没有ws-loading的情况下发送了send(),感谢您的帮助