Basic Service Configuration

Service Overview

ServiceConf This configuration is used to represent a configuration of our independent service.He is quoted by our rest,zrpc and so on. Of course, we can simply define our services.

Example:

  1. package main
  2. import (
  3. "github.com/zeromicro/go-zero/core/conf"
  4. "github.com/zeromicro/go-zero/core/service"
  5. "github.com/zeromicro/go-zero/zrpc"
  6. )
  7. type JobConfig struct {
  8. service.ServiceConf
  9. UserRpc zrpc.RpcClientConf
  10. }
  11. func main() {
  12. var c JobConfig
  13. conf.MustLoad("config.yaml", &c)
  14. c.MustSetUp()
  15. // do your job
  16. }

As above, we defined a JobConfig, and initially set MustSetup at startup, so that we can start a service service, which automatically integrates Metrics, Prometheus, Trace , DevServer, Log and other capabilities.

Definition of parameters

ServiceConf configuration defined as follows:

  1. // A ServiceConf is a service config.
  2. type ServiceConf struct {
  3. Name string
  4. Log logx.LogConf
  5. Mode string `json:",default=pro,options=dev|test|rt|pre|pro"`
  6. MetricsUrl string `json:",optional"`
  7. // Deprecated: please use DevServer
  8. Prometheus prometheus.Config `json:",optional"`
  9. Telemetry trace.Config `json:",optional"`
  10. DevServer devserver.Config `json:",optional"`
  11. }
ParamsDataTypeDefault valueNoteEnum Values
Namestring-Define the name of the service, which will appear in log and tracer
Loglogx.LogConf-Refer to log
ModestringproService environment. Dev is currently defined.In dev environment we will turn on reflectiondev,test,rt,pre, pro
MetricsUrlstringTap to report and we’ll report some metrics to the corresponding address, if empty, not an orphan
Prometheusprometheus.Config-References Prometheus.md
Telemetrytrace.Config-References trace.md
DevServerdevserver.Config-go-Zero version v1.4.3 and above