Skip to main content

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:

package main

import (
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/zrpc"
)

type JobConfig struct {
service.ServiceConf
UserRpc zrpc.RpcClientConf
}

func main() {
var c JobConfig
conf.MustLoad("config.yaml", &c)

c.MustSetUp()
// do your job
}

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:

// A ServiceConf is a service config.
type ServiceConf struct {
Name string
Log logx.LogConf
Mode string `json:",default=pro,options=dev|test|rt|pre|pro"`
MetricsUrl string `json:",optional"`
// Deprecated: please use DevServer
Prometheus prometheus.Config `json:",optional"`
Telemetry trace.Config `json:",optional"`
DevServer devserver.Config `json:",optional"`
}
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