首先很抱歉可能是一个糟糕的标题 - 我想我遇到的很多困难都与不知道我想要实现的目标的正确术语有关。
在 Go 中,我希望有一个程序,它在运行时可以动态创建二级二进制文件。用一个基本的 hello world 示例来说明 - 在伪代码中,因为我不知道如何实现它。
generator.go
-> Read in statement from statement.txt (i.e. "Hello World")
-> Insert this statement into the following program...
package main
import (
"fmt"
)
func main(){
fmt.Println([dynamic statement inserted here])
}
-> compile this code into subprogram
每当go run generator.go执行时subprogram都会创建一个二进制文件。运行这将输出Hello World. 将 statement.txt 更改为其他内容并go run generator.go再次执行将再次创建subprogram运行时将执行新语句的内容。
相关分类