LiFengMing LiFengMing
首页
云原生
中间件
工具导航
资源导航
  • 分类
  • 标签
  • 归档
关于作者
GitHub (opens new window)

LiFengMing

IT届李哥
首页
云原生
中间件
工具导航
资源导航
  • 分类
  • 标签
  • 归档
关于作者
GitHub (opens new window)
  • 编程语言

    • Go

      • Golang 编码最佳实践
        • 目录
        • 原文地址
    • Java

  • 问题排查手册

  • 容器编排技术

  • 云原生
  • 编程语言
  • Go
LiFengMing
2021-09-05
目录

Golang 编码最佳实践

# Go 语言实战: 编写可维护 Go 语言代码建议

# 目录

  • 1. 指导原则 (opens new window)
    • 1.1 简单性 (opens new window)
    • 1.2 可读性 (opens new window)
    • 1.3 生产力 (opens new window)
  • 2. 标识符 (opens new window)
    • 2.1 选择标识是为了清晰, 而不是简洁 (opens new window)
    • 2.2 标识符长度 (opens new window)
    • 2.3 不要用变量类型命名变量 (opens new window)
    • 2.4 使用一致的命名风格 (opens new window)
    • 2.5 使用一致的声明样式 (opens new window)
    • 2.6 成为团队的合作者 (opens new window)
  • 3. 注释 (opens new window)
    • 3.1 关于变量和常量的注释应描述其内容而非其目的 (opens new window)
    • 3.2 公共符号始终要注释 (opens new window)
  • 4. 包的设计 (opens new window)
    • 4.1 一个好的包从它的名字开始 (opens new window)
    • 4.2 避免使用类似 base 、common 或 util 的包名称 (opens new window)
    • 4.3 尽早 return 而不是深度嵌套 (opens new window)
    • 4.4 让零值更有用 (opens new window)
    • 4.5 避免包级别状态 (opens new window)
  • 5. 项目结构 (opens new window)
    • 5.1 考虑更少,更大的包 (opens new window)
    • 5.2 保持 main 包内容尽可能的少 (opens new window)
  • 6. API 设计 (opens new window)
    • 6.1 设计难以被误用的 API (opens new window)
    • 6.2 为其默认用例设计 API (opens new window)
    • 6.3 让函数定义它们所需的行为 (opens new window)
  • 7. 错误处理 (opens new window)
    • 7.1 通过消除错误来消除错误处理 (opens new window)
    • 7.2 错误只处理一次 (opens new window)
  • 8. 并发 (opens new window)
    • 8.1 保持自己忙碌或做自己的工作 (opens new window)
    • 8.2 将并发性留给调用者 (opens new window)
    • 8.3 永远不要启动一个停止不了的 goroutine (opens new window)

# 原文地址

  • https://dave.cheney.net/practical-go/presentations/qcon-china.html

  • https://github.com/llitfkitfk/go-best-practice

  • https://go.dev/play/

编辑 (opens new window)
#Golang
上次更新: 2025/01/19, 23:15:59
高性能无锁队列简介

高性能无锁队列简介→

最近更新
01
云原生资源
05-25
02
快速搭建Spring项目
03-27
03
kafka版本迭代说明
03-11
更多文章>
Theme by Vdoing | Copyright © 2018-2025 LiFengMing | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式