自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(18)
  • 收藏
  • 关注

翻译 go实现迷宫算法

maze_test.gopackage algorithm import ( "fmt" "os" "testing") type point struct { i, j int} var dirs = [4]point{ {-1, 0}, {0, -1}, {1, 0}, {0, 1},} func (p point) add(r point) point { return point{ p.i + r.i, p.j + r.j, }} /..

2021-10-22 01:35:48 169

原创 [go-micro实战]15 Hytrix服务降级

修改代码package Serverimport ( "context" "gitee.com/Hind3ight/easy-go-micro/go-micro/Services" "github.com/afex/hystrix-go/hystrix" "github.com/gin-gonic/gin" "strconv")// 服务降级调用的函数func defaultProds() (*Services.ProdListResponse, error) { models

2021-10-17 21:40:27 145 1

原创 [go-micro实战]14 Hystrix捕获超时

修改ProdService.go(实际业务),延迟生成数据func (s *ProdService) GetProdList(c context.Context, in *Services.ProdRequest, res *Services.ProdListResponse) error { time.Sleep(time.Second * 3) // hystrix使用 模拟延迟 models := make([]*Services.ProdModel, 0) var i int32 f

2021-10-17 21:30:37 184

原创 [go-micro实战]14 gin.wrap的使用

日志加入(测试用)package mainimport ( "context" "flag" "fmt" "gitee.com/Hind3ight/easy-go-micro/go-micro/Server" "gitee.com/Hind3ight/easy-go-micro/go-micro/Services" "github.com/gin-gonic/gin" "github.com/micro/go-micro" "github.com/micro/go-micro/cl

2021-10-17 20:42:42 658

原创 [go-micro实战]13 一点点封装

将prod_main.go的gin相关处理函数分离出来,并引入中间件,使用context传入prod_main.gopackage mainimport ( "flag" "fmt" "gitee.com/Hind3ight/easy-go-micro/go-micro/Server" "gitee.com/Hind3ight/easy-go-micro/go-micro/Services" "github.com/gin-gonic/gin" "github.com/micro/

2021-10-17 20:30:23 89

原创 [go-micro实战]12 在gin中调用构建的rpc服务

目录结构prod_main.gopackage mainimport ( "context" "flag" "fmt" "gitee.com/Hind3ight/easy-go-micro/go-micro/Services" "github.com/gin-gonic/gin" "github.com/micro/go-micro" "github.com/micro/go-micro/registry" "github.com/micro/go-micro/web".

2021-10-17 20:12:04 1040

原创 [go-micro实战]11 使用grpc构建简易的商品服务 注册到consul

新建项目 目录结构为1. 编写Models.proto(模型)和ProdServices.proto(定义传输接受的数据)Models.protosyntax = "proto3";package Services;option go_package= "../Services";// 商品模型message ProdModel { // @inject_tag: json:"pid" int32 ProdID = 1; // @inject_tag: json:".

2021-10-17 18:09:28 223

原创 [go-micro实战]10 处理模型中json tag不一致

go get github.com/favadi/protoc-go-inject-tag下载第三方工具包,go build并将文件放入bin目录下添加注释//option go_package = "gitee.com/Hind3ight/easy-go-micro/go-micro/models";message ProdModel { // @gotags: json:"ip" int32 ProdID = 1; // @gotags: json:"pName" s.

2021-10-14 23:24:09 390

原创 [go-micro实战]9 引入protobuf、生成参数和模型

models/protos/prod.protosyntax = "proto3";package models;option go_package = "工作目录下的prod.proto所在文件夹";message ProdModel { int32 ProdID = 1; int32 ProdName = 2;}message ProdRequest { int32 size = 1;}message ProdListResponse { repeated Pr

2021-10-14 21:03:42 368

原创 [go-micro实战]9 带入参调用http api

helper/prodHelper.gopackage helpertype ProdsRequest struct { Size int `form:"size"`}prod_main.gopackage mainimport ( "flag" "fmt" "gitee.com/Hind3ight/easy-go-micro/go-micro/helper" "gitee.com/Hind3ight/easy-go-micro/go-micro/model" "gi

2021-10-14 20:14:16 276

原创 [go-micro实战]8 插件方式调用http api

Go-Micro客户端请求报500错误的解决方法Go-Micro客户端请求报500错误的解决方法_Korbin的博客-CSDN博客prod_main.gopackage mainimport ( "flag" "fmt" "gitee.com/Hind3ight/easy-go-micro/go-micro/model" "github.com/gin-gonic/gin" "github.com/micro/go-micro/registry" "github.com/mi.

2021-10-14 19:51:29 181

原创 [go-micro实战]7 基本方式调用http api

consul_test.gopackage mainimport ( "fmt" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/registry" "github.com/micro/go-plugins/registry/consul" "io/ioutil" "log" "net/http" "testing" "time")func callAPI(addr string,

2021-10-14 07:15:32 149

原创 [go-micro实战]6 consul服务发现

consul_test.go 实现轮询package mainimport ( "fmt" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/registry" "github.com/micro/go-plugins/registry/consul" "log" "testing" "time")func TestConsul(t *testing.T) { consulReg :=

2021-10-14 07:04:31 87

原创 [go-micro实战]5 micro自带命令行(有问题)

<!doctype html><html dir="ltr" lang="zh" dark> <head> <meta charset="utf-8"> <title>新标签页</title> <style> html { background-attachment: fixed; background-color: rgba(28,31..

2021-10-14 05:57:29 253

原创 [go-micro实战]4 consul服务发现

consul_test.gopackage mainimport ( "fmt" "github.com/micro/go-micro/client/selector" "github.com/micro/go-micro/registry" "github.com/micro/go-plugins/registry/consul" "log" "testing")func TestConsul(t *testing.T) { consulReg := consul.NewRe

2021-10-14 02:30:37 210

原创 [go-micro实战]3 主站商品API运行

product.gopackage modelimport "strconv"type ProductInfo struct { ProdID int ProdName string}func NewProd(id int, pName string) *ProductInfo { return &ProductInfo{ ProdID: id, ProdName: pName, }}// 生成假的商品数据func GenFakerProdList

2021-10-14 02:15:27 89

原创 [go-micro实战]2 Consul 服务注册

func CreateCmsNews(c *gin.Context) { var CN model.CmsNews _ = c.ShouldBindJSON(&CN) xUserId := c.Request.Header["X-User-Id"] CN.UserId, _ = strconv.Atoi(xUserId[0]) if err := service.CreateCmsNews(CN); err != nil { global.GVA_LOG.Error("创建失败!",.

2021-10-14 01:47:09 170

原创 [go-micro实战]1 创建第一个API

func CreateCmsNews(c *gin.Context) { var CN model.CmsNews _ = c.ShouldBindJSON(&CN) xUserId := c.Request.Header["X-User-Id"] CN.UserId, _ = strconv.Atoi(xUserId[0]) if err := service.CreateCmsNews(CN); err != nil { global.GVA_LOG.Error("创建失败!",.

2021-10-13 22:30:51 268

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除