geektutu / blog

极客兔兔的博客,Coding Coding 创建有趣的开源项目。
https://geektutu.com
Apache License 2.0
166 stars 21 forks source link

Go RPC & TLS 鉴权简明教程 | 快速入门 | 极客兔兔 #57

Open geektutu opened 4 years ago

geektutu commented 4 years ago

https://geektutu.com/post/quick-go-rpc.html

本文介绍了 Go 语言(Golang)中远程过程调用(Remote Procedure Call, RPC)的使用方式,使用 Golang 标准库 net/rpc,同时介绍了异步调用,以及如何使用 TLS/SSL/HTTPS 实现服务器端和客户端的单向鉴权、双向鉴权。

bxclib2 commented 3 years ago

您好博主感谢您的教程。对初学者帮助很大。 可不可以麻烦解释下这个循环?谢谢
for { conn, _ := listener.Accept() defer conn.Close() go rpc.ServeConn(conn) }

geektutu commented 3 years ago

listener.Accept() 阻塞等待客户端与服务端建立连接,建立连接后交给 rpc.ServeConn 异步处理。因为可能有多个客户端建立连接,所以需要无限循环,每建立一个链接,就异步处理,然后继续等待下一个连接建立。

826541814 commented 3 years ago

感谢博主的教程,我在使用tls进行通信时,遇到了证书的问题,可以请教一下在创建证书时,server和client证书的host应该怎么填吗? 报错为:can not create tls.Dialx509: certificate is not valid for any names, but wanted to match localhostcan not create tls.Dialx509: certificate relies on legacy Common Name field, use SANs or temporarily enable Common Name matching with GODEBUG=x509ignoreCN=0

826541814 commented 3 years ago

关于证书的问题,我找到了另一片教程,有同样问题的童鞋可以参考。粗略地说是因为新版本的go禁用了x509,所以要换另一种方式配置。 GO 1.15 以上版本解决GRPC X509 Common Name field, use SANs or temporarily enable Common Name matching