在go項目中讀取配置文件時,如果使用的是相對路徑,在執行run test時也會在test文件所在的目錄下去讀取配置文件,如果文件沒在此目錄下會報錯:“open env1.json: The system cannot find the file specified."。
os.Getwd()得到的是test文件所在的路徑。
在windows中可以使用絕對路徑讀取。eg:“D:\\Projects\\gowork\\src\\hello\\env1.json”