Search code examples
gogo-micro

How to fix port for Go-Micro Service


I am running go-micro , But unable to set constant port for my service. Is there any way to assign port to service.

If i am running my service, it gives different port on every execution. i want it to fix.


Solution

  • You can specify the port in the server you must be creating for your micro-service. Since you haven't shared any sample code, here's a proposed solution that might work for you:

     service := micro.NewService(
        micro.Name(serviceName),
        micro.Server(
          server.NewServer(
            server.Name(serviceName),
            server.Address(":8080"),
          ),
        ),
      )
    
      service.Init()
    

    Let me know if it is not the way you're using go-micro.