简体   繁体   中英

Combine multiple applications into single binary

Suppose I have four applications:

  1. http-gateway
  2. NATS
  3. Business Logic Client
  4. Business Logic Server
Gateway <--> NATS <---> B.L.

My project structure is as follows:

nats-cluster\
  cmd\
    gateway\gatway.go
    blclient\blclient.go
    blserver\blserver.go
  gateway\
  blclient\
  blserver\

Currently, I have to run four of them separately and only then they can talk with each other. Gateway and BLclient use request-reply pattern while blclient uses grpc to exchange messages with blserver . I wanted to know if there is any method to generate a single binary in Go so that the application can be run through a single binary.

Is there any way to combine multiple app binaries into a single one in Go?

I embed the NATS server in the Simple IoT application. Here is how I do it:

https://github.com/simpleiot/simpleiot/blob/master/cmd/siot/main.go#L452

https://github.com/simpleiot/simpleiot/blob/master/natsserver/nats-server.go

Works great and super easy to do.

For some applications, it makes sense to bundle everything in one Go application as deployment is much simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM