go-micro源码阅读笔记1
最近在看微服务,跟大佬们请教了下很多微服务的知识,然后看教程自己实践,在此特别感谢0.01km(QQ昵称)大佬的帮助
临沂ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
本节主要是针对与go-micro服务注册的过程中源码阅读的分享,
s := micro.NewService(
micro.Name("go.micro.srv.user"),
micro.Version("latest"),
)
s.Init()
这里做了很多事
func newOptions(opts ...Option) Options {
opt := Options{
Broker: broker.DefaultBroker,
Cmd: cmd.DefaultCmd,
Client: client.DefaultClient,
Server: server.DefaultServer,
Registry: registry.DefaultRegistry,
Transport: transport.DefaultTransport,
Context: context.Background(),
}
}
这块初始化Options结构体,如果想要修改consul默认的注册地址,必须要修改NewRegistry函数,里面赋值
type Options struct {
Addrs []string //注册ip地址:192.168.1.2:8080
Timeout time.Duration
Secure bool
TLSConfig *tls.Config
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
}
//这里是获取默认的配置
func configure(c *consulRegistry, opts ...Option) {
// set opts
for _, o := range opts {
o(&c.opts)
}
// use default config
config := consul.DefaultConfig()
//consul默认配置
func defaultConfig(transportFn func() *http.Transport) *Config {
config := &Config{
Address: "127.0.0.1:8500",
Scheme: "http",
Transport: transportFn(),
}
if addr := os.Getenv(HTTPAddrEnvName); addr != "" {
config.Address = addr
}
if token := os.Getenv(HTTPTokenEnvName); token != "" {
config.Token = token
}
if auth := os.Getenv(HTTPAuthEnvName); auth != "" {
var username, password string
if strings.Contains(auth, ":") {
split := strings.SplitN(auth, ":", 2)
username = split[0]
password = split[1]
} else {
username = auth
}
好了,下节继续分享其他部分
文章题目:go-micro源码阅读笔记1
文章路径:http://scyanting.com/article/ihcdjj.html