_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q17600 | RootTypeSpec | train | func RootTypeSpec(s TypeSpec) TypeSpec {
if t, ok := s.(*TypedefSpec); ok {
return t.root
}
return s
} | go | {
"resource": ""
} |
q17601 | Link | train | 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,
S... | go | {
"resource": ""
} |
q17602 | ForEachTypeReference | train | 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 | {
"resource": ""
} |
q17603 | compileTypeReference | train | 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 as... | go | {
"resource": ""
} |
q17604 | NewServer | train | func NewServer(p protocol.Protocol, h Handler) Server {
return Server{p: p, h: h}
} | go | {
"resource": ""
} |
q17605 | Handle | train | 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 ... | go | {
"resource": ""
} |
q17606 | tappExc | train | func tappExc(err error, typ exception.ExceptionType) (wire.Value, error) {
return (&exception.TApplicationException{
Message: ptr.String(err.Error()),
Type: &typ,
}).ToWire()
} | go | {
"resource": ""
} |
q17607 | Name | train | 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 | {
"resource": ""
} |
q17608 | Close | train | func (mh MultiHandle) Close() error {
return concurrent.Range(mh, func(_ int, h Handle) error {
return h.Close()
})
} | go | {
"resource": ""
} |
q17609 | ServiceGenerator | train | 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 | {
"resource": ""
} |
q17610 | Handle | train | func (msg MultiServiceGenerator) Handle() Handle {
mh := make(MultiHandle, len(msg))
for i, sg := range msg {
mh[i] = sg.Handle()
}
return mh
} | go | {
"resource": ""
} |
q17611 | Generate | train | 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 {
... | go | {
"resource": ""
} |
q17612 | NewTransportHandle | train | 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}
}
... | go | {
"resource": ""
} |
q17613 | Service | train | 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[functionNam... | go | {
"resource": ""
} |
q17614 | ServiceFunction | train | 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 ... | go | {
"resource": ""
} |
q17615 | functionParams | train | 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>
`,... | go | {
"resource": ""
} |
q17616 | functionNewArgs | train | 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> <typeRefer... | go | {
"resource": ""
} |
q17617 | BorrowWriter | train | func BorrowWriter(w io.Writer) *Writer {
writer := writerPool.Get().(*Writer)
writer.writer = w
return writer
} | go | {
"resource": ""
} |
q17618 | WriteValue | train | 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))
... | go | {
"resource": ""
} |
q17619 | Info | train | func (c *Constant) Info() DefinitionInfo {
return DefinitionInfo{Name: c.Name, Line: c.Line}
} | go | {
"resource": ""
} |
q17620 | Info | train | func (t *Typedef) Info() DefinitionInfo {
return DefinitionInfo{Name: t.Name, Line: t.Line}
} | go | {
"resource": ""
} |
q17621 | Info | train | func (e *Enum) Info() DefinitionInfo {
return DefinitionInfo{Name: e.Name, Line: e.Line}
} | go | {
"resource": ""
} |
q17622 | Info | train | func (s *Struct) Info() DefinitionInfo {
return DefinitionInfo{Name: s.Name, Line: s.Line}
} | go | {
"resource": ""
} |
q17623 | Info | train | func (s *Service) Info() DefinitionInfo {
return DefinitionInfo{Name: s.Name, Line: s.Line}
} | go | {
"resource": ""
} |
q17624 | curryGenerator | train | 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 | {
"resource": ""
} |
q17625 | NewGenerator | train | 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()),
mangl... | go | {
"resource": ""
} |
q17626 | checkNoZap | train | func checkNoZap(g Generator) bool {
if gen, ok := g.(*generator); ok {
return gen.noZap
}
return false
} | go | {
"resource": ""
} |
q17627 | TextTemplate | train | 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": ... | go | {
"resource": ""
} |
q17628 | appendDecl | train | func (g *generator) appendDecl(decl ast.Decl) {
g.decls = append(g.decls, decl)
} | go | {
"resource": ""
} |
q17629 | Generate | train | 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.Outpu... | go | {
"resource": ""
} |
q17630 | Visit | train | func (f VisitorFunc) Visit(w Walker, n Node) Visitor {
f(w, n)
return f
} | go | {
"resource": ""
} |
q17631 | Handle | train | 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... | go | {
"resource": ""
} |
q17632 | UnmarshalFlag | train | 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 := _pluginExecPr... | go | {
"resource": ""
} |
q17633 | Handle | train | 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 {
retu... | go | {
"resource": ""
} |
q17634 | ToWirePtr | train | 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)", varNam... | go | {
"resource": ""
} |
q17635 | FromWirePtr | train | 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, ou... | go | {
"resource": ""
} |
q17636 | TypeCode | train | 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... | go | {
"resource": ""
} |
q17637 | isRequired | train | 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 {
... | go | {
"resource": ""
} |
q17638 | compileField | train | 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 &&... | go | {
"resource": ""
} |
q17639 | Link | train | 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 | {
"resource": ""
} |
q17640 | compileFields | train | 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,... | go | {
"resource": ""
} |
q17641 | FindByName | train | 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 | {
"resource": ""
} |
q17642 | Link | train | func (fg FieldGroup) Link(scope Scope) error {
for _, field := range fg {
if err := field.Link(scope); err != nil {
return err
}
}
return nil
} | go | {
"resource": ""
} |
q17643 | ForEachTypeReference | train | 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 | {
"resource": ""
} |
q17644 | LookupType | train | func (m *Module) LookupType(name string) (TypeSpec, error) {
if t, ok := m.Types[name]; ok {
return t, nil
}
return nil, lookupError{Name: name}
} | go | {
"resource": ""
} |
q17645 | LookupConstant | train | func (m *Module) LookupConstant(name string) (*Constant, error) {
if c, ok := m.Constants[name]; ok {
return c, nil
}
return nil, lookupError{Name: name}
} | go | {
"resource": ""
} |
q17646 | LookupService | train | func (m *Module) LookupService(name string) (*ServiceSpec, error) {
if s, ok := m.Services[name]; ok {
return s, nil
}
return nil, lookupError{Name: name}
} | go | {
"resource": ""
} |
q17647 | LookupInclude | train | 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 | {
"resource": ""
} |
q17648 | Walk | train | 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{}{... | go | {
"resource": ""
} |
q17649 | compileConstantValue | train | 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 compileConstantL... | go | {
"resource": ""
} |
q17650 | Link | train | 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 | {
"resource": ""
} |
q17651 | Link | train | 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(... | go | {
"resource": ""
} |
q17652 | Link | train | 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 | {
"resource": ""
} |
q17653 | Link | train | 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 | {
"resource": ""
} |
q17654 | buildConstantStruct | train | 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)] = pa... | go | {
"resource": ""
} |
q17655 | Link | train | 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 {
... | go | {
"resource": ""
} |
q17656 | Link | train | 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, ... | go | {
"resource": ""
} |
q17657 | Link | train | 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([]Constan... | go | {
"resource": ""
} |
q17658 | Link | train | 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))
f... | go | {
"resource": ""
} |
q17659 | Link | train | 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 | {
"resource": ""
} |
q17660 | Link | train | 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 | {
"resource": ""
} |
q17661 | Link | train | 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 := splitInclud... | go | {
"resource": ""
} |
q17662 | lookupEnum | train | 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 | {
"resource": ""
} |
q17663 | NewClient | train | 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)
}
i... | go | {
"resource": ""
} |
q17664 | Send | train | 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 | {
"resource": ""
} |
q17665 | Close | train | 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(erro... | go | {
"resource": ""
} |
q17666 | Equals | train | 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 | {
"resource": ""
} |
q17667 | Equals | train | 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 | {
"resource": ""
} |
q17668 | LineNumber | train | func LineNumber(n Node) int {
if nl, ok := n.(nodeWithLine); ok {
return nl.lineNumber()
}
return 0
} | go | {
"resource": ""
} |
q17669 | Read | train | 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... | go | {
"resource": ""
} |
q17670 | Close | train | 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 | {
"resource": ""
} |
q17671 | unsafeStringToBytes | train | 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 | {
"resource": ""
} |
q17672 | typedef | train | 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 isPrimi... | go | {
"resource": ""
} |
q17673 | EncodeResponse | train | 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 | {
"resource": ""
} |
q17674 | visited | train | func (f typeCycleFinder) visited(s TypeSpec) bool {
for _, t := range f {
if t == s {
return true
}
}
return false
} | go | {
"resource": ""
} |
q17675 | cloneWithPart | train | 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 | {
"resource": ""
} |
q17676 | newImporter | train | func newImporter(ns Namespace) importer {
return importer{
ns: ns,
imports: make(map[string]*ast.ImportSpec),
}
} | go | {
"resource": ""
} |
q17677 | AddImportSpec | train | 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 | {
"resource": ""
} |
q17678 | Import | train | 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.i... | go | {
"resource": ""
} |
q17679 | importDecl | train | 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:... | go | {
"resource": ""
} |
q17680 | Write | train | 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 | {
"resource": ""
} |
q17681 | ReadReply | train | 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 en... | go | {
"resource": ""
} |
q17682 | compileMapType | train | 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 n... | go | {
"resource": ""
} |
q17683 | Link | train | 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 | {
"resource": ""
} |
q17684 | ThriftName | train | func (m *MapSpec) ThriftName() string {
return fmt.Sprintf(
"map<%s, %s>", m.KeySpec.ThriftName(), m.ValueSpec.ThriftName(),
)
} | go | {
"resource": ""
} |
q17685 | ForEachTypeReference | train | func (m *MapSpec) ForEachTypeReference(f func(TypeSpec) error) error {
if err := f(m.KeySpec); err != nil {
return err
}
return f(m.ValueSpec)
} | go | {
"resource": ""
} |
q17686 | compileListType | train | 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 | {
"resource": ""
} |
q17687 | Link | train | 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 | {
"resource": ""
} |
q17688 | ForEachTypeReference | train | func (l *ListSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return f(l.ValueSpec)
} | go | {
"resource": ""
} |
q17689 | compileSetType | train | 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 | {
"resource": ""
} |
q17690 | Link | train | 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 | {
"resource": ""
} |
q17691 | ForEachTypeReference | train | func (s *SetSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return f(s.ValueSpec)
} | go | {
"resource": ""
} |
q17692 | compileStruct | train | 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... | go | {
"resource": ""
} |
q17693 | Link | train | func (s *StructSpec) Link(scope Scope) (TypeSpec, error) {
if s.linked() {
return s, nil
}
err := s.Fields.Link(scope)
return s, err
} | go | {
"resource": ""
} |
q17694 | ForEachTypeReference | train | func (s *StructSpec) ForEachTypeReference(f func(TypeSpec) error) error {
return s.Fields.ForEachTypeReference(f)
} | go | {
"resource": ""
} |
q17695 | verifyAncestry | train | 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(
... | go | {
"resource": ""
} |
q17696 | findCommonAncestor | train | 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)
}
thriftD... | go | {
"resource": ""
} |
q17697 | commonPrefix | train | 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 | {
"resource": ""
} |
q17698 | determinePackagePrefix | train | 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... | go | {
"resource": ""
} |
q17699 | Parse | train | 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
... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.