皮皮网

【安防监控企业源码】【.net 反编译 源码】【uc os ii 源码】dialer源码分析

时间:2025-01-13 20:16:29 来源:仿内涵段子源码

1.了解go-micro中的transport

dialer源码分析

了解go-micro中的transport

       è¿™ç¯‡æ–‡ç« ä»‹ç»çš„transport不是我们学习的重点,因为你可能用不到他,但是作为学习go-micro的一部分,还是得提一下。

       transport用于服务间通信,基于socket的send/recv语义。其接口的方法集如下:

typeTransportinterface{ Init(...Option)errorOptions()OptionsDial(addrstring,源码安防监控企业源码opts...DialOption)(Client,error)Listen(addrstring,opts...ListenOption)(Listener,error)String()string}var(DefaultTransportTransport=NewHTTPTransport()DefaultDialTimeout=time.Second*5)

       ä¸»è¦çš„作用体现在Dial和Listen方法中,

func(h*/asim/go-micro/examples/v3/greeter/srv/proto/hello""github.com/asim/go-micro/v3""github.com/asim/go-micro/v3/util/log""google.golang.org/grpc")typeSaystruct{ }func(s*Say)Hello(ctxcontext.Context,req*hello.Request,rsp*hello.Response)error{ log.Log("ReceivedSay.Hellorequest")rsp.Msg="Hello"+req.Namereturnnil}funcmain(){ gofunc(){ for{ grpc.DialContext(context.TODO(),".0.0.1:")time.Sleep(time.Second)}}()service:=micro.NewService(micro.Name("go.micro.srv.greeter"),)//optionallysetupcommandlineusageservice.Init()//RegisterHandlershello.RegisterSayHandler(service.Server(),new(Say))//Runserveriferr:=service.Run();err!=nil{ log.Fatal(err)}}

       æœ‰å…³æœåŠ¡é—´é€šä¿¡ä½¿ç”¨çš„proto结构体

syntax="proto3";packagego.micro.srv.greeter;serviceSay{ rpcHello(Request)returns(Response){ }}messageRequest{ stringname=1;}messageResponse{ stringmsg=1;}

       å¯åŠ¨æœåŠ¡çš„时候,通过日志输出,可以大致的了解启动过程

--::file=v3@v3.5.2-0.-cbbbc/service.go:level=infoStarting[service]go.micro.srv.greeter--::file=server/rpc_server.go:level=infoTransport[.Connvarerrerror//TODO:supportdialoptionhereratherthanusinginternalconfigifh.opts.Secure||h.opts.TLSConfig!=nil{ config:=h.opts.TLSConfigifconfig==nil{ config=&tls.Config{ InsecureSkipVerify:true,}}config.NextProtos=[]string{ ".Conn,error){ returntls.DialWithDialer(&net.Dialer{ Timeout:dopts.Timeout},"tcp",addr,config)})(addr)}else{ conn,err=newConn(func(addrstring)(net.Conn,error){ returnnet.DialTimeout("tcp",addr,dopts.Timeout)})(addr)}iferr!=nil{ returnnil,err}return&.Connvarerrerror//TODO:supportdialoptionhereratherthanusinginternalconfigifh.opts.Secure||h.opts.TLSConfig!=nil{ config:=h.opts.TLSConfigifconfig==nil{ config=&tls.Config{ InsecureSkipVerify:true,}}config.NextProtos=[]string{ ".Conn,error){ returntls.DialWithDialer(&net.Dialer{ Timeout:dopts.Timeout},"tcp",addr,config)})(addr)}else{ conn,err=newConn(func(addrstring)(net.Conn,error){ returnnet.DialTimeout("tcp",addr,dopts.Timeout)})(addr)}iferr!=nil{ returnnil,err}return&.Connvarerrerror//TODO:supportdialoptionhereratherthanusinginternalconfigifh.opts.Secure||h.opts.TLSConfig!=nil{ config:=h.opts.TLSConfigifconfig==nil{ config=&tls.Config{ InsecureSkipVerify:true,}}config.NextProtos=[]string{ ".Conn,error){ returntls.DialWithDialer(&net.Dialer{ Timeout:dopts.Timeout},"tcp",addr,config)})(addr)}else{ conn,err=newConn(func(addrstring)(net.Conn,error){ returnnet.DialTimeout("tcp",addr,dopts.Timeout)})(addr)}iferr!=nil{ returnnil,err}return&.Connvarerrerror//TODO:supportdialoptionhereratherthanusinginternalconfigifh.opts.Secure||h.opts.TLSConfig!=nil{ config:=h.opts.TLSConfigifconfig==nil{ config=&tls.Config{ InsecureSkipVerify:true,}}config.NextProtos=[]string{ ".Conn,error){ returntls.DialWithDialer(&net.Dialer{ Timeout:dopts.Timeout},"tcp",addr,config)})(addr)}else{ conn,err=newConn(func(addrstring)(net.Conn,error){ returnnet.DialTimeout("tcp",addr,dopts.Timeout)})(addr)}iferr!=nil{ returnnil,err}return&httpTransportClient{ ht:h,ad

推荐资讯
內政部將完成組織改造! 歷任內政部長回娘家

內政部將完成組織改造! 歷任內政部長回娘家

图灵对话源码_图灵语言

图灵对话源码_图灵语言

fusion布局源码_fusionapp布局源码

fusion布局源码_fusionapp布局源码

creo模型源码

creo模型源码

俄羅斯總統普京與朝鮮最高領導人金正恩舉行會談

俄羅斯總統普京與朝鮮最高領導人金正恩舉行會談

autowired源码分析

autowired源码分析

copyright © 2016 powered by 皮皮网   sitemap