基本介绍

服务端支持配置文件,所有的配置将会自动映射到配置对象中。配置对象如下:

  1. // GrpcServerConfig is the configuration for server.
  2. type GrpcServerConfig struct {
  3. Address string // (optional) Address for server listening.
  4. Name string // (optional) Name for current service.
  5. Logger *glog.Logger // (optional) Logger for server.
  6. LogPath string // (optional) LogPath specifies the directory for storing logging files.
  7. LogStdout bool // (optional) LogStdout specifies whether printing logging content to stdout.
  8. ErrorStack bool // (optional) ErrorStack specifies whether logging stack information when error.
  9. ErrorLogEnabled bool // (optional) ErrorLogEnabled enables error logging content to files.
  10. ErrorLogPattern string // (optional) ErrorLogPattern specifies the error log file pattern like: error-{Ymd}.log
  11. AccessLogEnabled bool // (optional) AccessLogEnabled enables access logging content to file.
  12. AccessLogPattern string // (optional) AccessLogPattern specifies the error log file pattern like: access-{Ymd}.log
  13. }

配置文件的自动读取逻辑与框架一致,详细介绍请参考章节:配置管理

配置模板

一个完整的配置模板示例:

  1. grpc:
  2. name: "demo" # 服务名称
  3. address: ":8000" # 自定义服务监听地址
  4. logPath: "./log" # 日志存储目录路径
  5. logStdout: true # 日志是否输出到终端
  6. errorLogEnabled: true # 是否开启错误日志记录
  7. accessLogEnabled: true # 是否开启访问日志记录
  8. errorStack: true # 当产生错误时,是否记录错误堆栈