Skip to content

golang-everyday/golang-everyday

Repository files navigation

golang-everyday

jaywcjlove/sb jaywcjlove/sb License Stars Forks Issues Author Author

目录

Golang语法

🚀 Golang开发技巧

  • 使用 go fmt / gofmt 格式化你的代码 e.g.

  • 多个 if 语句尽量折叠成 switch

  • 尽量用 chan struct{} 来传递信号, chan bool 表达的不够清楚

  • 总是把 for-select 换成一个函数

  • 分组定义 const 类型声明和 var 逻辑类型声明

  • 为整型常量值实现 Stringer 接口

  • 用 defer 来检查你的错误

  • 在使用 iota 时一定指定一中类型

    e.g.

    type TxType uint8
    
    const (
    	Normal TxType = iota
    	TorrentFile
    )
  • 从 map 中取值时,尽量判断 key 是否存在,否则当 key 不存在时会得到一个默认值

    e.g.

    value, ok := map["no_key"]
  • 在读取 http body 时,一定不要忘了 close ,否则会造成内存泄露

    e.g.

🖋 编程题

⬆ 返回顶部

💸 经典面试题

  • 使用两个 goroutine 交替打印一个打印数字一个字母 最后结果 12AB34CD56EF78GH910IJ 解答
  • 输入一个 n,打印 n 阶数字螺旋 解答
  • 两个有序数组从小到大排列,把它们快速合并为一个有序数组,从小到大排列。留意时间和复杂度。解答 测试
  • Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2,3,5 解答 测试

⬆ 返回顶部

🗺 外文翻译

Understand Go pointers in less than 800 words or your money back 原文 译文

⬆ 返回顶部

📚 书籍下载

⬆ 返回顶部

💻 开源项目

⬆ 返回顶部

📝 博客链接

⬆ 返回顶部

🔨 开发工具

  • vscode 插件

    插件名称 插件描述
    GitLens 非常方便的查看文件代码的 commit 信息(提交时间,提交人等)。
    Code Runner 针对非常多的语言而快速方便执行的小插件。
    filesize 在 VSCode 底部工具栏,非常方便的显示文件大小。
    Go Go 语言插件。
    Terminal 命令行工具插件。
    Vim Vim 插件
    VSCode Great Icons VSCode 美化不同的文件。re
    WakaTime 统计项目代码的时间。
    BetterComments 代码注释
    Beautify 格式化 js ,json,html 代码。
    Auto Import 自动倒包
    Bookmarks 好用的书签
    Bracket Pair Colorizer 多种颜色括号,结构清晰明了
    Code Runner 一键运行代码
    gomodifytags Go tool to modify struct field tags
    Toggle between terminal and editor focus Terminal 和编辑器之间焦点切换
  • 建议配置CDPATH 环境变量,这样我们在任何地方都能进入 github 下的项目了

  • vscode代码补全

⬆ 返回顶部

💐 贡献者

evolution-ant mxdwater

About

Share your work and study experience in golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages