goto 语句通过标签进行代码间的无条件跳转。goto 语句可以在快速跳出循环、避免重复退出上有一定的帮助。Go 语言中使用 goto 语句能简化一些代码的实现过程。
使用 goto 集中处理错误
package main
import "fmt"
func main() {
for x := 0; x < 10; x++ {
for y := 0; y < 10; y++ {
if y == 2 {
// 跳转到标签
goto breakHere
结构标签
structtag提供了一种解析和处理struct tag Go字段的方法。 它被之类的工具使用。 有关更多示例,请签。
安装
go get github.com/fatih/structtag
例
package main
import (
"fmt"
"reflect"
"sort"
"github.com/fatih/structtag"
)
func main () {
type t struct {
t string `json:"foo,omitempty,