Go
Go 中的时间和时区问题
· ☕ 4 分钟
1. 时间与时区 1.1 时间标准 UTC,世界标准时间,是现在的时间标准,以原子时计时。 GMT,格林威治时间,是以前的时间标准,规定太阳每天经过位于英国伦敦郊区的皇家格林威治天文台的时间为中午 12 点。 UTC 时间更加准确,但如果对精度要求不高,可以视两种标准等

Go 私有包的构建和使用
· ☕ 2 分钟
1. 创建一个 Go Modules 项目 创建目录 1 2 mkdir go-test cd go-test 初始化包 1 2 3 4 5 go mod init gitlab.private.com/shaowenchen/go-test go: creating new go.mod: module gitlab.private.com/shaowenchen/go-test go: to add module requirements and sums: go mod tidy 添加业务代码 main.go 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package main import ( "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "hello world.", }) }) r.Run() } 下载依赖到 vendor 1 2 go mod tidy go mod vendor 本地运行 1 2 3 4 5 go run

本地执行没问题, GitHub Actions 却一直报错
· ☕ 2 分钟
1. 一个令人困惑的问题 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 name: Go on: [push, pull_request] jobs: build: name: CI runs-on: ubuntu-latest steps: - name: Set up Go 1.13 uses: actions/setup-go@v1 with: go-version: 1.13 - name: Check out code into the Go module directory uses: actions/checkout@v2 - name: Check pr is properly formatted run: diff -u <(echo -n) <(gofmt -d ./pkg ./cmd ./tools ./test) - name: Test & Build run: make all 上面是项目中 workflow 的一部分, 主要用来检测代码风格、执行单元测试、

实用的算法之布隆过滤
· ☕ 4 分钟
1. 什么是布隆过滤 布隆过滤(Bloom Filter)是布隆在 1970 年提出的一种数据结构。 将元素(x、y、z)通过一系列函数,映射到一个二进制向量(0101 序列),用于快速判断元素 w 是否在一个集合当中。如下图(来自维基百科): 相较于使用单个映射函数

一起来学 Go --(6)Interface
· ☕ 3 分钟
1. 面向接口编程 1.1 特征 面向接口编程,强调的是模块之间通过接口进行交互。首先,调用方指定一组方法签名,然后,由被调用方实现这组方法。 接口编程与其他编程显著不同的一点是,接口编程关注的是方法,而不是属性。在很多的编程场景中,方法是围绕属性进行定义