英文:
How to implement CLI client to golang daemon?
问题
我有一个使用Golang编写的Linux守护进程,带有HTTP API。在启动时,它会初始化变量,并且每当我请求API时,它都会进行响应。初始化是一个复杂的操作:读取许多配置文件,添加许多对象等等。
我的问题是,如果主进程死掉,我就无法使用HTTP API。我的代码并不完美,有时会出现堆栈溢出或崩溃,或者用户禁用了Linux服务。但我仍然需要一些低级功能来工作。
如果我尝试在命令行界面实现Web API的所有功能,启动将会非常缓慢,对系统来说也很困难。但是,如果实现在CLI和Web API之间分离,会出现不一致的问题。例如:我可以在Web API内部启动创建操作,同时在CLI内部删除所有操作。我必须实现锁定功能来防止这种情况发生。(我认为在这一方面编写代码并不好)
我不使用数据库服务器(也不需要)。也许我可以将数据存储在文件中或使用一些共享内存?
我的问题是,我如何在Golang守护进程和CLI客户端之间共享对象数据?
英文:
I have a linux daemon with http api which I have wrote on golang. At start he initialize variables and all time when I ask api - he is answer. Init is hard operation: read many config's, add many object's etc.
My problem that if main process die I can't use http api ;). My code isn't perfect and sometimes he stack or die, or user's disable linux service. But I still need some low level functionality to work.
If I try to implement all functions of web api at cli: his start will be very slow and hard for system. But I have more problem if implementation will be separated between CLI & web api: inconsistent. For example: I can start inside web api create && at same time inside CLI - delete all. I must implement lock function to prevent this. (I think write code at this side isn't good)
I don't use database server (and don't need). Maybe I can store inside files or use some shared memory?
My question is how can I share object's data between golang daemon and CLI-client?
答案1
得分: 1
Go语言内置了一个用于Go进程之间简单通信的RPC系统。你还可以查看0mq或使用D-Bus。
英文:
Go has a built-in RPC system for easy communication between Go processes. You could also take a look at 0mq, or using D-Bus.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论