Go Core - Array + Slice
|Word Count:0|Reading Time:1mins
Author: zhongmingmao
Copyright Notice: All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Related Articles

2022-05-15
Go Core - List + Ring

2022-05-15
Go Core - Entity

2022-12-20
Go - Main + Init
main.main main 包中的 main 函数 - 所有可执行程序的用户层执行逻辑的入口函数 123456package main// 无参数 + 无返回值func main() { // 用户层执行逻辑} 可执行程序的 main 包必须定义 main 函数,否则会编译报错function main is undeclared in the main package main.go1package main 123$ go build main.go# command-line-argumentsruntime.main_main·f: function main is undeclared in the main package 在启动了多个 goroutine 的 Go 应用中,main.main 将在 Go 应用的主 goroutine 中执行 main.main 函数返回意味着整个 Go 程序结束 除了 main 包外,其它包也可以拥有自己的 main 函数 但依据 Go 的可见性规则,非 main 包中的 main 函数仅限于包内使用 123...
2022-02-06
Cloud Native Foundation - Go Sync
线程安全 锁 Go 不仅提供了基于 CSP 的通讯模型,也支持基于共享内存的多线程数据访问 sync 包提供了锁的基本原语 同步工具 用途 sync.Mutex 互斥锁:Lock加锁,Unlock解锁 sync.RWMutex 读写分离锁:不限制并发读,只限制并发写和并发读写 sync.WaitGroup 等待一组 goroutine 返回,类似于 Java 的 CountDownLatch sync.Once 保证某段代码只执行1次,典型场景:单例模式 sync.Cond 让一组 goroutine 在满足特定条件时被唤醒,典型场景:生产者消费者模型 Mutex12345678910111213141516171819202122232425262728293031323334353637func unsafeWrite() { // fatal error: concurrent map writes conflictMap := map[int]int{} for i := 0; i < 100; i++ ...

2022-12-21
Go - Web
API 项目结构1234567891011121314151617$ tree.├── cmd│ └── bookstore│ └── main.go├── go.mod├── internal│ └── store│ └── memstore.go├── server│ ├── middleware│ │ └── middleware.go│ └── server.go└── store ├── factory │ └── factory.go └── store.go 逻辑结构 具体实现store 定义 Domain 和 Action store/store.go12345678910111213141516package storetype Book struct { Id string `json:"id"` Name string `json:"name"` Authors []string `json:"autho...

2022-04-30
Go Engineering - Foundation - Linting
golangci-lint 优点 速度快 基于 gometalinter 开发,平均速度比 gometalinter 快 5 倍 并行检查代码 + 复用 go build 缓存 + 缓存分析结果 可配置 支持 YAML 格式的配置文件 IDE 集成 VS Code + Goland Linter 聚合器 集成了很多 Linter,无需单独安装,并且支持自定义 Linter 最小误报数 调整了所集成的 Linter 的默认设置,大幅减少误报 良好的输出 检查出问题的源码文件、行号和错误行内容 不符合检查规则的原因 报错的 Linter 更迭速度快 不断有新的 Linter 被集成进来 使用者:Google、Facebook、Istio、Red Hat OpenShift 等 golangci-lint 命令 cache123456789$ golangci-lint cache statusDir: /Users/zhongmingmao/Library/Caches/golangci-lintSize: 1.9MiB$ golangci-lint cache clea...
Announcement
Things are always unexpected!






