duanfeigui6655 2017-07-15 07:49
浏览 116
已采纳

如何使用golang微服务? [关闭]

My company use Go to build some HTTP API services. We want these services share one HTTP port.

So the solution right now is we create a project named router, and router import some modules, every request pass through router to their own modules.
But the question is that if one of these modules process crashed, the router just crash.

Is there any solutions?

Require:

  1. One http port.
  2. Every service is independent.

I know go-kit and go micro, also I have tried, but still not too understand.

  • 写回答

3条回答 默认 最新

  • dongmin4990 2017-07-15 08:15
    关注

    Go-kit and go-micro are for writing microservices, it won't solve your problem.

    You should use a reverse proxy in front of your applications, for instance Nginx: https://www.nginx.com/resources/admin-guide/reverse-proxy/

    Here is an example of a nginx configuration file that does what you want:

    server {
       listen 80 default_server;
       server_name your-domain;
    
       location /app1 {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_pass http://localhost:3000;
       }
    
       location /app2 {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_pass http://localhost:4000;
       }
    }
    

    This way, you still deploy your applications on different ports, but they will only be exposed through the port 80.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?