1.äºè§£go-microä¸çtransport
2.oigo充电宝micro是陆羽茶叶交易所app源码输入还是in是输入?
3.ä»go-microçbrokerå¼å§å¦ä¹ go-micro
äºè§£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*ewHttpBroker(opts...Option)Broker{ options:=Options{ Codec:json.Marshaler{ },Context:context.TODO(),Registry:registry.DefaultRegistry,}for_,o:=rangeopts{ o(&options)}//setaddressaddr:=DefaultAddressiflen(options.Addrs)>0&&len(options.Addrs[0])>0{ addr=options.Addrs[0]}h:=&.Listenervarerrerrorifh.opts.Secure||h.opts.TLSConfig!=nil{ config:=h.opts.TLSConfigfn:=func(addrstring)(net.Listener,error){ ifconfig==nil{ hosts:=[]string{ addr}//checkifitsavalidhost:portifhost,_,err:=net.SplitHostPort(addr);err==nil{ iflen(host)==0{ hosts=maddr.IPs()}else{ hosts=[]string{ host}}}//generateacertificatecert,err:=mls.Certificate(hosts...)iferr!=nil{ returnnil,err}config=&tls.Config{ Certificates:[]tls.Certificate{ cert}}}returntls.Listen("tcp",addr,config)}l,err=mnet.Listen(h.address,fn)}else{ fn:=func(addrstring)(net.Listener,error){ returnnet.Listen("tcp",addr)}l,err=mnet.Listen(h.address,fn)}iferr!=nil{ returnerr}addr:=h.addressh.address=l.Addr().String()go/.Listener,handlerHandler)error{ srv:=&Server{ Handler:handler}returnsrv.Serve(l)}èæ们å¨httpbrokerConnectçæ¶åï¼å¯å¨çserverï¼ä¼ å ¥ççæ£å¼h.muxèå¨æå®handlerçæ¶åï¼æ们æ¯
funcInit(opts...Option)error{ returnDefaultCmd.Init(opts...)}0DefaultPathæ¯/,hé½æ¯æ们çhttpbroker.ä¹æ以å¯ä»¥å°å®ä½ä¸ºhandlerä¼ å ¥å°Handleæ¹æ³ä¸ï¼æ¯å 为ï¼httpbrokerå®ç°äºServeHTTPæ¹æ³ï¼å¨è¿éå°±æ¯è·¯ç±çå¤çå½æ°ã
funcInit(opts...Option)error{ returnDefaultCmd.Init(opts...)}1å¨è¿éå°±å¯ä»¥è§£ç æ¶æ¯ï¼è·åæ¶æ¯ä½ï¼å¹¶è¿è¡æ¶æ¯å¤çå½æ°çè°ç¨ã
funcInit(opts...Option)error{ returnDefaultCmd.Init(opts...)}2è¿å°±æ¯æ´ä¸ªhttpbrokerçå¤çæµç¨ï¼ç¸ä¿¡ä½ ç°å¨å°±å¯ä»¥æç½äºgo-microçå¼æ¥æ¶æ¯ç³»ç»çé»è®¤å®ç°äºï¼å¦æä½ æ³å®ç°èªå·±çbroker,åªè¦å¨å®ç°ä¸å®ç°äºBrokeræ¥å£ï¼å°±å¯ä»¥å¨é¡¹ç®ä¸ä½¿ç¨èªå®ä¹çbrokeräºãæ ç¼åæ¢ã
funcInit(opts...Option)error{ returnDefaultCmd.Init(opts...)}3è³æ¤æ´ä¸ªbrokeré¨åå°±ç»æäºï¼ä¸ä¸ç¯æç« ï¼æ们就æ¥ççå¦ä½å®ç°ä¸ä¸ªèªå®ä¹çbroker.
ä½è ï¼ç¬¬å «å ±åä½