相关疑难解决方法(0)

关键字var后面的下划线和接口名称是什么意思?

来自http://golang.org/src/pkg/database/sql/driver/types.go :

type ValueConverter interface {
    // ConvertValue converts a value to a driver Value.
    ConvertValue(v interface{}) (Value, error)
}

var Bool boolType

type boolType struct{}

var _ ValueConverter = boolType{} // line 58

func (boolType) String() string { return "Bool" }

func (boolType) ConvertValue(src interface{}) (Value, error) {....}
Run Code Online (Sandbox Code Playgroud)

我知道ValueConverter是一个接口名称.第58行似乎声明boolType实现接口ValueConverter,但这是必要的吗?我删除了第58行,代码运行良好.

syntax interface go underscores

66
推荐指数
2
解决办法
1万
查看次数

Golang Godoc-解释组类型声明

我在GIN库和Google文档中看到了一段GO代码,如下所示:

type (
    T0 []string
    T1 []string
    T2 struct{ a, b int }
    T3 struct{ a, c int }
    T4 func(int, float64) *T0
    T5 func(x int, y float64) *[]string
)
Run Code Online (Sandbox Code Playgroud)

我不明白的是,该分组在做什么,以及此实现的目的是什么(除非我错过了,否则讨论该主题的文档并不多)

杜松子酒图书馆的另一个例子

type (
    RoutesInfo []RouteInfo
    RouteInfo  struct {
        Method  string
        Path    string
        Handler string
    }
        Engine struct {
        RouterGroup
        HTMLRender  render.HTMLRender
        allNoRoute  HandlersChain
        allNoMethod HandlersChain
        noRoute     HandlersChain
        noMethod    HandlersChain
        pool        sync.Pool
        trees       methodTrees

        RedirectTrailingSlash bool


        RedirectFixedPath bool      
        HandleMethodNotAllowed bool
        ForwardedByClientIP    bool
    }
)
Run Code Online (Sandbox Code Playgroud)

最后-抱歉,这是另一个主题,但与此主题相关

var _ IRouter = &Engine{} …
Run Code Online (Sandbox Code Playgroud)

go data-structures godoc

2
推荐指数
1
解决办法
531
查看次数

标签 统计

go ×2

data-structures ×1

godoc ×1

interface ×1

syntax ×1

underscores ×1