Golang Errors

Using Error Wrapping An error often “bubbles up” a call chain of multiple functions. In other words, a function receives an error and passes it back to its caller through a return value. The caller might do the same, and so on, until a function up the call chain handles or logs the error. An error can be “wrapped” around another error using fmt.Errorf() and the special formatting verb %w. ...

February 4, 2025 · 4 min · KKKZOZ

Golang Struct and Interfaces

这里简单总结一下三种组合方式: interface 中嵌套 interface struct 中嵌套 struct struct 中嵌套 interface interface 中嵌套 interface 这种组合方式体现了接口隔离原则(ISP)和接口组合原则, 通过接口嵌套,我们可以构建更大的接口 // 基础读接口 type Reader interface { Read(p []byte) (n int, err error) } // 基础写接口 type Writer interface { Write(p []byte) (n int, err error) } // 组合接口 type ReadWriter interface { Reader // 嵌套 Reader 接口 Writer // 嵌套 Writer 接口 } struct 中嵌套 struct 这种组合方式体现了组合优于继承12的原则,是 Go 中实现代码复用的重要方式 // 地址信息 type Address struct { Street string City string Country string } // 用户信息 type User struct { Name string Age int Address // 嵌套 Address struct } // 使用示例 func main() { user := User{ Name: "张三", Age: 25, Address: Address{ Street: "中关村大街", City: "北京", Country: "中国", }, } // 可以直接访问嵌套字段 fmt.Println(user.Street) // 输出: 中关村大街 } struct 中嵌套 interface 这种组合方式体现了依赖倒置原则(DIP),常用于策略模式的实现 ...

January 28, 2025 · 2 min · KKKZOZ

Chrome Plugin Recommendation

Summary 这篇文章记录几个我非常喜欢的 Chrome 插件 PrintFriendly1 Make web pages printer-friendly and convert them to PDFs. Easily remove ads and navigation, and customize what you print or PDF. ...

January 23, 2025 · 1 min · KKKZOZ

Aerospace

Concepts Each workspace contains its own single root node Each non-leaf node is called a “Container” Each container can contain arbitrary number of children nodes Windows are the only possible leaf nodes. Windows contain zero children nodes Every container has two properties: Layout (Possible values: tiles, accordion) Orientation (Possible values: horizontal, vertical) Some examples: In total, AeroSpace provides 4 possible layouts: h_tiles horizontal tiles (in i3, it’s called “horizontal split”) v_tiles vertical tiles (in i3, it’s called “vertical split”) h_accordion horizontal accordion (analog of i3’s “tabbed layout”) v_accordion vertical accordion (analog of i3’s “stacked layout”) Accordion is a layout where windows are placed on top of each other. ...

December 24, 2024 · 2 min · KKKZOZ

From Clicks to Commands: A Windows User's Survival Guide

本篇 Blog 正在更新中 这篇 Blog 主要记录了一些在 Unix 终端环境下对应的 Windows 下的常见的鼠标操作 主要面向 Linux 和 MacOS 的新手们,所以有些信息会被简化或者忽略 可为什么要用终端/命令行呢? 就像“为什么使用 Vim”一样,原因有很多,对于我来说,它足够简单,足够快,支持许多的自定义,是 Programmable 的 在程序员的世界里,你真的能够做到(抖个机灵哈哈哈): 如果你觉得终端难用,就去定制你的 Shell 配置;如果你觉得命令不够方便,就写个函数或别名把它封装得更好;如果你觉得工具功能太弱,就用脚本扩展它的能力;如果你觉得操作繁琐,就从自动化开始,一点点改善工作流程,而不是一昧地抱怨,排斥,逃向 GUI。 Left Click 首先需要学习的肯定是鼠标左键的双击 — 打开某个文件夹,以及打开某个文件夹后的结果:查看这个文件夹的内容 对应到终端中: cd 跳转到某个文件夹 ls 展示文件夹的内容 > ls Applications Playground DataGripProjects Projects Desktop Public Documents Scripts Downloads Temp Dropbox Virtual Machines.localized Library Zotero Movies dotfiles-main Music go Pictures > cd Projects 在使用 cd 命令时,不用把文件夹的名字输入完整 比如想要 cd Projects,只需要输入 cd Pro,然后按下键盘上的 Tab 键,就能触发自动补全 ...

November 26, 2024 · 3 min · KKKZOZ