GO编程:小技巧( 二 )

func f(a int, _ string) {}

  • 如果你要比较时间戳,请使用 time.Before 或 time.After ,不要使用 time.Sub 来获得 duration (持续时间),然后检查它的值 。
  • 带有上下文的函数第一个参数名为 ctx,形如:func foo(ctx Context, ...)
  • 几个相同类型的参数定义可以用简短的方式来进行
func f(a int, b int, s string, p string)func f(a, b int, s, p string)