英文:
golang windows service package initialize settings
问题
我正在尝试使用这个包创建一个使用golang的Windows服务:
godoc.org/golang.org/x/sys/windows/svc
一切都很顺利,直到我添加了一个init函数来初始化设置。然后服务就无法启动了。我试图通过这个包加载config.json:
github.com/spf13/viper
然后我得到的错误是:
无法启动服务:服务未能及时响应启动或控制请求。
英文:
I am trying to create a golang windows service utilizing this package
godoc.org/golang.org/x/sys/windows/svc
Everything works great until I add an init func to initialize settings. The service then fails to start. I am attempting to load config.json via this package
github.com/spf13/viper
The error I get then is:
could not start service: the service did not response to the start or control request in a timely fashion.
答案1
得分: 2
@JimB 谢谢。就是这样,
在调试模式下,它会在exe所在的文件夹中查找,
而在服务模式下,它会在system32文件夹中查找。
我安装了github.com/kardianos/osext,
并使用了函数ExecutableFolder()来返回到exe文件的主文件夹。这样它就能找到我的配置文件并加载了。
英文:
@JimB thank you. that was it,
running in debug it looks in the folder that the exe is in,
when running in service it looks in the system32 folder.
I installed github.com/kardianos/osext
and used the func ExecutableFolder() to get back to the main folder of the exe file. Which then allowed it to find my config file and load.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论