T
T
Tokenchik2020-01-28 13:07:59
go
Tokenchik, 2020-01-28 13:07:59

Are there examples of a go project structure with workers?

It is necessary to implement several workers for one go project. How do you usually structure such a project?
At the moment, the structure is something like this:
config
--config.go
utils
--error_handler.go
--init.go
models
--users
--posts
worker1.go
worker2.go

As you can see, to run a specific worker, I run them through go run { worker name}.
However, I have certain doubts about the correctness of this action, I would like to know how they usually do in such situations.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2020-01-28
@Tokenchik

It makes sense to compile the CLI application and run the binary with the necessary parameters, like this

yourprog worker1
yourprog worker2

You can use these libraries:
https://github.com/urfave/cli (good and simple, I advise you to start with it)
https://github.com/spf13/cobra (very powerful, it is used by Docker)
You have a project structure will also change a little, in Go it is customary to make a cmd daddy, like this:
cmd/
cmd/worker1.go
cmd/worker2.go There
is a sample in each of the libraries that I wrote above.
There was already a question about the structure of the project in Go, here is a well described Project structure in Golang?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question