V
V
Valeriy Solovyov2014-11-09 18:35:08
go
Valeriy Solovyov, 2014-11-09 18:35:08

How to write CLI client for golang daemon?

Hello everyone
There is a go daemon that provides an http api. I do not know how to make an architecture and write a CLI client?
The initialization of the daemon itself takes some time (several seconds) and loads the processor. The task was to write a CLI client that would:

  • you can perform tasks without a running daemon
  • don't overload the system
  • perform tasks through the CLI client and http api and not get an inconsistent system: we create something on the CLI client, and delete something on the server

There is no database in the system and a full-fledged server is a redundant solution. Some shared cache/memory would do:
  • If the cache is not full - fills the first instance (CLI client or http daemon)
  • If the cache is already full - read
  • If the cache is already full, but rotten - read and update

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Lerg, 2014-11-09
@Lerg

Let the CLI client connect only to the running server over the network via localhost.
And it uses either the same http api, or another, specifically for CLI control.

V
Valeriy Solovyov, 2014-11-10
@sumej

How do clis work for (let's say) Open vSwitch or other non-networking daemons (examples don't come to mind)?
I have already thought about implementing storage in a local database: sqlite / xml files. But how are functions called through cli not over the network?

U
uvelichitel, 2014-11-10
@uvelichitel

RemoteProcedureCall golang.org/pkg/net/rpc to register the required methods on the daemon as exportable. Call via unix sockets (you can even use stdin). General data is simply stored in a file, if you need RAM speed, then MemoryMappedFile golang.org/pkg/syscall/#Mmap

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question