Golang

Golang 标签下共有 3 篇文章

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 …