id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c8900
err) } pkgPath = mockPkg.PkgPath } tmpl, err := template.New("moq").Funcs(templateFuncs).Parse(moqTemplate) if err != nil { return nil, err } return &Mocker{ tmpl: tmpl, srcPkg: srcPkg, pkgName: packageName, pkgPath: pkgPath, imports: make(map[string]bool), }, nil }
c8901
mocksMethods { doc.Imports = append(doc.Imports, "sync") } for pkgToImport := range m.imports { doc.Imports = append(doc.Imports, stripVendorPath(pkgToImport)) } if tpkg.Name() != m.pkgName { doc.SourcePackagePrefix = tpkg.Name() + "." doc.Imports = append(doc.Imports, tpkg.Path()) } var buf bytes.Buf...
c8902
return } s.state = terminated s.Unlock() done := make(chan struct{}) if s.sendControl(stopSupervisor{done}) { <-done } }
c8903
} } return nil, fmt.Errorf("no config named %q", config.CurrentContext) configFound: } if ctx.Cluster == "" { return nil, fmt.Errorf("context doesn't have a cluster") } if ctx.AuthInfo == "" { return nil, fmt.Errorf("context doesn't have a user") } var ( user AuthInfo cluster Cluster ) for _,...
c8904
:= Cluster{ Server: server.String(), CertificateAuthority: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt", } user := AuthInfo{TokenFile: "/var/run/secrets/kubernetes.io/serviceaccount/token"} return newClient(cluster, user, string(namespace)) }
c8905
// If an HTTP error was returned by the API server, it will be of type // *k8s.APIError. This can be used to inspect the status code. if apiErr, ok := err.(*k8s.APIError); ok { // Resource already exists. Carry on. if apiErr.Code == http.StatusConflict { return nil } } return fmt.Errorf("create configmap...
c8906
return } l.stmts = append(l.stmts, key+"="+val) }
c8907
return } } l.stmts = append(l.stmts, key+" in ("+strings.Join(vals, ", ")+")") }
c8908
string, v url.Values) string { v.Set(name, value) return base }) }
c8909
strconv.FormatInt(int64(d/time.Second), 10), ) }
c8910
if err := yaml.Unmarshal(data, &config); err != nil { return nil, fmt.Errorf("unmarshal kubeconfig: %v", err) } return k8s.NewClient(&config) }
c8911
data, err := marshalPB(i) return contentTypePB, data, err } data, err := json.Marshal(i) return contentTypeJSON, data, err }
c8912
ok := i.(json.Unmarshaler); !ok { return fmt.Errorf("cannot decode json payload into protobuf object %T", i) } } if err := json.Unmarshal(data, i); err != nil { return fmt.Errorf("decode json: %v", err) } return nil }
c8913
return w.watcher.Next(r) }
c8914
= int64(*t.Nanos) } return json.Marshal(time.Unix(seconds, nanos)) }
c8915
t.Get(key) != nil }
c8916
h.Item): h = h.Left case less(h.Item, key): h = h.Right default: return h.Item } } return nil }
c8917
h.Left != nil { h = h.Left } return h.Item }
c8918
h.Right != nil { h = h.Right } return h.Item }
c8919
item) t.root.Black = true if replaced == nil { t.count++ } return replaced }
c8920
nil item") } t.root = t.insertNoReplace(t.root, item) t.root.Black = true t.count++ }
c8921
isRed(h.Right) { flip(h) } return h }
c8922
= true } if deleted != nil { t.count-- } return deleted }
c8923
var deleted Item h.Left, deleted = deleteMin(h.Left) return fixUp(h), deleted }
c8924
= true } if deleted != nil { t.count-- } return deleted }
c8925
t.root.Black = true } if deleted != nil { t.count-- } return deleted }
c8926
ItemIterator) { t.ascendGreaterOrEqual(t.root, pivot, iterator) }
c8927
ItemIterator) { t.descendLessOrEqual(t.root, pivot, iterator) }
c8928
r.ctx[key] = value return r }
c8929
func() error { return UnmarshalPayload(reader, model) }) }
c8930
elems, err = UnmarshalManyPayload(reader, kind) return err }) return }
c8931
included } } for _, data := range payload.Data { model := reflect.New(t.Elem()) err := unmarshalNode(data, model, &includedMap) if err != nil { return nil, err } models = append(models, model.Interface()) } return models, nil }
c8932
pointer so it's value // can be set by assignValue field.Set(reflect.New(field.Type().Elem())) field = field.Elem() } assignValue(field, value) }
c8933
reflect.Uint32, reflect.Uint64, reflect.Uintptr: field.SetUint(value.Uint()) case reflect.Float32, reflect.Float64: field.SetFloat(value.Float()) case reflect.String: field.SetString(value.String()) case reflect.Bool: field.SetBool(value.Bool()) default: field.Set(value) } }
c8934
} if metableModels, ok := models.(Metable); ok { payload.Meta = metableModels.JSONAPIMeta() } return payload, nil case reflect.Ptr: // Check that the pointer was to a struct if reflect.Indirect(vals).Kind() != reflect.Struct { return nil, ErrUnexpectedType } return marshalOne(models) default: ...
c8935
&OnePayload{Data: rootNode} payload.Included = nodeMapValues(&included) return payload, nil }
c8936
{ return nil, err } payload.Data = append(payload.Data, node) } payload.Included = nodeMapValues(&included) return payload, nil }
c8937
fmt.Sprintf("https://example.com/blogs/%d", blog.ID), } }
c8938
} } if relation == "current_post" { return &jsonapi.Links{ "related": fmt.Sprintf("https://example.com/blogs/%d/current_post", blog.ID), } } return nil }
c8939
return &jsonapi.Meta{ "detail": "current post meta information", } } return nil }
c8940
"\n") { out += transform(idx, line) } return }
c8941
"\033[%d;%dH", y, x) }
c8942
applyTransform(str, func(idx int, line string) string { return fmt.Sprintf("\033[%d;%dH%s", y+idx, x, line) }) }
c8943
func(idx int, line string) string { return fmt.Sprintf("%s%s", RESET_LINE, line) }) }
c8944
return -1 } return int(ws.Col) }
c8945
if err != nil { return -1 } return int(ws.Row) }
c8946
Output.WriteString(str) } Output.Flush() Screen.Reset() }
c8947
out = append(out, []float64{r[0], r[index]}) } return }
c8948
based on the MaxAge // If MaxAge <= 0, we don't set the Expires attribute, making the cookie // session-only. if cs.maxAge > 0 { cookie.Expires = time.Now().Add( time.Duration(cs.maxAge) * time.Second) } // Write the authenticated cookie to the response. http.SetCookie(w, cookie) return nil }
c8949
return func(cs *csrf) { cs.opts.RequestHeader = header } }
c8950
cs.opts.CookieName = name } }
c8951
to override the default. cs.opts.Secure = true cs.opts.HttpOnly = true // Range over each options function and apply it // to our csrf type to configure it. Options functions are // applied in order, with any conflicting options overriding // earlier calls. for _, option := range opts { option(cs) } retur...
c8952
ok := val.(error); ok { return err } } return nil }
c8953
contextSave(r, errorKey, err) }
c8954
} if sameOrigin(r.URL, referer) == false { r = envError(r, ErrBadReferer) cs.opts.ErrorHandler.ServeHTTP(w, r) return } } // If the token returned from the session store is nil for non-idempotent // ("unsafe") methods, call the error handler. if realToken == nil { r = envError(r, ErrNoTo...
c8955
http.StatusText(http.StatusForbidden), FailureReason(r)), http.StatusForbidden) return }
c8956
return nil, err } return GoToSexp(iface, env) }
c8957
*SexpSymbol: return `"` + e.name + `"` default: return exp.SexpString(nil) } }
c8958
err := decoder.Decode(&iface) if err != nil { panic(err) } VPrintf("\n decoded type : %T\n", iface) VPrintf("\n decoded value: %#v\n", iface) return iface, nil }
c8959
encoder.Encode(&iface) if err != nil { panic(err) } return w.Bytes() }
c8960
nil { return nil, fmt.Errorf("MsgpackToSexp failed at GoToSexp step: '%s", err) } return sexp, nil }
c8961
//fmt.Printf("\n decoded type : %T\n", iface) //fmt.Printf("\n decoded value: %#v\n", iface) return iface, nil }
c8962
lexer.buffer.Reset() lexer.AppendToken(lexer.Token(TokenComment, str)) }
c8963
label = "scope " + s.Name if s.IsGlobal { label += " (global)" } } str, err := s.Show(s.env, ps, s.Name) if err != nil { return "(" + label + ")" } return head + " " + str + " )" }
c8964
return stack.lookupSymbol(sym, 1, nil) }
c8965
MakeList([]Sexp{ env.MakeSymbol("quote"), env.MakeSymbol("msgmap"), &SexpStr{S: args[0].(*SexpSymbol).name}, }), }), nil }
c8966
SexpEnd.Val { return false } } return true }
c8967
confusion generally. if _, dup := n[k]; dup { panic(fmt.Sprintf(" duplicate function '%s' not allowed", k)) } n[k] = v } } return n }
c8968
ColonAccessFunction, "hset": HashAccessFunction, "hdel": HashAccessFunction, "keys": HashAccessFunction, "hpair": GenericHpairFunction, "slice": SliceFunction, "len": LenFunction, "append": AppendFunction, "appendslice": AppendFunction, "concat": Co...
c8969
return HashAccessFunction(env, name, args) case *SexpArray: return ArrayAccessFunction(env, name, args) } return SexpNull, fmt.Errorf("first argument to hget function must be hash or array") }
c8970
" argument to be a symbol; we got %T", s) } if !sym.isDot { Q("assignment sees LHS symbol but is not dot, binding '%s' to '%s'\n", sym.name, args[1].SexpString(nil)) err := env.LexicalBindSymbol(sym, args[1]) if err != nil { return SexpNull, err } return args[1], nil } Q("assignment calling dotGe...
c8971
return fmt.Errorf("Cannot access private member '%s' of package '%s'", noDot, pkg.PackageName) } return nil }
c8972
} return *setVal, nil } // handle multiple paths that index into hashes after the // the first key := path[0][1:] // strip off the dot //Q("\n in dotGetSetHelper(), looking up '%s'\n", key) ret, err, _ = env.LexicalLookupSymbol(env.MakeSymbol(key), false) if err != nil { Q("\n in dotGetSetHelpe...
c8973
default: return SexpNull, fmt.Errorf("Cannot convert %s to uint64", TypeOf(args[0]).SexpString(nil)) } return &SexpUint64{Val: val}, nil }
c8974
if pos < 0 || pos >= len(seq.Val) { return SexpNull, fmt.Errorf("hpair position request %d out of bounds", pos) } return Cons(&SexpInt{Val: int64(pos)}, Cons(seq.Val[pos], SexpNull)), nil default: return SexpNull, errors.New("first argument of to hpair function must be hash, list, or array") } //return Sex...
c8975
{ p.JsonTagMap[k] = v } p.DetOrder = src.DetOrder // for using these as a scoping model p.DefnEnv = src.DefnEnv p.SuperClass = src.SuperClass p.ZMain = src.ZMain p.ZMethods = make(map[string]*SexpFunction) for k, v := range src.ZMethods { p.ZMethods[k] = v } p.Env = src.Env }
c8976
if err == ParserHaltRequested { return } err = p.GetMoreInput(expressions, err) if err == ParserHaltRequested { return } // GetMoreInput will have delivered what we gave them. Reset since we // don't own that memory any more. expressions = make([]Sexp, 0, SliceDefaultCap) } ...
c8977
P("found an SexpEnd token, omitting it") continue } xs = append(xs, x[i]) } } switch err { case nil: line += "\n" + nextline // no problem, parsing went fine. return line, xs, nil case ResetRequested: continue case ErrMoreInputNeeded: continue default: return "", nil,...
c8978
ts()) fmt.Printf(format, a...) }
c8979
} else if p > 0 { prefix = string(beg[:p]) extendme = string(beg[p:]) } Q("prefix = '%s'\nextendme = '%s'\n", prefix, extendme) for _, n := range completion_keywords { if strings.HasPrefix(n, strings.ToLower(extendme)) { Q("n='%s' has prefix = '%s'\n", n, extendme) c = append(c, n) } } return pr...
c8980
an LVALUE. right, err := pr.Expression(env, bp-1) if err != nil { return SexpNull, err } if op == "=" || op == ":=" { oper = operSet } list := MakeList([]Sexp{ oper, left, right, }) Q("assignment returning list: '%v'", list.SexpString(nil)) return list, nil }, IsAssign: tru...
c8981
Q("postfix assignment returning list: '%v'", list.SexpString(nil)) return list, nil }, } env.infixOps[op] = iop return iop }
c8982
Advance, p.NextToken = '%v'", p.NextToken.SexpString(nil)) return nil }
c8983
//P("LookupSymbolInParentChainOfClosures(sym='%s') found in scope '%s'\n", sym.name, scope.Name) return exp, err, scope } cur = par par = par.parent } return SexpNull, SymNotFound, nil }
c8984
} return reflect.ValueOf(iface).IsNil() }
c8985
pth, err) } //P("pkg = '%#v'", pkg) asPkg, isPkg := pkg.(*Stack) if !isPkg || !asPkg.IsPackage { return SexpNull, fmt.Errorf("import error: attempt to import path '%s' resulted value that was not a package, but rather '%T'", pth, pkg) } if n == 1 { alias = asPkg.PackageName } //P("using alias = '%s'", al...
c8986
way the stack remains clean... Q: how does this extra popping not mess up the expressions? gen.AddInstruction(PopInstr(0)) } gen.Tail = oldtail err := gen.Generate(expressions[size-1]) if err != nil { return err } gen.AddInstruction(RemoveScopeInstr{}) return nil }
c8987
:= range try { b := try[i] if FileExists(b) { ShellCmd = b return } } } }
c8988
with args='%#v'", args) return SystemFunction(env, name, args) }
c8989
} fmt.Printf("%s %d: %s\n", extra, i, instr.InstrString()) } if pc == len(fun) { fmt.Printf(" PC just past end at %d -----\n\n", pc) } }
c8990
instruc[i].(type) { case LoopStartInstr: if loop.loop == target { return i, nil } } } return -1, fmt.Errorf("could not find loop target '%s'", target.stmtname.name) }
c8991
toSplit := s1.S splitter := s2.S s := strings.Split(toSplit, splitter) split := make([]Sexp, len(s)) for i := range split { split[i] = &SexpStr{S: s[i]} } return env.NewSexpArray(split), nil }
c8992
case '[': squares++ case ']': squares-- } } return parens == 0 && squares == 0 }
c8993
err = env.parser.ParseTokens() if len(x) > 0 { for i := range x { if x[i] == SexpEnd { P("found an SexpEnd token, omitting it") continue } xs = append(xs, x[i]) } } switch err { case nil: line += "\n" + nextline Q("no problem parsing line '%s' into '%s', proceeding...\n", line...
c8994
RFC3999Nano timestamp that we want to convert to time.Time") } tm, err := time.ParseInLocation(time.RFC3339Nano, str.S, NYC) if err != nil { return SexpNull, err } return &SexpTime{Tm: tm.In(NYC)}, nil }
c8995
:= os.Open(file) if err != nil { return SexpNull, err } defer f.Close() err = env2.LoadFile(f) if err != nil { return SexpNull, err } _, err = env2.Run() return SexpNull, err }
c8996
return err } //P("end of SourceExpressions, result going onto datastack is: '%s'", result.SexpString(0)) env.datastack.PushExpr(result) //P("debug done with Run in source, now stack is:") //env.datastack.PrintStack() env.pc = curpc env.curfunc = curfunc return nil }
c8997
var err error if f, err = os.Open(t.S); err != nil { return err } defer f.Close() if err = env.SourceFile(f); err != nil { return err } default: return fmt.Errorf("source: Expected `string`, `list`, `array`. Instead found type %T val %v", item, item) } return nil }
c8998
0; j < maxnfield; j++ { for i := range p.Fields { Q("i= %v, j=%v, len(w[i])=%v check=%v", i, j, len(w[i]), len(w[i]) < j) if j < len(w[i]) { biggestCol[j] = maxi(biggestCol[j], w[i][j]+1) } } } Q("RecordDefn::SexpString(): maxnfield = %v, out of %v", maxnfield, len(p.Fields)) Q("RecordDefn::SexpSt...
c8999
str += key.SexpString(nil) + ":" } wide = append(wide, len(str)) wide = append(wide, len(val.SexpString(nil))+1) } else { panic(err) } } return wide }