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.


package main

import (

type JobConfig struct {
UserRpc zrpc.RpcClientConf

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

// 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
DevServerdevserver.Config-go-Zero version v1.4.3 and above