我会建议你按照命令行上的Go文档的建议使用标志-X-X importpath.name=value Set the value of the string variable in importpath named name to value. This is only effective if the variable is declared in the source code either uninitialized or initialized to a constant string expression. -X will not work if the initializer makes a function call or refers to other variables. Note that before Go 1.5 this option took two separate arguments.这样,您就可以调用引用它的任何文件的位置。.env例如go build -ldflags="-X 'package_path.variable_name=new_value'" 那是go build -ldflags "-X 'my/main/config.Version=v1.0.0'" -o $(MY_BIN) $(MY_SRC)