工作中用Go: 工具篇

简介: 工作中用Go: 工具篇

工具篇 - goland

代码风格统一

action on save

image.png

Optimize import

一般会group成3-4类(上面配置了 goimports, 下面的配置可选)

  • go源码
  • 引入的pkg
  • 项目内pkg
  • _ 引入用来初始化的 pkg

image.png

before commit

image.png

码出高效: Ide feature trainer

goland 有非常多高效的操作, 强烈推荐

image.png

go struct <-> json

image.png

快速查看go源码

在对应package上使用 cmd-b 

Context action(option-enter): 当前上下文支持的快捷操作

非常智能, 生产力工具

image.png

重构(ctrl-T): 代码修改推荐走重构, ide 帮助省一堆的修改

image.png

使用 test 快速验证go代码

image.png

使用 scratch 快速验证go代码

image.png

工具篇 - CI

golangci-lint

go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go run -v . # 文件/目录

一份统一的 golangci-lint 配置, 供参考

# 项目下的 .golangci.yaml 文件
# 省略其他配置, 只保留了线上开启的 lint
linters:
# Disable all linters.
  # Default: false
  disable-all: true
# Enable specific linter
  # https://golangci-lint.run/usage/linters/#enabled-by-default-linters
  enable:
    - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
    - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
    - ineffassign # Detects when assignments to existing variables are not used
    - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
    - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
    - bodyclose # checks whether HTTP response body is closed successfully
    - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
    - makezero # Finds slice declarations with non-zero initial length
    - exportloopref # checks for pointers to enclosing loop variables
    #- exhaustive # check exhaustiveness of enum switch statements
    - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
    - nilerr # Finds the code that returns nil even if it checks that the error is not nil.
    #- contextcheck # check the function whether use a non-inherited context
    - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
    #- gosec # Inspects source code for security problems
    # - deadcode # Finds unused code #TODO
    # - structcheck # Finds unused struct fields
    # - unused # Checks Go code for unused constants, variables, functions and types
    # - varcheck # Finds unused global variables and constants
    # - gosimple # Linter for Go source code that specializes in simplifying a code
    # - gofmt # Linter for Go source code that specializes in simplifying a code
  # Run only fast linters from enabled linters set (first run won't be fast)
  # Default: false
  fast: false


静态检查修复建议

静态检查定义与修复建议: https://staticcheck.io/docs/checks

image.png

image.png

写在最后

得益于:

Go语言本身出色的工具链

IDE的强大支持

研发效能平台助力


使用Go语言统一技术栈, 可以轻松减少大量重复性工作, 高效写出「值得信赖」的代码

目录
相关文章
|
1月前
|
网络协议 Linux Go
分享一个go开发的工具-SNMP Server
分享一个go开发的工具-SNMP Server
35 0
|
2月前
|
测试技术 API 开发者
【Docker项目实战】在Docker环境下部署go-file文件分享工具
【2月更文挑战第15天】在Docker环境下部署go-file文件分享工具
75 1
|
7月前
|
关系型数据库 MySQL Go
Go语言微服务框架 - 8.Gormer迭代-定制专属的ORM代码生成工具
我们对比一下GORM库提供的`gorm.Model`,它在新增、修改时,会自动修改对应的时间,这个可以帮我们减少很多重复性的代码编写。这里,我就针对现有的gormer工具做一个示例性的迭代。
51 0
|
1月前
|
搜索推荐 Linux Go
分享一个go开发的端口转发工具-port-forward
分享一个go开发的端口转发工具-port-forward
28 0
|
1月前
|
Go
推荐一个go写的RTSP转直播工具
推荐一个go写的RTSP转直播工具
12 0
|
2月前
|
大数据 Java Go
Go语言在大数据处理中的核心技术与工具
【2月更文挑战第22天】本文深入探讨了Go语言在大数据处理领域的核心技术与工具。通过分析Go语言的并发编程模型、内存管理、标准库以及第三方工具库等方面,展现了其在大数据处理中的优势和实际应用。同时,本文也讨论了如何使用这些技术与工具构建高效、稳定的大数据处理系统,为开发者提供了有价值的参考。
|
3月前
|
设计模式 测试技术 Go
Go 项目必备:Wire 依赖注入工具的深度解析与实战应用
在现代软件开发中,依赖注入(Dependency Injection,简称 DI)已经成为一种广泛采用的设计模式。它的核心思想是通过外部定义的方式,将组件之间的依赖关系解耦,从而提高代码的可维护性、可扩展性和可测试性。然而,随着项目规模的增长,手动管理复杂的依赖关系变得日益困难。这时,依赖注入代码生成工具就显得尤为重要。在众多工具中,Wire 以其简洁、强大和易用性脱颖而出,成为 Go 语言项目中的宠儿。本文将带你深入了解 Wire 的安装、基本使用、核心概念以及高级用法,并通过一个实际的 web 博客项目示例,展示如何利用 Wire 简化依赖注入的实现。准备好了吗?让我们开始这场代码解耦的奇
|
10月前
|
分布式计算 监控 安全
GO语言安全工具开发方向探索
GO语言安全工具开发方向探索
147 0
|
7月前
|
小程序 编译器 Go
Go team 开源项目 Go Cloud 使用的依赖注入工具 Wire 怎么使用?
Go team 开源项目 Go Cloud 使用的依赖注入工具 Wire 怎么使用?
31 0
|
7月前
|
程序员 测试技术 Go
提升效率!Go语言开发者不可错过的必备工具集合!
提升效率!Go语言开发者不可错过的必备工具集合!
86 0