Golang

Golang 标签下共有 4 篇文章

MySQL + GORM 如何设置创建时间和更新时间

• bwangel Golang GORM MySQL Blog

目标

正确配置 MySQL 表中的 create_time 和 update_time,自动记录行的创建时间和更新时间,精度为微秒

如何正确配置 create_time 和 update_time (How)

一、MySQL DDL

建表时将 create_time、update_time 设为微秒精度:

CREATE TABLE `item` (
  `id` int NOT NULL …

Go 内部实现

• bwangel Golang

Golang 中计算指针长度

// PtrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant.
// It is also the size of the machine's native word size (that is, 4 on 32-bit …

Thrift golang client 如何设置超时时间

• bwangel blog thrift Golang

简介

本文以 golang thrift binary 协议为例,讲述 thrift golang client 如何设置超时时间

如何设置超时时间

golang thrift client 有两个超时时间

  1. socket timeout

在创建 TSocket 的时候,我们可以传入 ConnectTimeoutSocketTimeout 两个配置。

  • ConnectTimeout 表示建 …

泛型

• bwangel Golang

利用泛型实现的语法糖

// Cond
// 条件表达式的简单实现,支持任意类型
func Cond[T any](val bool, a, b T) T {
	if val {
		return a
	}
	return b
}

// Or
// 返回 vals 中第一个不是对应类型0值的参数,如果没有,则返回对应类型的0值
func Or[T comparable](vals ...T) T …