IT七剑客 IT七剑客
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
首页
wresource
郭霖
孤寒者
IT邦德
沉默王二
老麦
stackoverflow
GitHub (opens new window)
  • 从零开始写 k8s 发布工具(一)

  • 从零开始写 k8s 发布工具(二)

  • 从零开始写 k8s 发布工具(三)

  • 从零开始写 k8s 发布工具(四)

  • istio的环境准备

    • 安装 docker-k3s-istio 开发环境
    • istio初始化第一个项目
    • istio升级项目
      • review
      • prod
    • 使用 lego 创建 https 证书
  • istioVirtualService

  • 老麦 Go
  • istio的环境准备
老麦
2023-02-01
目录

istio升级项目

# 升级项目

之前的项目中只有 prod 服务,具有版本的区分。 现在对项目进行一些升级, 模拟一个多服务的项目。

  1. 两个服务, review / prod
  2. 服务之前还有调用关系。 prod -> review

# review

这次新加入了 review 评论服务。

{
  "1": {
    "id": "1",
    "name": "zhangsan",
    "commment": "istio 功能很强大, 就是配置太麻烦"
  },
  "2": {
    "id": "1",
    "name": "wangwu",
    "commment": "《istio in action》 真是一本了不起的书"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

# prod

升级 prod 服务, 除了之前返回本身的数据信息之外,还需要返回关联的评论信息。

type Product struct {
	Name    string
	Price   int
	Reviews interface{}  // 评论信息
}
1
2
3
4
5

这部分评论信息的来源就是上面新添加的评论服务。

func getReivews() (map[string]model.Review, error) {

	reviews := make(map[string]model.Review)

	resp, err := http.Get("http://svc-review/review/all")
	if err != nil {
		return nil, fmt.Errorf("reqeust svc-review failed: %v", err)
	}
	defer resp.Body.Close()

	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("read body failed: %v", err)
	}

	err = json.Unmarshal(data, &reviews)
	if err != nil {
		return nil, fmt.Errorf("json unmarshal data failed: %v", err)
	}

	return reviews, nil
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

完整结果如下

{
  "data": {
    "Name": "istio in action",
    "Price": 300,
    "Reviews": {
      "1": {
        "id": "1",
        "name": "zhangsan",
        "commment": "istio 功能很强大, 就是配置太麻烦"
      },
      "2": {
        "id": "1",
        "name": "wangwu",
        "commment": "《istio in action》 真是一本了不起的书"
      }
    }
  },
  "version": "v1.1.0"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
上次更新: 2023/04/05, 05:23:58
istio初始化第一个项目
使用 lego 创建 https 证书

← istio初始化第一个项目 使用 lego 创建 https 证书→

最近更新
01
How the creator of Angular is dehydrating the web (Ep 574)
06-07
02
For those who just don’t Git it (Ep 573)
06-07
03
Modern work requires attention. Constant alerts steal it
06-07
更多文章>
Theme by Vdoing | Copyright © 2022-2024 IT七剑客 | MIT License
  • 闽ICP备2021006579号-4
  • 闽公网安备 35012102500470号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式