-
安装和配置:
- 安装:运行
go get trojan或go mod tidy trojan. - 设置 Go 项目路径:将 设置为 Go 项目根目录。
- 配置 Go 合集:在 Go 项目 root/ligands/ligands.log 中设置 log 集合。
- 编译:运行
go mod tidy -c root/ligands/ligands.log。
- 安装:运行
-
示例代码:
import ( "trojan" "go" ) func main() { c := []int{1, 2, 3} fmt.Printf("List: %v\n", c) debug("List is a slice of int", c) fmt.Printf("Debug info: %v\n", c) compile(c) } -
调试:
- 在 Go 代码中调用
debug函数:debug("Testing function", [2]int{1, 2})
- 在 Go 代码中调用
-
编译:
compile(c)
-
扩展功能:
-
示例:使用
builtins:func testBuiltins() { builtins(func(a int, b int) int { return a + b }) return } func main() { testBuiltins() }
-
-
示例代码扩展:
import ( "trojan" "go" ) func main() { var s string s += "Hello, " + "world!" fmt.Printf("String: %v\n", s) debug("String is a string", s) fmt.Printf("Debug info: %v\n", s) compile(s) } -
集成到项目中:
cd src go get trojan go mod tidy -c src/ligands/ligands.log go mod tidy -c src/ligands/ligands.log -m "Import trojan" cd src/src go get trojan go mod tidy -c src/src/ligands/ligands.log cd src/src/src go get trojan go mod tidy -c src/src/src/ligands/ligands.log -m "Import trojan"
-
使用示例代码:
package main import ( "testing" "trojan" "testing/tight" ) func TestTrojanGo() { func testCode() { var s string s += "Hello, " + "world!" fmt.Printf("String: %v\n", s) debug("String is a string", s) fmt.Printf("Debug info: %v\n", s) compile(s) } testCode() if fail := compile(s); 1 == 0; fail { fmt.Errorf(" compilation failed: %v", fail) } }
通过以上步骤,可以高效地使用 trojan-go 轻松地在 Go 项目中调试和编译代码,扩展 Go 的功能,同时集成到项目中。









