编程笔记

lifelong learning & practice makes perfect

中文翻译:<微服务与事件驱动架构>

第一章

要点

  1. 康威定律
  2. 微服务
  3. 事件驱动架构

Concept

  1. 康威定律: 设计系统的组织……受到约束,产生的设计是这些组织的沟通结构的副本

    Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations. - Melvin Conway(1967)

    references:

    • 阿里肥侠文章:”微服务架构的理论基础 - 康威定律” https://developer.aliyun.com/article/8611

    • 康威定律详细介绍

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      第一定律
      Communication dictates design
      组织沟通方式会通过系统设计表达出来
      第二定律
      There is never enough time to do something right, but there is always enough time to do it over
      时间再多一件事情也不可能做的完美,但总有时间做完一件事情
      第三定律
      There is a homomorphism from the linear graph of a system to the linear graph of its design organization
      线型系统和线型组织架构间有潜在的异质同态特性
      第四定律
      The structures of large systems tend to disintegrate during development, qualitatively more so than with small ystems
      大的系统组织总是比小系统更倾向于分解
  2. 微服务

    The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services , which may be written in different programming languages and use different data storage technologies.
    – James Lewis and Martin Fowler

    Martin Fowler是国际著名的OO专家,敏捷开发方法的创始人之一,现为ThoughtWorks公司的首席科学家.福勒(Martin Fowler),在面向对象分析设计、UML、模式、软件开发方法学、XP、重构等方面,都是世界顶级的专家,现为Thought Works公司的首席科学家。Thought Works是一家从事企业应用开发和集成的公司。早在20世纪80年代,Fowler就是使用对象技术构建多层企业应用的倡导者,他著有几本经典书籍:《企业应用架构模式》、《UML精粹》和《重构》等。—— 百度百科

  3. 微服务问题
    微服务架构需要考虑的问题,包括

  • API Gateway
  • 服务间调用
  • 服务发现
  • 服务容错
  • 服务部署
  • 数据调用

What

How

Display

  1. go tool pprof -http=:9999 cpu.pprof

Benchmark & pprof

  1. gen

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21

    func fib(n int) int {
    if n == 0 || n == 1 {
    return n
    }
    return fib(n-2) + fib(n-1)
    }

    func BenchmarkFib(b *testing.B) {
    for n := 0; n < b.N; n++ {
    fib(30) // run fib(30) b.N times
    }
    }
    只需要在 go test 添加 -cpuprofile 参数即可生成 BenchmarkFib 对应的 CPU profile 文件:
    $ go test -bench="Fib$" -cpuprofile=cpu.pprof .
    goos: linux
    goarch: amd64
    pkg: example
    BenchmarkFib-8 196 6071636 ns/op
    PASS
    ok example 2.046s

References

  1. 极客兔兔https://geektutu.com/post/hpg-pprof.html

正则匹配/regexp 规则

元字符

  1. ^ 匹配输入字符串的开始位置
  2. $ 匹配输入字符串的结束位置

example

vin码

1
2
3
4
5
6
7
8
// 完整匹配: ^[A-HJ-NPR-Z\d]{8}[X\d][A-HJ-NPR-Z\d]{3}\d{5}$
// vin码可能不在字符串最前面,有可能在中间
// 去掉^(匹配字符串开头,在多行模式中匹配每一行的开头)和$
var vinPattern = regexp.MustCompile(`[A-HJ-NPR-Z\d]{8}[X\d][A-HJ-NPR-Z\d]{3}\d{5}`)
in := "车架号:LFV2A21K2J4076260"
vin:= vinPattern.FindAllString(in, -1)
fmt.Println(vin)
// => LFV2A21K2J4076260

references

条件格式

  1. 求交/差集
    使用条件格式=>突出显示单元规则=>重复值,可以将两列数据相同的值高亮显示:
    高亮部分为交集,其余为差集

    阅读全文 »

redis

连接

  1. 通过select选库

    1
    2
    3
    4
    5
    r := redis.NewRedis(redisAddr, "node", password)
    err = r.Pipelined(func(p redis.Pipeliner) error {
    p.Select(1)
    return nil
    })

问题

  1. https://programnotes.cn/golang-1000-question/
  2. code,repo in github <git@github.com:yiGmMk/golang-1000-question.git>
  3. 代码允许环境:
    • go version go1.15.3 linux/amd64

const

  1. [001]iota,有常量如下,second数值是?

    1
    2
    3
    4
    5
    6
    const (
    first = 1
    second =iota
    third
    fourth
    )

string

  1. [002]strings.ReplaceAll,代码如下,replace的值是?

    1
    2
    3
    4
    origin := "   特斯拉Model X    "
    replace := strings.ReplaceAll(origin, " ", "")

    fmt.Printf("origin:%s\nreplace:%s\n", origin, replace)

    答: “ 特斯拉Model X “,即origin

解答

  1. https://programnotes.cn/golang-1000-question-answer/
  2. code,repo in github <git@github.com:yiGmMk/golang-1000-question.git>
  3. 代码允许环境:
    • go version go1.15.3 linux/amd64

const

  1. [001]iota,有常量如下,second数值是?

    1
    2
    3
    4
    5
    6
    const (
    first = 1
    second =iota
    third
    fourth
    )

string

  1. [002]strings.ReplaceAll,代码如下,replace的值是?

    1
    2
    3
    4
    origin := "   特斯拉Model X    "
    replace := strings.ReplaceAll(origin, " ", "")

    fmt.Printf("origin:%s\nreplace:%s\n", origin, replace)

广告屏蔽类

  1. AdGuard 广告拦截器

  2. uBlock Origin
    屏蔽效果好,支持使用选择器手动添加,屏蔽页面上指定的各种广告

代码查看

  1. Octotree - GitHub code tree

影音娱乐

  1. Listen 1
    支持通过url导入各平台的歌单

文档

  1. 超级复制

  2. Redirector 自动跳转,看一些有镜像站的文档,网页很方便

    • edge插件地址https://microsoftedge.microsoft.com/addons/detail/redirector/jdhdjbcalnfbmfdpfggcogaegfcjdcfp?hl=zh-CN

    • golang官方文档自动跳转设置(跳转到golang.google.cn)

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      {
      "createdBy": "Redirector v3.5.4",
      "createdAt": "2021-12-15T10:57:39.405Z",
      "redirects": [
      {
      "description": "重定向golang官方文档",
      "exampleUrl": "https://golang.org/",
      "exampleResult": "https://golang.google.cn/",
      "error": null,
      "includePattern": "*golang.org*",
      "excludePattern": "",
      "patternDesc": "",
      "redirectUrl": "$1golang.google.cn$2",
      "patternType": "W",
      "processMatches": "noProcessing",
      "disabled": false,
      "grouped": false,
      "appliesTo": [
      "main_frame"
      ]
      }
      ]
      }
  3. 彩云小译 翻译网页支持双语阅读

    • 收费
    • 对比阅读

下载

  1. IDM Integration Module
  • 多线程,不限速,下载超快
  • 收费

代码

  1. Go Search Extension
    快速搜索go package。

golang.org

  1. effective go: https://golang.google.cn/doc/effective_go.html

面试

  1. go面试题:https://github.com/lifei6671/interview-go
  2. go https://github.com/shomali11/go-interview

其他

  1. 国光: https://www.sqlsec.com/
  2. Go Questions: https://golang.design/go-questions/

golang blog

  1. 曹春晖: https://xargin.com/
  2. 兔兔(7天从零实现系列): https://geektutu.com/post/gee.html
  3. go by example:https://golangbyexample.com/

golang book

golang 社区

  1. GOCN: https://gocn.vip/