id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
17,600 |
thriftrw/thriftrw-go
|
compile/type.go
|
RootTypeSpec
|
func RootTypeSpec(s TypeSpec) TypeSpec {
if t, ok := s.(*TypedefSpec); ok {
return t.root
}
return s
}
|
go
|
func RootTypeSpec(s TypeSpec) TypeSpec {
if t, ok := s.(*TypedefSpec); ok {
return t.root
}
return s
}
|
[
"func",
"RootTypeSpec",
"(",
"s",
"TypeSpec",
")",
"TypeSpec",
"{",
"if",
"t",
",",
"ok",
":=",
"s",
".",
"(",
"*",
"TypedefSpec",
")",
";",
"ok",
"{",
"return",
"t",
".",
"root",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// RootTypeSpec returns the TypeSpec that the given linked TypeSpec points to.
//
// For most types, this is the type itself. For Typedefs, it is the root
// TypeSpec of the Typedef's target.
|
[
"RootTypeSpec",
"returns",
"the",
"TypeSpec",
"that",
"the",
"given",
"linked",
"TypeSpec",
"points",
"to",
".",
"For",
"most",
"types",
"this",
"is",
"the",
"type",
"itself",
".",
"For",
"Typedefs",
"it",
"is",
"the",
"root",
"TypeSpec",
"of",
"the",
"Typedef",
"s",
"target",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/type.go#L69-L74
|
17,601 |
thriftrw/thriftrw-go
|
compile/type.go
|
Link
|
func (r typeSpecReference) Link(scope Scope) (TypeSpec, error) {
src := ast.TypeReference(r)
t, err := scope.LookupType(src.Name)
if err == nil {
return t.Link(scope)
}
mname, iname := splitInclude(src.Name)
if len(mname) == 0 {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
includedScope, err := getIncludedScope(scope, mname)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
t, err = typeSpecReference{Name: iname}.Link(includedScope)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
return t, nil
}
|
go
|
func (r typeSpecReference) Link(scope Scope) (TypeSpec, error) {
src := ast.TypeReference(r)
t, err := scope.LookupType(src.Name)
if err == nil {
return t.Link(scope)
}
mname, iname := splitInclude(src.Name)
if len(mname) == 0 {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
includedScope, err := getIncludedScope(scope, mname)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
t, err = typeSpecReference{Name: iname}.Link(includedScope)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
return t, nil
}
|
[
"func",
"(",
"r",
"typeSpecReference",
")",
"Link",
"(",
"scope",
"Scope",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"src",
":=",
"ast",
".",
"TypeReference",
"(",
"r",
")",
"\n",
"t",
",",
"err",
":=",
"scope",
".",
"LookupType",
"(",
"src",
".",
"Name",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"t",
".",
"Link",
"(",
"scope",
")",
"\n",
"}",
"\n\n",
"mname",
",",
"iname",
":=",
"splitInclude",
"(",
"src",
".",
"Name",
")",
"\n",
"if",
"len",
"(",
"mname",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"includedScope",
",",
"err",
":=",
"getIncludedScope",
"(",
"scope",
",",
"mname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"t",
",",
"err",
"=",
"typeSpecReference",
"{",
"Name",
":",
"iname",
"}",
".",
"Link",
"(",
"includedScope",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] |
// Link replaces the typeSpecReference with an actual linked TypeSpec.
|
[
"Link",
"replaces",
"the",
"typeSpecReference",
"with",
"an",
"actual",
"linked",
"TypeSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/type.go#L88-L126
|
17,602 |
thriftrw/thriftrw-go
|
compile/type.go
|
ForEachTypeReference
|
func (r typeSpecReference) ForEachTypeReference(func(TypeSpec) error) error {
panic(fmt.Sprintf(
"ForEachTypeReference() called on unresolved TypeSpec reference %v."+
"Make sure you called Link().", r,
))
}
|
go
|
func (r typeSpecReference) ForEachTypeReference(func(TypeSpec) error) error {
panic(fmt.Sprintf(
"ForEachTypeReference() called on unresolved TypeSpec reference %v."+
"Make sure you called Link().", r,
))
}
|
[
"func",
"(",
"r",
"typeSpecReference",
")",
"ForEachTypeReference",
"(",
"func",
"(",
"TypeSpec",
")",
"error",
")",
"error",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"r",
",",
")",
")",
"\n",
"}"
] |
// ForEachTypeReference on an unresolved typeSpecReference will cause a system
// panic.
|
[
"ForEachTypeReference",
"on",
"an",
"unresolved",
"typeSpecReference",
"will",
"cause",
"a",
"system",
"panic",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/type.go#L146-L151
|
17,603 |
thriftrw/thriftrw-go
|
compile/type.go
|
compileTypeReference
|
func compileTypeReference(typ ast.Type) (TypeSpec, error) {
if typ == nil {
return nil, nil
}
switch t := typ.(type) {
case ast.BaseType:
return compileBaseType(t)
case ast.MapType:
return compileMapType(t)
case ast.ListType:
return compileListType(t)
case ast.SetType:
return compileSetType(t)
case ast.TypeReference:
return typeSpecReference(t), nil
default:
panic(fmt.Sprintf("unknown type %v", typ))
}
}
|
go
|
func compileTypeReference(typ ast.Type) (TypeSpec, error) {
if typ == nil {
return nil, nil
}
switch t := typ.(type) {
case ast.BaseType:
return compileBaseType(t)
case ast.MapType:
return compileMapType(t)
case ast.ListType:
return compileListType(t)
case ast.SetType:
return compileSetType(t)
case ast.TypeReference:
return typeSpecReference(t), nil
default:
panic(fmt.Sprintf("unknown type %v", typ))
}
}
|
[
"func",
"compileTypeReference",
"(",
"typ",
"ast",
".",
"Type",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"if",
"typ",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"switch",
"t",
":=",
"typ",
".",
"(",
"type",
")",
"{",
"case",
"ast",
".",
"BaseType",
":",
"return",
"compileBaseType",
"(",
"t",
")",
"\n",
"case",
"ast",
".",
"MapType",
":",
"return",
"compileMapType",
"(",
"t",
")",
"\n",
"case",
"ast",
".",
"ListType",
":",
"return",
"compileListType",
"(",
"t",
")",
"\n",
"case",
"ast",
".",
"SetType",
":",
"return",
"compileSetType",
"(",
"t",
")",
"\n",
"case",
"ast",
".",
"TypeReference",
":",
"return",
"typeSpecReference",
"(",
"t",
")",
",",
"nil",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"typ",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// compileTypeReference compiles the given AST type reference into a TypeSpec.
//
// The returned TypeSpec may need to be linked eventually.
|
[
"compileTypeReference",
"compiles",
"the",
"given",
"AST",
"type",
"reference",
"into",
"a",
"TypeSpec",
".",
"The",
"returned",
"TypeSpec",
"may",
"need",
"to",
"be",
"linked",
"eventually",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/type.go#L171-L189
|
17,604 |
thriftrw/thriftrw-go
|
internal/envelope/server.go
|
NewServer
|
func NewServer(p protocol.Protocol, h Handler) Server {
return Server{p: p, h: h}
}
|
go
|
func NewServer(p protocol.Protocol, h Handler) Server {
return Server{p: p, h: h}
}
|
[
"func",
"NewServer",
"(",
"p",
"protocol",
".",
"Protocol",
",",
"h",
"Handler",
")",
"Server",
"{",
"return",
"Server",
"{",
"p",
":",
"p",
",",
"h",
":",
"h",
"}",
"\n",
"}"
] |
// NewServer builds a new server.
|
[
"NewServer",
"builds",
"a",
"new",
"server",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/envelope/server.go#L57-L59
|
17,605 |
thriftrw/thriftrw-go
|
internal/envelope/server.go
|
Handle
|
func (s Server) Handle(data []byte) ([]byte, error) {
request, err := s.p.DecodeEnveloped(bytes.NewReader(data))
if err != nil {
return nil, err
}
response := wire.Envelope{
Name: request.Name,
SeqID: request.SeqID,
Type: wire.Reply,
}
response.Value, err = s.h.Handle(request.Name, request.Value)
if err != nil {
response.Type = wire.Exception
switch err.(type) {
case ErrUnknownMethod:
response.Value, err = tappExc(err, exception.ExceptionTypeUnknownMethod)
default:
response.Value, err = tappExc(err, exception.ExceptionTypeInternalError)
}
if err != nil {
return nil, err
}
}
var buff bytes.Buffer
if err := s.p.EncodeEnveloped(response, &buff); err != nil {
return nil, err
}
return buff.Bytes(), nil
}
|
go
|
func (s Server) Handle(data []byte) ([]byte, error) {
request, err := s.p.DecodeEnveloped(bytes.NewReader(data))
if err != nil {
return nil, err
}
response := wire.Envelope{
Name: request.Name,
SeqID: request.SeqID,
Type: wire.Reply,
}
response.Value, err = s.h.Handle(request.Name, request.Value)
if err != nil {
response.Type = wire.Exception
switch err.(type) {
case ErrUnknownMethod:
response.Value, err = tappExc(err, exception.ExceptionTypeUnknownMethod)
default:
response.Value, err = tappExc(err, exception.ExceptionTypeInternalError)
}
if err != nil {
return nil, err
}
}
var buff bytes.Buffer
if err := s.p.EncodeEnveloped(response, &buff); err != nil {
return nil, err
}
return buff.Bytes(), nil
}
|
[
"func",
"(",
"s",
"Server",
")",
"Handle",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"request",
",",
"err",
":=",
"s",
".",
"p",
".",
"DecodeEnveloped",
"(",
"bytes",
".",
"NewReader",
"(",
"data",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"response",
":=",
"wire",
".",
"Envelope",
"{",
"Name",
":",
"request",
".",
"Name",
",",
"SeqID",
":",
"request",
".",
"SeqID",
",",
"Type",
":",
"wire",
".",
"Reply",
",",
"}",
"\n\n",
"response",
".",
"Value",
",",
"err",
"=",
"s",
".",
"h",
".",
"Handle",
"(",
"request",
".",
"Name",
",",
"request",
".",
"Value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"response",
".",
"Type",
"=",
"wire",
".",
"Exception",
"\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"ErrUnknownMethod",
":",
"response",
".",
"Value",
",",
"err",
"=",
"tappExc",
"(",
"err",
",",
"exception",
".",
"ExceptionTypeUnknownMethod",
")",
"\n",
"default",
":",
"response",
".",
"Value",
",",
"err",
"=",
"tappExc",
"(",
"err",
",",
"exception",
".",
"ExceptionTypeInternalError",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"buff",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"s",
".",
"p",
".",
"EncodeEnveloped",
"(",
"response",
",",
"&",
"buff",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"buff",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// Handle handles the given binary payload.
|
[
"Handle",
"handles",
"the",
"given",
"binary",
"payload",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/envelope/server.go#L62-L95
|
17,606 |
thriftrw/thriftrw-go
|
internal/envelope/server.go
|
tappExc
|
func tappExc(err error, typ exception.ExceptionType) (wire.Value, error) {
return (&exception.TApplicationException{
Message: ptr.String(err.Error()),
Type: &typ,
}).ToWire()
}
|
go
|
func tappExc(err error, typ exception.ExceptionType) (wire.Value, error) {
return (&exception.TApplicationException{
Message: ptr.String(err.Error()),
Type: &typ,
}).ToWire()
}
|
[
"func",
"tappExc",
"(",
"err",
"error",
",",
"typ",
"exception",
".",
"ExceptionType",
")",
"(",
"wire",
".",
"Value",
",",
"error",
")",
"{",
"return",
"(",
"&",
"exception",
".",
"TApplicationException",
"{",
"Message",
":",
"ptr",
".",
"String",
"(",
"err",
".",
"Error",
"(",
")",
")",
",",
"Type",
":",
"&",
"typ",
",",
"}",
")",
".",
"ToWire",
"(",
")",
"\n",
"}"
] |
// Helper to build TApplicationException wire.Values
|
[
"Helper",
"to",
"build",
"TApplicationException",
"wire",
".",
"Values"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/envelope/server.go#L98-L103
|
17,607 |
thriftrw/thriftrw-go
|
internal/plugin/multi.go
|
Name
|
func (mh MultiHandle) Name() string {
names := make([]string, 0, len(mh))
for _, h := range mh {
names = append(names, h.Name())
}
return fmt.Sprintf("MultiHandle{%v}", strings.Join(names, ", "))
}
|
go
|
func (mh MultiHandle) Name() string {
names := make([]string, 0, len(mh))
for _, h := range mh {
names = append(names, h.Name())
}
return fmt.Sprintf("MultiHandle{%v}", strings.Join(names, ", "))
}
|
[
"func",
"(",
"mh",
"MultiHandle",
")",
"Name",
"(",
")",
"string",
"{",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"mh",
")",
")",
"\n",
"for",
"_",
",",
"h",
":=",
"range",
"mh",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"h",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"names",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] |
// Name is the combined name of this plugin
|
[
"Name",
"is",
"the",
"combined",
"name",
"of",
"this",
"plugin"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/multi.go#L36-L42
|
17,608 |
thriftrw/thriftrw-go
|
internal/plugin/multi.go
|
Close
|
func (mh MultiHandle) Close() error {
return concurrent.Range(mh, func(_ int, h Handle) error {
return h.Close()
})
}
|
go
|
func (mh MultiHandle) Close() error {
return concurrent.Range(mh, func(_ int, h Handle) error {
return h.Close()
})
}
|
[
"func",
"(",
"mh",
"MultiHandle",
")",
"Close",
"(",
")",
"error",
"{",
"return",
"concurrent",
".",
"Range",
"(",
"mh",
",",
"func",
"(",
"_",
"int",
",",
"h",
"Handle",
")",
"error",
"{",
"return",
"h",
".",
"Close",
"(",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// Close closes all Handles associated with this MultiHandle.
|
[
"Close",
"closes",
"all",
"Handles",
"associated",
"with",
"this",
"MultiHandle",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/multi.go#L45-L49
|
17,609 |
thriftrw/thriftrw-go
|
internal/plugin/multi.go
|
ServiceGenerator
|
func (mh MultiHandle) ServiceGenerator() ServiceGenerator {
msg := make(MultiServiceGenerator, 0, len(mh))
for _, h := range mh {
if sg := h.ServiceGenerator(); sg != nil {
msg = append(msg, sg)
}
}
return msg
}
|
go
|
func (mh MultiHandle) ServiceGenerator() ServiceGenerator {
msg := make(MultiServiceGenerator, 0, len(mh))
for _, h := range mh {
if sg := h.ServiceGenerator(); sg != nil {
msg = append(msg, sg)
}
}
return msg
}
|
[
"func",
"(",
"mh",
"MultiHandle",
")",
"ServiceGenerator",
"(",
")",
"ServiceGenerator",
"{",
"msg",
":=",
"make",
"(",
"MultiServiceGenerator",
",",
"0",
",",
"len",
"(",
"mh",
")",
")",
"\n",
"for",
"_",
",",
"h",
":=",
"range",
"mh",
"{",
"if",
"sg",
":=",
"h",
".",
"ServiceGenerator",
"(",
")",
";",
"sg",
"!=",
"nil",
"{",
"msg",
"=",
"append",
"(",
"msg",
",",
"sg",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"msg",
"\n",
"}"
] |
// ServiceGenerator returns a ServiceGenerator which calls into the
// ServiceGenerators of all plugins associated with this MultiHandle and
// consolidates their results.
|
[
"ServiceGenerator",
"returns",
"a",
"ServiceGenerator",
"which",
"calls",
"into",
"the",
"ServiceGenerators",
"of",
"all",
"plugins",
"associated",
"with",
"this",
"MultiHandle",
"and",
"consolidates",
"their",
"results",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/multi.go#L54-L62
|
17,610 |
thriftrw/thriftrw-go
|
internal/plugin/multi.go
|
Handle
|
func (msg MultiServiceGenerator) Handle() Handle {
mh := make(MultiHandle, len(msg))
for i, sg := range msg {
mh[i] = sg.Handle()
}
return mh
}
|
go
|
func (msg MultiServiceGenerator) Handle() Handle {
mh := make(MultiHandle, len(msg))
for i, sg := range msg {
mh[i] = sg.Handle()
}
return mh
}
|
[
"func",
"(",
"msg",
"MultiServiceGenerator",
")",
"Handle",
"(",
")",
"Handle",
"{",
"mh",
":=",
"make",
"(",
"MultiHandle",
",",
"len",
"(",
"msg",
")",
")",
"\n",
"for",
"i",
",",
"sg",
":=",
"range",
"msg",
"{",
"mh",
"[",
"i",
"]",
"=",
"sg",
".",
"Handle",
"(",
")",
"\n",
"}",
"\n",
"return",
"mh",
"\n",
"}"
] |
// Handle returns a reference to the Handle that owns this ServiceGenerator.
|
[
"Handle",
"returns",
"a",
"reference",
"to",
"the",
"Handle",
"that",
"owns",
"this",
"ServiceGenerator",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/multi.go#L69-L75
|
17,611 |
thriftrw/thriftrw-go
|
internal/plugin/multi.go
|
Generate
|
func (msg MultiServiceGenerator) Generate(req *api.GenerateServiceRequest) (*api.GenerateServiceResponse, error) {
var (
lock sync.Mutex
files = make(map[string][]byte)
usedPaths = make(map[string]string) // path -> plugin name
)
err := concurrent.Range(msg, func(_ int, sg ServiceGenerator) error {
res, err := sg.Generate(req)
if err != nil {
return err
}
lock.Lock()
defer lock.Unlock()
pluginName := sg.Handle().Name()
for path, contents := range res.Files {
if takenBy, taken := usedPaths[path]; taken {
return fmt.Errorf("plugin conflict: cannot write file %q for plugin %q: "+
"plugin %q already wrote to that file", path, pluginName, takenBy)
}
usedPaths[path] = pluginName
files[path] = contents
}
return nil
})
return &api.GenerateServiceResponse{Files: files}, err
}
|
go
|
func (msg MultiServiceGenerator) Generate(req *api.GenerateServiceRequest) (*api.GenerateServiceResponse, error) {
var (
lock sync.Mutex
files = make(map[string][]byte)
usedPaths = make(map[string]string) // path -> plugin name
)
err := concurrent.Range(msg, func(_ int, sg ServiceGenerator) error {
res, err := sg.Generate(req)
if err != nil {
return err
}
lock.Lock()
defer lock.Unlock()
pluginName := sg.Handle().Name()
for path, contents := range res.Files {
if takenBy, taken := usedPaths[path]; taken {
return fmt.Errorf("plugin conflict: cannot write file %q for plugin %q: "+
"plugin %q already wrote to that file", path, pluginName, takenBy)
}
usedPaths[path] = pluginName
files[path] = contents
}
return nil
})
return &api.GenerateServiceResponse{Files: files}, err
}
|
[
"func",
"(",
"msg",
"MultiServiceGenerator",
")",
"Generate",
"(",
"req",
"*",
"api",
".",
"GenerateServiceRequest",
")",
"(",
"*",
"api",
".",
"GenerateServiceResponse",
",",
"error",
")",
"{",
"var",
"(",
"lock",
"sync",
".",
"Mutex",
"\n",
"files",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
")",
"\n",
"usedPaths",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"// path -> plugin name",
"\n",
")",
"\n\n",
"err",
":=",
"concurrent",
".",
"Range",
"(",
"msg",
",",
"func",
"(",
"_",
"int",
",",
"sg",
"ServiceGenerator",
")",
"error",
"{",
"res",
",",
"err",
":=",
"sg",
".",
"Generate",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"pluginName",
":=",
"sg",
".",
"Handle",
"(",
")",
".",
"Name",
"(",
")",
"\n",
"for",
"path",
",",
"contents",
":=",
"range",
"res",
".",
"Files",
"{",
"if",
"takenBy",
",",
"taken",
":=",
"usedPaths",
"[",
"path",
"]",
";",
"taken",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"path",
",",
"pluginName",
",",
"takenBy",
")",
"\n",
"}",
"\n\n",
"usedPaths",
"[",
"path",
"]",
"=",
"pluginName",
"\n",
"files",
"[",
"path",
"]",
"=",
"contents",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"&",
"api",
".",
"GenerateServiceResponse",
"{",
"Files",
":",
"files",
"}",
",",
"err",
"\n",
"}"
] |
// Generate calls all the service generators associated with this plugin and
// consolidates their output.
//
// Any conflicts in the generated files will result in a failure.
|
[
"Generate",
"calls",
"all",
"the",
"service",
"generators",
"associated",
"with",
"this",
"plugin",
"and",
"consolidates",
"their",
"output",
".",
"Any",
"conflicts",
"in",
"the",
"generated",
"files",
"will",
"result",
"in",
"a",
"failure",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/multi.go#L81-L112
|
17,612 |
thriftrw/thriftrw-go
|
internal/plugin/transport.go
|
NewTransportHandle
|
func NewTransportHandle(name string, t envelope.Transport) (Handle, error) {
client := api.NewPluginClient(multiplex.NewClient(
"Plugin",
envelope.NewClient(_proto, t),
))
handshake, err := client.Handshake(&api.HandshakeRequest{})
if err != nil {
return nil, errHandshakeFailed{Name: name, Reason: err}
}
if handshake.Name != name {
return nil, errHandshakeFailed{
Name: name,
Reason: errNameMismatch{Want: name, Got: handshake.Name},
}
}
if handshake.APIVersion != api.APIVersion {
return nil, errHandshakeFailed{
Name: name,
Reason: errAPIVersionMismatch{Want: api.APIVersion, Got: handshake.APIVersion},
}
}
features := make(map[api.Feature]struct{}, len(handshake.Features))
for _, feature := range handshake.Features {
features[feature] = struct{}{}
}
return &transportHandle{
name: name,
Transport: t,
Client: client,
Running: atomic.NewBool(true),
Features: features,
}, nil
}
|
go
|
func NewTransportHandle(name string, t envelope.Transport) (Handle, error) {
client := api.NewPluginClient(multiplex.NewClient(
"Plugin",
envelope.NewClient(_proto, t),
))
handshake, err := client.Handshake(&api.HandshakeRequest{})
if err != nil {
return nil, errHandshakeFailed{Name: name, Reason: err}
}
if handshake.Name != name {
return nil, errHandshakeFailed{
Name: name,
Reason: errNameMismatch{Want: name, Got: handshake.Name},
}
}
if handshake.APIVersion != api.APIVersion {
return nil, errHandshakeFailed{
Name: name,
Reason: errAPIVersionMismatch{Want: api.APIVersion, Got: handshake.APIVersion},
}
}
features := make(map[api.Feature]struct{}, len(handshake.Features))
for _, feature := range handshake.Features {
features[feature] = struct{}{}
}
return &transportHandle{
name: name,
Transport: t,
Client: client,
Running: atomic.NewBool(true),
Features: features,
}, nil
}
|
[
"func",
"NewTransportHandle",
"(",
"name",
"string",
",",
"t",
"envelope",
".",
"Transport",
")",
"(",
"Handle",
",",
"error",
")",
"{",
"client",
":=",
"api",
".",
"NewPluginClient",
"(",
"multiplex",
".",
"NewClient",
"(",
"\"",
"\"",
",",
"envelope",
".",
"NewClient",
"(",
"_proto",
",",
"t",
")",
",",
")",
")",
"\n\n",
"handshake",
",",
"err",
":=",
"client",
".",
"Handshake",
"(",
"&",
"api",
".",
"HandshakeRequest",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errHandshakeFailed",
"{",
"Name",
":",
"name",
",",
"Reason",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"if",
"handshake",
".",
"Name",
"!=",
"name",
"{",
"return",
"nil",
",",
"errHandshakeFailed",
"{",
"Name",
":",
"name",
",",
"Reason",
":",
"errNameMismatch",
"{",
"Want",
":",
"name",
",",
"Got",
":",
"handshake",
".",
"Name",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"if",
"handshake",
".",
"APIVersion",
"!=",
"api",
".",
"APIVersion",
"{",
"return",
"nil",
",",
"errHandshakeFailed",
"{",
"Name",
":",
"name",
",",
"Reason",
":",
"errAPIVersionMismatch",
"{",
"Want",
":",
"api",
".",
"APIVersion",
",",
"Got",
":",
"handshake",
".",
"APIVersion",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"features",
":=",
"make",
"(",
"map",
"[",
"api",
".",
"Feature",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"handshake",
".",
"Features",
")",
")",
"\n",
"for",
"_",
",",
"feature",
":=",
"range",
"handshake",
".",
"Features",
"{",
"features",
"[",
"feature",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"transportHandle",
"{",
"name",
":",
"name",
",",
"Transport",
":",
"t",
",",
"Client",
":",
"client",
",",
"Running",
":",
"atomic",
".",
"NewBool",
"(",
"true",
")",
",",
"Features",
":",
"features",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewTransportHandle builds a new Handle which speaks to the given transport.
//
// If the transport is an io.Closer, it will be closed when the handle is closed.
|
[
"NewTransportHandle",
"builds",
"a",
"new",
"Handle",
"which",
"speaks",
"to",
"the",
"given",
"transport",
".",
"If",
"the",
"transport",
"is",
"an",
"io",
".",
"Closer",
"it",
"will",
"be",
"closed",
"when",
"the",
"handle",
"is",
"closed",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/transport.go#L52-L89
|
17,613 |
thriftrw/thriftrw-go
|
gen/service.go
|
Service
|
func Service(g Generator, s *compile.ServiceSpec) (map[string]*bytes.Buffer, error) {
files := make(map[string]*bytes.Buffer)
for _, functionName := range sortStringKeys(s.Functions) {
fileName := fmt.Sprintf("%s_%s.go", strings.ToLower(s.Name), strings.ToLower(functionName))
function := s.Functions[functionName]
if err := ServiceFunction(g, s, function); err != nil {
return nil, fmt.Errorf(
"could not generate types for %s.%s: %v",
s.Name, functionName, err)
}
buff := new(bytes.Buffer)
if err := g.Write(buff, token.NewFileSet()); err != nil {
return nil, fmt.Errorf("could not write %s.%s: %v", s.Name, functionName, err)
}
// TODO check for conflicts
files[fileName] = buff
}
return files, nil
}
|
go
|
func Service(g Generator, s *compile.ServiceSpec) (map[string]*bytes.Buffer, error) {
files := make(map[string]*bytes.Buffer)
for _, functionName := range sortStringKeys(s.Functions) {
fileName := fmt.Sprintf("%s_%s.go", strings.ToLower(s.Name), strings.ToLower(functionName))
function := s.Functions[functionName]
if err := ServiceFunction(g, s, function); err != nil {
return nil, fmt.Errorf(
"could not generate types for %s.%s: %v",
s.Name, functionName, err)
}
buff := new(bytes.Buffer)
if err := g.Write(buff, token.NewFileSet()); err != nil {
return nil, fmt.Errorf("could not write %s.%s: %v", s.Name, functionName, err)
}
// TODO check for conflicts
files[fileName] = buff
}
return files, nil
}
|
[
"func",
"Service",
"(",
"g",
"Generator",
",",
"s",
"*",
"compile",
".",
"ServiceSpec",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"files",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"bytes",
".",
"Buffer",
")",
"\n\n",
"for",
"_",
",",
"functionName",
":=",
"range",
"sortStringKeys",
"(",
"s",
".",
"Functions",
")",
"{",
"fileName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"s",
".",
"Name",
")",
",",
"strings",
".",
"ToLower",
"(",
"functionName",
")",
")",
"\n\n",
"function",
":=",
"s",
".",
"Functions",
"[",
"functionName",
"]",
"\n",
"if",
"err",
":=",
"ServiceFunction",
"(",
"g",
",",
"s",
",",
"function",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"functionName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"buff",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"if",
"err",
":=",
"g",
".",
"Write",
"(",
"buff",
",",
"token",
".",
"NewFileSet",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"functionName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// TODO check for conflicts",
"files",
"[",
"fileName",
"]",
"=",
"buff",
"\n",
"}",
"\n\n",
"return",
"files",
",",
"nil",
"\n",
"}"
] |
// Service generates code for the given service.
//
// Returns a map from file name to contents for that file. The file names are
// relative to the package directory for the service.
|
[
"Service",
"generates",
"code",
"for",
"the",
"given",
"service",
".",
"Returns",
"a",
"map",
"from",
"file",
"name",
"to",
"contents",
"for",
"that",
"file",
".",
"The",
"file",
"names",
"are",
"relative",
"to",
"the",
"package",
"directory",
"for",
"the",
"service",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/service.go#L36-L59
|
17,614 |
thriftrw/thriftrw-go
|
gen/service.go
|
ServiceFunction
|
func ServiceFunction(g Generator, s *compile.ServiceSpec, f *compile.FunctionSpec) error {
argsName := functionNamePrefix(s, f) + "Args"
argsGen := fieldGroupGenerator{
Namespace: NewNamespace(),
Name: argsName,
Fields: compile.FieldGroup(f.ArgsSpec),
Doc: fmt.Sprintf(
"%v represents the arguments for the %v.%v function.\n\n"+
"The arguments for %v are sent and received over the wire as this struct.",
argsName, s.Name, f.Name, f.Name,
),
}
if err := argsGen.Generate(g); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if err := functionArgsEnveloper(g, s, f); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if err := functionHelper(g, s, f); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if f.ResultSpec == nil {
return nil
}
resultFields := make(compile.FieldGroup, 0, len(f.ResultSpec.Exceptions)+1)
if f.ResultSpec.ReturnType != nil {
resultFields = append(resultFields, &compile.FieldSpec{
ID: 0,
Name: "success",
Type: f.ResultSpec.ReturnType,
Doc: fmt.Sprintf("Value returned by %v after a successful execution.", f.Name),
})
}
resultFields = append(resultFields, f.ResultSpec.Exceptions...)
resultName := functionNamePrefix(s, f) + "Result"
resultDoc := fmt.Sprintf(
"%v represents the result of a %v.%v function call.\n\n"+
"The result of a %v execution is sent and received over the wire as this struct.",
resultName, s.Name, f.Name, f.Name,
)
if f.ResultSpec.ReturnType != nil {
resultDoc += fmt.Sprintf("\n\nSuccess is set only if the function did not throw an exception.")
}
resultGen := fieldGroupGenerator{
Namespace: NewNamespace(),
Name: resultName,
Fields: resultFields,
IsUnion: true,
AllowEmptyUnion: f.ResultSpec.ReturnType == nil,
Doc: resultDoc,
}
if err := resultGen.Generate(g); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if err := functionResponseEnveloper(g, s, f); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
// TODO(abg): If we receive unknown exceptions over the wire, we need to
// throw a generic error.
return nil
}
|
go
|
func ServiceFunction(g Generator, s *compile.ServiceSpec, f *compile.FunctionSpec) error {
argsName := functionNamePrefix(s, f) + "Args"
argsGen := fieldGroupGenerator{
Namespace: NewNamespace(),
Name: argsName,
Fields: compile.FieldGroup(f.ArgsSpec),
Doc: fmt.Sprintf(
"%v represents the arguments for the %v.%v function.\n\n"+
"The arguments for %v are sent and received over the wire as this struct.",
argsName, s.Name, f.Name, f.Name,
),
}
if err := argsGen.Generate(g); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if err := functionArgsEnveloper(g, s, f); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if err := functionHelper(g, s, f); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if f.ResultSpec == nil {
return nil
}
resultFields := make(compile.FieldGroup, 0, len(f.ResultSpec.Exceptions)+1)
if f.ResultSpec.ReturnType != nil {
resultFields = append(resultFields, &compile.FieldSpec{
ID: 0,
Name: "success",
Type: f.ResultSpec.ReturnType,
Doc: fmt.Sprintf("Value returned by %v after a successful execution.", f.Name),
})
}
resultFields = append(resultFields, f.ResultSpec.Exceptions...)
resultName := functionNamePrefix(s, f) + "Result"
resultDoc := fmt.Sprintf(
"%v represents the result of a %v.%v function call.\n\n"+
"The result of a %v execution is sent and received over the wire as this struct.",
resultName, s.Name, f.Name, f.Name,
)
if f.ResultSpec.ReturnType != nil {
resultDoc += fmt.Sprintf("\n\nSuccess is set only if the function did not throw an exception.")
}
resultGen := fieldGroupGenerator{
Namespace: NewNamespace(),
Name: resultName,
Fields: resultFields,
IsUnion: true,
AllowEmptyUnion: f.ResultSpec.ReturnType == nil,
Doc: resultDoc,
}
if err := resultGen.Generate(g); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
if err := functionResponseEnveloper(g, s, f); err != nil {
return wrapGenerateError(fmt.Sprintf("%s.%s", s.Name, f.Name), err)
}
// TODO(abg): If we receive unknown exceptions over the wire, we need to
// throw a generic error.
return nil
}
|
[
"func",
"ServiceFunction",
"(",
"g",
"Generator",
",",
"s",
"*",
"compile",
".",
"ServiceSpec",
",",
"f",
"*",
"compile",
".",
"FunctionSpec",
")",
"error",
"{",
"argsName",
":=",
"functionNamePrefix",
"(",
"s",
",",
"f",
")",
"+",
"\"",
"\"",
"\n",
"argsGen",
":=",
"fieldGroupGenerator",
"{",
"Namespace",
":",
"NewNamespace",
"(",
")",
",",
"Name",
":",
"argsName",
",",
"Fields",
":",
"compile",
".",
"FieldGroup",
"(",
"f",
".",
"ArgsSpec",
")",
",",
"Doc",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
"+",
"\"",
"\"",
",",
"argsName",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
",",
"f",
".",
"Name",
",",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"argsGen",
".",
"Generate",
"(",
"g",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"wrapGenerateError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"functionArgsEnveloper",
"(",
"g",
",",
"s",
",",
"f",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"wrapGenerateError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"functionHelper",
"(",
"g",
",",
"s",
",",
"f",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"wrapGenerateError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"f",
".",
"ResultSpec",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"resultFields",
":=",
"make",
"(",
"compile",
".",
"FieldGroup",
",",
"0",
",",
"len",
"(",
"f",
".",
"ResultSpec",
".",
"Exceptions",
")",
"+",
"1",
")",
"\n",
"if",
"f",
".",
"ResultSpec",
".",
"ReturnType",
"!=",
"nil",
"{",
"resultFields",
"=",
"append",
"(",
"resultFields",
",",
"&",
"compile",
".",
"FieldSpec",
"{",
"ID",
":",
"0",
",",
"Name",
":",
"\"",
"\"",
",",
"Type",
":",
"f",
".",
"ResultSpec",
".",
"ReturnType",
",",
"Doc",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"resultFields",
"=",
"append",
"(",
"resultFields",
",",
"f",
".",
"ResultSpec",
".",
"Exceptions",
"...",
")",
"\n\n",
"resultName",
":=",
"functionNamePrefix",
"(",
"s",
",",
"f",
")",
"+",
"\"",
"\"",
"\n",
"resultDoc",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
"+",
"\"",
"\"",
",",
"resultName",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
",",
"f",
".",
"Name",
",",
")",
"\n",
"if",
"f",
".",
"ResultSpec",
".",
"ReturnType",
"!=",
"nil",
"{",
"resultDoc",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
")",
"\n",
"}",
"\n\n",
"resultGen",
":=",
"fieldGroupGenerator",
"{",
"Namespace",
":",
"NewNamespace",
"(",
")",
",",
"Name",
":",
"resultName",
",",
"Fields",
":",
"resultFields",
",",
"IsUnion",
":",
"true",
",",
"AllowEmptyUnion",
":",
"f",
".",
"ResultSpec",
".",
"ReturnType",
"==",
"nil",
",",
"Doc",
":",
"resultDoc",
",",
"}",
"\n",
"if",
"err",
":=",
"resultGen",
".",
"Generate",
"(",
"g",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"wrapGenerateError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"functionResponseEnveloper",
"(",
"g",
",",
"s",
",",
"f",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"wrapGenerateError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"f",
".",
"Name",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// TODO(abg): If we receive unknown exceptions over the wire, we need to",
"// throw a generic error.",
"return",
"nil",
"\n",
"}"
] |
// ServiceFunction generates code for the given function of the given service.
|
[
"ServiceFunction",
"generates",
"code",
"for",
"the",
"given",
"function",
"of",
"the",
"given",
"service",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/service.go#L62-L128
|
17,615 |
thriftrw/thriftrw-go
|
gen/service.go
|
functionParams
|
func functionParams(g Generator, f *compile.FunctionSpec) (string, error) {
return g.TextTemplate(
`
<- $params := newNamespace ->
<- range .ArgsSpec>
<- if .Required>
<$params.NewName .Name> <typeReference .Type>,
<- else>
<$params.NewName .Name> <typeReferencePtr .Type>,
<- end ->
<end>
`, f)
}
|
go
|
func functionParams(g Generator, f *compile.FunctionSpec) (string, error) {
return g.TextTemplate(
`
<- $params := newNamespace ->
<- range .ArgsSpec>
<- if .Required>
<$params.NewName .Name> <typeReference .Type>,
<- else>
<$params.NewName .Name> <typeReferencePtr .Type>,
<- end ->
<end>
`, f)
}
|
[
"func",
"functionParams",
"(",
"g",
"Generator",
",",
"f",
"*",
"compile",
".",
"FunctionSpec",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"g",
".",
"TextTemplate",
"(",
"`\n\t\t<- $params := newNamespace ->\n\t\t<- range .ArgsSpec>\n\t\t\t<- if .Required>\n\t\t\t\t<$params.NewName .Name> <typeReference .Type>,\n\t\t\t<- else>\n\t\t\t\t<$params.NewName .Name> <typeReferencePtr .Type>,\n\t\t\t<- end ->\n\t\t<end>\n\t\t`",
",",
"f",
")",
"\n",
"}"
] |
// functionParams returns a named parameter list for the given function.
|
[
"functionParams",
"returns",
"a",
"named",
"parameter",
"list",
"for",
"the",
"given",
"function",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/service.go#L131-L143
|
17,616 |
thriftrw/thriftrw-go
|
gen/service.go
|
functionNewArgs
|
func functionNewArgs(g Generator, s *compile.ServiceSpec, f *compile.FunctionSpec) (string, error) {
return g.TextTemplate(
`
<- $f := .Function ->
<- $prefix := namePrefix .Service $f ->
<- $params := newNamespace ->
func(
<- range $f.ArgsSpec>
<- if .Required>
<$params.NewName .Name> <typeReference .Type>,
<- else>
<$params.NewName .Name> <typeReferencePtr .Type>,
<- end ->
<end>
) *<$prefix>Args {
return &<$prefix>Args{
<range $f.ArgsSpec>
<- if .Required ->
<goCase .Name>: <$params.Rotate .Name>,
<- else ->
<goCase .Name>: <$params.Rotate .Name>,
<- end>
<end>
}
}
`,
struct {
Service *compile.ServiceSpec
Function *compile.FunctionSpec
}{
Service: s,
Function: f,
},
TemplateFunc("namePrefix", functionNamePrefix))
}
|
go
|
func functionNewArgs(g Generator, s *compile.ServiceSpec, f *compile.FunctionSpec) (string, error) {
return g.TextTemplate(
`
<- $f := .Function ->
<- $prefix := namePrefix .Service $f ->
<- $params := newNamespace ->
func(
<- range $f.ArgsSpec>
<- if .Required>
<$params.NewName .Name> <typeReference .Type>,
<- else>
<$params.NewName .Name> <typeReferencePtr .Type>,
<- end ->
<end>
) *<$prefix>Args {
return &<$prefix>Args{
<range $f.ArgsSpec>
<- if .Required ->
<goCase .Name>: <$params.Rotate .Name>,
<- else ->
<goCase .Name>: <$params.Rotate .Name>,
<- end>
<end>
}
}
`,
struct {
Service *compile.ServiceSpec
Function *compile.FunctionSpec
}{
Service: s,
Function: f,
},
TemplateFunc("namePrefix", functionNamePrefix))
}
|
[
"func",
"functionNewArgs",
"(",
"g",
"Generator",
",",
"s",
"*",
"compile",
".",
"ServiceSpec",
",",
"f",
"*",
"compile",
".",
"FunctionSpec",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"g",
".",
"TextTemplate",
"(",
"`\n\t\t<- $f := .Function ->\n\t\t<- $prefix := namePrefix .Service $f ->\n\t\t<- $params := newNamespace ->\n\t\tfunc(\n\t\t\t<- range $f.ArgsSpec>\n\t\t\t\t<- if .Required>\n\t\t\t\t\t<$params.NewName .Name> <typeReference .Type>,\n\t\t\t\t<- else>\n\t\t\t\t\t<$params.NewName .Name> <typeReferencePtr .Type>,\n\t\t\t\t<- end ->\n\t\t\t<end>\n\t\t) *<$prefix>Args {\n\t\t\treturn &<$prefix>Args{\n\t\t\t<range $f.ArgsSpec>\n\t\t\t\t<- if .Required ->\n\t\t\t\t\t<goCase .Name>: <$params.Rotate .Name>,\n\t\t\t\t<- else ->\n\t\t\t\t\t<goCase .Name>: <$params.Rotate .Name>,\n\t\t\t\t<- end>\n\t\t\t<end>\n\t\t\t}\n\t\t}\n\t\t`",
",",
"struct",
"{",
"Service",
"*",
"compile",
".",
"ServiceSpec",
"\n",
"Function",
"*",
"compile",
".",
"FunctionSpec",
"\n",
"}",
"{",
"Service",
":",
"s",
",",
"Function",
":",
"f",
",",
"}",
",",
"TemplateFunc",
"(",
"\"",
"\"",
",",
"functionNamePrefix",
")",
")",
"\n",
"}"
] |
// functionNewArgs generates an expression which provides the NewArgs function
// for the given Thrift function.
|
[
"functionNewArgs",
"generates",
"an",
"expression",
"which",
"provides",
"the",
"NewArgs",
"function",
"for",
"the",
"given",
"Thrift",
"function",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/service.go#L267-L301
|
17,617 |
thriftrw/thriftrw-go
|
protocol/binary/writer.go
|
BorrowWriter
|
func BorrowWriter(w io.Writer) *Writer {
writer := writerPool.Get().(*Writer)
writer.writer = w
return writer
}
|
go
|
func BorrowWriter(w io.Writer) *Writer {
writer := writerPool.Get().(*Writer)
writer.writer = w
return writer
}
|
[
"func",
"BorrowWriter",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Writer",
"{",
"writer",
":=",
"writerPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"Writer",
")",
"\n",
"writer",
".",
"writer",
"=",
"w",
"\n",
"return",
"writer",
"\n",
"}"
] |
// BorrowWriter fetches a Writer from the system that will write its output to
// the given io.Writer.
//
// This Writer must be returned back using ReturnWriter.
|
[
"BorrowWriter",
"fetches",
"a",
"Writer",
"from",
"the",
"system",
"that",
"will",
"write",
"its",
"output",
"to",
"the",
"given",
"io",
".",
"Writer",
".",
"This",
"Writer",
"must",
"be",
"returned",
"back",
"using",
"ReturnWriter",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/protocol/binary/writer.go#L61-L65
|
17,618 |
thriftrw/thriftrw-go
|
protocol/binary/writer.go
|
WriteValue
|
func (bw *Writer) WriteValue(v wire.Value) error {
switch v.Type() {
case wire.TBool:
if v.GetBool() {
return bw.writeByte(1)
}
return bw.writeByte(0)
case wire.TI8:
return bw.writeByte(byte(v.GetI8()))
case wire.TDouble:
value := math.Float64bits(v.GetDouble())
return bw.writeInt64(int64(value))
case wire.TI16:
return bw.writeInt16(v.GetI16())
case wire.TI32:
return bw.writeInt32(v.GetI32())
case wire.TI64:
return bw.writeInt64(v.GetI64())
case wire.TBinary:
b := v.GetBinary()
if err := bw.writeInt32(int32(len(b))); err != nil {
return err
}
return bw.write(b)
case wire.TStruct:
return bw.writeStruct(v.GetStruct())
case wire.TMap:
return bw.writeMap(v.GetMap())
case wire.TSet:
return bw.writeSet(v.GetSet())
case wire.TList:
return bw.writeList(v.GetList())
default:
return fmt.Errorf("unknown ttype %v", v.Type())
}
}
|
go
|
func (bw *Writer) WriteValue(v wire.Value) error {
switch v.Type() {
case wire.TBool:
if v.GetBool() {
return bw.writeByte(1)
}
return bw.writeByte(0)
case wire.TI8:
return bw.writeByte(byte(v.GetI8()))
case wire.TDouble:
value := math.Float64bits(v.GetDouble())
return bw.writeInt64(int64(value))
case wire.TI16:
return bw.writeInt16(v.GetI16())
case wire.TI32:
return bw.writeInt32(v.GetI32())
case wire.TI64:
return bw.writeInt64(v.GetI64())
case wire.TBinary:
b := v.GetBinary()
if err := bw.writeInt32(int32(len(b))); err != nil {
return err
}
return bw.write(b)
case wire.TStruct:
return bw.writeStruct(v.GetStruct())
case wire.TMap:
return bw.writeMap(v.GetMap())
case wire.TSet:
return bw.writeSet(v.GetSet())
case wire.TList:
return bw.writeList(v.GetList())
default:
return fmt.Errorf("unknown ttype %v", v.Type())
}
}
|
[
"func",
"(",
"bw",
"*",
"Writer",
")",
"WriteValue",
"(",
"v",
"wire",
".",
"Value",
")",
"error",
"{",
"switch",
"v",
".",
"Type",
"(",
")",
"{",
"case",
"wire",
".",
"TBool",
":",
"if",
"v",
".",
"GetBool",
"(",
")",
"{",
"return",
"bw",
".",
"writeByte",
"(",
"1",
")",
"\n",
"}",
"\n",
"return",
"bw",
".",
"writeByte",
"(",
"0",
")",
"\n\n",
"case",
"wire",
".",
"TI8",
":",
"return",
"bw",
".",
"writeByte",
"(",
"byte",
"(",
"v",
".",
"GetI8",
"(",
")",
")",
")",
"\n\n",
"case",
"wire",
".",
"TDouble",
":",
"value",
":=",
"math",
".",
"Float64bits",
"(",
"v",
".",
"GetDouble",
"(",
")",
")",
"\n",
"return",
"bw",
".",
"writeInt64",
"(",
"int64",
"(",
"value",
")",
")",
"\n\n",
"case",
"wire",
".",
"TI16",
":",
"return",
"bw",
".",
"writeInt16",
"(",
"v",
".",
"GetI16",
"(",
")",
")",
"\n\n",
"case",
"wire",
".",
"TI32",
":",
"return",
"bw",
".",
"writeInt32",
"(",
"v",
".",
"GetI32",
"(",
")",
")",
"\n\n",
"case",
"wire",
".",
"TI64",
":",
"return",
"bw",
".",
"writeInt64",
"(",
"v",
".",
"GetI64",
"(",
")",
")",
"\n\n",
"case",
"wire",
".",
"TBinary",
":",
"b",
":=",
"v",
".",
"GetBinary",
"(",
")",
"\n",
"if",
"err",
":=",
"bw",
".",
"writeInt32",
"(",
"int32",
"(",
"len",
"(",
"b",
")",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"bw",
".",
"write",
"(",
"b",
")",
"\n\n",
"case",
"wire",
".",
"TStruct",
":",
"return",
"bw",
".",
"writeStruct",
"(",
"v",
".",
"GetStruct",
"(",
")",
")",
"\n\n",
"case",
"wire",
".",
"TMap",
":",
"return",
"bw",
".",
"writeMap",
"(",
"v",
".",
"GetMap",
"(",
")",
")",
"\n\n",
"case",
"wire",
".",
"TSet",
":",
"return",
"bw",
".",
"writeSet",
"(",
"v",
".",
"GetSet",
"(",
")",
")",
"\n\n",
"case",
"wire",
".",
"TList",
":",
"return",
"bw",
".",
"writeList",
"(",
"v",
".",
"GetList",
"(",
")",
")",
"\n\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// WriteValue writes the given Thrift value to the underlying stream using the
// Thrift Binary Protocol.
|
[
"WriteValue",
"writes",
"the",
"given",
"Thrift",
"value",
"to",
"the",
"underlying",
"stream",
"using",
"the",
"Thrift",
"Binary",
"Protocol",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/protocol/binary/writer.go#L200-L246
|
17,619 |
thriftrw/thriftrw-go
|
ast/definition.go
|
Info
|
func (c *Constant) Info() DefinitionInfo {
return DefinitionInfo{Name: c.Name, Line: c.Line}
}
|
go
|
func (c *Constant) Info() DefinitionInfo {
return DefinitionInfo{Name: c.Name, Line: c.Line}
}
|
[
"func",
"(",
"c",
"*",
"Constant",
")",
"Info",
"(",
")",
"DefinitionInfo",
"{",
"return",
"DefinitionInfo",
"{",
"Name",
":",
"c",
".",
"Name",
",",
"Line",
":",
"c",
".",
"Line",
"}",
"\n",
"}"
] |
// Info for Constant
|
[
"Info",
"for",
"Constant"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/definition.go#L61-L63
|
17,620 |
thriftrw/thriftrw-go
|
ast/definition.go
|
Info
|
func (t *Typedef) Info() DefinitionInfo {
return DefinitionInfo{Name: t.Name, Line: t.Line}
}
|
go
|
func (t *Typedef) Info() DefinitionInfo {
return DefinitionInfo{Name: t.Name, Line: t.Line}
}
|
[
"func",
"(",
"t",
"*",
"Typedef",
")",
"Info",
"(",
")",
"DefinitionInfo",
"{",
"return",
"DefinitionInfo",
"{",
"Name",
":",
"t",
".",
"Name",
",",
"Line",
":",
"t",
".",
"Line",
"}",
"\n",
"}"
] |
// Info for Typedef.
|
[
"Info",
"for",
"Typedef",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/definition.go#L91-L93
|
17,621 |
thriftrw/thriftrw-go
|
ast/definition.go
|
Info
|
func (e *Enum) Info() DefinitionInfo {
return DefinitionInfo{Name: e.Name, Line: e.Line}
}
|
go
|
func (e *Enum) Info() DefinitionInfo {
return DefinitionInfo{Name: e.Name, Line: e.Line}
}
|
[
"func",
"(",
"e",
"*",
"Enum",
")",
"Info",
"(",
")",
"DefinitionInfo",
"{",
"return",
"DefinitionInfo",
"{",
"Name",
":",
"e",
".",
"Name",
",",
"Line",
":",
"e",
".",
"Line",
"}",
"\n",
"}"
] |
// Info for Enum.
|
[
"Info",
"for",
"Enum",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/definition.go#L128-L130
|
17,622 |
thriftrw/thriftrw-go
|
ast/definition.go
|
Info
|
func (s *Struct) Info() DefinitionInfo {
return DefinitionInfo{Name: s.Name, Line: s.Line}
}
|
go
|
func (s *Struct) Info() DefinitionInfo {
return DefinitionInfo{Name: s.Name, Line: s.Line}
}
|
[
"func",
"(",
"s",
"*",
"Struct",
")",
"Info",
"(",
")",
"DefinitionInfo",
"{",
"return",
"DefinitionInfo",
"{",
"Name",
":",
"s",
".",
"Name",
",",
"Line",
":",
"s",
".",
"Line",
"}",
"\n",
"}"
] |
// Info for Struct.
|
[
"Info",
"for",
"Struct",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/definition.go#L207-L209
|
17,623 |
thriftrw/thriftrw-go
|
ast/definition.go
|
Info
|
func (s *Service) Info() DefinitionInfo {
return DefinitionInfo{Name: s.Name, Line: s.Line}
}
|
go
|
func (s *Service) Info() DefinitionInfo {
return DefinitionInfo{Name: s.Name, Line: s.Line}
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"Info",
"(",
")",
"DefinitionInfo",
"{",
"return",
"DefinitionInfo",
"{",
"Name",
":",
"s",
".",
"Name",
",",
"Line",
":",
"s",
".",
"Line",
"}",
"\n",
"}"
] |
// Info for Service.
|
[
"Info",
"for",
"Service",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/definition.go#L243-L245
|
17,624 |
thriftrw/thriftrw-go
|
gen/generator.go
|
curryGenerator
|
func curryGenerator(f interface{}, g Generator) interface{} {
typ := reflect.TypeOf(f)
if typ.NumIn() > 0 && typ.In(0) == _typeOfGenerator {
return curry.One(f, g)
}
return f
}
|
go
|
func curryGenerator(f interface{}, g Generator) interface{} {
typ := reflect.TypeOf(f)
if typ.NumIn() > 0 && typ.In(0) == _typeOfGenerator {
return curry.One(f, g)
}
return f
}
|
[
"func",
"curryGenerator",
"(",
"f",
"interface",
"{",
"}",
",",
"g",
"Generator",
")",
"interface",
"{",
"}",
"{",
"typ",
":=",
"reflect",
".",
"TypeOf",
"(",
"f",
")",
"\n",
"if",
"typ",
".",
"NumIn",
"(",
")",
">",
"0",
"&&",
"typ",
".",
"In",
"(",
"0",
")",
"==",
"_typeOfGenerator",
"{",
"return",
"curry",
".",
"One",
"(",
"f",
",",
"g",
")",
"\n",
"}",
"\n",
"return",
"f",
"\n",
"}"
] |
// curryGenerator adds g as the first argument to f if f accepts it. Otherwise f
// is returned unmodified.
|
[
"curryGenerator",
"adds",
"g",
"as",
"the",
"first",
"argument",
"to",
"f",
"if",
"f",
"accepts",
"it",
".",
"Otherwise",
"f",
"is",
"returned",
"unmodified",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/generator.go#L113-L119
|
17,625 |
thriftrw/thriftrw-go
|
gen/generator.go
|
NewGenerator
|
func NewGenerator(o *GeneratorOptions) Generator {
// TODO(abg): Determine package name from `namespace go` directive.
namespace := NewNamespace()
return &generator{
PackageName: o.PackageName,
ImportPath: o.ImportPath,
Namespace: namespace,
importer: newImporter(namespace.Child()),
mangler: newMangler(),
thriftImporter: o.Importer,
fset: token.NewFileSet(),
noZap: o.NoZap,
}
}
|
go
|
func NewGenerator(o *GeneratorOptions) Generator {
// TODO(abg): Determine package name from `namespace go` directive.
namespace := NewNamespace()
return &generator{
PackageName: o.PackageName,
ImportPath: o.ImportPath,
Namespace: namespace,
importer: newImporter(namespace.Child()),
mangler: newMangler(),
thriftImporter: o.Importer,
fset: token.NewFileSet(),
noZap: o.NoZap,
}
}
|
[
"func",
"NewGenerator",
"(",
"o",
"*",
"GeneratorOptions",
")",
"Generator",
"{",
"// TODO(abg): Determine package name from `namespace go` directive.",
"namespace",
":=",
"NewNamespace",
"(",
")",
"\n",
"return",
"&",
"generator",
"{",
"PackageName",
":",
"o",
".",
"PackageName",
",",
"ImportPath",
":",
"o",
".",
"ImportPath",
",",
"Namespace",
":",
"namespace",
",",
"importer",
":",
"newImporter",
"(",
"namespace",
".",
"Child",
"(",
")",
")",
",",
"mangler",
":",
"newMangler",
"(",
")",
",",
"thriftImporter",
":",
"o",
".",
"Importer",
",",
"fset",
":",
"token",
".",
"NewFileSet",
"(",
")",
",",
"noZap",
":",
"o",
".",
"NoZap",
",",
"}",
"\n",
"}"
] |
// NewGenerator sets up a new generator for Go code.
|
[
"NewGenerator",
"sets",
"up",
"a",
"new",
"generator",
"for",
"Go",
"code",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/generator.go#L153-L166
|
17,626 |
thriftrw/thriftrw-go
|
gen/generator.go
|
checkNoZap
|
func checkNoZap(g Generator) bool {
if gen, ok := g.(*generator); ok {
return gen.noZap
}
return false
}
|
go
|
func checkNoZap(g Generator) bool {
if gen, ok := g.(*generator); ok {
return gen.noZap
}
return false
}
|
[
"func",
"checkNoZap",
"(",
"g",
"Generator",
")",
"bool",
"{",
"if",
"gen",
",",
"ok",
":=",
"g",
".",
"(",
"*",
"generator",
")",
";",
"ok",
"{",
"return",
"gen",
".",
"noZap",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// checkNoZap returns whether the NoZap flag is passed.
|
[
"checkNoZap",
"returns",
"whether",
"the",
"NoZap",
"flag",
"is",
"passed",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/generator.go#L169-L174
|
17,627 |
thriftrw/thriftrw-go
|
gen/generator.go
|
TextTemplate
|
func (g *generator) TextTemplate(s string, data interface{}, opts ...TemplateOption) (string, error) {
templateFuncs := template.FuncMap{
"formatDoc": formatDoc,
"goCase": goCase,
"goName": goName,
"import": g.Import,
"isHashable": isHashable,
"setUsesMap": setUsesMap,
"isPrimitiveType": isPrimitiveType,
"isStructType": isStructType,
"newNamespace": g.Namespace.Child,
"newVar": g.Namespace.Child().NewName,
"typeName": curryGenerator(typeName, g),
"typeReference": curryGenerator(typeReference, g),
"typeReferencePtr": curryGenerator(typeReferencePtr, g),
"fromWire": curryGenerator(g.w.FromWire, g),
"fromWirePtr": curryGenerator(g.w.FromWirePtr, g),
"toWire": curryGenerator(g.w.ToWire, g),
"toWirePtr": curryGenerator(g.w.ToWirePtr, g),
"typeCode": curryGenerator(TypeCode, g),
"equals": curryGenerator(g.e.Equals, g),
"equalsPtr": curryGenerator(g.e.EqualsPtr, g),
"zapEncodeBegin": curryGenerator(g.z.zapEncodeBegin, g),
"zapEncodeEnd": g.z.zapEncodeEnd,
"zapEncoder": curryGenerator(g.z.zapEncoder, g),
"zapMarshaler": curryGenerator(g.z.zapMarshaler, g),
"zapMarshalerPtr": curryGenerator(g.z.zapMarshalerPtr, g),
}
tmpl := template.New("thriftrw").Delims("<", ">").Funcs(templateFuncs)
for _, opt := range opts {
tmpl = opt(g, tmpl)
}
tmpl, err := tmpl.Parse(s)
if err != nil {
return "", err
}
buff := bytes.Buffer{}
if err := tmpl.Execute(&buff, data); err != nil {
return "", err
}
return buff.String(), nil
}
|
go
|
func (g *generator) TextTemplate(s string, data interface{}, opts ...TemplateOption) (string, error) {
templateFuncs := template.FuncMap{
"formatDoc": formatDoc,
"goCase": goCase,
"goName": goName,
"import": g.Import,
"isHashable": isHashable,
"setUsesMap": setUsesMap,
"isPrimitiveType": isPrimitiveType,
"isStructType": isStructType,
"newNamespace": g.Namespace.Child,
"newVar": g.Namespace.Child().NewName,
"typeName": curryGenerator(typeName, g),
"typeReference": curryGenerator(typeReference, g),
"typeReferencePtr": curryGenerator(typeReferencePtr, g),
"fromWire": curryGenerator(g.w.FromWire, g),
"fromWirePtr": curryGenerator(g.w.FromWirePtr, g),
"toWire": curryGenerator(g.w.ToWire, g),
"toWirePtr": curryGenerator(g.w.ToWirePtr, g),
"typeCode": curryGenerator(TypeCode, g),
"equals": curryGenerator(g.e.Equals, g),
"equalsPtr": curryGenerator(g.e.EqualsPtr, g),
"zapEncodeBegin": curryGenerator(g.z.zapEncodeBegin, g),
"zapEncodeEnd": g.z.zapEncodeEnd,
"zapEncoder": curryGenerator(g.z.zapEncoder, g),
"zapMarshaler": curryGenerator(g.z.zapMarshaler, g),
"zapMarshalerPtr": curryGenerator(g.z.zapMarshalerPtr, g),
}
tmpl := template.New("thriftrw").Delims("<", ">").Funcs(templateFuncs)
for _, opt := range opts {
tmpl = opt(g, tmpl)
}
tmpl, err := tmpl.Parse(s)
if err != nil {
return "", err
}
buff := bytes.Buffer{}
if err := tmpl.Execute(&buff, data); err != nil {
return "", err
}
return buff.String(), nil
}
|
[
"func",
"(",
"g",
"*",
"generator",
")",
"TextTemplate",
"(",
"s",
"string",
",",
"data",
"interface",
"{",
"}",
",",
"opts",
"...",
"TemplateOption",
")",
"(",
"string",
",",
"error",
")",
"{",
"templateFuncs",
":=",
"template",
".",
"FuncMap",
"{",
"\"",
"\"",
":",
"formatDoc",
",",
"\"",
"\"",
":",
"goCase",
",",
"\"",
"\"",
":",
"goName",
",",
"\"",
"\"",
":",
"g",
".",
"Import",
",",
"\"",
"\"",
":",
"isHashable",
",",
"\"",
"\"",
":",
"setUsesMap",
",",
"\"",
"\"",
":",
"isPrimitiveType",
",",
"\"",
"\"",
":",
"isStructType",
",",
"\"",
"\"",
":",
"g",
".",
"Namespace",
".",
"Child",
",",
"\"",
"\"",
":",
"g",
".",
"Namespace",
".",
"Child",
"(",
")",
".",
"NewName",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"typeName",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"typeReference",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"typeReferencePtr",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"w",
".",
"FromWire",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"w",
".",
"FromWirePtr",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"w",
".",
"ToWire",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"w",
".",
"ToWirePtr",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"TypeCode",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"e",
".",
"Equals",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"e",
".",
"EqualsPtr",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"z",
".",
"zapEncodeBegin",
",",
"g",
")",
",",
"\"",
"\"",
":",
"g",
".",
"z",
".",
"zapEncodeEnd",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"z",
".",
"zapEncoder",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"z",
".",
"zapMarshaler",
",",
"g",
")",
",",
"\"",
"\"",
":",
"curryGenerator",
"(",
"g",
".",
"z",
".",
"zapMarshalerPtr",
",",
"g",
")",
",",
"}",
"\n\n",
"tmpl",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Delims",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Funcs",
"(",
"templateFuncs",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"tmpl",
"=",
"opt",
"(",
"g",
",",
"tmpl",
")",
"\n",
"}",
"\n\n",
"tmpl",
",",
"err",
":=",
"tmpl",
".",
"Parse",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"buff",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"if",
"err",
":=",
"tmpl",
".",
"Execute",
"(",
"&",
"buff",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"buff",
".",
"String",
"(",
")",
",",
"nil",
"\n\n",
"}"
] |
// TextTemplate renders the given template with the given template context.
|
[
"TextTemplate",
"renders",
"the",
"given",
"template",
"with",
"the",
"given",
"template",
"context",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/generator.go#L217-L263
|
17,628 |
thriftrw/thriftrw-go
|
gen/generator.go
|
appendDecl
|
func (g *generator) appendDecl(decl ast.Decl) {
g.decls = append(g.decls, decl)
}
|
go
|
func (g *generator) appendDecl(decl ast.Decl) {
g.decls = append(g.decls, decl)
}
|
[
"func",
"(",
"g",
"*",
"generator",
")",
"appendDecl",
"(",
"decl",
"ast",
".",
"Decl",
")",
"{",
"g",
".",
"decls",
"=",
"append",
"(",
"g",
".",
"decls",
",",
"decl",
")",
"\n",
"}"
] |
// appendDecl appends a new declaration to the generator.
|
[
"appendDecl",
"appends",
"a",
"new",
"declaration",
"to",
"the",
"generator",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/generator.go#L515-L517
|
17,629 |
thriftrw/thriftrw-go
|
gen/generate.go
|
Generate
|
func Generate(m *compile.Module, o *Options) error {
if !filepath.IsAbs(o.ThriftRoot) {
return fmt.Errorf(
"ThriftRoot must be an absolute path: %q is not absolute",
o.ThriftRoot)
}
if !filepath.IsAbs(o.OutputDir) {
return fmt.Errorf(
"OutputDir must be an absolute path: %q is not absolute",
o.OutputDir)
}
importer := thriftPackageImporter{
ImportPrefix: o.PackagePrefix,
ThriftRoot: o.ThriftRoot,
}
// Mapping of filenames relative to OutputDir to their contents.
files := make(map[string][]byte)
genBuilder := newGenerateServiceBuilder(importer)
generate := func(m *compile.Module) error {
moduleFiles, err := generateModule(m, importer, genBuilder, o)
if err != nil {
return generateError{Name: m.ThriftPath, Reason: err}
}
if err := mergeFiles(files, moduleFiles); err != nil {
return generateError{Name: m.ThriftPath, Reason: err}
}
return nil
}
// Note that we call generate directly on only those modules that we need
// to generate code for. If the user used --no-recurse, we're not going to
// generate code for included modules.
if o.NoRecurse {
if err := generate(m); err != nil {
return err
}
} else {
if err := m.Walk(generate); err != nil {
return err
}
}
plug := o.Plugin
if plug == nil {
plug = plugin.EmptyHandle
}
if sgen := plug.ServiceGenerator(); sgen != nil {
res, err := sgen.Generate(genBuilder.Build())
if err != nil {
return err
}
if err := mergeFiles(files, res.Files); err != nil {
return err
}
}
for relPath, contents := range files {
fullPath := filepath.Join(o.OutputDir, relPath)
directory := filepath.Dir(fullPath)
if err := os.MkdirAll(directory, 0755); err != nil {
return fmt.Errorf("could not create directory %q: %v", directory, err)
}
if err := ioutil.WriteFile(fullPath, contents, 0644); err != nil {
return fmt.Errorf("failed to write %q: %v", fullPath, err)
}
}
return nil
}
|
go
|
func Generate(m *compile.Module, o *Options) error {
if !filepath.IsAbs(o.ThriftRoot) {
return fmt.Errorf(
"ThriftRoot must be an absolute path: %q is not absolute",
o.ThriftRoot)
}
if !filepath.IsAbs(o.OutputDir) {
return fmt.Errorf(
"OutputDir must be an absolute path: %q is not absolute",
o.OutputDir)
}
importer := thriftPackageImporter{
ImportPrefix: o.PackagePrefix,
ThriftRoot: o.ThriftRoot,
}
// Mapping of filenames relative to OutputDir to their contents.
files := make(map[string][]byte)
genBuilder := newGenerateServiceBuilder(importer)
generate := func(m *compile.Module) error {
moduleFiles, err := generateModule(m, importer, genBuilder, o)
if err != nil {
return generateError{Name: m.ThriftPath, Reason: err}
}
if err := mergeFiles(files, moduleFiles); err != nil {
return generateError{Name: m.ThriftPath, Reason: err}
}
return nil
}
// Note that we call generate directly on only those modules that we need
// to generate code for. If the user used --no-recurse, we're not going to
// generate code for included modules.
if o.NoRecurse {
if err := generate(m); err != nil {
return err
}
} else {
if err := m.Walk(generate); err != nil {
return err
}
}
plug := o.Plugin
if plug == nil {
plug = plugin.EmptyHandle
}
if sgen := plug.ServiceGenerator(); sgen != nil {
res, err := sgen.Generate(genBuilder.Build())
if err != nil {
return err
}
if err := mergeFiles(files, res.Files); err != nil {
return err
}
}
for relPath, contents := range files {
fullPath := filepath.Join(o.OutputDir, relPath)
directory := filepath.Dir(fullPath)
if err := os.MkdirAll(directory, 0755); err != nil {
return fmt.Errorf("could not create directory %q: %v", directory, err)
}
if err := ioutil.WriteFile(fullPath, contents, 0644); err != nil {
return fmt.Errorf("failed to write %q: %v", fullPath, err)
}
}
return nil
}
|
[
"func",
"Generate",
"(",
"m",
"*",
"compile",
".",
"Module",
",",
"o",
"*",
"Options",
")",
"error",
"{",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"o",
".",
"ThriftRoot",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
".",
"ThriftRoot",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"o",
".",
"OutputDir",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"o",
".",
"OutputDir",
")",
"\n",
"}",
"\n\n",
"importer",
":=",
"thriftPackageImporter",
"{",
"ImportPrefix",
":",
"o",
".",
"PackagePrefix",
",",
"ThriftRoot",
":",
"o",
".",
"ThriftRoot",
",",
"}",
"\n\n",
"// Mapping of filenames relative to OutputDir to their contents.",
"files",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
")",
"\n",
"genBuilder",
":=",
"newGenerateServiceBuilder",
"(",
"importer",
")",
"\n\n",
"generate",
":=",
"func",
"(",
"m",
"*",
"compile",
".",
"Module",
")",
"error",
"{",
"moduleFiles",
",",
"err",
":=",
"generateModule",
"(",
"m",
",",
"importer",
",",
"genBuilder",
",",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"generateError",
"{",
"Name",
":",
"m",
".",
"ThriftPath",
",",
"Reason",
":",
"err",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"mergeFiles",
"(",
"files",
",",
"moduleFiles",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"generateError",
"{",
"Name",
":",
"m",
".",
"ThriftPath",
",",
"Reason",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Note that we call generate directly on only those modules that we need",
"// to generate code for. If the user used --no-recurse, we're not going to",
"// generate code for included modules.",
"if",
"o",
".",
"NoRecurse",
"{",
"if",
"err",
":=",
"generate",
"(",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"m",
".",
"Walk",
"(",
"generate",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"plug",
":=",
"o",
".",
"Plugin",
"\n",
"if",
"plug",
"==",
"nil",
"{",
"plug",
"=",
"plugin",
".",
"EmptyHandle",
"\n",
"}",
"\n\n",
"if",
"sgen",
":=",
"plug",
".",
"ServiceGenerator",
"(",
")",
";",
"sgen",
"!=",
"nil",
"{",
"res",
",",
"err",
":=",
"sgen",
".",
"Generate",
"(",
"genBuilder",
".",
"Build",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"mergeFiles",
"(",
"files",
",",
"res",
".",
"Files",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"relPath",
",",
"contents",
":=",
"range",
"files",
"{",
"fullPath",
":=",
"filepath",
".",
"Join",
"(",
"o",
".",
"OutputDir",
",",
"relPath",
")",
"\n",
"directory",
":=",
"filepath",
".",
"Dir",
"(",
"fullPath",
")",
"\n\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"directory",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"directory",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"fullPath",
",",
"contents",
",",
"0644",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"fullPath",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Generate generates code based on the given options.
|
[
"Generate",
"generates",
"code",
"based",
"on",
"the",
"given",
"options",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/generate.go#L82-L158
|
17,630 |
thriftrw/thriftrw-go
|
ast/visitor.go
|
Visit
|
func (f VisitorFunc) Visit(w Walker, n Node) Visitor {
f(w, n)
return f
}
|
go
|
func (f VisitorFunc) Visit(w Walker, n Node) Visitor {
f(w, n)
return f
}
|
[
"func",
"(",
"f",
"VisitorFunc",
")",
"Visit",
"(",
"w",
"Walker",
",",
"n",
"Node",
")",
"Visitor",
"{",
"f",
"(",
"w",
",",
"n",
")",
"\n",
"return",
"f",
"\n",
"}"
] |
// Visit the given node and its descendants.
|
[
"Visit",
"the",
"given",
"node",
"and",
"its",
"descendants",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/visitor.go#L48-L51
|
17,631 |
thriftrw/thriftrw-go
|
internal/plugin/flag.go
|
Handle
|
func (f *Flag) Handle() (Handle, error) {
transport, err := process.NewClient(f.Command)
if err != nil {
return nil, fmt.Errorf("failed to open plugin %q: %v", f.Name, err)
}
handle, err := NewTransportHandle(f.Name, transport)
if err != nil {
return nil, multierr.Combine(
fmt.Errorf("failed to open plugin %q: %v", f.Name, err),
transport.Close(),
)
}
return handle, nil
}
|
go
|
func (f *Flag) Handle() (Handle, error) {
transport, err := process.NewClient(f.Command)
if err != nil {
return nil, fmt.Errorf("failed to open plugin %q: %v", f.Name, err)
}
handle, err := NewTransportHandle(f.Name, transport)
if err != nil {
return nil, multierr.Combine(
fmt.Errorf("failed to open plugin %q: %v", f.Name, err),
transport.Close(),
)
}
return handle, nil
}
|
[
"func",
"(",
"f",
"*",
"Flag",
")",
"Handle",
"(",
")",
"(",
"Handle",
",",
"error",
")",
"{",
"transport",
",",
"err",
":=",
"process",
".",
"NewClient",
"(",
"f",
".",
"Command",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"handle",
",",
"err",
":=",
"NewTransportHandle",
"(",
"f",
".",
"Name",
",",
"transport",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"multierr",
".",
"Combine",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
",",
"err",
")",
",",
"transport",
".",
"Close",
"(",
")",
",",
")",
"\n",
"}",
"\n\n",
"return",
"handle",
",",
"nil",
"\n",
"}"
] |
// Handle gets a Handle to this plugin specification.
//
// The returned handle MUST be closed by the caller if error was nil.
|
[
"Handle",
"gets",
"a",
"Handle",
"to",
"this",
"plugin",
"specification",
".",
"The",
"returned",
"handle",
"MUST",
"be",
"closed",
"by",
"the",
"caller",
"if",
"error",
"was",
"nil",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/flag.go#L57-L72
|
17,632 |
thriftrw/thriftrw-go
|
internal/plugin/flag.go
|
UnmarshalFlag
|
func (f *Flag) UnmarshalFlag(value string) error {
tokens, err := shlex.Split(value, true /* posix */)
if err != nil {
return fmt.Errorf("invalid plugin %q: %v", value, err)
}
if len(tokens) < 1 {
return fmt.Errorf("invalid plugin %q: please provide a name", value)
}
f.Name = tokens[0]
exe := _pluginExecPrefix + f.Name
path, err := exec.LookPath(exe)
if err != nil {
return fmt.Errorf("invalid plugin %q: could not find executable %q: %v", value, exe, err)
}
cmd := exec.Command(path, tokens[1:]...)
cmd.Stderr = os.Stderr // connect stderr so that plugins can log
f.Command = cmd
return nil
}
|
go
|
func (f *Flag) UnmarshalFlag(value string) error {
tokens, err := shlex.Split(value, true /* posix */)
if err != nil {
return fmt.Errorf("invalid plugin %q: %v", value, err)
}
if len(tokens) < 1 {
return fmt.Errorf("invalid plugin %q: please provide a name", value)
}
f.Name = tokens[0]
exe := _pluginExecPrefix + f.Name
path, err := exec.LookPath(exe)
if err != nil {
return fmt.Errorf("invalid plugin %q: could not find executable %q: %v", value, exe, err)
}
cmd := exec.Command(path, tokens[1:]...)
cmd.Stderr = os.Stderr // connect stderr so that plugins can log
f.Command = cmd
return nil
}
|
[
"func",
"(",
"f",
"*",
"Flag",
")",
"UnmarshalFlag",
"(",
"value",
"string",
")",
"error",
"{",
"tokens",
",",
"err",
":=",
"shlex",
".",
"Split",
"(",
"value",
",",
"true",
"/* posix */",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"tokens",
")",
"<",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
")",
"\n",
"}",
"\n\n",
"f",
".",
"Name",
"=",
"tokens",
"[",
"0",
"]",
"\n",
"exe",
":=",
"_pluginExecPrefix",
"+",
"f",
".",
"Name",
"\n",
"path",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"exe",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
",",
"exe",
",",
"err",
")",
"\n",
"}",
"\n\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"path",
",",
"tokens",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"// connect stderr so that plugins can log",
"\n\n",
"f",
".",
"Command",
"=",
"cmd",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalFlag parses a string specification of a plugin.
|
[
"UnmarshalFlag",
"parses",
"a",
"string",
"specification",
"of",
"a",
"plugin",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/flag.go#L75-L97
|
17,633 |
thriftrw/thriftrw-go
|
internal/plugin/flag.go
|
Handle
|
func (fs Flags) Handle() (MultiHandle, error) {
var (
lock sync.Mutex
multi MultiHandle
)
err := concurrent.Range(fs, func(_ int, f Flag) error {
h, err := f.Handle()
if err != nil {
return err
}
lock.Lock()
defer lock.Unlock()
multi = append(multi, h)
return nil
})
if err == nil {
return multi, nil
}
return nil, multierr.Append(err, multi.Close())
}
|
go
|
func (fs Flags) Handle() (MultiHandle, error) {
var (
lock sync.Mutex
multi MultiHandle
)
err := concurrent.Range(fs, func(_ int, f Flag) error {
h, err := f.Handle()
if err != nil {
return err
}
lock.Lock()
defer lock.Unlock()
multi = append(multi, h)
return nil
})
if err == nil {
return multi, nil
}
return nil, multierr.Append(err, multi.Close())
}
|
[
"func",
"(",
"fs",
"Flags",
")",
"Handle",
"(",
")",
"(",
"MultiHandle",
",",
"error",
")",
"{",
"var",
"(",
"lock",
"sync",
".",
"Mutex",
"\n",
"multi",
"MultiHandle",
"\n",
")",
"\n\n",
"err",
":=",
"concurrent",
".",
"Range",
"(",
"fs",
",",
"func",
"(",
"_",
"int",
",",
"f",
"Flag",
")",
"error",
"{",
"h",
",",
"err",
":=",
"f",
".",
"Handle",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"multi",
"=",
"append",
"(",
"multi",
",",
"h",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"multi",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"multierr",
".",
"Append",
"(",
"err",
",",
"multi",
".",
"Close",
"(",
")",
")",
"\n",
"}"
] |
// Handle gets a MultiHandle to all the plugins in this list or nil if the
// list is empty.
//
// The returned handle MUST be closed by the caller if error was nil.
|
[
"Handle",
"gets",
"a",
"MultiHandle",
"to",
"all",
"the",
"plugins",
"in",
"this",
"list",
"or",
"nil",
"if",
"the",
"list",
"is",
"empty",
".",
"The",
"returned",
"handle",
"MUST",
"be",
"closed",
"by",
"the",
"caller",
"if",
"error",
"was",
"nil",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/plugin/flag.go#L106-L130
|
17,634 |
thriftrw/thriftrw-go
|
gen/wire.go
|
ToWirePtr
|
func (w *WireGenerator) ToWirePtr(g Generator, spec compile.TypeSpec, varName string) (string, error) {
switch spec.(type) {
case *compile.BoolSpec, *compile.I8Spec, *compile.I16Spec, *compile.I32Spec,
*compile.I64Spec, *compile.DoubleSpec, *compile.StringSpec:
return w.ToWire(g, spec, fmt.Sprintf("*(%s)", varName))
default:
// Everything else is either a reference type or has a ToWire method
// on it that does automatic dereferencing.
return w.ToWire(g, spec, varName)
}
}
|
go
|
func (w *WireGenerator) ToWirePtr(g Generator, spec compile.TypeSpec, varName string) (string, error) {
switch spec.(type) {
case *compile.BoolSpec, *compile.I8Spec, *compile.I16Spec, *compile.I32Spec,
*compile.I64Spec, *compile.DoubleSpec, *compile.StringSpec:
return w.ToWire(g, spec, fmt.Sprintf("*(%s)", varName))
default:
// Everything else is either a reference type or has a ToWire method
// on it that does automatic dereferencing.
return w.ToWire(g, spec, varName)
}
}
|
[
"func",
"(",
"w",
"*",
"WireGenerator",
")",
"ToWirePtr",
"(",
"g",
"Generator",
",",
"spec",
"compile",
".",
"TypeSpec",
",",
"varName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"switch",
"spec",
".",
"(",
"type",
")",
"{",
"case",
"*",
"compile",
".",
"BoolSpec",
",",
"*",
"compile",
".",
"I8Spec",
",",
"*",
"compile",
".",
"I16Spec",
",",
"*",
"compile",
".",
"I32Spec",
",",
"*",
"compile",
".",
"I64Spec",
",",
"*",
"compile",
".",
"DoubleSpec",
",",
"*",
"compile",
".",
"StringSpec",
":",
"return",
"w",
".",
"ToWire",
"(",
"g",
",",
"spec",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"varName",
")",
")",
"\n",
"default",
":",
"// Everything else is either a reference type or has a ToWire method",
"// on it that does automatic dereferencing.",
"return",
"w",
".",
"ToWire",
"(",
"g",
",",
"spec",
",",
"varName",
")",
"\n",
"}",
"\n",
"}"
] |
// ToWirePtr is the same as ToWire expect `varName` is expected to be a
// reference to a value of the given type.
|
[
"ToWirePtr",
"is",
"the",
"same",
"as",
"ToWire",
"expect",
"varName",
"is",
"expected",
"to",
"be",
"a",
"reference",
"to",
"a",
"value",
"of",
"the",
"given",
"type",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/wire.go#L115-L125
|
17,635 |
thriftrw/thriftrw-go
|
gen/wire.go
|
FromWirePtr
|
func (w *WireGenerator) FromWirePtr(g Generator, spec compile.TypeSpec, lhs string, value string) (string, error) {
if !isPrimitiveType(spec) {
// Everything else can be assigned to directly.
out, err := w.FromWire(g, spec, value)
if err != nil {
return "", err
}
return fmt.Sprintf("%s, err = %s", lhs, out), err
}
return g.TextTemplate(
`
<- $x := newVar "x" ->
var <$x> <typeReference .Spec>
<$x>, err = <fromWire .Spec .Value>
<.LHS> = &<$x ->
`,
struct {
Spec compile.TypeSpec
LHS string
Value string
}{Spec: spec, LHS: lhs, Value: value},
)
}
|
go
|
func (w *WireGenerator) FromWirePtr(g Generator, spec compile.TypeSpec, lhs string, value string) (string, error) {
if !isPrimitiveType(spec) {
// Everything else can be assigned to directly.
out, err := w.FromWire(g, spec, value)
if err != nil {
return "", err
}
return fmt.Sprintf("%s, err = %s", lhs, out), err
}
return g.TextTemplate(
`
<- $x := newVar "x" ->
var <$x> <typeReference .Spec>
<$x>, err = <fromWire .Spec .Value>
<.LHS> = &<$x ->
`,
struct {
Spec compile.TypeSpec
LHS string
Value string
}{Spec: spec, LHS: lhs, Value: value},
)
}
|
[
"func",
"(",
"w",
"*",
"WireGenerator",
")",
"FromWirePtr",
"(",
"g",
"Generator",
",",
"spec",
"compile",
".",
"TypeSpec",
",",
"lhs",
"string",
",",
"value",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"isPrimitiveType",
"(",
"spec",
")",
"{",
"// Everything else can be assigned to directly.",
"out",
",",
"err",
":=",
"w",
".",
"FromWire",
"(",
"g",
",",
"spec",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"lhs",
",",
"out",
")",
",",
"err",
"\n",
"}",
"\n",
"return",
"g",
".",
"TextTemplate",
"(",
"`\n\t\t\t<- $x := newVar \"x\" ->\n\t\t\tvar <$x> <typeReference .Spec>\n\t\t\t<$x>, err = <fromWire .Spec .Value>\n\t\t\t<.LHS> = &<$x ->\n\t\t\t`",
",",
"struct",
"{",
"Spec",
"compile",
".",
"TypeSpec",
"\n",
"LHS",
"string",
"\n",
"Value",
"string",
"\n",
"}",
"{",
"Spec",
":",
"spec",
",",
"LHS",
":",
"lhs",
",",
"Value",
":",
"value",
"}",
",",
")",
"\n",
"}"
] |
// FromWirePtr generates a string assigning the given Value to the given lhs,
// which is a pointer to a value of the given type.
//
// A variable err of type error MUST be in scope and will be assigned the
// parse error, if any.
|
[
"FromWirePtr",
"generates",
"a",
"string",
"assigning",
"the",
"given",
"Value",
"to",
"the",
"given",
"lhs",
"which",
"is",
"a",
"pointer",
"to",
"a",
"value",
"of",
"the",
"given",
"type",
".",
"A",
"variable",
"err",
"of",
"type",
"error",
"MUST",
"be",
"in",
"scope",
"and",
"will",
"be",
"assigned",
"the",
"parse",
"error",
"if",
"any",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/wire.go#L193-L215
|
17,636 |
thriftrw/thriftrw-go
|
gen/wire.go
|
TypeCode
|
func TypeCode(g Generator, spec compile.TypeSpec) string {
wire := g.Import("go.uber.org/thriftrw/wire")
spec = compile.RootTypeSpec(spec)
switch spec.(type) {
case *compile.BoolSpec:
return fmt.Sprintf("%s.TBool", wire)
case *compile.I8Spec:
return fmt.Sprintf("%s.TI8", wire)
case *compile.I16Spec:
return fmt.Sprintf("%s.TI16", wire)
case *compile.I32Spec:
return fmt.Sprintf("%s.TI32", wire)
case *compile.I64Spec:
return fmt.Sprintf("%s.TI64", wire)
case *compile.DoubleSpec:
return fmt.Sprintf("%s.TDouble", wire)
case *compile.StringSpec, *compile.BinarySpec:
return fmt.Sprintf("%s.TBinary", wire)
case *compile.MapSpec:
return fmt.Sprintf("%s.TMap", wire)
case *compile.ListSpec:
return fmt.Sprintf("%s.TList", wire)
case *compile.SetSpec:
return fmt.Sprintf("%s.TSet", wire)
case *compile.EnumSpec:
return fmt.Sprintf("%s.TI32", wire)
case *compile.StructSpec:
return fmt.Sprintf("%s.TStruct", wire)
default:
panic(fmt.Sprintf("unknown type spec %v (type %T)", spec, spec))
}
}
|
go
|
func TypeCode(g Generator, spec compile.TypeSpec) string {
wire := g.Import("go.uber.org/thriftrw/wire")
spec = compile.RootTypeSpec(spec)
switch spec.(type) {
case *compile.BoolSpec:
return fmt.Sprintf("%s.TBool", wire)
case *compile.I8Spec:
return fmt.Sprintf("%s.TI8", wire)
case *compile.I16Spec:
return fmt.Sprintf("%s.TI16", wire)
case *compile.I32Spec:
return fmt.Sprintf("%s.TI32", wire)
case *compile.I64Spec:
return fmt.Sprintf("%s.TI64", wire)
case *compile.DoubleSpec:
return fmt.Sprintf("%s.TDouble", wire)
case *compile.StringSpec, *compile.BinarySpec:
return fmt.Sprintf("%s.TBinary", wire)
case *compile.MapSpec:
return fmt.Sprintf("%s.TMap", wire)
case *compile.ListSpec:
return fmt.Sprintf("%s.TList", wire)
case *compile.SetSpec:
return fmt.Sprintf("%s.TSet", wire)
case *compile.EnumSpec:
return fmt.Sprintf("%s.TI32", wire)
case *compile.StructSpec:
return fmt.Sprintf("%s.TStruct", wire)
default:
panic(fmt.Sprintf("unknown type spec %v (type %T)", spec, spec))
}
}
|
[
"func",
"TypeCode",
"(",
"g",
"Generator",
",",
"spec",
"compile",
".",
"TypeSpec",
")",
"string",
"{",
"wire",
":=",
"g",
".",
"Import",
"(",
"\"",
"\"",
")",
"\n",
"spec",
"=",
"compile",
".",
"RootTypeSpec",
"(",
"spec",
")",
"\n\n",
"switch",
"spec",
".",
"(",
"type",
")",
"{",
"case",
"*",
"compile",
".",
"BoolSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"I8Spec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"I16Spec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"I32Spec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"I64Spec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"DoubleSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"StringSpec",
",",
"*",
"compile",
".",
"BinarySpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"MapSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"ListSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"SetSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"EnumSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"case",
"*",
"compile",
".",
"StructSpec",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"wire",
")",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"spec",
",",
"spec",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// TypeCode gets an expression of type 'wire.Type' that represents the
// over-the-wire type code for the given TypeSpec.
|
[
"TypeCode",
"gets",
"an",
"expression",
"of",
"type",
"wire",
".",
"Type",
"that",
"represents",
"the",
"over",
"-",
"the",
"-",
"wire",
"type",
"code",
"for",
"the",
"given",
"TypeSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/wire.go#L219-L251
|
17,637 |
thriftrw/thriftrw-go
|
compile/field.go
|
isRequired
|
func (r fieldRequiredness) isRequired(src *ast.Field) (bool, error) {
switch r {
case explicitRequiredness:
if src.Requiredness == ast.Unspecified {
return false, requirednessRequiredError{
FieldName: src.Name,
Line: src.Line,
}
}
case noRequiredFields:
if src.Requiredness == ast.Required {
return false, cannotBeRequiredError{
FieldName: src.Name,
Line: src.Line,
}
}
default:
// do nothing
}
// A field is considered required only if it was marked required AND it
// does not have a default value.
return (src.Requiredness == ast.Required && src.Default == nil), nil
}
|
go
|
func (r fieldRequiredness) isRequired(src *ast.Field) (bool, error) {
switch r {
case explicitRequiredness:
if src.Requiredness == ast.Unspecified {
return false, requirednessRequiredError{
FieldName: src.Name,
Line: src.Line,
}
}
case noRequiredFields:
if src.Requiredness == ast.Required {
return false, cannotBeRequiredError{
FieldName: src.Name,
Line: src.Line,
}
}
default:
// do nothing
}
// A field is considered required only if it was marked required AND it
// does not have a default value.
return (src.Requiredness == ast.Required && src.Default == nil), nil
}
|
[
"func",
"(",
"r",
"fieldRequiredness",
")",
"isRequired",
"(",
"src",
"*",
"ast",
".",
"Field",
")",
"(",
"bool",
",",
"error",
")",
"{",
"switch",
"r",
"{",
"case",
"explicitRequiredness",
":",
"if",
"src",
".",
"Requiredness",
"==",
"ast",
".",
"Unspecified",
"{",
"return",
"false",
",",
"requirednessRequiredError",
"{",
"FieldName",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"}",
"\n",
"}",
"\n",
"case",
"noRequiredFields",
":",
"if",
"src",
".",
"Requiredness",
"==",
"ast",
".",
"Required",
"{",
"return",
"false",
",",
"cannotBeRequiredError",
"{",
"FieldName",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"}",
"\n",
"}",
"\n",
"default",
":",
"// do nothing",
"}",
"\n\n",
"// A field is considered required only if it was marked required AND it",
"// does not have a default value.",
"return",
"(",
"src",
".",
"Requiredness",
"==",
"ast",
".",
"Required",
"&&",
"src",
".",
"Default",
"==",
"nil",
")",
",",
"nil",
"\n",
"}"
] |
// isRequired checks if a field should be required based on the
// fieldRequiredness setting. An error is returned if the specified requiredness
// is disallowed by this configuration.
|
[
"isRequired",
"checks",
"if",
"a",
"field",
"should",
"be",
"required",
"based",
"on",
"the",
"fieldRequiredness",
"setting",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"specified",
"requiredness",
"is",
"disallowed",
"by",
"this",
"configuration",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L56-L79
|
17,638 |
thriftrw/thriftrw-go
|
compile/field.go
|
compileField
|
func compileField(src *ast.Field, options fieldOptions) (*FieldSpec, error) {
if src.ID < 1 || src.ID > math.MaxInt16 {
return nil, fieldIDOutOfBoundsError{ID: src.ID, Name: src.Name}
}
required, err := options.requiredness.isRequired(src)
if err != nil {
return nil, err
}
if options.disallowDefaultValue && src.Default != nil {
return nil, defaultValueNotAllowedError{
FieldName: src.Name,
Line: src.Line,
}
}
annotations, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
typ, err := compileTypeReference(src.Type)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
return &FieldSpec{
// TODO(abg): perform bounds check on field ID
ID: int16(src.ID),
Name: src.Name,
Type: typ,
Doc: src.Doc,
Required: required,
Default: compileConstantValue(src.Default),
Annotations: annotations,
}, nil
}
|
go
|
func compileField(src *ast.Field, options fieldOptions) (*FieldSpec, error) {
if src.ID < 1 || src.ID > math.MaxInt16 {
return nil, fieldIDOutOfBoundsError{ID: src.ID, Name: src.Name}
}
required, err := options.requiredness.isRequired(src)
if err != nil {
return nil, err
}
if options.disallowDefaultValue && src.Default != nil {
return nil, defaultValueNotAllowedError{
FieldName: src.Name,
Line: src.Line,
}
}
annotations, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
typ, err := compileTypeReference(src.Type)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
return &FieldSpec{
// TODO(abg): perform bounds check on field ID
ID: int16(src.ID),
Name: src.Name,
Type: typ,
Doc: src.Doc,
Required: required,
Default: compileConstantValue(src.Default),
Annotations: annotations,
}, nil
}
|
[
"func",
"compileField",
"(",
"src",
"*",
"ast",
".",
"Field",
",",
"options",
"fieldOptions",
")",
"(",
"*",
"FieldSpec",
",",
"error",
")",
"{",
"if",
"src",
".",
"ID",
"<",
"1",
"||",
"src",
".",
"ID",
">",
"math",
".",
"MaxInt16",
"{",
"return",
"nil",
",",
"fieldIDOutOfBoundsError",
"{",
"ID",
":",
"src",
".",
"ID",
",",
"Name",
":",
"src",
".",
"Name",
"}",
"\n",
"}",
"\n\n",
"required",
",",
"err",
":=",
"options",
".",
"requiredness",
".",
"isRequired",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"options",
".",
"disallowDefaultValue",
"&&",
"src",
".",
"Default",
"!=",
"nil",
"{",
"return",
"nil",
",",
"defaultValueNotAllowedError",
"{",
"FieldName",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"}",
"\n",
"}",
"\n\n",
"annotations",
",",
"err",
":=",
"compileAnnotations",
"(",
"src",
".",
"Annotations",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"typ",
",",
"err",
":=",
"compileTypeReference",
"(",
"src",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"FieldSpec",
"{",
"// TODO(abg): perform bounds check on field ID",
"ID",
":",
"int16",
"(",
"src",
".",
"ID",
")",
",",
"Name",
":",
"src",
".",
"Name",
",",
"Type",
":",
"typ",
",",
"Doc",
":",
"src",
".",
"Doc",
",",
"Required",
":",
"required",
",",
"Default",
":",
"compileConstantValue",
"(",
"src",
".",
"Default",
")",
",",
"Annotations",
":",
"annotations",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// compileField compiles the given Field source into a FieldSpec.
|
[
"compileField",
"compiles",
"the",
"given",
"Field",
"source",
"into",
"a",
"FieldSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L105-L150
|
17,639 |
thriftrw/thriftrw-go
|
compile/field.go
|
Link
|
func (f *FieldSpec) Link(scope Scope) (err error) {
if f.Type, err = f.Type.Link(scope); err != nil {
return err
}
if f.Default != nil {
f.Default, err = f.Default.Link(scope, f.Type)
}
return err
}
|
go
|
func (f *FieldSpec) Link(scope Scope) (err error) {
if f.Type, err = f.Type.Link(scope); err != nil {
return err
}
if f.Default != nil {
f.Default, err = f.Default.Link(scope, f.Type)
}
return err
}
|
[
"func",
"(",
"f",
"*",
"FieldSpec",
")",
"Link",
"(",
"scope",
"Scope",
")",
"(",
"err",
"error",
")",
"{",
"if",
"f",
".",
"Type",
",",
"err",
"=",
"f",
".",
"Type",
".",
"Link",
"(",
"scope",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"f",
".",
"Default",
"!=",
"nil",
"{",
"f",
".",
"Default",
",",
"err",
"=",
"f",
".",
"Default",
".",
"Link",
"(",
"scope",
",",
"f",
".",
"Type",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Link links together any references made by the FieldSpec.
|
[
"Link",
"links",
"together",
"any",
"references",
"made",
"by",
"the",
"FieldSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L158-L166
|
17,640 |
thriftrw/thriftrw-go
|
compile/field.go
|
compileFields
|
func compileFields(src []*ast.Field, options fieldOptions) (FieldGroup, error) {
fieldsNS := newNamespace(caseInsensitive)
usedIDs := make(map[int16]string)
fields := make([]*FieldSpec, 0, len(src))
for _, astField := range src {
if err := fieldsNS.claim(astField.Name, astField.Line); err != nil {
return nil, compileError{
Target: astField.Name,
Line: astField.Line,
Reason: err,
}
}
field, err := compileField(astField, options)
if err != nil {
return nil, compileError{
Target: astField.Name,
Line: astField.Line,
Reason: err,
}
}
if conflictingField, ok := usedIDs[field.ID]; ok {
return nil, compileError{
Target: astField.Name,
Line: astField.Line,
Reason: fieldIDConflictError{
ID: field.ID,
Name: conflictingField,
},
}
}
fields = append(fields, field)
usedIDs[field.ID] = field.Name
}
return FieldGroup(fields), nil
}
|
go
|
func compileFields(src []*ast.Field, options fieldOptions) (FieldGroup, error) {
fieldsNS := newNamespace(caseInsensitive)
usedIDs := make(map[int16]string)
fields := make([]*FieldSpec, 0, len(src))
for _, astField := range src {
if err := fieldsNS.claim(astField.Name, astField.Line); err != nil {
return nil, compileError{
Target: astField.Name,
Line: astField.Line,
Reason: err,
}
}
field, err := compileField(astField, options)
if err != nil {
return nil, compileError{
Target: astField.Name,
Line: astField.Line,
Reason: err,
}
}
if conflictingField, ok := usedIDs[field.ID]; ok {
return nil, compileError{
Target: astField.Name,
Line: astField.Line,
Reason: fieldIDConflictError{
ID: field.ID,
Name: conflictingField,
},
}
}
fields = append(fields, field)
usedIDs[field.ID] = field.Name
}
return FieldGroup(fields), nil
}
|
[
"func",
"compileFields",
"(",
"src",
"[",
"]",
"*",
"ast",
".",
"Field",
",",
"options",
"fieldOptions",
")",
"(",
"FieldGroup",
",",
"error",
")",
"{",
"fieldsNS",
":=",
"newNamespace",
"(",
"caseInsensitive",
")",
"\n",
"usedIDs",
":=",
"make",
"(",
"map",
"[",
"int16",
"]",
"string",
")",
"\n\n",
"fields",
":=",
"make",
"(",
"[",
"]",
"*",
"FieldSpec",
",",
"0",
",",
"len",
"(",
"src",
")",
")",
"\n",
"for",
"_",
",",
"astField",
":=",
"range",
"src",
"{",
"if",
"err",
":=",
"fieldsNS",
".",
"claim",
"(",
"astField",
".",
"Name",
",",
"astField",
".",
"Line",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"astField",
".",
"Name",
",",
"Line",
":",
"astField",
".",
"Line",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"field",
",",
"err",
":=",
"compileField",
"(",
"astField",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"astField",
".",
"Name",
",",
"Line",
":",
"astField",
".",
"Line",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"if",
"conflictingField",
",",
"ok",
":=",
"usedIDs",
"[",
"field",
".",
"ID",
"]",
";",
"ok",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"astField",
".",
"Name",
",",
"Line",
":",
"astField",
".",
"Line",
",",
"Reason",
":",
"fieldIDConflictError",
"{",
"ID",
":",
"field",
".",
"ID",
",",
"Name",
":",
"conflictingField",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"fields",
"=",
"append",
"(",
"fields",
",",
"field",
")",
"\n",
"usedIDs",
"[",
"field",
".",
"ID",
"]",
"=",
"field",
".",
"Name",
"\n",
"}",
"\n\n",
"return",
"FieldGroup",
"(",
"fields",
")",
",",
"nil",
"\n",
"}"
] |
// compileFields compiles a collection of AST fields into a FieldGroup.
|
[
"compileFields",
"compiles",
"a",
"collection",
"of",
"AST",
"fields",
"into",
"a",
"FieldGroup",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L177-L216
|
17,641 |
thriftrw/thriftrw-go
|
compile/field.go
|
FindByName
|
func (fg FieldGroup) FindByName(name string) (*FieldSpec, error) {
for _, field := range fg {
if field.Name == name {
return field, nil
}
}
return nil, fmt.Errorf("unknown field %v", name)
}
|
go
|
func (fg FieldGroup) FindByName(name string) (*FieldSpec, error) {
for _, field := range fg {
if field.Name == name {
return field, nil
}
}
return nil, fmt.Errorf("unknown field %v", name)
}
|
[
"func",
"(",
"fg",
"FieldGroup",
")",
"FindByName",
"(",
"name",
"string",
")",
"(",
"*",
"FieldSpec",
",",
"error",
")",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"fg",
"{",
"if",
"field",
".",
"Name",
"==",
"name",
"{",
"return",
"field",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] |
// FindByName retrieves the FieldSpec for the field with the given name.
|
[
"FindByName",
"retrieves",
"the",
"FieldSpec",
"for",
"the",
"field",
"with",
"the",
"given",
"name",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L219-L226
|
17,642 |
thriftrw/thriftrw-go
|
compile/field.go
|
Link
|
func (fg FieldGroup) Link(scope Scope) error {
for _, field := range fg {
if err := field.Link(scope); err != nil {
return err
}
}
return nil
}
|
go
|
func (fg FieldGroup) Link(scope Scope) error {
for _, field := range fg {
if err := field.Link(scope); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"fg",
"FieldGroup",
")",
"Link",
"(",
"scope",
"Scope",
")",
"error",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"fg",
"{",
"if",
"err",
":=",
"field",
".",
"Link",
"(",
"scope",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Link resolves references made by fields inside the FieldGroup.
|
[
"Link",
"resolves",
"references",
"made",
"by",
"fields",
"inside",
"the",
"FieldGroup",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L229-L237
|
17,643 |
thriftrw/thriftrw-go
|
compile/field.go
|
ForEachTypeReference
|
func (fg FieldGroup) ForEachTypeReference(f func(TypeSpec) error) error {
for _, field := range fg {
if err := f(field.Type); err != nil {
return err
}
}
return nil
}
|
go
|
func (fg FieldGroup) ForEachTypeReference(f func(TypeSpec) error) error {
for _, field := range fg {
if err := f(field.Type); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"fg",
"FieldGroup",
")",
"ForEachTypeReference",
"(",
"f",
"func",
"(",
"TypeSpec",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"fg",
"{",
"if",
"err",
":=",
"f",
"(",
"field",
".",
"Type",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ForEachTypeReference applies the given function on each TypeSpec in the
// FieldGroup.
|
[
"ForEachTypeReference",
"applies",
"the",
"given",
"function",
"on",
"each",
"TypeSpec",
"in",
"the",
"FieldGroup",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/field.go#L241-L248
|
17,644 |
thriftrw/thriftrw-go
|
compile/module.go
|
LookupType
|
func (m *Module) LookupType(name string) (TypeSpec, error) {
if t, ok := m.Types[name]; ok {
return t, nil
}
return nil, lookupError{Name: name}
}
|
go
|
func (m *Module) LookupType(name string) (TypeSpec, error) {
if t, ok := m.Types[name]; ok {
return t, nil
}
return nil, lookupError{Name: name}
}
|
[
"func",
"(",
"m",
"*",
"Module",
")",
"LookupType",
"(",
"name",
"string",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"if",
"t",
",",
"ok",
":=",
"m",
".",
"Types",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"t",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"lookupError",
"{",
"Name",
":",
"name",
"}",
"\n",
"}"
] |
// LookupType for Module.
|
[
"LookupType",
"for",
"Module",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/module.go#L53-L59
|
17,645 |
thriftrw/thriftrw-go
|
compile/module.go
|
LookupConstant
|
func (m *Module) LookupConstant(name string) (*Constant, error) {
if c, ok := m.Constants[name]; ok {
return c, nil
}
return nil, lookupError{Name: name}
}
|
go
|
func (m *Module) LookupConstant(name string) (*Constant, error) {
if c, ok := m.Constants[name]; ok {
return c, nil
}
return nil, lookupError{Name: name}
}
|
[
"func",
"(",
"m",
"*",
"Module",
")",
"LookupConstant",
"(",
"name",
"string",
")",
"(",
"*",
"Constant",
",",
"error",
")",
"{",
"if",
"c",
",",
"ok",
":=",
"m",
".",
"Constants",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"lookupError",
"{",
"Name",
":",
"name",
"}",
"\n",
"}"
] |
// LookupConstant for Module.
|
[
"LookupConstant",
"for",
"Module",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/module.go#L62-L68
|
17,646 |
thriftrw/thriftrw-go
|
compile/module.go
|
LookupService
|
func (m *Module) LookupService(name string) (*ServiceSpec, error) {
if s, ok := m.Services[name]; ok {
return s, nil
}
return nil, lookupError{Name: name}
}
|
go
|
func (m *Module) LookupService(name string) (*ServiceSpec, error) {
if s, ok := m.Services[name]; ok {
return s, nil
}
return nil, lookupError{Name: name}
}
|
[
"func",
"(",
"m",
"*",
"Module",
")",
"LookupService",
"(",
"name",
"string",
")",
"(",
"*",
"ServiceSpec",
",",
"error",
")",
"{",
"if",
"s",
",",
"ok",
":=",
"m",
".",
"Services",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"lookupError",
"{",
"Name",
":",
"name",
"}",
"\n",
"}"
] |
// LookupService for Module.
|
[
"LookupService",
"for",
"Module",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/module.go#L71-L77
|
17,647 |
thriftrw/thriftrw-go
|
compile/module.go
|
LookupInclude
|
func (m *Module) LookupInclude(name string) (Scope, error) {
if s, ok := m.Includes[name]; ok {
return s.Module, nil
}
return nil, lookupError{Name: name}
}
|
go
|
func (m *Module) LookupInclude(name string) (Scope, error) {
if s, ok := m.Includes[name]; ok {
return s.Module, nil
}
return nil, lookupError{Name: name}
}
|
[
"func",
"(",
"m",
"*",
"Module",
")",
"LookupInclude",
"(",
"name",
"string",
")",
"(",
"Scope",
",",
"error",
")",
"{",
"if",
"s",
",",
"ok",
":=",
"m",
".",
"Includes",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"s",
".",
"Module",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"lookupError",
"{",
"Name",
":",
"name",
"}",
"\n",
"}"
] |
// LookupInclude for Module.
|
[
"LookupInclude",
"for",
"Module",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/module.go#L80-L86
|
17,648 |
thriftrw/thriftrw-go
|
compile/module.go
|
Walk
|
func (m *Module) Walk(f func(*Module) error) error {
visited := make(map[string]struct{})
toVisit := make([]*Module, 0, 100)
toVisit = append(toVisit, m)
for len(toVisit) > 0 {
m := toVisit[0]
toVisit = toVisit[1:]
if _, ok := visited[m.ThriftPath]; ok {
continue
}
visited[m.ThriftPath] = struct{}{}
for _, inc := range m.Includes {
toVisit = append(toVisit, inc.Module)
}
if err := f(m); err != nil {
return err
}
}
return nil
}
|
go
|
func (m *Module) Walk(f func(*Module) error) error {
visited := make(map[string]struct{})
toVisit := make([]*Module, 0, 100)
toVisit = append(toVisit, m)
for len(toVisit) > 0 {
m := toVisit[0]
toVisit = toVisit[1:]
if _, ok := visited[m.ThriftPath]; ok {
continue
}
visited[m.ThriftPath] = struct{}{}
for _, inc := range m.Includes {
toVisit = append(toVisit, inc.Module)
}
if err := f(m); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Module",
")",
"Walk",
"(",
"f",
"func",
"(",
"*",
"Module",
")",
"error",
")",
"error",
"{",
"visited",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n\n",
"toVisit",
":=",
"make",
"(",
"[",
"]",
"*",
"Module",
",",
"0",
",",
"100",
")",
"\n",
"toVisit",
"=",
"append",
"(",
"toVisit",
",",
"m",
")",
"\n\n",
"for",
"len",
"(",
"toVisit",
")",
">",
"0",
"{",
"m",
":=",
"toVisit",
"[",
"0",
"]",
"\n",
"toVisit",
"=",
"toVisit",
"[",
"1",
":",
"]",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"visited",
"[",
"m",
".",
"ThriftPath",
"]",
";",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"visited",
"[",
"m",
".",
"ThriftPath",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"inc",
":=",
"range",
"m",
".",
"Includes",
"{",
"toVisit",
"=",
"append",
"(",
"toVisit",
",",
"inc",
".",
"Module",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"f",
"(",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Walk the module tree starting at the given module. This module and all its
// direct and transitive dependencies will be visited exactly once in an
// unspecified order. The walk will stop on the first error returned by `f`.
|
[
"Walk",
"the",
"module",
"tree",
"starting",
"at",
"the",
"given",
"module",
".",
"This",
"module",
"and",
"all",
"its",
"direct",
"and",
"transitive",
"dependencies",
"will",
"be",
"visited",
"exactly",
"once",
"in",
"an",
"unspecified",
"order",
".",
"The",
"walk",
"will",
"stop",
"on",
"the",
"first",
"error",
"returned",
"by",
"f",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/module.go#L91-L116
|
17,649 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
compileConstantValue
|
func compileConstantValue(v ast.ConstantValue) ConstantValue {
if v == nil {
return nil
}
// TODO(abg): Support typedefs
switch src := v.(type) {
case ast.ConstantReference:
return constantReference(src)
case ast.ConstantMap:
return compileConstantMap(src)
case ast.ConstantList:
return compileConstantList(src)
case ast.ConstantBoolean:
return ConstantBool(src)
case ast.ConstantInteger:
return ConstantInt(src)
case ast.ConstantString:
return ConstantString(src)
case ast.ConstantDouble:
return ConstantDouble(src)
default:
panic(fmt.Sprintf("unknown constant value of type %T: %v", src, src))
}
}
|
go
|
func compileConstantValue(v ast.ConstantValue) ConstantValue {
if v == nil {
return nil
}
// TODO(abg): Support typedefs
switch src := v.(type) {
case ast.ConstantReference:
return constantReference(src)
case ast.ConstantMap:
return compileConstantMap(src)
case ast.ConstantList:
return compileConstantList(src)
case ast.ConstantBoolean:
return ConstantBool(src)
case ast.ConstantInteger:
return ConstantInt(src)
case ast.ConstantString:
return ConstantString(src)
case ast.ConstantDouble:
return ConstantDouble(src)
default:
panic(fmt.Sprintf("unknown constant value of type %T: %v", src, src))
}
}
|
[
"func",
"compileConstantValue",
"(",
"v",
"ast",
".",
"ConstantValue",
")",
"ConstantValue",
"{",
"if",
"v",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// TODO(abg): Support typedefs",
"switch",
"src",
":=",
"v",
".",
"(",
"type",
")",
"{",
"case",
"ast",
".",
"ConstantReference",
":",
"return",
"constantReference",
"(",
"src",
")",
"\n",
"case",
"ast",
".",
"ConstantMap",
":",
"return",
"compileConstantMap",
"(",
"src",
")",
"\n",
"case",
"ast",
".",
"ConstantList",
":",
"return",
"compileConstantList",
"(",
"src",
")",
"\n",
"case",
"ast",
".",
"ConstantBoolean",
":",
"return",
"ConstantBool",
"(",
"src",
")",
"\n",
"case",
"ast",
".",
"ConstantInteger",
":",
"return",
"ConstantInt",
"(",
"src",
")",
"\n",
"case",
"ast",
".",
"ConstantString",
":",
"return",
"ConstantString",
"(",
"src",
")",
"\n",
"case",
"ast",
".",
"ConstantDouble",
":",
"return",
"ConstantDouble",
"(",
"src",
")",
"\n",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"src",
",",
"src",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// compileConstantValue compiles a constant value AST into a ConstantValue.
|
[
"compileConstantValue",
"compiles",
"a",
"constant",
"value",
"AST",
"into",
"a",
"ConstantValue",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L38-L63
|
17,650 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantBool) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if _, ok := RootTypeSpec(t).(*BoolSpec); !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
return c, nil
}
|
go
|
func (c ConstantBool) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if _, ok := RootTypeSpec(t).(*BoolSpec); !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
return c, nil
}
|
[
"func",
"(",
"c",
"ConstantBool",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"RootTypeSpec",
"(",
"t",
")",
".",
"(",
"*",
"BoolSpec",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantBool
|
[
"Link",
"for",
"ConstantBool"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L80-L85
|
17,651 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantInt) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
rt := RootTypeSpec(t)
switch spec := rt.(type) {
case *I8Spec, *I16Spec, *I32Spec, *I64Spec:
// TODO bounds checks?
return c, nil
case *DoubleSpec:
return ConstantDouble(float64(c)).Link(scope, t)
case *BoolSpec:
switch v := int64(c); v {
case 0, 1:
return ConstantBool(v == 1).Link(scope, t)
default:
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: errors.New("the value must be 0 or 1"),
}
}
case *EnumSpec:
for _, item := range spec.Items {
if item.Value == int32(c) {
return EnumItemReference{Enum: spec, Item: &item}, nil
}
}
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: fmt.Errorf(
"%v is not a valid value for enum %q", int32(c), spec.ThriftName()),
}
}
return nil, constantValueCastError{Value: c, Type: t}
// TODO: AST for constants will need to track positions for us to
// include them in the error messages.
}
|
go
|
func (c ConstantInt) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
rt := RootTypeSpec(t)
switch spec := rt.(type) {
case *I8Spec, *I16Spec, *I32Spec, *I64Spec:
// TODO bounds checks?
return c, nil
case *DoubleSpec:
return ConstantDouble(float64(c)).Link(scope, t)
case *BoolSpec:
switch v := int64(c); v {
case 0, 1:
return ConstantBool(v == 1).Link(scope, t)
default:
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: errors.New("the value must be 0 or 1"),
}
}
case *EnumSpec:
for _, item := range spec.Items {
if item.Value == int32(c) {
return EnumItemReference{Enum: spec, Item: &item}, nil
}
}
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: fmt.Errorf(
"%v is not a valid value for enum %q", int32(c), spec.ThriftName()),
}
}
return nil, constantValueCastError{Value: c, Type: t}
// TODO: AST for constants will need to track positions for us to
// include them in the error messages.
}
|
[
"func",
"(",
"c",
"ConstantInt",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"rt",
":=",
"RootTypeSpec",
"(",
"t",
")",
"\n",
"switch",
"spec",
":=",
"rt",
".",
"(",
"type",
")",
"{",
"case",
"*",
"I8Spec",
",",
"*",
"I16Spec",
",",
"*",
"I32Spec",
",",
"*",
"I64Spec",
":",
"// TODO bounds checks?",
"return",
"c",
",",
"nil",
"\n",
"case",
"*",
"DoubleSpec",
":",
"return",
"ConstantDouble",
"(",
"float64",
"(",
"c",
")",
")",
".",
"Link",
"(",
"scope",
",",
"t",
")",
"\n",
"case",
"*",
"BoolSpec",
":",
"switch",
"v",
":=",
"int64",
"(",
"c",
")",
";",
"v",
"{",
"case",
"0",
",",
"1",
":",
"return",
"ConstantBool",
"(",
"v",
"==",
"1",
")",
".",
"Link",
"(",
"scope",
",",
"t",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
",",
"Reason",
":",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
",",
"}",
"\n",
"}",
"\n",
"case",
"*",
"EnumSpec",
":",
"for",
"_",
",",
"item",
":=",
"range",
"spec",
".",
"Items",
"{",
"if",
"item",
".",
"Value",
"==",
"int32",
"(",
"c",
")",
"{",
"return",
"EnumItemReference",
"{",
"Enum",
":",
"spec",
",",
"Item",
":",
"&",
"item",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
",",
"Reason",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"int32",
"(",
"c",
")",
",",
"spec",
".",
"ThriftName",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"// TODO: AST for constants will need to track positions for us to",
"// include them in the error messages.",
"}"
] |
// Link for ConstantInt.
|
[
"Link",
"for",
"ConstantInt",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L88-L125
|
17,652 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantString) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
// TODO(abg): Are binary literals a thing?
if _, ok := RootTypeSpec(t).(*StringSpec); !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
return c, nil
}
|
go
|
func (c ConstantString) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
// TODO(abg): Are binary literals a thing?
if _, ok := RootTypeSpec(t).(*StringSpec); !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
return c, nil
}
|
[
"func",
"(",
"c",
"ConstantString",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"// TODO(abg): Are binary literals a thing?",
"if",
"_",
",",
"ok",
":=",
"RootTypeSpec",
"(",
"t",
")",
".",
"(",
"*",
"StringSpec",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantString.
|
[
"Link",
"for",
"ConstantString",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L128-L134
|
17,653 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantDouble) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if _, ok := RootTypeSpec(t).(*DoubleSpec); !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
return c, nil
}
|
go
|
func (c ConstantDouble) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if _, ok := RootTypeSpec(t).(*DoubleSpec); !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
return c, nil
}
|
[
"func",
"(",
"c",
"ConstantDouble",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"RootTypeSpec",
"(",
"t",
")",
".",
"(",
"*",
"DoubleSpec",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantDouble.
|
[
"Link",
"for",
"ConstantDouble",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L137-L142
|
17,654 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
buildConstantStruct
|
func buildConstantStruct(c ConstantMap) (*ConstantStruct, error) {
fields := make(map[string]ConstantValue, len(c))
for _, pair := range c {
s, isString := pair.Key.(ConstantString)
if !isString {
return nil, fmt.Errorf(
"%v is not a string: all keys must be strings", pair.Key)
}
fields[string(s)] = pair.Value
}
return &ConstantStruct{Fields: fields}, nil
}
|
go
|
func buildConstantStruct(c ConstantMap) (*ConstantStruct, error) {
fields := make(map[string]ConstantValue, len(c))
for _, pair := range c {
s, isString := pair.Key.(ConstantString)
if !isString {
return nil, fmt.Errorf(
"%v is not a string: all keys must be strings", pair.Key)
}
fields[string(s)] = pair.Value
}
return &ConstantStruct{Fields: fields}, nil
}
|
[
"func",
"buildConstantStruct",
"(",
"c",
"ConstantMap",
")",
"(",
"*",
"ConstantStruct",
",",
"error",
")",
"{",
"fields",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"ConstantValue",
",",
"len",
"(",
"c",
")",
")",
"\n",
"for",
"_",
",",
"pair",
":=",
"range",
"c",
"{",
"s",
",",
"isString",
":=",
"pair",
".",
"Key",
".",
"(",
"ConstantString",
")",
"\n",
"if",
"!",
"isString",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pair",
".",
"Key",
")",
"\n",
"}",
"\n",
"fields",
"[",
"string",
"(",
"s",
")",
"]",
"=",
"pair",
".",
"Value",
"\n",
"}",
"\n",
"return",
"&",
"ConstantStruct",
"{",
"Fields",
":",
"fields",
"}",
",",
"nil",
"\n",
"}"
] |
// buildConstantStruct builds a constant struct from a ConstantMap.
|
[
"buildConstantStruct",
"builds",
"a",
"constant",
"struct",
"from",
"a",
"ConstantMap",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L150-L161
|
17,655 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c *ConstantStruct) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
s, ok := RootTypeSpec(t).(*StructSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
for _, field := range s.Fields {
f, ok := c.Fields[field.Name]
if !ok {
if field.Default == nil {
if field.Required {
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: fmt.Errorf("%q is a required field", field.Name),
}
}
continue
}
f = field.Default
c.Fields[field.Name] = f
}
f, err := f.Link(scope, field.Type)
if err != nil {
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: constantStructFieldCastError{
FieldName: field.Name,
Reason: err,
},
}
}
c.Fields[field.Name] = f
}
return c, nil
}
|
go
|
func (c *ConstantStruct) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
s, ok := RootTypeSpec(t).(*StructSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
for _, field := range s.Fields {
f, ok := c.Fields[field.Name]
if !ok {
if field.Default == nil {
if field.Required {
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: fmt.Errorf("%q is a required field", field.Name),
}
}
continue
}
f = field.Default
c.Fields[field.Name] = f
}
f, err := f.Link(scope, field.Type)
if err != nil {
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: constantStructFieldCastError{
FieldName: field.Name,
Reason: err,
},
}
}
c.Fields[field.Name] = f
}
return c, nil
}
|
[
"func",
"(",
"c",
"*",
"ConstantStruct",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"s",
",",
"ok",
":=",
"RootTypeSpec",
"(",
"t",
")",
".",
"(",
"*",
"StructSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"field",
":=",
"range",
"s",
".",
"Fields",
"{",
"f",
",",
"ok",
":=",
"c",
".",
"Fields",
"[",
"field",
".",
"Name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"if",
"field",
".",
"Default",
"==",
"nil",
"{",
"if",
"field",
".",
"Required",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
",",
"Reason",
":",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"field",
".",
"Name",
")",
",",
"}",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"f",
"=",
"field",
".",
"Default",
"\n",
"c",
".",
"Fields",
"[",
"field",
".",
"Name",
"]",
"=",
"f",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"f",
".",
"Link",
"(",
"scope",
",",
"field",
".",
"Type",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
",",
"Reason",
":",
"constantStructFieldCastError",
"{",
"FieldName",
":",
"field",
".",
"Name",
",",
"Reason",
":",
"err",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"Fields",
"[",
"field",
".",
"Name",
"]",
"=",
"f",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantStruct
|
[
"Link",
"for",
"ConstantStruct"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L164-L203
|
17,656 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantMap) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
rt := RootTypeSpec(t)
if _, isStruct := rt.(*StructSpec); isStruct {
cs, err := buildConstantStruct(c)
if err != nil {
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: err,
}
}
return cs.Link(scope, t)
}
m, ok := rt.(*MapSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
items := make([]ConstantValuePair, len(c))
for i, item := range c {
key, err := item.Key.Link(scope, m.KeySpec)
if err != nil {
return nil, err
}
value, err := item.Value.Link(scope, m.ValueSpec)
if err != nil {
return nil, err
}
// TODO(abg): Duplicate key check
items[i] = ConstantValuePair{Key: key, Value: value}
}
return ConstantMap(items), nil
}
|
go
|
func (c ConstantMap) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
rt := RootTypeSpec(t)
if _, isStruct := rt.(*StructSpec); isStruct {
cs, err := buildConstantStruct(c)
if err != nil {
return nil, constantValueCastError{
Value: c,
Type: t,
Reason: err,
}
}
return cs.Link(scope, t)
}
m, ok := rt.(*MapSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
items := make([]ConstantValuePair, len(c))
for i, item := range c {
key, err := item.Key.Link(scope, m.KeySpec)
if err != nil {
return nil, err
}
value, err := item.Value.Link(scope, m.ValueSpec)
if err != nil {
return nil, err
}
// TODO(abg): Duplicate key check
items[i] = ConstantValuePair{Key: key, Value: value}
}
return ConstantMap(items), nil
}
|
[
"func",
"(",
"c",
"ConstantMap",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"rt",
":=",
"RootTypeSpec",
"(",
"t",
")",
"\n",
"if",
"_",
",",
"isStruct",
":=",
"rt",
".",
"(",
"*",
"StructSpec",
")",
";",
"isStruct",
"{",
"cs",
",",
"err",
":=",
"buildConstantStruct",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n",
"return",
"cs",
".",
"Link",
"(",
"scope",
",",
"t",
")",
"\n",
"}",
"\n\n",
"m",
",",
"ok",
":=",
"rt",
".",
"(",
"*",
"MapSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n\n",
"items",
":=",
"make",
"(",
"[",
"]",
"ConstantValuePair",
",",
"len",
"(",
"c",
")",
")",
"\n",
"for",
"i",
",",
"item",
":=",
"range",
"c",
"{",
"key",
",",
"err",
":=",
"item",
".",
"Key",
".",
"Link",
"(",
"scope",
",",
"m",
".",
"KeySpec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"value",
",",
"err",
":=",
"item",
".",
"Value",
".",
"Link",
"(",
"scope",
",",
"m",
".",
"ValueSpec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// TODO(abg): Duplicate key check",
"items",
"[",
"i",
"]",
"=",
"ConstantValuePair",
"{",
"Key",
":",
"key",
",",
"Value",
":",
"value",
"}",
"\n",
"}",
"\n\n",
"return",
"ConstantMap",
"(",
"items",
")",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantMap.
|
[
"Link",
"for",
"ConstantMap",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L226-L262
|
17,657 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantSet) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
s, ok := RootTypeSpec(t).(*SetSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
// TODO(abg): Track whether things are linked so that we don't re-link here
// TODO(abg): Fail for duplicates
values := make([]ConstantValue, len(c))
for i, v := range c {
value, err := v.Link(scope, s.ValueSpec)
if err != nil {
return nil, err
}
values[i] = value
}
return ConstantSet(values), nil
}
|
go
|
func (c ConstantSet) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
s, ok := RootTypeSpec(t).(*SetSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
// TODO(abg): Track whether things are linked so that we don't re-link here
// TODO(abg): Fail for duplicates
values := make([]ConstantValue, len(c))
for i, v := range c {
value, err := v.Link(scope, s.ValueSpec)
if err != nil {
return nil, err
}
values[i] = value
}
return ConstantSet(values), nil
}
|
[
"func",
"(",
"c",
"ConstantSet",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"s",
",",
"ok",
":=",
"RootTypeSpec",
"(",
"t",
")",
".",
"(",
"*",
"SetSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n\n",
"// TODO(abg): Track whether things are linked so that we don't re-link here",
"// TODO(abg): Fail for duplicates",
"values",
":=",
"make",
"(",
"[",
"]",
"ConstantValue",
",",
"len",
"(",
"c",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"c",
"{",
"value",
",",
"err",
":=",
"v",
".",
"Link",
"(",
"scope",
",",
"s",
".",
"ValueSpec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"values",
"[",
"i",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"return",
"ConstantSet",
"(",
"values",
")",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantSet.
|
[
"Link",
"for",
"ConstantSet",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L268-L286
|
17,658 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstantList) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
rt := RootTypeSpec(t)
if _, isSet := rt.(*SetSpec); isSet {
return ConstantSet(c).Link(scope, t)
}
l, ok := rt.(*ListSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
values := make([]ConstantValue, len(c))
for i, v := range c {
value, err := v.Link(scope, l.ValueSpec)
if err != nil {
return nil, err
}
values[i] = value
}
return ConstantList(values), nil
}
|
go
|
func (c ConstantList) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
rt := RootTypeSpec(t)
if _, isSet := rt.(*SetSpec); isSet {
return ConstantSet(c).Link(scope, t)
}
l, ok := rt.(*ListSpec)
if !ok {
return nil, constantValueCastError{Value: c, Type: t}
}
values := make([]ConstantValue, len(c))
for i, v := range c {
value, err := v.Link(scope, l.ValueSpec)
if err != nil {
return nil, err
}
values[i] = value
}
return ConstantList(values), nil
}
|
[
"func",
"(",
"c",
"ConstantList",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"rt",
":=",
"RootTypeSpec",
"(",
"t",
")",
"\n",
"if",
"_",
",",
"isSet",
":=",
"rt",
".",
"(",
"*",
"SetSpec",
")",
";",
"isSet",
"{",
"return",
"ConstantSet",
"(",
"c",
")",
".",
"Link",
"(",
"scope",
",",
"t",
")",
"\n",
"}",
"\n\n",
"l",
",",
"ok",
":=",
"rt",
".",
"(",
"*",
"ListSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"c",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n\n",
"values",
":=",
"make",
"(",
"[",
"]",
"ConstantValue",
",",
"len",
"(",
"c",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"c",
"{",
"value",
",",
"err",
":=",
"v",
".",
"Link",
"(",
"scope",
",",
"l",
".",
"ValueSpec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"values",
"[",
"i",
"]",
"=",
"value",
"\n",
"}",
"\n\n",
"return",
"ConstantList",
"(",
"values",
")",
",",
"nil",
"\n",
"}"
] |
// Link for ConstantList.
|
[
"Link",
"for",
"ConstantList",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L300-L321
|
17,659 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (c ConstReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if t == c.Target.Type {
return c, nil
}
return c.Target.Value.Link(scope, t)
}
|
go
|
func (c ConstReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if t == c.Target.Type {
return c, nil
}
return c.Target.Value.Link(scope, t)
}
|
[
"func",
"(",
"c",
"ConstReference",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"if",
"t",
"==",
"c",
".",
"Target",
".",
"Type",
"{",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"return",
"c",
".",
"Target",
".",
"Value",
".",
"Link",
"(",
"scope",
",",
"t",
")",
"\n",
"}"
] |
// Link for ConstReference.
|
[
"Link",
"for",
"ConstReference",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L330-L335
|
17,660 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (e EnumItemReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if RootTypeSpec(t) != e.Enum {
return nil, constantValueCastError{Value: e, Type: t}
}
return e, nil
}
|
go
|
func (e EnumItemReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
if RootTypeSpec(t) != e.Enum {
return nil, constantValueCastError{Value: e, Type: t}
}
return e, nil
}
|
[
"func",
"(",
"e",
"EnumItemReference",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"if",
"RootTypeSpec",
"(",
"t",
")",
"!=",
"e",
".",
"Enum",
"{",
"return",
"nil",
",",
"constantValueCastError",
"{",
"Value",
":",
"e",
",",
"Type",
":",
"t",
"}",
"\n",
"}",
"\n",
"return",
"e",
",",
"nil",
"\n",
"}"
] |
// Link for EnumItemReference.
|
[
"Link",
"for",
"EnumItemReference",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L345-L350
|
17,661 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
Link
|
func (r constantReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
src := ast.ConstantReference(r)
c, err := scope.LookupConstant(src.Name)
if err == nil {
if err := c.Link(scope); err != nil {
return nil, err
}
return ConstReference{Target: c}.Link(scope, t)
}
mname, iname := splitInclude(src.Name)
if len(mname) == 0 {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
if enum, ok := lookupEnum(scope, mname); ok {
if item, ok := enum.LookupItem(iname); ok {
return EnumItemReference{
Enum: enum,
Item: item,
}, nil
}
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: unrecognizedEnumItemError{
EnumName: mname,
ItemName: iname,
},
}
}
includedScope, err := getIncludedScope(scope, mname)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
value, err := constantReference{Name: iname}.Link(includedScope, t)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
return value, nil
}
|
go
|
func (r constantReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
src := ast.ConstantReference(r)
c, err := scope.LookupConstant(src.Name)
if err == nil {
if err := c.Link(scope); err != nil {
return nil, err
}
return ConstReference{Target: c}.Link(scope, t)
}
mname, iname := splitInclude(src.Name)
if len(mname) == 0 {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
if enum, ok := lookupEnum(scope, mname); ok {
if item, ok := enum.LookupItem(iname); ok {
return EnumItemReference{
Enum: enum,
Item: item,
}, nil
}
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: unrecognizedEnumItemError{
EnumName: mname,
ItemName: iname,
},
}
}
includedScope, err := getIncludedScope(scope, mname)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
value, err := constantReference{Name: iname}.Link(includedScope, t)
if err != nil {
return nil, referenceError{
Target: src.Name,
Line: src.Line,
ScopeName: scope.GetName(),
Reason: err,
}
}
return value, nil
}
|
[
"func",
"(",
"r",
"constantReference",
")",
"Link",
"(",
"scope",
"Scope",
",",
"t",
"TypeSpec",
")",
"(",
"ConstantValue",
",",
"error",
")",
"{",
"src",
":=",
"ast",
".",
"ConstantReference",
"(",
"r",
")",
"\n\n",
"c",
",",
"err",
":=",
"scope",
".",
"LookupConstant",
"(",
"src",
".",
"Name",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"err",
":=",
"c",
".",
"Link",
"(",
"scope",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ConstReference",
"{",
"Target",
":",
"c",
"}",
".",
"Link",
"(",
"scope",
",",
"t",
")",
"\n",
"}",
"\n\n",
"mname",
",",
"iname",
":=",
"splitInclude",
"(",
"src",
".",
"Name",
")",
"\n",
"if",
"len",
"(",
"mname",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"if",
"enum",
",",
"ok",
":=",
"lookupEnum",
"(",
"scope",
",",
"mname",
")",
";",
"ok",
"{",
"if",
"item",
",",
"ok",
":=",
"enum",
".",
"LookupItem",
"(",
"iname",
")",
";",
"ok",
"{",
"return",
"EnumItemReference",
"{",
"Enum",
":",
"enum",
",",
"Item",
":",
"item",
",",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"unrecognizedEnumItemError",
"{",
"EnumName",
":",
"mname",
",",
"ItemName",
":",
"iname",
",",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"includedScope",
",",
"err",
":=",
"getIncludedScope",
"(",
"scope",
",",
"mname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"value",
",",
"err",
":=",
"constantReference",
"{",
"Name",
":",
"iname",
"}",
".",
"Link",
"(",
"includedScope",
",",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"referenceError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"ScopeName",
":",
"scope",
".",
"GetName",
"(",
")",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"value",
",",
"nil",
"\n",
"}"
] |
// Link a constantReference.
//
// This resolves the reference to a ConstReference or an EnumItemReference.
|
[
"Link",
"a",
"constantReference",
".",
"This",
"resolves",
"the",
"reference",
"to",
"a",
"ConstReference",
"or",
"an",
"EnumItemReference",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L361-L422
|
17,662 |
thriftrw/thriftrw-go
|
compile/constant_value.go
|
lookupEnum
|
func lookupEnum(scope Scope, name string) (*EnumSpec, bool) {
t, err := scope.LookupType(name)
if err != nil {
return nil, false
}
if enum, ok := t.(*EnumSpec); ok {
return enum, true
}
return nil, false
}
|
go
|
func lookupEnum(scope Scope, name string) (*EnumSpec, bool) {
t, err := scope.LookupType(name)
if err != nil {
return nil, false
}
if enum, ok := t.(*EnumSpec); ok {
return enum, true
}
return nil, false
}
|
[
"func",
"lookupEnum",
"(",
"scope",
"Scope",
",",
"name",
"string",
")",
"(",
"*",
"EnumSpec",
",",
"bool",
")",
"{",
"t",
",",
"err",
":=",
"scope",
".",
"LookupType",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"if",
"enum",
",",
"ok",
":=",
"t",
".",
"(",
"*",
"EnumSpec",
")",
";",
"ok",
"{",
"return",
"enum",
",",
"true",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] |
// lookupEnum looks up an enum with the given name in the given scope.
|
[
"lookupEnum",
"looks",
"up",
"an",
"enum",
"with",
"the",
"given",
"name",
"in",
"the",
"given",
"scope",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/constant_value.go#L425-L435
|
17,663 |
thriftrw/thriftrw-go
|
internal/process/client.go
|
NewClient
|
func NewClient(cmd *exec.Cmd) (*Client, error) {
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, fmt.Errorf("failed to create stdout pipe to %q: %v", cmd.Path, err)
}
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, fmt.Errorf("failed to create stdin pipe to %q: %v", cmd.Path, err)
}
if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("failed to start %q: %v", cmd.Path, err)
}
return &Client{
stdout: stdout,
stdin: stdin,
running: atomic.NewBool(true),
client: frame.NewClient(stdin, stdout),
cmd: cmd,
}, nil
}
|
go
|
func NewClient(cmd *exec.Cmd) (*Client, error) {
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, fmt.Errorf("failed to create stdout pipe to %q: %v", cmd.Path, err)
}
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, fmt.Errorf("failed to create stdin pipe to %q: %v", cmd.Path, err)
}
if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("failed to start %q: %v", cmd.Path, err)
}
return &Client{
stdout: stdout,
stdin: stdin,
running: atomic.NewBool(true),
client: frame.NewClient(stdin, stdout),
cmd: cmd,
}, nil
}
|
[
"func",
"NewClient",
"(",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"stdout",
",",
"err",
":=",
"cmd",
".",
"StdoutPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"err",
")",
"\n",
"}",
"\n\n",
"stdin",
",",
"err",
":=",
"cmd",
".",
"StdinPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"cmd",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
"{",
"stdout",
":",
"stdout",
",",
"stdin",
":",
"stdin",
",",
"running",
":",
"atomic",
".",
"NewBool",
"(",
"true",
")",
",",
"client",
":",
"frame",
".",
"NewClient",
"(",
"stdin",
",",
"stdout",
")",
",",
"cmd",
":",
"cmd",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewClient starts up the given external process and communicates with it over
// stdin and stdout using framed requests and responses.
//
// The Cmd MUST NOT have Stdout or Stdin set.
|
[
"NewClient",
"starts",
"up",
"the",
"given",
"external",
"process",
"and",
"communicates",
"with",
"it",
"over",
"stdin",
"and",
"stdout",
"using",
"framed",
"requests",
"and",
"responses",
".",
"The",
"Cmd",
"MUST",
"NOT",
"have",
"Stdout",
"or",
"Stdin",
"set",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/process/client.go#L48-L70
|
17,664 |
thriftrw/thriftrw-go
|
internal/process/client.go
|
Send
|
func (c *Client) Send(data []byte) ([]byte, error) {
if !c.running.Load() {
panic(fmt.Sprintf("process.Client for %q has been closed", c.cmd.Path))
}
return c.client.Send(data)
}
|
go
|
func (c *Client) Send(data []byte) ([]byte, error) {
if !c.running.Load() {
panic(fmt.Sprintf("process.Client for %q has been closed", c.cmd.Path))
}
return c.client.Send(data)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Send",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"!",
"c",
".",
"running",
".",
"Load",
"(",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"cmd",
".",
"Path",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"client",
".",
"Send",
"(",
"data",
")",
"\n",
"}"
] |
// Send sends the given frame to the external process and returns the response.
//
// Panics if Close was already called.
|
[
"Send",
"sends",
"the",
"given",
"frame",
"to",
"the",
"external",
"process",
"and",
"returns",
"the",
"response",
".",
"Panics",
"if",
"Close",
"was",
"already",
"called",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/process/client.go#L75-L81
|
17,665 |
thriftrw/thriftrw-go
|
internal/process/client.go
|
Close
|
func (c *Client) Close() error {
if !c.running.Swap(false) {
return nil // already stopped
}
var errors []error
if err := c.stdout.Close(); err != nil {
errors = append(errors, fmt.Errorf("failed to detach stdout from %q: %v", c.cmd.Path, err))
}
if err := c.stdin.Close(); err != nil {
errors = append(errors, fmt.Errorf("failed to detach stdin from %q: %v", c.cmd.Path, err))
}
if err := c.cmd.Wait(); err != nil {
errors = append(errors, fmt.Errorf("%q failed with: %v", c.cmd.Path, err))
}
return multierr.Combine(errors...)
}
|
go
|
func (c *Client) Close() error {
if !c.running.Swap(false) {
return nil // already stopped
}
var errors []error
if err := c.stdout.Close(); err != nil {
errors = append(errors, fmt.Errorf("failed to detach stdout from %q: %v", c.cmd.Path, err))
}
if err := c.stdin.Close(); err != nil {
errors = append(errors, fmt.Errorf("failed to detach stdin from %q: %v", c.cmd.Path, err))
}
if err := c.cmd.Wait(); err != nil {
errors = append(errors, fmt.Errorf("%q failed with: %v", c.cmd.Path, err))
}
return multierr.Combine(errors...)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"!",
"c",
".",
"running",
".",
"Swap",
"(",
"false",
")",
"{",
"return",
"nil",
"// already stopped",
"\n",
"}",
"\n\n",
"var",
"errors",
"[",
"]",
"error",
"\n",
"if",
"err",
":=",
"c",
".",
"stdout",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"cmd",
".",
"Path",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"stdin",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"cmd",
".",
"Path",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"cmd",
".",
"Wait",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"cmd",
".",
"Path",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"multierr",
".",
"Combine",
"(",
"errors",
"...",
")",
"\n",
"}"
] |
// Close detaches from the external process and waits for it to exit.
|
[
"Close",
"detaches",
"from",
"the",
"external",
"process",
"and",
"waits",
"for",
"it",
"to",
"exit",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/process/client.go#L84-L100
|
17,666 |
thriftrw/thriftrw-go
|
plugin/api/plugin_goodbye.go
|
Equals
|
func (v *Plugin_Goodbye_Args) Equals(rhs *Plugin_Goodbye_Args) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
|
go
|
func (v *Plugin_Goodbye_Args) Equals(rhs *Plugin_Goodbye_Args) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
|
[
"func",
"(",
"v",
"*",
"Plugin_Goodbye_Args",
")",
"Equals",
"(",
"rhs",
"*",
"Plugin_Goodbye_Args",
")",
"bool",
"{",
"if",
"v",
"==",
"nil",
"{",
"return",
"rhs",
"==",
"nil",
"\n",
"}",
"else",
"if",
"rhs",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// Equals returns true if all the fields of this Plugin_Goodbye_Args match the
// provided Plugin_Goodbye_Args.
//
// This function performs a deep comparison.
|
[
"Equals",
"returns",
"true",
"if",
"all",
"the",
"fields",
"of",
"this",
"Plugin_Goodbye_Args",
"match",
"the",
"provided",
"Plugin_Goodbye_Args",
".",
"This",
"function",
"performs",
"a",
"deep",
"comparison",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/plugin/api/plugin_goodbye.go#L107-L115
|
17,667 |
thriftrw/thriftrw-go
|
plugin/api/plugin_goodbye.go
|
Equals
|
func (v *Plugin_Goodbye_Result) Equals(rhs *Plugin_Goodbye_Result) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
|
go
|
func (v *Plugin_Goodbye_Result) Equals(rhs *Plugin_Goodbye_Result) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
|
[
"func",
"(",
"v",
"*",
"Plugin_Goodbye_Result",
")",
"Equals",
"(",
"rhs",
"*",
"Plugin_Goodbye_Result",
")",
"bool",
"{",
"if",
"v",
"==",
"nil",
"{",
"return",
"rhs",
"==",
"nil",
"\n",
"}",
"else",
"if",
"rhs",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// Equals returns true if all the fields of this Plugin_Goodbye_Result match the
// provided Plugin_Goodbye_Result.
//
// This function performs a deep comparison.
|
[
"Equals",
"returns",
"true",
"if",
"all",
"the",
"fields",
"of",
"this",
"Plugin_Goodbye_Result",
"match",
"the",
"provided",
"Plugin_Goodbye_Result",
".",
"This",
"function",
"performs",
"a",
"deep",
"comparison",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/plugin/api/plugin_goodbye.go#L284-L292
|
17,668 |
thriftrw/thriftrw-go
|
ast/line_no.go
|
LineNumber
|
func LineNumber(n Node) int {
if nl, ok := n.(nodeWithLine); ok {
return nl.lineNumber()
}
return 0
}
|
go
|
func LineNumber(n Node) int {
if nl, ok := n.(nodeWithLine); ok {
return nl.lineNumber()
}
return 0
}
|
[
"func",
"LineNumber",
"(",
"n",
"Node",
")",
"int",
"{",
"if",
"nl",
",",
"ok",
":=",
"n",
".",
"(",
"nodeWithLine",
")",
";",
"ok",
"{",
"return",
"nl",
".",
"lineNumber",
"(",
")",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] |
// LineNumber returns the line in the file at which the given node was defined
// or 0 if the Node does not record its line number.
|
[
"LineNumber",
"returns",
"the",
"line",
"in",
"the",
"file",
"at",
"which",
"the",
"given",
"node",
"was",
"defined",
"or",
"0",
"if",
"the",
"Node",
"does",
"not",
"record",
"its",
"line",
"number",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/ast/line_no.go#L33-L38
|
17,669 |
thriftrw/thriftrw-go
|
internal/frame/reader.go
|
Read
|
func (r *Reader) Read() ([]byte, error) {
r.Lock()
defer r.Unlock()
if _, err := io.ReadFull(r.r, r.buff[:]); err != nil {
return nil, err
}
length := int64(binary.BigEndian.Uint32(r.buff[:]))
if length < _fastPathFrameSize {
return r.readFastPath(length)
}
var buff bytes.Buffer
_, err := io.CopyN(&buff, r.r, length)
if err != nil {
return nil, err
}
return buff.Bytes(), nil
}
|
go
|
func (r *Reader) Read() ([]byte, error) {
r.Lock()
defer r.Unlock()
if _, err := io.ReadFull(r.r, r.buff[:]); err != nil {
return nil, err
}
length := int64(binary.BigEndian.Uint32(r.buff[:]))
if length < _fastPathFrameSize {
return r.readFastPath(length)
}
var buff bytes.Buffer
_, err := io.CopyN(&buff, r.r, length)
if err != nil {
return nil, err
}
return buff.Bytes(), nil
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"Read",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"r",
".",
"r",
",",
"r",
".",
"buff",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"length",
":=",
"int64",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"r",
".",
"buff",
"[",
":",
"]",
")",
")",
"\n",
"if",
"length",
"<",
"_fastPathFrameSize",
"{",
"return",
"r",
".",
"readFastPath",
"(",
"length",
")",
"\n",
"}",
"\n\n",
"var",
"buff",
"bytes",
".",
"Buffer",
"\n",
"_",
",",
"err",
":=",
"io",
".",
"CopyN",
"(",
"&",
"buff",
",",
"r",
".",
"r",
",",
"length",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"buff",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// Read reads the next frame from the Reader.
|
[
"Read",
"reads",
"the",
"next",
"frame",
"from",
"the",
"Reader",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/frame/reader.go#L53-L73
|
17,670 |
thriftrw/thriftrw-go
|
internal/frame/reader.go
|
Close
|
func (r *Reader) Close() error {
if r.closed.Swap(true) {
return nil // already closed
}
if c, ok := r.r.(io.Closer); ok {
return c.Close()
}
return nil
}
|
go
|
func (r *Reader) Close() error {
if r.closed.Swap(true) {
return nil // already closed
}
if c, ok := r.r.(io.Closer); ok {
return c.Close()
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"Reader",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"r",
".",
"closed",
".",
"Swap",
"(",
"true",
")",
"{",
"return",
"nil",
"// already closed",
"\n",
"}",
"\n\n",
"if",
"c",
",",
"ok",
":=",
"r",
".",
"r",
".",
"(",
"io",
".",
"Closer",
")",
";",
"ok",
"{",
"return",
"c",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close closes the given Reader.
|
[
"Close",
"closes",
"the",
"given",
"Reader",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/frame/reader.go#L85-L94
|
17,671 |
thriftrw/thriftrw-go
|
wire/unsafe.go
|
unsafeStringToBytes
|
func unsafeStringToBytes(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
sliceHeader := reflect.SliceHeader{
Data: sh.Data,
Len: sh.Len,
Cap: sh.Len,
}
return *(*[]byte)(unsafe.Pointer(&sliceHeader))
}
|
go
|
func unsafeStringToBytes(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
sliceHeader := reflect.SliceHeader{
Data: sh.Data,
Len: sh.Len,
Cap: sh.Len,
}
return *(*[]byte)(unsafe.Pointer(&sliceHeader))
}
|
[
"func",
"unsafeStringToBytes",
"(",
"s",
"string",
")",
"[",
"]",
"byte",
"{",
"sh",
":=",
"(",
"*",
"reflect",
".",
"StringHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"s",
")",
")",
"\n",
"sliceHeader",
":=",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"sh",
".",
"Data",
",",
"Len",
":",
"sh",
".",
"Len",
",",
"Cap",
":",
"sh",
".",
"Len",
",",
"}",
"\n",
"return",
"*",
"(",
"*",
"[",
"]",
"byte",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"sliceHeader",
")",
")",
"\n",
"}"
] |
// unsafeStringToBytes converts a string into a byte slice without allocating
// new memory for it with the assumption that the resulting byte slice will not
// be mutated.
|
[
"unsafeStringToBytes",
"converts",
"a",
"string",
"into",
"a",
"byte",
"slice",
"without",
"allocating",
"new",
"memory",
"for",
"it",
"with",
"the",
"assumption",
"that",
"the",
"resulting",
"byte",
"slice",
"will",
"not",
"be",
"mutated",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/wire/unsafe.go#L31-L39
|
17,672 |
thriftrw/thriftrw-go
|
gen/typedef.go
|
typedef
|
func typedef(g Generator, spec *compile.TypedefSpec) error {
err := g.DeclareFromTemplate(
`
<$fmt := import "fmt">
<$wire := import "go.uber.org/thriftrw/wire">
<$typedefType := typeReference .>
<formatDoc .Doc>type <typeName .> <typeName .Target>
<$v := newVar "v">
<$x := newVar "x">
<- if isPrimitiveType .>
// <typeName .>Ptr returns a pointer to a <$typedefType>
func (<$v> <typeName .>) Ptr() *<$typedefType>{
return &<$v>
}
<- end>
// ToWire translates <typeName .> into a Thrift-level intermediate
// representation. This intermediate representation may be serialized
// into bytes using a ThriftRW protocol implementation.
func (<$v> <$typedefType>) ToWire() (<$wire>.Value, error) {
<$x> := (<typeReference .Target>)(<$v>)
return <toWire .Target $x>
}
// String returns a readable string representation of <typeName .>.
func (<$v> <$typedefType>) String() string {
<$x> := (<typeReference .Target>)(<$v>)
return <$fmt>.Sprint(<$x>)
}
<$w := newVar "w">
// FromWire deserializes <typeName .> from its Thrift-level
// representation. The Thrift-level representation may be obtained
// from a ThriftRW protocol implementation.
func (<$v> *<typeName .>) FromWire(<$w> <$wire>.Value) error {
<if isStructType . ->
return (<typeReference .Target>)(<$v>).FromWire(<$w>)
<- else ->
<$x>, err := <fromWire .Target $w>
*<$v> = (<$typedefType>)(<$x>)
return err
<- end>
}
<$lhs := newVar "lhs">
<$rhs := newVar "rhs">
// Equals returns true if this <typeName .> is equal to the provided
// <typeName .>.
func (<$lhs> <$typedefType>) Equals(<$rhs> <$typedefType>) bool {
<- $lhsCast := printf "(%v)(%v)" (typeReference .Target) $lhs ->
<- $rhsCast := printf "(%v)(%v)" (typeReference .Target) $rhs ->
return <equals .Target $lhsCast $rhsCast>
}
<if not (checkNoZap) ->
</* We want the behavior of the underlying type for typedefs: in the case that
they are objects or arrays, we need to cast to the underlying object or array;
else, zapMarshaler in zap.go will take care of it. */>
<if (eq (zapEncoder .Target) "Object") ->
<$zapcore := import "go.uber.org/zap/zapcore">
<$enc := newVar "enc">
func (<$v> <$typedefType>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error {
return (<zapMarshaler . $v>).MarshalLogObject(<$enc>)
}
<- end>
<if (eq (zapEncoder .Target) "Array") ->
<$zapcore := import "go.uber.org/zap/zapcore">
<$enc := newVar "enc">
func (<$v> <$typedefType>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error {
return (<zapMarshaler . $v>).MarshalLogArray(<$enc>)
}
<- end>
<- end>
`,
spec,
TemplateFunc("checkNoZap", checkNoZap),
)
return wrapGenerateError(spec.Name, err)
}
|
go
|
func typedef(g Generator, spec *compile.TypedefSpec) error {
err := g.DeclareFromTemplate(
`
<$fmt := import "fmt">
<$wire := import "go.uber.org/thriftrw/wire">
<$typedefType := typeReference .>
<formatDoc .Doc>type <typeName .> <typeName .Target>
<$v := newVar "v">
<$x := newVar "x">
<- if isPrimitiveType .>
// <typeName .>Ptr returns a pointer to a <$typedefType>
func (<$v> <typeName .>) Ptr() *<$typedefType>{
return &<$v>
}
<- end>
// ToWire translates <typeName .> into a Thrift-level intermediate
// representation. This intermediate representation may be serialized
// into bytes using a ThriftRW protocol implementation.
func (<$v> <$typedefType>) ToWire() (<$wire>.Value, error) {
<$x> := (<typeReference .Target>)(<$v>)
return <toWire .Target $x>
}
// String returns a readable string representation of <typeName .>.
func (<$v> <$typedefType>) String() string {
<$x> := (<typeReference .Target>)(<$v>)
return <$fmt>.Sprint(<$x>)
}
<$w := newVar "w">
// FromWire deserializes <typeName .> from its Thrift-level
// representation. The Thrift-level representation may be obtained
// from a ThriftRW protocol implementation.
func (<$v> *<typeName .>) FromWire(<$w> <$wire>.Value) error {
<if isStructType . ->
return (<typeReference .Target>)(<$v>).FromWire(<$w>)
<- else ->
<$x>, err := <fromWire .Target $w>
*<$v> = (<$typedefType>)(<$x>)
return err
<- end>
}
<$lhs := newVar "lhs">
<$rhs := newVar "rhs">
// Equals returns true if this <typeName .> is equal to the provided
// <typeName .>.
func (<$lhs> <$typedefType>) Equals(<$rhs> <$typedefType>) bool {
<- $lhsCast := printf "(%v)(%v)" (typeReference .Target) $lhs ->
<- $rhsCast := printf "(%v)(%v)" (typeReference .Target) $rhs ->
return <equals .Target $lhsCast $rhsCast>
}
<if not (checkNoZap) ->
</* We want the behavior of the underlying type for typedefs: in the case that
they are objects or arrays, we need to cast to the underlying object or array;
else, zapMarshaler in zap.go will take care of it. */>
<if (eq (zapEncoder .Target) "Object") ->
<$zapcore := import "go.uber.org/zap/zapcore">
<$enc := newVar "enc">
func (<$v> <$typedefType>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error {
return (<zapMarshaler . $v>).MarshalLogObject(<$enc>)
}
<- end>
<if (eq (zapEncoder .Target) "Array") ->
<$zapcore := import "go.uber.org/zap/zapcore">
<$enc := newVar "enc">
func (<$v> <$typedefType>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error {
return (<zapMarshaler . $v>).MarshalLogArray(<$enc>)
}
<- end>
<- end>
`,
spec,
TemplateFunc("checkNoZap", checkNoZap),
)
return wrapGenerateError(spec.Name, err)
}
|
[
"func",
"typedef",
"(",
"g",
"Generator",
",",
"spec",
"*",
"compile",
".",
"TypedefSpec",
")",
"error",
"{",
"err",
":=",
"g",
".",
"DeclareFromTemplate",
"(",
"`\n\t\t<$fmt := import \"fmt\">\n\t\t<$wire := import \"go.uber.org/thriftrw/wire\">\n\t\t<$typedefType := typeReference .>\n\n\t\t<formatDoc .Doc>type <typeName .> <typeName .Target>\n\n\t\t<$v := newVar \"v\">\n\t\t<$x := newVar \"x\">\n\n\t\t<- if isPrimitiveType .>\n\t\t// <typeName .>Ptr returns a pointer to a <$typedefType>\n\t\tfunc (<$v> <typeName .>) Ptr() *<$typedefType>{\n\t\t\treturn &<$v>\n\t\t}\n\t\t<- end>\n\n\t\t// ToWire translates <typeName .> into a Thrift-level intermediate\n\t\t// representation. This intermediate representation may be serialized\n\t\t// into bytes using a ThriftRW protocol implementation.\n\t\tfunc (<$v> <$typedefType>) ToWire() (<$wire>.Value, error) {\n\t\t\t<$x> := (<typeReference .Target>)(<$v>)\n\t\t\treturn <toWire .Target $x>\n\t\t}\n\n\t\t// String returns a readable string representation of <typeName .>.\n\t\tfunc (<$v> <$typedefType>) String() string {\n\t\t\t<$x> := (<typeReference .Target>)(<$v>)\n\t\t\treturn <$fmt>.Sprint(<$x>)\n\t\t}\n\n\t\t<$w := newVar \"w\">\n\t\t// FromWire deserializes <typeName .> from its Thrift-level\n\t\t// representation. The Thrift-level representation may be obtained\n\t\t// from a ThriftRW protocol implementation.\n\t\tfunc (<$v> *<typeName .>) FromWire(<$w> <$wire>.Value) error {\n\t\t\t<if isStructType . ->\n\t\t\t\treturn (<typeReference .Target>)(<$v>).FromWire(<$w>)\n\t\t\t<- else ->\n\t\t\t\t<$x>, err := <fromWire .Target $w>\n\t\t\t\t*<$v> = (<$typedefType>)(<$x>)\n\t\t\t\treturn err\n\t\t\t<- end>\n\t\t}\n\n\t\t<$lhs := newVar \"lhs\">\n\t\t<$rhs := newVar \"rhs\">\n\t\t// Equals returns true if this <typeName .> is equal to the provided\n\t\t// <typeName .>.\n\t\tfunc (<$lhs> <$typedefType>) Equals(<$rhs> <$typedefType>) bool {\n\t\t\t<- $lhsCast := printf \"(%v)(%v)\" (typeReference .Target) $lhs ->\n\t\t\t<- $rhsCast := printf \"(%v)(%v)\" (typeReference .Target) $rhs ->\n\t\t\treturn <equals .Target $lhsCast $rhsCast>\n\t\t}\n\n\t\t<if not (checkNoZap) ->\n\t\t</* We want the behavior of the underlying type for typedefs: in the case that\n\t\t\t\tthey are objects or arrays, we need to cast to the underlying object or array;\n\t\t\t\telse, zapMarshaler in zap.go will take care of it. */>\n\t\t<if (eq (zapEncoder .Target) \"Object\") ->\n\t\t\t<$zapcore := import \"go.uber.org/zap/zapcore\">\n\t\t\t<$enc := newVar \"enc\">\n\t\t\tfunc (<$v> <$typedefType>) MarshalLogObject(<$enc> <$zapcore>.ObjectEncoder) error {\n\t\t\t\treturn (<zapMarshaler . $v>).MarshalLogObject(<$enc>)\n\t\t\t}\n\t\t<- end>\n\n\t\t<if (eq (zapEncoder .Target) \"Array\") ->\n\t\t\t<$zapcore := import \"go.uber.org/zap/zapcore\">\n\t\t\t<$enc := newVar \"enc\">\n\t\t\tfunc (<$v> <$typedefType>) MarshalLogArray(<$enc> <$zapcore>.ArrayEncoder) error {\n\t\t\t\treturn (<zapMarshaler . $v>).MarshalLogArray(<$enc>)\n\t\t\t}\n\t\t<- end>\n\t\t<- end>\n\t\t`",
",",
"spec",
",",
"TemplateFunc",
"(",
"\"",
"\"",
",",
"checkNoZap",
")",
",",
")",
"\n",
"return",
"wrapGenerateError",
"(",
"spec",
".",
"Name",
",",
"err",
")",
"\n",
"}"
] |
// typedef generates code for the given typedef.
|
[
"typedef",
"generates",
"code",
"for",
"the",
"given",
"typedef",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/typedef.go#L56-L138
|
17,673 |
thriftrw/thriftrw-go
|
protocol/binary.go
|
EncodeResponse
|
func (r EnvelopeV0Responder) EncodeResponse(v wire.Value, t wire.EnvelopeType, w io.Writer) error {
writer := binary.BorrowWriter(w)
err := writer.WriteLegacyEnveloped(wire.Envelope{
Name: r.Name,
Type: t,
SeqID: r.SeqID,
Value: v,
})
binary.ReturnWriter(writer)
return err
}
|
go
|
func (r EnvelopeV0Responder) EncodeResponse(v wire.Value, t wire.EnvelopeType, w io.Writer) error {
writer := binary.BorrowWriter(w)
err := writer.WriteLegacyEnveloped(wire.Envelope{
Name: r.Name,
Type: t,
SeqID: r.SeqID,
Value: v,
})
binary.ReturnWriter(writer)
return err
}
|
[
"func",
"(",
"r",
"EnvelopeV0Responder",
")",
"EncodeResponse",
"(",
"v",
"wire",
".",
"Value",
",",
"t",
"wire",
".",
"EnvelopeType",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"writer",
":=",
"binary",
".",
"BorrowWriter",
"(",
"w",
")",
"\n",
"err",
":=",
"writer",
".",
"WriteLegacyEnveloped",
"(",
"wire",
".",
"Envelope",
"{",
"Name",
":",
"r",
".",
"Name",
",",
"Type",
":",
"t",
",",
"SeqID",
":",
"r",
".",
"SeqID",
",",
"Value",
":",
"v",
",",
"}",
")",
"\n",
"binary",
".",
"ReturnWriter",
"(",
"writer",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// EncodeResponse writes the response to the writer using a non-strict
// envelope.
|
[
"EncodeResponse",
"writes",
"the",
"response",
"to",
"the",
"writer",
"using",
"a",
"non",
"-",
"strict",
"envelope",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/protocol/binary.go#L235-L245
|
17,674 |
thriftrw/thriftrw-go
|
compile/cycle.go
|
visited
|
func (f typeCycleFinder) visited(s TypeSpec) bool {
for _, t := range f {
if t == s {
return true
}
}
return false
}
|
go
|
func (f typeCycleFinder) visited(s TypeSpec) bool {
for _, t := range f {
if t == s {
return true
}
}
return false
}
|
[
"func",
"(",
"f",
"typeCycleFinder",
")",
"visited",
"(",
"s",
"TypeSpec",
")",
"bool",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"f",
"{",
"if",
"t",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// visited returns true if the given TypeSpec has already been visited.
// Otherwise it returns false, and marks the TypeSpec as visited.
|
[
"visited",
"returns",
"true",
"if",
"the",
"given",
"TypeSpec",
"has",
"already",
"been",
"visited",
".",
"Otherwise",
"it",
"returns",
"false",
"and",
"marks",
"the",
"TypeSpec",
"as",
"visited",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/cycle.go#L33-L40
|
17,675 |
thriftrw/thriftrw-go
|
compile/cycle.go
|
cloneWithPart
|
func (f typeCycleFinder) cloneWithPart(s TypeSpec) typeCycleFinder {
newf := make(typeCycleFinder, 0, len(f)+1)
newf = append(newf, f...)
newf = append(newf, s)
return newf
}
|
go
|
func (f typeCycleFinder) cloneWithPart(s TypeSpec) typeCycleFinder {
newf := make(typeCycleFinder, 0, len(f)+1)
newf = append(newf, f...)
newf = append(newf, s)
return newf
}
|
[
"func",
"(",
"f",
"typeCycleFinder",
")",
"cloneWithPart",
"(",
"s",
"TypeSpec",
")",
"typeCycleFinder",
"{",
"newf",
":=",
"make",
"(",
"typeCycleFinder",
",",
"0",
",",
"len",
"(",
"f",
")",
"+",
"1",
")",
"\n",
"newf",
"=",
"append",
"(",
"newf",
",",
"f",
"...",
")",
"\n",
"newf",
"=",
"append",
"(",
"newf",
",",
"s",
")",
"\n",
"return",
"newf",
"\n",
"}"
] |
// cloneWithPart creates a copy of this typeCycleFinder with the given
// TypeSpec added to the chain.
|
[
"cloneWithPart",
"creates",
"a",
"copy",
"of",
"this",
"typeCycleFinder",
"with",
"the",
"given",
"TypeSpec",
"added",
"to",
"the",
"chain",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/cycle.go#L44-L49
|
17,676 |
thriftrw/thriftrw-go
|
gen/imports.go
|
newImporter
|
func newImporter(ns Namespace) importer {
return importer{
ns: ns,
imports: make(map[string]*ast.ImportSpec),
}
}
|
go
|
func newImporter(ns Namespace) importer {
return importer{
ns: ns,
imports: make(map[string]*ast.ImportSpec),
}
}
|
[
"func",
"newImporter",
"(",
"ns",
"Namespace",
")",
"importer",
"{",
"return",
"importer",
"{",
"ns",
":",
"ns",
",",
"imports",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"ImportSpec",
")",
",",
"}",
"\n",
"}"
] |
// newImporter builds a new importer.
|
[
"newImporter",
"builds",
"a",
"new",
"importer",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/imports.go#L39-L44
|
17,677 |
thriftrw/thriftrw-go
|
gen/imports.go
|
AddImportSpec
|
func (i importer) AddImportSpec(spec *ast.ImportSpec) error {
path := spec.Path.Value
name := filepath.Base(path)
if spec.Name != nil {
name = spec.Name.Name
}
if err := i.ns.Reserve(name); err != nil {
return err
}
i.imports[path] = spec
return nil
}
|
go
|
func (i importer) AddImportSpec(spec *ast.ImportSpec) error {
path := spec.Path.Value
name := filepath.Base(path)
if spec.Name != nil {
name = spec.Name.Name
}
if err := i.ns.Reserve(name); err != nil {
return err
}
i.imports[path] = spec
return nil
}
|
[
"func",
"(",
"i",
"importer",
")",
"AddImportSpec",
"(",
"spec",
"*",
"ast",
".",
"ImportSpec",
")",
"error",
"{",
"path",
":=",
"spec",
".",
"Path",
".",
"Value",
"\n",
"name",
":=",
"filepath",
".",
"Base",
"(",
"path",
")",
"\n",
"if",
"spec",
".",
"Name",
"!=",
"nil",
"{",
"name",
"=",
"spec",
".",
"Name",
".",
"Name",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"i",
".",
"ns",
".",
"Reserve",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"i",
".",
"imports",
"[",
"path",
"]",
"=",
"spec",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddImportSpec allows adding existing import specs to the importer.
//
// An error is returned if there's a naming conflict.
|
[
"AddImportSpec",
"allows",
"adding",
"existing",
"import",
"specs",
"to",
"the",
"importer",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"s",
"a",
"naming",
"conflict",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/imports.go#L49-L62
|
17,678 |
thriftrw/thriftrw-go
|
gen/imports.go
|
Import
|
func (i importer) Import(path string) string {
if imp, ok := i.imports[path]; ok {
if imp.Name != nil {
return imp.Name.Name
}
return filepath.Base(path)
}
name := i.ns.NewName(goast.DeterminePackageName(path))
astImport := &ast.ImportSpec{
Name: ast.NewIdent(name),
Path: stringLiteral(path),
}
i.imports[path] = astImport
return name
}
|
go
|
func (i importer) Import(path string) string {
if imp, ok := i.imports[path]; ok {
if imp.Name != nil {
return imp.Name.Name
}
return filepath.Base(path)
}
name := i.ns.NewName(goast.DeterminePackageName(path))
astImport := &ast.ImportSpec{
Name: ast.NewIdent(name),
Path: stringLiteral(path),
}
i.imports[path] = astImport
return name
}
|
[
"func",
"(",
"i",
"importer",
")",
"Import",
"(",
"path",
"string",
")",
"string",
"{",
"if",
"imp",
",",
"ok",
":=",
"i",
".",
"imports",
"[",
"path",
"]",
";",
"ok",
"{",
"if",
"imp",
".",
"Name",
"!=",
"nil",
"{",
"return",
"imp",
".",
"Name",
".",
"Name",
"\n",
"}",
"\n",
"return",
"filepath",
".",
"Base",
"(",
"path",
")",
"\n",
"}",
"\n\n",
"name",
":=",
"i",
".",
"ns",
".",
"NewName",
"(",
"goast",
".",
"DeterminePackageName",
"(",
"path",
")",
")",
"\n",
"astImport",
":=",
"&",
"ast",
".",
"ImportSpec",
"{",
"Name",
":",
"ast",
".",
"NewIdent",
"(",
"name",
")",
",",
"Path",
":",
"stringLiteral",
"(",
"path",
")",
",",
"}",
"\n\n",
"i",
".",
"imports",
"[",
"path",
"]",
"=",
"astImport",
"\n",
"return",
"name",
"\n",
"}"
] |
// Import ensures that the generated module has the given module imported and
// returns the name that should be used by the generated code to reference items
// defined in the module.
|
[
"Import",
"ensures",
"that",
"the",
"generated",
"module",
"has",
"the",
"given",
"module",
"imported",
"and",
"returns",
"the",
"name",
"that",
"should",
"be",
"used",
"by",
"the",
"generated",
"code",
"to",
"reference",
"items",
"defined",
"in",
"the",
"module",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/imports.go#L67-L83
|
17,679 |
thriftrw/thriftrw-go
|
gen/imports.go
|
importDecl
|
func (i importer) importDecl() ast.Decl {
imports := i.imports
if imports == nil || len(imports) == 0 {
return nil
}
specs := make([]ast.Spec, 0, len(imports))
for _, iname := range sortStringKeys(imports) {
imp := imports[iname]
specs = append(specs, imp)
}
decl := &ast.GenDecl{Tok: token.IMPORT, Specs: specs}
if len(specs) > 1 {
// Just need a non-zero value for Lparen to get the parens added.
decl.Lparen = token.Pos(1)
}
return decl
}
|
go
|
func (i importer) importDecl() ast.Decl {
imports := i.imports
if imports == nil || len(imports) == 0 {
return nil
}
specs := make([]ast.Spec, 0, len(imports))
for _, iname := range sortStringKeys(imports) {
imp := imports[iname]
specs = append(specs, imp)
}
decl := &ast.GenDecl{Tok: token.IMPORT, Specs: specs}
if len(specs) > 1 {
// Just need a non-zero value for Lparen to get the parens added.
decl.Lparen = token.Pos(1)
}
return decl
}
|
[
"func",
"(",
"i",
"importer",
")",
"importDecl",
"(",
")",
"ast",
".",
"Decl",
"{",
"imports",
":=",
"i",
".",
"imports",
"\n",
"if",
"imports",
"==",
"nil",
"||",
"len",
"(",
"imports",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"specs",
":=",
"make",
"(",
"[",
"]",
"ast",
".",
"Spec",
",",
"0",
",",
"len",
"(",
"imports",
")",
")",
"\n",
"for",
"_",
",",
"iname",
":=",
"range",
"sortStringKeys",
"(",
"imports",
")",
"{",
"imp",
":=",
"imports",
"[",
"iname",
"]",
"\n",
"specs",
"=",
"append",
"(",
"specs",
",",
"imp",
")",
"\n",
"}",
"\n\n",
"decl",
":=",
"&",
"ast",
".",
"GenDecl",
"{",
"Tok",
":",
"token",
".",
"IMPORT",
",",
"Specs",
":",
"specs",
"}",
"\n",
"if",
"len",
"(",
"specs",
")",
">",
"1",
"{",
"// Just need a non-zero value for Lparen to get the parens added.",
"decl",
".",
"Lparen",
"=",
"token",
".",
"Pos",
"(",
"1",
")",
"\n",
"}",
"\n\n",
"return",
"decl",
"\n",
"}"
] |
// importDecl builds an import declation from the given list of imports.
|
[
"importDecl",
"builds",
"an",
"import",
"declation",
"from",
"the",
"given",
"list",
"of",
"imports",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/gen/imports.go#L86-L105
|
17,680 |
thriftrw/thriftrw-go
|
envelope/envelope.go
|
Write
|
func Write(p protocol.Protocol, w io.Writer, seqID int32, e Enveloper) error {
body, err := e.ToWire()
if err != nil {
return err
}
return p.EncodeEnveloped(wire.Envelope{
SeqID: seqID,
Name: e.MethodName(),
Type: e.EnvelopeType(),
Value: body,
}, w)
}
|
go
|
func Write(p protocol.Protocol, w io.Writer, seqID int32, e Enveloper) error {
body, err := e.ToWire()
if err != nil {
return err
}
return p.EncodeEnveloped(wire.Envelope{
SeqID: seqID,
Name: e.MethodName(),
Type: e.EnvelopeType(),
Value: body,
}, w)
}
|
[
"func",
"Write",
"(",
"p",
"protocol",
".",
"Protocol",
",",
"w",
"io",
".",
"Writer",
",",
"seqID",
"int32",
",",
"e",
"Enveloper",
")",
"error",
"{",
"body",
",",
"err",
":=",
"e",
".",
"ToWire",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"p",
".",
"EncodeEnveloped",
"(",
"wire",
".",
"Envelope",
"{",
"SeqID",
":",
"seqID",
",",
"Name",
":",
"e",
".",
"MethodName",
"(",
")",
",",
"Type",
":",
"e",
".",
"EnvelopeType",
"(",
")",
",",
"Value",
":",
"body",
",",
"}",
",",
"w",
")",
"\n",
"}"
] |
// Write writes an Envelope to the given writer.
|
[
"Write",
"writes",
"an",
"Envelope",
"to",
"the",
"given",
"writer",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/envelope/envelope.go#L41-L52
|
17,681 |
thriftrw/thriftrw-go
|
envelope/envelope.go
|
ReadReply
|
func ReadReply(p protocol.Protocol, r io.ReaderAt) (_ wire.Value, seqID int32, _ error) {
envelope, err := p.DecodeEnveloped(r)
if err != nil {
return wire.Value{}, 0, err
}
switch {
case envelope.Type == wire.Reply:
return envelope.Value, envelope.SeqID, nil
case envelope.Type != wire.Exception:
return envelope.Value, envelope.SeqID, fmt.Errorf("unknown envelope type for reply, got %v", envelope.Type)
}
// Decode the exception payload.
ex := &exception.TApplicationException{}
if err := ex.FromWire(envelope.Value); err != nil {
return envelope.Value, envelope.SeqID, fmt.Errorf("failed to decode exception: %v", err)
}
return envelope.Value, envelope.SeqID, ex
}
|
go
|
func ReadReply(p protocol.Protocol, r io.ReaderAt) (_ wire.Value, seqID int32, _ error) {
envelope, err := p.DecodeEnveloped(r)
if err != nil {
return wire.Value{}, 0, err
}
switch {
case envelope.Type == wire.Reply:
return envelope.Value, envelope.SeqID, nil
case envelope.Type != wire.Exception:
return envelope.Value, envelope.SeqID, fmt.Errorf("unknown envelope type for reply, got %v", envelope.Type)
}
// Decode the exception payload.
ex := &exception.TApplicationException{}
if err := ex.FromWire(envelope.Value); err != nil {
return envelope.Value, envelope.SeqID, fmt.Errorf("failed to decode exception: %v", err)
}
return envelope.Value, envelope.SeqID, ex
}
|
[
"func",
"ReadReply",
"(",
"p",
"protocol",
".",
"Protocol",
",",
"r",
"io",
".",
"ReaderAt",
")",
"(",
"_",
"wire",
".",
"Value",
",",
"seqID",
"int32",
",",
"_",
"error",
")",
"{",
"envelope",
",",
"err",
":=",
"p",
".",
"DecodeEnveloped",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"wire",
".",
"Value",
"{",
"}",
",",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"{",
"case",
"envelope",
".",
"Type",
"==",
"wire",
".",
"Reply",
":",
"return",
"envelope",
".",
"Value",
",",
"envelope",
".",
"SeqID",
",",
"nil",
"\n",
"case",
"envelope",
".",
"Type",
"!=",
"wire",
".",
"Exception",
":",
"return",
"envelope",
".",
"Value",
",",
"envelope",
".",
"SeqID",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"envelope",
".",
"Type",
")",
"\n",
"}",
"\n\n",
"// Decode the exception payload.",
"ex",
":=",
"&",
"exception",
".",
"TApplicationException",
"{",
"}",
"\n",
"if",
"err",
":=",
"ex",
".",
"FromWire",
"(",
"envelope",
".",
"Value",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"envelope",
".",
"Value",
",",
"envelope",
".",
"SeqID",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"envelope",
".",
"Value",
",",
"envelope",
".",
"SeqID",
",",
"ex",
"\n",
"}"
] |
// ReadReply reads enveloped responses from the given reader.
|
[
"ReadReply",
"reads",
"enveloped",
"responses",
"from",
"the",
"given",
"reader",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/envelope/envelope.go#L55-L75
|
17,682 |
thriftrw/thriftrw-go
|
compile/container.go
|
compileMapType
|
func compileMapType(src ast.MapType) (*MapSpec, error) {
annots, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, err
}
keySpec, err := compileTypeReference(src.KeyType)
if err != nil {
return nil, err
}
valueSpec, err := compileTypeReference(src.ValueType)
if err != nil {
return nil, err
}
return &MapSpec{
KeySpec: keySpec,
ValueSpec: valueSpec,
Annotations: annots,
}, nil
}
|
go
|
func compileMapType(src ast.MapType) (*MapSpec, error) {
annots, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, err
}
keySpec, err := compileTypeReference(src.KeyType)
if err != nil {
return nil, err
}
valueSpec, err := compileTypeReference(src.ValueType)
if err != nil {
return nil, err
}
return &MapSpec{
KeySpec: keySpec,
ValueSpec: valueSpec,
Annotations: annots,
}, nil
}
|
[
"func",
"compileMapType",
"(",
"src",
"ast",
".",
"MapType",
")",
"(",
"*",
"MapSpec",
",",
"error",
")",
"{",
"annots",
",",
"err",
":=",
"compileAnnotations",
"(",
"src",
".",
"Annotations",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"keySpec",
",",
"err",
":=",
"compileTypeReference",
"(",
"src",
".",
"KeyType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"valueSpec",
",",
"err",
":=",
"compileTypeReference",
"(",
"src",
".",
"ValueType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"MapSpec",
"{",
"KeySpec",
":",
"keySpec",
",",
"ValueSpec",
":",
"valueSpec",
",",
"Annotations",
":",
"annots",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// compileMapType compiles the given MapType AST into a MapSpec.
|
[
"compileMapType",
"compiles",
"the",
"given",
"MapType",
"AST",
"into",
"a",
"MapSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L40-L61
|
17,683 |
thriftrw/thriftrw-go
|
compile/container.go
|
Link
|
func (m *MapSpec) Link(scope Scope) (TypeSpec, error) {
if m.linked() {
return m, nil
}
var err error
m.KeySpec, err = m.KeySpec.Link(scope)
if err != nil {
return m, err
}
m.ValueSpec, err = m.ValueSpec.Link(scope)
if err != nil {
return m, err
}
return m, nil
}
|
go
|
func (m *MapSpec) Link(scope Scope) (TypeSpec, error) {
if m.linked() {
return m, nil
}
var err error
m.KeySpec, err = m.KeySpec.Link(scope)
if err != nil {
return m, err
}
m.ValueSpec, err = m.ValueSpec.Link(scope)
if err != nil {
return m, err
}
return m, nil
}
|
[
"func",
"(",
"m",
"*",
"MapSpec",
")",
"Link",
"(",
"scope",
"Scope",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"if",
"m",
".",
"linked",
"(",
")",
"{",
"return",
"m",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"m",
".",
"KeySpec",
",",
"err",
"=",
"m",
".",
"KeySpec",
".",
"Link",
"(",
"scope",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"m",
",",
"err",
"\n",
"}",
"\n\n",
"m",
".",
"ValueSpec",
",",
"err",
"=",
"m",
".",
"ValueSpec",
".",
"Link",
"(",
"scope",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"m",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] |
// Link resolves the type references in the MapSpec.
|
[
"Link",
"resolves",
"the",
"type",
"references",
"in",
"the",
"MapSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L64-L81
|
17,684 |
thriftrw/thriftrw-go
|
compile/container.go
|
ThriftName
|
func (m *MapSpec) ThriftName() string {
return fmt.Sprintf(
"map<%s, %s>", m.KeySpec.ThriftName(), m.ValueSpec.ThriftName(),
)
}
|
go
|
func (m *MapSpec) ThriftName() string {
return fmt.Sprintf(
"map<%s, %s>", m.KeySpec.ThriftName(), m.ValueSpec.ThriftName(),
)
}
|
[
"func",
"(",
"m",
"*",
"MapSpec",
")",
"ThriftName",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"m",
".",
"KeySpec",
".",
"ThriftName",
"(",
")",
",",
"m",
".",
"ValueSpec",
".",
"ThriftName",
"(",
")",
",",
")",
"\n",
"}"
] |
// ThriftName for MapSpec
|
[
"ThriftName",
"for",
"MapSpec"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L84-L88
|
17,685 |
thriftrw/thriftrw-go
|
compile/container.go
|
ForEachTypeReference
|
func (m *MapSpec) ForEachTypeReference(f func(TypeSpec) error) error {
if err := f(m.KeySpec); err != nil {
return err
}
return f(m.ValueSpec)
}
|
go
|
func (m *MapSpec) ForEachTypeReference(f func(TypeSpec) error) error {
if err := f(m.KeySpec); err != nil {
return err
}
return f(m.ValueSpec)
}
|
[
"func",
"(",
"m",
"*",
"MapSpec",
")",
"ForEachTypeReference",
"(",
"f",
"func",
"(",
"TypeSpec",
")",
"error",
")",
"error",
"{",
"if",
"err",
":=",
"f",
"(",
"m",
".",
"KeySpec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"f",
"(",
"m",
".",
"ValueSpec",
")",
"\n",
"}"
] |
// ForEachTypeReference for MapSpec
|
[
"ForEachTypeReference",
"for",
"MapSpec"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L96-L101
|
17,686 |
thriftrw/thriftrw-go
|
compile/container.go
|
compileListType
|
func compileListType(src ast.ListType) (*ListSpec, error) {
annots, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, err
}
valueSpec, err := compileTypeReference(src.ValueType)
if err != nil {
return nil, err
}
return &ListSpec{
ValueSpec: valueSpec,
Annotations: annots,
}, nil
}
|
go
|
func compileListType(src ast.ListType) (*ListSpec, error) {
annots, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, err
}
valueSpec, err := compileTypeReference(src.ValueType)
if err != nil {
return nil, err
}
return &ListSpec{
ValueSpec: valueSpec,
Annotations: annots,
}, nil
}
|
[
"func",
"compileListType",
"(",
"src",
"ast",
".",
"ListType",
")",
"(",
"*",
"ListSpec",
",",
"error",
")",
"{",
"annots",
",",
"err",
":=",
"compileAnnotations",
"(",
"src",
".",
"Annotations",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"valueSpec",
",",
"err",
":=",
"compileTypeReference",
"(",
"src",
".",
"ValueType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"ListSpec",
"{",
"ValueSpec",
":",
"valueSpec",
",",
"Annotations",
":",
"annots",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// compileListSpec compiles the given ListType AST into a ListSpec.
|
[
"compileListSpec",
"compiles",
"the",
"given",
"ListType",
"AST",
"into",
"a",
"ListSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L120-L135
|
17,687 |
thriftrw/thriftrw-go
|
compile/container.go
|
Link
|
func (l *ListSpec) Link(scope Scope) (TypeSpec, error) {
if l.linked() {
return l, nil
}
var err error
l.ValueSpec, err = l.ValueSpec.Link(scope)
return l, err
}
|
go
|
func (l *ListSpec) Link(scope Scope) (TypeSpec, error) {
if l.linked() {
return l, nil
}
var err error
l.ValueSpec, err = l.ValueSpec.Link(scope)
return l, err
}
|
[
"func",
"(",
"l",
"*",
"ListSpec",
")",
"Link",
"(",
"scope",
"Scope",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"if",
"l",
".",
"linked",
"(",
")",
"{",
"return",
"l",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"l",
".",
"ValueSpec",
",",
"err",
"=",
"l",
".",
"ValueSpec",
".",
"Link",
"(",
"scope",
")",
"\n",
"return",
"l",
",",
"err",
"\n",
"}"
] |
// Link resolves the type references in the ListSpec.
|
[
"Link",
"resolves",
"the",
"type",
"references",
"in",
"the",
"ListSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L138-L146
|
17,688 |
thriftrw/thriftrw-go
|
compile/container.go
|
ForEachTypeReference
|
func (l *ListSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return f(l.ValueSpec)
}
|
go
|
func (l *ListSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return f(l.ValueSpec)
}
|
[
"func",
"(",
"l",
"*",
"ListSpec",
")",
"ForEachTypeReference",
"(",
"f",
"func",
"(",
"TypeSpec",
")",
"error",
")",
"error",
"{",
"return",
"f",
"(",
"l",
".",
"ValueSpec",
")",
"\n",
"}"
] |
// ForEachTypeReference for ListSpec
|
[
"ForEachTypeReference",
"for",
"ListSpec"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L159-L161
|
17,689 |
thriftrw/thriftrw-go
|
compile/container.go
|
compileSetType
|
func compileSetType(src ast.SetType) (*SetSpec, error) {
annots, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, err
}
valueSpec, err := compileTypeReference(src.ValueType)
if err != nil {
return nil, err
}
return &SetSpec{
ValueSpec: valueSpec,
Annotations: annots,
}, nil
}
|
go
|
func compileSetType(src ast.SetType) (*SetSpec, error) {
annots, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, err
}
valueSpec, err := compileTypeReference(src.ValueType)
if err != nil {
return nil, err
}
return &SetSpec{
ValueSpec: valueSpec,
Annotations: annots,
}, nil
}
|
[
"func",
"compileSetType",
"(",
"src",
"ast",
".",
"SetType",
")",
"(",
"*",
"SetSpec",
",",
"error",
")",
"{",
"annots",
",",
"err",
":=",
"compileAnnotations",
"(",
"src",
".",
"Annotations",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"valueSpec",
",",
"err",
":=",
"compileTypeReference",
"(",
"src",
".",
"ValueType",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"SetSpec",
"{",
"ValueSpec",
":",
"valueSpec",
",",
"Annotations",
":",
"annots",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// compileSetSpec compiles the given SetType AST into a SetSpec.
|
[
"compileSetSpec",
"compiles",
"the",
"given",
"SetType",
"AST",
"into",
"a",
"SetSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L180-L195
|
17,690 |
thriftrw/thriftrw-go
|
compile/container.go
|
Link
|
func (s *SetSpec) Link(scope Scope) (TypeSpec, error) {
if s.linked() {
return s, nil
}
var err error
s.ValueSpec, err = s.ValueSpec.Link(scope)
return s, err
}
|
go
|
func (s *SetSpec) Link(scope Scope) (TypeSpec, error) {
if s.linked() {
return s, nil
}
var err error
s.ValueSpec, err = s.ValueSpec.Link(scope)
return s, err
}
|
[
"func",
"(",
"s",
"*",
"SetSpec",
")",
"Link",
"(",
"scope",
"Scope",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"if",
"s",
".",
"linked",
"(",
")",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"s",
".",
"ValueSpec",
",",
"err",
"=",
"s",
".",
"ValueSpec",
".",
"Link",
"(",
"scope",
")",
"\n",
"return",
"s",
",",
"err",
"\n",
"}"
] |
// Link resolves the type references in the SetSpec.
|
[
"Link",
"resolves",
"the",
"type",
"references",
"in",
"the",
"SetSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L198-L206
|
17,691 |
thriftrw/thriftrw-go
|
compile/container.go
|
ForEachTypeReference
|
func (s *SetSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return f(s.ValueSpec)
}
|
go
|
func (s *SetSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return f(s.ValueSpec)
}
|
[
"func",
"(",
"s",
"*",
"SetSpec",
")",
"ForEachTypeReference",
"(",
"f",
"func",
"(",
"TypeSpec",
")",
"error",
")",
"error",
"{",
"return",
"f",
"(",
"s",
".",
"ValueSpec",
")",
"\n",
"}"
] |
// ForEachTypeReference for SetSpec
|
[
"ForEachTypeReference",
"for",
"SetSpec"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/container.go#L219-L221
|
17,692 |
thriftrw/thriftrw-go
|
compile/struct.go
|
compileStruct
|
func compileStruct(file string, src *ast.Struct, requiredness fieldRequiredness) (*StructSpec, error) {
opts := fieldOptions{requiredness: requiredness}
if src.Type == ast.UnionType {
opts.requiredness = noRequiredFields
opts.disallowDefaultValue = true
}
fields, err := compileFields(src.Fields, opts)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
annotations, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
return &StructSpec{
Name: src.Name,
File: file,
Type: src.Type,
Fields: fields,
Doc: src.Doc,
Annotations: annotations,
}, nil
}
|
go
|
func compileStruct(file string, src *ast.Struct, requiredness fieldRequiredness) (*StructSpec, error) {
opts := fieldOptions{requiredness: requiredness}
if src.Type == ast.UnionType {
opts.requiredness = noRequiredFields
opts.disallowDefaultValue = true
}
fields, err := compileFields(src.Fields, opts)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
annotations, err := compileAnnotations(src.Annotations)
if err != nil {
return nil, compileError{
Target: src.Name,
Line: src.Line,
Reason: err,
}
}
return &StructSpec{
Name: src.Name,
File: file,
Type: src.Type,
Fields: fields,
Doc: src.Doc,
Annotations: annotations,
}, nil
}
|
[
"func",
"compileStruct",
"(",
"file",
"string",
",",
"src",
"*",
"ast",
".",
"Struct",
",",
"requiredness",
"fieldRequiredness",
")",
"(",
"*",
"StructSpec",
",",
"error",
")",
"{",
"opts",
":=",
"fieldOptions",
"{",
"requiredness",
":",
"requiredness",
"}",
"\n\n",
"if",
"src",
".",
"Type",
"==",
"ast",
".",
"UnionType",
"{",
"opts",
".",
"requiredness",
"=",
"noRequiredFields",
"\n",
"opts",
".",
"disallowDefaultValue",
"=",
"true",
"\n",
"}",
"\n\n",
"fields",
",",
"err",
":=",
"compileFields",
"(",
"src",
".",
"Fields",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"annotations",
",",
"err",
":=",
"compileAnnotations",
"(",
"src",
".",
"Annotations",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"compileError",
"{",
"Target",
":",
"src",
".",
"Name",
",",
"Line",
":",
"src",
".",
"Line",
",",
"Reason",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"StructSpec",
"{",
"Name",
":",
"src",
".",
"Name",
",",
"File",
":",
"file",
",",
"Type",
":",
"src",
".",
"Type",
",",
"Fields",
":",
"fields",
",",
"Doc",
":",
"src",
".",
"Doc",
",",
"Annotations",
":",
"annotations",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// compileStruct compiles a struct AST into a StructSpec.
|
[
"compileStruct",
"compiles",
"a",
"struct",
"AST",
"into",
"a",
"StructSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/struct.go#L41-L75
|
17,693 |
thriftrw/thriftrw-go
|
compile/struct.go
|
Link
|
func (s *StructSpec) Link(scope Scope) (TypeSpec, error) {
if s.linked() {
return s, nil
}
err := s.Fields.Link(scope)
return s, err
}
|
go
|
func (s *StructSpec) Link(scope Scope) (TypeSpec, error) {
if s.linked() {
return s, nil
}
err := s.Fields.Link(scope)
return s, err
}
|
[
"func",
"(",
"s",
"*",
"StructSpec",
")",
"Link",
"(",
"scope",
"Scope",
")",
"(",
"TypeSpec",
",",
"error",
")",
"{",
"if",
"s",
".",
"linked",
"(",
")",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n\n",
"err",
":=",
"s",
".",
"Fields",
".",
"Link",
"(",
"scope",
")",
"\n",
"return",
"s",
",",
"err",
"\n",
"}"
] |
// Link links together all references in the StructSpec.
|
[
"Link",
"links",
"together",
"all",
"references",
"in",
"the",
"StructSpec",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/struct.go#L78-L85
|
17,694 |
thriftrw/thriftrw-go
|
compile/struct.go
|
ForEachTypeReference
|
func (s *StructSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return s.Fields.ForEachTypeReference(f)
}
|
go
|
func (s *StructSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return s.Fields.ForEachTypeReference(f)
}
|
[
"func",
"(",
"s",
"*",
"StructSpec",
")",
"ForEachTypeReference",
"(",
"f",
"func",
"(",
"TypeSpec",
")",
"error",
")",
"error",
"{",
"return",
"s",
".",
"Fields",
".",
"ForEachTypeReference",
"(",
"f",
")",
"\n",
"}"
] |
// ForEachTypeReference for StructSpec
|
[
"ForEachTypeReference",
"for",
"StructSpec"
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/compile/struct.go#L109-L111
|
17,695 |
thriftrw/thriftrw-go
|
main.go
|
verifyAncestry
|
func verifyAncestry(m *compile.Module, root string) error {
return m.Walk(func(m *compile.Module) error {
path, err := filepath.Rel(root, m.ThriftPath)
if err != nil {
return fmt.Errorf(
"could not resolve path for %q: %v", m.ThriftPath, err)
}
if strings.HasPrefix(path, "..") {
return fmt.Errorf(
"%q is not contained in the %q directory tree",
m.ThriftPath, root)
}
return nil
})
}
|
go
|
func verifyAncestry(m *compile.Module, root string) error {
return m.Walk(func(m *compile.Module) error {
path, err := filepath.Rel(root, m.ThriftPath)
if err != nil {
return fmt.Errorf(
"could not resolve path for %q: %v", m.ThriftPath, err)
}
if strings.HasPrefix(path, "..") {
return fmt.Errorf(
"%q is not contained in the %q directory tree",
m.ThriftPath, root)
}
return nil
})
}
|
[
"func",
"verifyAncestry",
"(",
"m",
"*",
"compile",
".",
"Module",
",",
"root",
"string",
")",
"error",
"{",
"return",
"m",
".",
"Walk",
"(",
"func",
"(",
"m",
"*",
"compile",
".",
"Module",
")",
"error",
"{",
"path",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"root",
",",
"m",
".",
"ThriftPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"ThriftPath",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"\"",
"\"",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"m",
".",
"ThriftPath",
",",
"root",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] |
// verifyAncestry verifies that the Thrift file for the given module and the
// Thrift files for all imported modules are contained within the directory
// tree rooted at the given path.
|
[
"verifyAncestry",
"verifies",
"that",
"the",
"Thrift",
"file",
"for",
"the",
"given",
"module",
"and",
"the",
"Thrift",
"files",
"for",
"all",
"imported",
"modules",
"are",
"contained",
"within",
"the",
"directory",
"tree",
"rooted",
"at",
"the",
"given",
"path",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/main.go#L193-L209
|
17,696 |
thriftrw/thriftrw-go
|
main.go
|
findCommonAncestor
|
func findCommonAncestor(m *compile.Module) (string, error) {
var result []string
var lastString string
err := m.Walk(func(m *compile.Module) error {
thriftPath := m.ThriftPath
if !filepath.IsAbs(thriftPath) {
return fmt.Errorf(
"ThriftPath must be absolute: %q is not absolute", thriftPath)
}
thriftDir := filepath.Dir(thriftPath)
// Split("/foo/bar", "/") = ["", "foo", "bar"]
parts := strings.Split(thriftDir, string(filepath.Separator))
if result == nil {
result = parts
lastString = thriftPath
return nil
}
result = commonPrefix(result, parts)
if len(result) == 1 && result[0] == "" {
return fmt.Errorf(
"%q does not share an ancestor with %q",
thriftPath, lastString)
}
lastString = thriftPath
return nil
})
if err != nil {
return "", err
}
return strings.Join(result, string(filepath.Separator)), nil
}
|
go
|
func findCommonAncestor(m *compile.Module) (string, error) {
var result []string
var lastString string
err := m.Walk(func(m *compile.Module) error {
thriftPath := m.ThriftPath
if !filepath.IsAbs(thriftPath) {
return fmt.Errorf(
"ThriftPath must be absolute: %q is not absolute", thriftPath)
}
thriftDir := filepath.Dir(thriftPath)
// Split("/foo/bar", "/") = ["", "foo", "bar"]
parts := strings.Split(thriftDir, string(filepath.Separator))
if result == nil {
result = parts
lastString = thriftPath
return nil
}
result = commonPrefix(result, parts)
if len(result) == 1 && result[0] == "" {
return fmt.Errorf(
"%q does not share an ancestor with %q",
thriftPath, lastString)
}
lastString = thriftPath
return nil
})
if err != nil {
return "", err
}
return strings.Join(result, string(filepath.Separator)), nil
}
|
[
"func",
"findCommonAncestor",
"(",
"m",
"*",
"compile",
".",
"Module",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"string",
"\n",
"var",
"lastString",
"string",
"\n\n",
"err",
":=",
"m",
".",
"Walk",
"(",
"func",
"(",
"m",
"*",
"compile",
".",
"Module",
")",
"error",
"{",
"thriftPath",
":=",
"m",
".",
"ThriftPath",
"\n",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"thriftPath",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"thriftPath",
")",
"\n",
"}",
"\n\n",
"thriftDir",
":=",
"filepath",
".",
"Dir",
"(",
"thriftPath",
")",
"\n\n",
"// Split(\"/foo/bar\", \"/\") = [\"\", \"foo\", \"bar\"]",
"parts",
":=",
"strings",
".",
"Split",
"(",
"thriftDir",
",",
"string",
"(",
"filepath",
".",
"Separator",
")",
")",
"\n",
"if",
"result",
"==",
"nil",
"{",
"result",
"=",
"parts",
"\n",
"lastString",
"=",
"thriftPath",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"result",
"=",
"commonPrefix",
"(",
"result",
",",
"parts",
")",
"\n",
"if",
"len",
"(",
"result",
")",
"==",
"1",
"&&",
"result",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"thriftPath",
",",
"lastString",
")",
"\n",
"}",
"\n\n",
"lastString",
"=",
"thriftPath",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"result",
",",
"string",
"(",
"filepath",
".",
"Separator",
")",
")",
",",
"nil",
"\n",
"}"
] |
// findCommonAncestor finds the deepest common ancestor for the given module
// and all modules imported by it.
|
[
"findCommonAncestor",
"finds",
"the",
"deepest",
"common",
"ancestor",
"for",
"the",
"given",
"module",
"and",
"all",
"modules",
"imported",
"by",
"it",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/main.go#L213-L249
|
17,697 |
thriftrw/thriftrw-go
|
main.go
|
commonPrefix
|
func commonPrefix(l, r []string) []string {
var i int
for i = 0; i < len(l) && i < len(r); i++ {
if l[i] != r[i] {
break
}
}
return l[:i]
}
|
go
|
func commonPrefix(l, r []string) []string {
var i int
for i = 0; i < len(l) && i < len(r); i++ {
if l[i] != r[i] {
break
}
}
return l[:i]
}
|
[
"func",
"commonPrefix",
"(",
"l",
",",
"r",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"i",
"int",
"\n",
"for",
"i",
"=",
"0",
";",
"i",
"<",
"len",
"(",
"l",
")",
"&&",
"i",
"<",
"len",
"(",
"r",
")",
";",
"i",
"++",
"{",
"if",
"l",
"[",
"i",
"]",
"!=",
"r",
"[",
"i",
"]",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"l",
"[",
":",
"i",
"]",
"\n",
"}"
] |
// commonPrefix finds the shortest common prefix for the two lists.
//
// An empty slice may be returned if the two lists don't have a common prefix.
|
[
"commonPrefix",
"finds",
"the",
"shortest",
"common",
"prefix",
"for",
"the",
"two",
"lists",
".",
"An",
"empty",
"slice",
"may",
"be",
"returned",
"if",
"the",
"two",
"lists",
"don",
"t",
"have",
"a",
"common",
"prefix",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/main.go#L254-L262
|
17,698 |
thriftrw/thriftrw-go
|
main.go
|
determinePackagePrefix
|
func determinePackagePrefix(dir string) (string, error) {
gopathList := os.Getenv("GOPATH")
if gopathList == "" {
return "", errors.New("$GOPATH is not set")
}
for _, gopath := range filepath.SplitList(gopathList) {
packagePath, err := filepath.Rel(filepath.Join(gopath, "src"), dir)
if err != nil {
return "", err
}
// The match is valid only if it's within the directory tree.
if !strings.HasPrefix(packagePath, "..") {
return packagePath, nil
}
}
return "", fmt.Errorf("directory %q is not inside $GOPATH/src", dir)
}
|
go
|
func determinePackagePrefix(dir string) (string, error) {
gopathList := os.Getenv("GOPATH")
if gopathList == "" {
return "", errors.New("$GOPATH is not set")
}
for _, gopath := range filepath.SplitList(gopathList) {
packagePath, err := filepath.Rel(filepath.Join(gopath, "src"), dir)
if err != nil {
return "", err
}
// The match is valid only if it's within the directory tree.
if !strings.HasPrefix(packagePath, "..") {
return packagePath, nil
}
}
return "", fmt.Errorf("directory %q is not inside $GOPATH/src", dir)
}
|
[
"func",
"determinePackagePrefix",
"(",
"dir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"gopathList",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"gopathList",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"gopath",
":=",
"range",
"filepath",
".",
"SplitList",
"(",
"gopathList",
")",
"{",
"packagePath",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"filepath",
".",
"Join",
"(",
"gopath",
",",
"\"",
"\"",
")",
",",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// The match is valid only if it's within the directory tree.",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"packagePath",
",",
"\"",
"\"",
")",
"{",
"return",
"packagePath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}"
] |
// determinePackagePrefix determines the package prefix for Go packages
// generated in this file.
//
// dir must be an absolute path.
|
[
"determinePackagePrefix",
"determines",
"the",
"package",
"prefix",
"for",
"Go",
"packages",
"generated",
"in",
"this",
"file",
".",
"dir",
"must",
"be",
"an",
"absolute",
"path",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/main.go#L268-L287
|
17,699 |
thriftrw/thriftrw-go
|
internal/semver/semver.go
|
Parse
|
func Parse(v string) (r Version, err error) {
parts := semVerRegex.FindStringSubmatch(v)
if parts == nil {
return r, fmt.Errorf(`cannot parse as semantic version: %q`, v)
}
if r.Major, err = parseUint(parts[1]); err != nil {
return r, err
}
if r.Minor, err = parseUint(parts[2]); err != nil {
return r, err
}
if r.Patch, err = parseUint(parts[3]); err != nil {
return r, err
}
if parts[4] != "" {
r.Pre = strings.Split(parts[4], ".")
}
r.Meta = parts[5]
return r, nil
}
|
go
|
func Parse(v string) (r Version, err error) {
parts := semVerRegex.FindStringSubmatch(v)
if parts == nil {
return r, fmt.Errorf(`cannot parse as semantic version: %q`, v)
}
if r.Major, err = parseUint(parts[1]); err != nil {
return r, err
}
if r.Minor, err = parseUint(parts[2]); err != nil {
return r, err
}
if r.Patch, err = parseUint(parts[3]); err != nil {
return r, err
}
if parts[4] != "" {
r.Pre = strings.Split(parts[4], ".")
}
r.Meta = parts[5]
return r, nil
}
|
[
"func",
"Parse",
"(",
"v",
"string",
")",
"(",
"r",
"Version",
",",
"err",
"error",
")",
"{",
"parts",
":=",
"semVerRegex",
".",
"FindStringSubmatch",
"(",
"v",
")",
"\n",
"if",
"parts",
"==",
"nil",
"{",
"return",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"`cannot parse as semantic version: %q`",
",",
"v",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Major",
",",
"err",
"=",
"parseUint",
"(",
"parts",
"[",
"1",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"Minor",
",",
"err",
"=",
"parseUint",
"(",
"parts",
"[",
"2",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"Patch",
",",
"err",
"=",
"parseUint",
"(",
"parts",
"[",
"3",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"parts",
"[",
"4",
"]",
"!=",
"\"",
"\"",
"{",
"r",
".",
"Pre",
"=",
"strings",
".",
"Split",
"(",
"parts",
"[",
"4",
"]",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"r",
".",
"Meta",
"=",
"parts",
"[",
"5",
"]",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] |
// Parse a semantic version string.
|
[
"Parse",
"a",
"semantic",
"version",
"string",
"."
] |
a9a6ad793beab07cc3385954d2e8af8abfaa83e2
|
https://github.com/thriftrw/thriftrw-go/blob/a9a6ad793beab07cc3385954d2e8af8abfaa83e2/internal/semver/semver.go#L49-L70
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.