1 Star 0 Fork 0

天雨流芳 / go-micro-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
options.go 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
天雨流芳 提交于 2024-04-01 17:43 . 链路追踪逻辑修改
package trace
import (
"errors"
"fmt"
"github.com/spf13/pflag"
)
const TraceName = "CZC"
type Options struct {
Name string `mapstructure:"name" json:"name"`
Endpoint string `mapstructure:"endpoint" json:"endpoint"`
Sampler float64 `mapstructure:"sampler" json:"sampler"`
Batcher string `mapstructure:"batcher" json:"batcher"`
}
func NewTelemetryOptions() *Options {
return &Options{
Name: "telemetry",
Endpoint: "http://127.0.0.1:14268/api/traces",
Sampler: 1.0,
Batcher: "jaeger",
}
}
func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.Name, "telemetry.name", o.Name, "telemetry name.")
fs.StringVar(&o.Endpoint, "telemetry.endpoint", o.Endpoint, "telemetry endpoint.")
fs.Float64Var(&o.Sampler, "telemetry.sampler", o.Sampler, "telemetry sampler.")
fs.StringVar(&o.Batcher, "telemetry.batcher", o.Batcher, "telemetry batcher.")
}
func (o *Options) Validate() error {
if o.Name == "" {
return errors.New("name is empty")
}
if o.Endpoint == "" {
return errors.New("endpoint is empty")
}
if o.Sampler == 0 {
return errors.New("sampler is empty")
}
if o.Batcher == "" {
return errors.New("batcher is empty")
}
if o.Batcher != kindJaeger && o.Batcher != kindZipkin {
return errors.New(fmt.Sprintf("batcher must in [%s,%s]", kindJaeger, kindZipkin))
}
return nil
}
1
https://gitee.com/tylf2018/go-micro-framework.git
git@gitee.com:tylf2018/go-micro-framework.git
tylf2018
go-micro-framework
go-micro-framework
4cc90ded505a

搜索帮助