I remember impulsively buying a tent last fall. Aside from setting it up once to check it out, it’s been sitting untouched ever since. The weather turned cold, and I never found the right opportunity to use it. The following weekends were busy with wedding photoshoots (I even ran a red light and lost six points on my license, so I haven’t driven since 😓), then there was a trip abroad, leave adjustments, the New Year, more leave adjustments, my sister starting school, my mom returning home, and days of continuous rain in between.
...
参考: 使用interface化解一场因操作系统不同导致的编译问题 Bug-resistant build constraints — Draft Design 构建约束 Go 语言的构建约束(Build Constraints)是一
...
判断 interface 是否为nil 1func interceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { 2 start := time.Now() 3 err := invoker(ctx, method, req, reply, cc, opts...) 4 logger.Infof("[gRPC] method=%s req=%v rep=%+v duration=%s error=%v", method, req, reply, time.Since(start), err) 5 if err != nil { 6 return err 7 } 8 9 return nil 10} gRPC 拦截器
...
语法糖 语法糖(Syntactic sugar)的概念是由英国计算机科学家彼得·兰丁提出的,用于表示编程语言中的某种类型的语法,这些语法不会影响
...
1. Background Recently, during a joint debugging session, I encountered a situation where a gRPC Server returned nil for a specific interface. Since the Server was functioning normally and the interface was implemented, there were no errors during the call. However, the program suddenly terminated without any log output. The issue was easily reproducible by simulating the return of nil data. In Debug mode, I could see the panic and the call stack information.
...
空结构体 在 Go 语言中,空结构体(struct{})是一种特殊的数据类型,它不占用任何内存空间。 1package main 2 3import ( 4 "fmt" 5 "unsafe" 6) 7 8func main() { 9 fmt.Println(unsafe.Sizeof(struct{}{})) // 0 10} 使用场景 作
...
Inspired By: Go 中 defer 的 5 个坑 - 第一部分 切忌在循环中使用 defer,除非你清楚自己在做什么,因为它们的执行结果常常会出人意料。在循环中的延迟函数会在函数
...
1$ pnpm add asar -g 2$ asar extract /[sourcePath]/app.asar /[targetPath]/ # Extract asar After extraction, the contents are as follows:
Unnecessary Locales: Remove unused language packs in the locales directory.
1// Set language pack before whenReady 2app.commandLine.appendSwitch('lang', 'en-US'); 3await app.whenReady() Dependencies: Ensure that development dependencies are not listed as production dependencies.
File Locking: If Electron-builder prompts that app.asar is occupied, close VS Code.
ogImage: https://image.coldcoding.top/file/AgACAgQAAyEGAASUgNIDAAOdZ-LLW2SY1yk2VuSGbtbqq3iEFT4AAgPGMRuknBlTlzRoYu-UvNoBAAMCAAN3AAM2BA.jpg
In Go, strings are immutable, meaning once created, their content cannot be modified. Therefore, each time you concatenate strings, a new string object is generated, which can have performance implications.
Common String Concatenation Methods Using the + Operator 1s1 := "Hello, " 2s2 := "world!" 3result := s1 + s2 Performance Analysis: Each use of the + operator creates a new string, allocating new space equal to the sum of the spaces occupied by the strings to be concatenated.
...
Channel 背景 在多核 CPU 机器下,为了充分利用多核计算机的资源,需要进行并发编程,提高对CPU的利用率,并发从大的角度上讲,并发分为传统并发和基于消息传
...