会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
离地最远的星
博客园
首页
新随笔
联系
订阅
管理
上一页
1
2
3
4
5
6
7
8
···
22
下一页
2019年12月26日
7.基本方式调用Api(http api)
摘要: 当服务很简单的时候可以用这种方法来做基本调用 package main import ( "fmt" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/registry" "github.com/micro/
阅读全文
posted @ 2019-12-26 14:49 离地最远的星
阅读(622)
评论(0)
推荐(0)
2019年12月25日
5.使用内置命令参数启动、注册多个服务
摘要: 看下面的代码调用了server.Init()之后就支持命令行读取配置了 package main import ( "github.com/gin-gonic/gin" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/w
阅读全文
posted @ 2019-12-25 16:23 离地最远的星
阅读(568)
评论(0)
推荐(0)
4.(服务发现1)获取consul服务列表,selector随机选择
摘要: 我们会使用主站api调用商品api 使用go-micro访问consul获取服务信息 package main import ( "fmt" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/registry
阅读全文
posted @ 2019-12-25 16:09 离地最远的星
阅读(2661)
评论(0)
推荐(0)
3.(服务注册)快速把服务注册到Consul中
摘要: 安装go-plugins go get -v github.com/micro/go-plugins,原来go-micro consul的支持已经迁移到了go-plugins里面 package main import ( "github.com/gin-gonic/gin" "github.com
阅读全文
posted @ 2019-12-25 15:52 离地最远的星
阅读(1526)
评论(0)
推荐(0)
2.引进外部框架gin生成web API
摘要: package main import ( "github.com/gin-gonic/gin" "github.com/micro/go-micro/web" ) func main() { ginRouter := gin.Default() ginRouter.Handle("GET", "/
阅读全文
posted @ 2019-12-25 15:08 离地最远的星
阅读(634)
评论(0)
推荐(0)
1.安装框架,创建第一个web api
摘要: 先下载Go Micro框架 go get -v github.com/micro/go-micro 启动一个简单的Server package main import ( "github.com/micro/go-micro/web" "net/http" ) func main() { /*第一种
阅读全文
posted @ 2019-12-25 14:55 离地最远的星
阅读(416)
评论(0)
推荐(0)
2019年12月24日
30.Jwt集成(4):请求tokenAPI、中间件的方式集成token认证、用户信息传递
摘要: 还是三步骤创建EndPoint,创建Transport,调用请求 第一步创建transport package Services import ( "context" "encoding/json" "errors" "github.com/tidwall/gjson" "io/ioutil" "net/http" ) func Deco...
阅读全文
posted @ 2019-12-24 15:24 离地最远的星
阅读(976)
评论(1)
推荐(0)
29.Jwt集成(3):token设置过期时间、异常判断
摘要: token设置过期时间 package main import ( "fmt" "github.com/dgrijalva/jwt-go" "io/ioutil" "log" "time" ) type UserClaim struct { Uname string `json:"username"` jwt....
阅读全文
posted @ 2019-12-24 13:36 离地最远的星
阅读(6567)
评论(0)
推荐(0)
28.Jwt集成(2):生成公私钥、非对称加密生成和解析token
摘要: 生成公钥和私钥代码 package utils import ( "crypto/rand" "crypto/rsa" "crypto/x509" "encoding/pem" "fmt" "io/ioutil" ) func GenRSAPubAndPri(bits int,filepath string ) error { //...
阅读全文
posted @ 2019-12-24 12:09 离地最远的星
阅读(3937)
评论(0)
推荐(0)
27.Jwt集成(1):使用第三方库,token的基本生成和验
摘要: 使用第三方库jwt-go进行加密和验证 package main import ( "fmt" "github.com/dgrijalva/jwt-go" ) type UserClaim struct { Uname string `json:"username"` jwt.StandardClaims //嵌套了...
阅读全文
posted @ 2019-12-24 11:28 离地最远的星
阅读(722)
评论(0)
推荐(0)
上一页
1
2
3
4
5
6
7
8
···
22
下一页
公告