基本介绍

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

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

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

配置模板

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

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







Content Menu

  • No labels