Command gencodec generates marshaling methods for Go struct types.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gencodec/vendor/github.com/garslo/gogen/var.go

44 lines
637 B

package gogen
import (
"fmt"
"go/ast"
"strconv"
)
type Var struct {
Name string
}
func (me Var) Expression() ast.Expr {
return &ast.Ident{
Name: me.Name,
Obj: &ast.Object{
Kind: ast.Var,
Name: me.Name,
},
}
}
// Things that are like Var but either deserve their own name, or have
// slightly different behaviors
type String struct {
Value string
}
func (me String) Expression() ast.Expr {
return Var{fmt.Sprintf(`"%s"`, me.Value)}.Expression()
}
func Int(value int) Var {
return Var{strconv.Itoa(value)}
}
func Pkg(value string) Var {
return Var{value}
}
func Name(value string) Var {
return Var{value}
}