go 常见问题

简介:   以下是我在go项目中碰到问题 1. 如何只测试指定的test文件,而不是所有的单元测试都跑一遍. go tool vet -test -v src\github.com\astaxie\beego\controller_test.

  以下是我在go项目中碰到问题

1. 如何只测试指定的test文件,而不是所有的单元测试都跑一遍.

go tool vet -test -v src\github.com\astaxie\beego\controller_test.go 

go tool vet 是个很不错的工具,里面有很强大的功能

go tool vet 参数

Usage of vet:
        vet [flags] directory...
        vet [flags] files... # Must be a single package
For more information run
        godoc golang.org/x/tools/cmd/vet

Flags:
  -all
        check everything; disabled if any explicit check is requested (default true)
  -asmdecl
        check assembly against Go declarations (default unset)
  -assign
        check for useless assignments (default unset)
  -atomic
        check for common mistaken usages of the sync/atomic package (default unset)
  -bool
        check for mistakes involving boolean operators (default unset)
  -buildtags
        check that +build tags are valid (default unset)
  -composites
        check that composite literals used field-keyed elements (default unset)
  -compositewhitelist
        use composite white list; for testing only (default true)
  -copylocks
        check that locks are not passed by value (default unset)
  -methods
        check that canonically named methods are canonically defined (default unset)
  -nilfunc
        check for comparisons between functions and nil (default unset)
  -printf
        check printf-like invocations (default unset)
  -printfuncs string
        comma-separated list of print function names to check
  -rangeloops
        check that range loop variables are used correctly (default unset)
  -shadow
        check for shadowed variables (experimental; must be set explicitly) (default unset)
  -shadowstrict
        whether to be strict about shadowing; can be noisy
  -shift
        check for useless shifts (default unset)
  -structtags
        check that struct field tags have canonical format and apply to exported fields as needed (default unset)
  -tags string
        comma-separated list of build tags to apply when parsing
  -test
        for testing only: sets -all and -shadow
  -unreachable
        check for unreachable code (default unset)
  -unsafeptr
        check for misuse of unsafe.Pointer (default unset)
  -unusedfuncs string
        comma-separated list of functions whose results must be used (default "errors.New,fmt.Errorf,fmt.Sprintf,fmt.Sprint,sort.Reverse")
  -unusedresult
        check for unused result of calls to functions in -unusedfuncs list and methods in -unusedstringmethods list (default unset)
  -unusedstringmethods string
        comma-separated list of names of methods of type func() string whose results must be used (default "Error,String")
  -v    verbose

  

 

 

目录
相关文章
|
编译器 Go
揭秘 Go 语言中空结构体的强大用法
Go 语言中的空结构体 `struct{}` 不包含任何字段,不占用内存空间。它在实际编程中有多种典型用法:1) 结合 map 实现集合(set)类型;2) 与 channel 搭配用于信号通知;3) 申请超大容量的 Slice 和 Array 以节省内存;4) 作为接口实现时明确表示不关注值。此外,需要注意的是,空结构体作为字段时可能会因内存对齐原因占用额外空间。建议将空结构体放在外层结构体的第一个字段以优化内存使用。
|
8月前
|
存储 安全 Java
【Golang】(4)Go里面的指针如何?函数与方法怎么不一样?带你了解Go不同于其他高级语言的语法
结构体可以存储一组不同类型的数据,是一种符合类型。Go抛弃了类与继承,同时也抛弃了构造方法,刻意弱化了面向对象的功能,Go并非是一个传统OOP的语言,但是Go依旧有着OOP的影子,通过结构体和方法也可以模拟出一个类。
399 2
|
运维 监控 算法
监控局域网其他电脑:Go 语言迪杰斯特拉算法的高效应用
在信息化时代,监控局域网成为网络管理与安全防护的关键需求。本文探讨了迪杰斯特拉(Dijkstra)算法在监控局域网中的应用,通过计算最短路径优化数据传输和故障检测。文中提供了使用Go语言实现的代码例程,展示了如何高效地进行网络监控,确保局域网的稳定运行和数据安全。迪杰斯特拉算法能减少传输延迟和带宽消耗,及时发现并处理网络故障,适用于复杂网络环境下的管理和维护。
|
10月前
|
Cloud Native 安全 Java
Go:为云原生而生的高效语言
Go:为云原生而生的高效语言
614 1
|
12月前
|
开发框架 JSON 中间件
Go语言Web开发框架实践:路由、中间件、参数校验
Gin框架以其极简风格、强大路由管理、灵活中间件机制及参数绑定校验系统著称。本文详解其核心功能:1) 路由管理,支持分组与路径参数;2) 中间件机制,实现全局与局部控制;3) 参数绑定,涵盖多种来源;4) 结构体绑定与字段校验,确保数据合法性;5) 自定义校验器扩展功能;6) 统一错误处理提升用户体验。Gin以清晰模块化、流程可控及自动化校验等优势,成为开发者的优选工具。
|
10月前
|
Cloud Native Go API
Go:为云原生而生的高效语言
Go:为云原生而生的高效语言
624 0
|
10月前
|
Cloud Native Java Go
Go:为云原生而生的高效语言
Go:为云原生而生的高效语言
443 0
|
10月前
|
Cloud Native Java 中间件
Go:为云原生而生的高效语言
Go:为云原生而生的高效语言
487 0
|
10月前
|
Cloud Native Java Go
Go:为云原生而生的高效语言
Go:为云原生而生的高效语言
581 0
|
12月前
|
JSON 编解码 API
Go语言网络编程:使用 net/http 构建 RESTful API
本章介绍如何使用 Go 语言的 `net/http` 标准库构建 RESTful API。内容涵盖 RESTful API 的基本概念及规范,包括 GET、POST、PUT 和 DELETE 方法的实现。通过定义用户数据结构和模拟数据库,逐步实现获取用户列表、创建用户、更新用户、删除用户的 HTTP 路由处理函数。同时提供辅助函数用于路径参数解析,并展示如何设置路由器启动服务。最后通过 curl 或 Postman 测试接口功能。章节总结了路由分发、JSON 编解码、方法区分、并发安全管理和路径参数解析等关键点,为更复杂需求推荐第三方框架如 Gin、Echo 和 Chi。

热门文章

最新文章