Gotron 开源项目使用教程
gotronGo Api for Electron项目地址:https://gitcode.com/gh_mirrors/go/gotron
1. 项目的目录结构及介绍
Gotron 项目的目录结构如下:
gotron/
├── cmd/
│ └── gotron/
│ └── main.go
├── examples/
│ ├── basic/
│ ├── custom_protocol/
│ ├── multiple_windows/
│ └── single_binary/
├── internal/
│ ├── assets/
│ ├── browser/
│ ├── protocol/
│ └── window/
├── pkg/
│ ├── gotron/
│ └── gotron-builder/
├── scripts/
│ └── build.sh
├── .gitignore
├── Dockerfile
├── go.mod
├── go.sum
└── README.md
目录结构介绍
cmd/
: 包含项目的入口文件。examples/
: 包含多个示例项目,展示如何使用 Gotron。internal/
: 包含项目的内部实现,如资源管理、浏览器控制、协议处理和窗口管理。pkg/
: 包含项目的公共包,如gotron
和gotron-builder
。scripts/
: 包含构建脚本。.gitignore
: Git 忽略文件。Dockerfile
: Docker 配置文件。go.mod
和go.sum
: Go 模块依赖管理文件。README.md
: 项目说明文档。
2. 项目的启动文件介绍
项目的启动文件位于 cmd/gotron/main.go
。该文件是 Gotron 项目的入口点,负责初始化和启动应用程序。
package main
import (
"github.com/Equanox/gotron"
"log"
)
func main() {
// Create a new browser window instance
window, err := gotron.New()
if err != nil {
log.Fatal(err)
}
// Alter default window size and window title.
window.WindowOptions.Width = 1200
window.WindowOptions.Height = 980
window.WindowOptions.Title = "Gotron"
// Start the browser window.
// This will establish a golang <=> nodejs bridge using websockets,
// to control ElectronBrowserWindow with our window variable.
err = window.Start()
if err != nil {
log.Fatal(err)
}
}
启动文件介绍
gotron.New()
: 创建一个新的浏览器窗口实例。window.WindowOptions
: 设置窗口的默认大小和标题。window.Start()
: 启动浏览器窗口。
3. 项目的配置文件介绍
Gotron 项目的配置文件主要包括 go.mod
和 go.sum
,这两个文件用于管理 Go 模块的依赖。
go.mod
go.mod
文件定义了项目的模块路径和所需的依赖项。
module github.com/Equanox/gotron
go 1.14
require (
github.com/asticode/go-astikit v0.1.0
github.com/asticode/go-astilectron v0.17.0
github.com/asticode/go-astilectron-bundler v0.7.10
github.com/asticode/go-astilectron-bootstrap v0.4.1
github.com/gorilla/websocket v1.4.2
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0
)
go.sum
go.sum
文件包含了每个依赖项的确切版本和哈希值,确保依赖项的完整性和安全性。
github.com/asticode/go-astikit v0.1.0 h1:4mJv5Xx/6w83+iPp7KVE1mDf+6SLI11YtkuAz/j/k8A=
github.com/asticode/go-astikit v0.1.0/go.mod h1:7WoHZZ/4l/s0JqjZF
gotronGo Api for Electron项目地址:https://gitcode.com/gh_mirrors/go/gotron