id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c21700
f.pkg.errorfAt(pos, 0.9, link(ref), category("comments"), "package comment is detached; there should be no blank lines between it and the package statement") return } } if f.f.Doc == nil { f.errorf(f.f, 0.2, link(ref), category("comments"), "should have a package comment, unless it's in another file for th...
c21701
isBlank(prev.Name) && prevPos.Line+1 == pos.Line { continue // A subsequent blank in a group. } } // This is the first blank import of a group. if imp.Doc == nil && imp.Comment == nil { ref := "" f.errorf(imp, 1, link(ref), category("imports"), "a blank import should be only in a main or test packa...
c21702
1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports") } } }
c21703
// inside a GenDecl, which usually has the doc doc := v.Doc if doc == nil { doc = lastGen.Doc } f.lintTypeDoc(v, doc) f.checkStutter(v.Name, "type") // Don't proceed inside types. return false case *ast.ValueSpec: f.lintValueSpecDoc(v, lastGen, genDeclMissingComments) return false ...
c21704
break } } if !strings.HasPrefix(s, t.Name.Name+" ") { f.errorf(doc, 1, link(docCommentsLink), category("comments"), `comment on exported type %v should be of the form "%v ..." (with optional leading article)`, t.Name, t.Name) } }
c21705
a // concrete type on the RHS. Note that our feeble lexical check here // will only pick up interface{} and other literal interface types; // that covers most of the cases we care to exclude right now. if _, ok := v.Type.(*ast.InterfaceType); ok { return false } // If the RHS is an untyped const,...
c21706
shortDecl = true } } lastStmt := ifStmt.Body.List[len(ifStmt.Body.List)-1] if _, ok := lastStmt.(*ast.ReturnStmt); ok { extra := "" if shortDecl { extra = " (move short variable declaration to its own line if necessary)" } f.errorf(ifStmt.Else, 1, link(styleGuideBase+"#indent-error-flow"),...
c21707
true } if isIdent(rs.Value, "_") { p := f.errorf(rs.Value, 1, category("range-loop"), "should omit 2nd value from range; this loop is equivalent to `for %s %s range ...`", f.render(rs.Key), rs.Tok) newRS := *rs // shallow copy newRS.Value = nil p.ReplacementLine = f.firstLineOf(&newRS, rs) } ret...
c21708
p := f.errorf(node, 1, category("errors"), "should replace %s(fmt.Sprintf(...)) with %s.Errorf(...)", f.render(se), errorfPrefix) m := f.srcLineWithMatch(ce, `^(.*)`+f.render(se)+`\(fmt\.Sprintf\((.*)\)\)(.*)$`) if m != nil { p.ReplacementLine = m[1] + errorfPrefix + ".Errorf(" + m[2] + ")" + m[3] } retur...
c21709
continue } id := spec.Names[0] prefix := "err" if id.IsExported() { prefix = "Err" } if !strings.HasPrefix(id.Name, prefix) { f.errorf(id, 0.9, category("naming"), "error var %s should have name of the form %sFoo", id.Name, prefix) } } } }
c21710
return true } clean, conf := lintErrorString(s) if clean { return true } f.errorf(str, conf, link(styleGuideBase+"#error-strings"), category("errors"), "error strings should not be capitalized or end with punctuation or a newline") return true }) }
c21711
f.errorf(n, 1, link(ref), category("naming"), `receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"`) return true } recv := receiverType(fn) if prev, ok := typeReceiver[recv]; ok && prev != name { f.errorf(n, 1, link(ref), category("naming"), "receiver name...
c21712
_, r := range ret[:len(ret)-1] { if isIdent(r.Type, "error") { f.errorf(fn, 0.9, category("arg-order"), "error should be the last type when returning multiple items") break // only flag one } } return true }) }
c21713
} for _, ret := range fn.Type.Results.List { typ := f.pkg.typeOf(ret.Type) if exportedType(typ) { continue } f.errorf(ret.Type, 0.8, category("unexported-type-in-api"), "exported %s %s returns unexported type %s, which can be annoying to use", thing, fn.Name.Name, typ) break // only flag o...
c21714
array, slice, pointer, chan return exportedType(T.Elem()) } // Be conservative about other types, such as struct, interface, etc. return true }
c21715
} // key is second argument to context.WithValue if len(x.Args) != 3 { return } key := f.pkg.typesInfo.Types[x.Args[1]] if ktyp, ok := key.Type.(*types.Basic); ok && ktyp.Kind() != types.Invalid { f.errorf(x, 1.0, category("context"), fmt.Sprintf("should not use basic type %s as key in context.WithValue", k...
c21716
any that show up after the first. for _, arg := range fn.Type.Params.List[1:] { if isPkgDot(arg.Type, "context", "Context") { f.errorf(fn, 0.9, link("https://golang.org/pkg/context/"), category("arg-order"), "context.Context should be the first parameter of a function") break // only flag one } } r...
c21717
exprStr) if err != nil { return "", false } if b, ok := tv.Type.(*types.Basic); ok { if dt, ok := basicTypeKinds[b.Kind()]; ok { return dt, true } } return "", false }
c21718
{ line = line[:i] } return f.indentOf(match) + line }
c21719
if err == nil && importPath == uq { return true } } } return false }
c21720
lo-- } for hi < len(src) && src[hi-1] != '\n' { hi++ } return string(src[lo:hi]) }
c21721
} else { out = append(out, allPackages(a)...) } continue } out = append(out, a) } return out }
c21722
return strings.HasPrefix(s, prefix) } return s[len(prefix)] == '/' && s[:len(prefix)] == prefix } }
c21723
Conn: conn, Plugins: c.config.Plugins, doneCtx: doneCtx, broker: broker, controller: plugin.NewGRPCControllerClient(conn), } return cl, nil }
c21724
:= m[os.Args[1]] if !ok { fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1]) os.Exit(1) } Serve(opts) }
c21725
{ case <-s.quit: return nil, errors.New("broker closed") case i := <-s.recv: return i, nil } }
c21726
return errors.New("broker closed") case s.send <- &sendErr{ i: i, ch: ch, }: } return <-ch }
c21727
close this goroutine if the server is shutdown // or the broker is shutdown. var g run.Group { // Serve on the listener, if shutting down call GracefulStop. g.Add(func() error { return server.Serve(listener) }, func(err error) { server.GracefulStop() }) } { // block on the closeCh or the doneCh. I...
c21728
close(b.doneCh) }) return nil }
c21729
!= nil { return nil, err } entry.Timestamp = t delete(raw, "@timestamp") } // Parse dynamic KV args from the hclog payload. for k, v := range raw { entry.KVPairs = append(entry.KVPairs, &logEntryKV{ Key: k, Value: v, }) } return entry, nil }
c21730
err } defer file.Close() _, err = io.Copy(s.Hash, file) if err != nil { return false, err } sum := s.Hash.Sum(nil) return subtle.ConstantTimeCompare(sum, s.Checksum) == 1, nil }
c21731
err = newGRPCClient(c.doneCtx, c) default: return nil, fmt.Errorf("unknown server protocol: %s", c.protocol) } if err != nil { c.client = nil return nil, err } return c.client, nil }
c21732
c.l.Unlock() return c.processKilled }
c21733
if err != nil { return err } certPool.AddCert(x509Cert) c.config.TLSConfig.RootCAs = certPool return nil }
c21734
if serverVersion != version { continue } return version, plugins, nil } return 0, nil, fmt.Errorf("Incompatible API version with plugin. "+ "Plugin version: %d, Client versions: %d", serverVersion, clientVersions) }
c21735
information as-is if c.config.Reattach != nil { return c.config.Reattach } return &ReattachConfig{ Protocol: c.protocol, Addr: c.address, Pid: c.config.Cmd.Process.Pid, } }
c21736
ProtocolInvalid } return c.protocol }
c21737
since gRPC uses its own mechanism for TLS. if c.protocol == ProtocolNetRPC && c.config.TLSConfig != nil { conn = tls.Client(conn, c.config.TLSConfig) } return conn, nil }
c21738
true, } der, err := x509.CreateCertificate(rand.Reader, template, template, key.Public(), key) if err != nil { return nil, nil, err } var certOut bytes.Buffer if err := pem.Encode(&certOut, &pem.Block{Type: "CERTIFICATE", Bytes: der}); err != nil { return nil, nil, err } keyBytes, err := x509....
c21739
:= syscall.GetExitCodeProcess(h, &ec); e != nil { return false } return ec == exit_STILL_ACTIVE }
c21740
We // carefully control the structure being encoded here and it should // always be successful. panic(err) } return buf.String() }
c21741
{ conn.Close() return nil, err } // Begin the stream syncing so that stdin, out, err work properly err = result.SyncStreams( c.config.SyncStdout, c.config.SyncStderr) if err != nil { result.Close() return nil, err } return result, nil }
c21742
// Connect stdout, stderr streams stdstream := make([]net.Conn, 2) for i, _ := range stdstream { stdstream[i], err = mux.Open() if err != nil { mux.Close() return nil, err } } // Create the broker and start it up broker := newMuxBroker(mux) go broker.Run() // Build the client using our broker and...
c21743
{ go copyStream("stdout", stdout, c.stdout) go copyStream("stderr", stderr, c.stderr) return nil }
c21744
if err := c.stderr.Close(); err != nil { return err } if err := c.broker.Close(); err != nil { return err } // Return back the error we got from Control.Quit. This is very important // since we MUST return non-nil error if this fails so that Client.Kill // will properly try a process.Kill. return returnErr...
c21745
struct{} return c.control.Call("Control.Ping", true, &empty) }
c21746
// Create the broker and start it up broker := newMuxBroker(mux) go broker.Run() // Use the control connection to build the dispenser and serve the // connection. server := rpc.NewServer() server.RegisterName("Control", &controlServer{ server: s, }) server.RegisterName("Dispenser", &dispenseServer{ brok...
c21747
if s.DoneCh != nil { close(s.DoneCh) s.DoneCh = nil } }
c21748
switch p.(type) { case GRPCPlugin: protoType = ProtocolGRPC default: protoType = ProtocolNetRPC } break } } for _, clientVersion := range clientVersions { if clientVersion == protoVersion { return protoVersion, protoType, pluginSet } } } // Return the lowest version a...
c21749
= proc.Signal(syscall.Signal(0)) } return err == nil }
c21750
plugin: plugin acceptAndServe error: %s", err) return } serve(conn, "Plugin", v) }
c21751
if !pidAlive(pid) { break } } return nil }
c21752
TODO: figure out why GracefullStop doesn't work. s.server.Stop() return resp, nil }
c21753
return true default: return false } }
c21754
c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
c21755
return false } if self.SampleFormat != other.SampleFormat { return false } return true }
c21756
start size := self.SampleFormat.BytesPerSample() for i := range out.Data { out.Data[i] = out.Data[i][start*size : end*size] } return }
c21757
range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
c21758
if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
c21759
streams = append(streams, stream.codec) } return }
c21760
!= nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
c21761
} } //println("shrink", self.curgopcount, self.maxgopcount, self.buf.Head, self.buf.Tail, "count", self.buf.Count, "size", self.buf.Size) self.cond.Broadcast() self.lock.Unlock() return }
c21762
cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
c21763
:= buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- } } return i } return cursor }
c21764
buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { gop++ } } } return i } return cursor }
c21765
buf.Get(self.pos) self.pos++ break } if self.que.closed { err = io.EOF break } self.que.cond.Wait() } self.que.cond.L.Unlock() return }
c21766
{}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
c21767
logger m.Map(m.logger) }
c21768
m.handlers = append(m.handlers, handler) }
c21769
m.createContext(res, req).run() }
c21770
custom host and port are passed. logger := m.Injector.Get(reflect.TypeOf(m.logger)).Interface().(*log.Logger) logger.Printf("listening on %s (%s)\n", addr, Env) logger.Fatalln(http.ListenAndServe(addr, m)) }
c21771
(*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
c21772
val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) return url } return r.pattern }
c21773
strconv.FormatInt(int64(v), 10)) case string: args = append(args, v) default: if v != nil { panic("Arguments passed to URLFor must be integers or strings") } } } return route.URLWith(args) }
c21774
== path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
c21775
if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for %s", req.Method, req.URL.Path, addr) rw := res.(ResponseWriter) c.Next() log.Printf("Completed %v %s in %v\n", rw.Status(), http.StatusText(rw.Status()), time.Since(start)) } }
c21776
== badHex || h3 == badHex || h4 == badHex { return utf8.RuneError, false } // Compose the hex digits return rune(h1<<12 + h2<<8 + h3<<4 + h4), true }
c21777
>= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return 0, false, false } if overflow = (b < v); overflow { break } v = b } if overflow { if neg && bio.Equal(bytes, []byte(minInt64)) { return b, true, false } return 0, false, true } if neg { return -v, true, false } else {...
c21778
switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
c21779
j-- if j < 0 || data[j] != '\\' { break // odd number of backslashes } j-- } } } else if c == '\\' { escaped = true } } return -1, escaped }
c21780
nil { return offset, e } if o == 0 { break } if t != NotExist { cb(v, t, offset+o-len(v), e) } if e != nil { break } offset += o skipToToken := nextToken(data[offset:]) if skipToToken == -1 { return offset, MalformedArrayError } offset += skipToToken if data[offset] == ']...
c21781
key = keyUnescaped } } // Step 2: skip the colon if off := nextToken(data[offset:]); off == -1 { return MalformedJsonError } else if offset += off; data[offset] != ':' { return MalformedJsonError } else { offset++ } // Step 3: find the associated value, then invoke the callback if val...
c21782
v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
c21783
// If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), nil } return ParseString(v) }
c21784
!= Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
c21785
!= Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
c21786
!= Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
c21787
err != nil { return 0, MalformedValueError } else { return v, nil } }
c21788
if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
c21789
f.err = fmt.Errorf(fmtStr, args...) } }
c21790
< 0 { right = left } f.rMargin = right }
c21791
f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
c21792
{ f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
c21793
= f.autoPageBreak margin = f.bMargin return }
c21794
{ f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
c21795
utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
c21796
break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
c21797
= 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
c21798
= 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
c21799
winding number rule opStr = "B" case "FD*", "DF*": // fill and then stroke the path, using the even-odd rule opStr = "B*" default: opStr = styleStr } return }