分类 go 中的文章

Go1.24 - 按行读取文件

Go1.24 - 按行读取文件 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2025/05/16/read-file-line-by-line-go124/ 在 go 1.24 中新增加了两个标准方法 - strings.Lines() 和 bytes.Lines()。 都使用 分隔符 \n 拆分对象。 都返回一个 Seq 的迭代对象。 Seq 迭代对象 Seq 迭代对象可以接受一个 回调函数 或 使用 for 循环 进行遍历。 使用 回调函数 时, 可以通过 return false 提前终止遍历。 1 2 3 4……

阅读全文

Go 1.24 - os.Root 锁定工作目录

Go 1.24 - os.Root 锁定工作目录 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2025/05/16/os-root-in-go124/ os.Root 可以锁定工作目录。 使用户无法打开目录外的文件,例如 ../../../etc/passwd 。 可以算一种 安全保护 最重要的是 强制约束用户, 限制用户行为, 检查计划外的使用逻辑 。 免得和煞笔瞎掰扯, 浪费时间。 使用 root, _ := os.OpenRoot(basedir) 锁定工作目录 以后的所有操作都要基于 root.Xzzzz() 展开 root.OpenFile(path) 在……

阅读全文

Gorm: 声明模型(1)

Gorm: 声明模型(1) 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2025/03/17/gorm-model-declaration/ 1. 数组字段 https://gorm.io/zh_CN/docs/models.html 如果表中有 slice 字段, 则需要使用 type 指定类型。 1 2 3 4 5 6 package dao type DemoTable struct { Users []string `gorm:"type:text[]"` // This is a slice of strings IDs []int `gorm:"type:int[]"` // This is a slice of integers } 2. 索引 https://gorm.io/zh_CN/docs/indexes.html 2.1 唯一作引 唯一索引有两种形式, uniqueIndex index:[name],unique : 自定义索引名字 1 2 3 4 5 type User struct { Name string `gorm:"index"` // 索引 Name4 string `gorm:"uniqueIndex"` // 唯一索引……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它