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

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

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

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

  • istio的环境准备

    • install
    • initial-project
    • upgrade-project
      • review
      • prod
    • lego-create-server-certificate
  • istioVirtualService

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

upgrade-project

# 升级项目

之前的项目中只有 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
编辑 (opens new window)
上次更新: 2023/02/05, 02:48:13
initial-project
lego-create-server-certificate

← initial-project lego-create-server-certificate→

最近更新
01
Coding 102 Writing code other people can read
02-26
02
Kotlin Flow响应式编程,StateFlow和SharedFlow
02-05
03
Kotlin Flow响应式编程,操作符函数进阶
02-05
更多文章>
Theme by Vdoing | Copyright © 2022-2023 IT七剑客 | MIT License
  • 闽ICP备2021006579号-4
  • 闽公网安备 35012102500470号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式