Protocol Servers

Introduction

you can extend your own protocol in go chassis, currently support rest(http) and gRPC

Configurations

protocols.{protocol_server_name}

(required, string) the name of the protocol server, it must be protocol name or consist of protocol name and a suffix. the suffix and protocol is connect with hyphen “-” like -{suffix}

protocols.{protocol_server_name}.advertiseAddress

(optional, string) server advertise address, if you use registry like service center, this address will be registered in service center, so that other service can discover your address

protocols.{protocol_server_name}.listenAddress

(required, string) server listen address, recommend to use 0.0.0.0:{port}, then go chassis will automatically generate advertise address, it is convenience to run in container because the internal IP is not sure until container runs

API

You can use WithServerMask to ignore protocol server configurations, just give protocol server name list. then chassis will not start them

chassis.Run(WithServerMask("rest-admin","grpc"))

Example

this config will launch 2 http server and 1 grpc server

servicecomb:
  protocols:
    rest:
      listenAddress: 0.0.0.0:5000
      cors:
        enable: true
        exposeHeaders: ["Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"]
        allowedHeaders: ["Origin", "Accept", "Content-Type", "Authorization"]
        allowedDomains: [""]
        allowedMethods: ["GET", "POST", "PUT", "DELETE", "PATCH"]        
        cookiesAllowed: false
        maxAge        : 5
    rest-admin:
      listenAddress: 0.0.0.0:5001
    grpc:
      listenAddress: 0.0.0.0:6000

for ipv6, need quotation marks. because [] is object list in yaml format

servicecomb:
  protocols:
    rest:
      listenAddress: "[2407:c080:17ff:ffff::7274:83a]:5000"

if you do not want to specify a port, you can leave the port empty (use quotes) or use 0, the system will give a random port for you

servicecomb:
  protocols:
    rest:
      listenAddress: 0.0.0.0:0
    grpc:
      listenAddress: "127.0.0.1:"