Documentation ¶
Overview ¶
Package gen generates code for errguard.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultTemplate = template.Must(template.New("defaultTemplate").Parse(`// Code generated by "{{.CommandLine}}"; DO NOT EDIT
package {{.Package}}
import ({{range .Imports}}
{{.}}{{end}}
"github.com/jjeffery/errguard"
)
{{range .Interfaces}}
type guard{{.Name}} struct{
inner {{.Name}}
}
func newGuard{{.Name}}(inner {{.Name}}) {{.Name}} {
return &guard{{.Name}}{ inner: inner }
}
{{range .Methods}}
func (g *guard{{.Interface.Name}}) {{.Name}}({{.ParamDecl}}) ({{.ResultDecl}}) {
var guard errguard.Guard
{{.ErrorVar}} = guard.Run({{.ContextExpr}}, func() error {
{{.ResultNames}} = g.inner.{{.Name}}({{.ArgNames}})
return {{.ErrorVar}}
})
return {{.ResultNames}}
}
{{end}}
{{end}}`))
DefaultTemplate is the template used by default for generating code.
Functions ¶
This section is empty.
Types ¶
type Method ¶
type Method struct { Interface *Interface Name string ArgNames string // Comma separated list of input argument names ParamDecl string // Parameters and types for method declaration ResultNames string // Comma separated list of result names ResultDecl string // Results for method declaration ErrorVar string // Name of the result error var ContextExpr string // Expression to use to obtain the context }
Method contains information about a single method needed by the template.
Click to show internal directories.
Click to hide internal directories.