26 lines
447 B
Go
26 lines
447 B
Go
|
package svc
|
||
|
|
||
|
import (
|
||
|
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/config"
|
||
|
"github.com/spf13/viper"
|
||
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||
|
)
|
||
|
|
||
|
type ServiceContext struct {
|
||
|
Config config.Config
|
||
|
EtcdCli *clientv3.Client
|
||
|
}
|
||
|
|
||
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||
|
|
||
|
cli, err := clientv3.NewFromURL(viper.GetString(config.EtcdAddrKey))
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
return &ServiceContext{
|
||
|
Config: c,
|
||
|
EtcdCli: cli,
|
||
|
}
|
||
|
}
|