_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q179300 | toRetryParameters | test | func (opt *RetryOptions) toRetryParameters() *pb.TaskQueueRetryParameters {
params := &pb.TaskQueueRetryParameters{}
if opt.RetryLimit > 0 {
params.RetryLimit = proto.Int32(opt.RetryLimit)
}
if opt.AgeLimit > 0 {
params.AgeLimitSec = proto.Int64(int64(opt.AgeLimit.Seconds()))
}
if opt.MinBackoff > 0 {
param... | go | {
"resource": ""
} |
q179301 | NewPOSTTask | test | func NewPOSTTask(path string, params url.Values) *Task {
h := make(http.Header)
h.Set("Content-Type", "application/x-www-form-urlencoded")
return &Task{
Path: path,
Payload: []byte(params.Encode()),
Header: h,
Method: "POST",
}
} | go | {
"resource": ""
} |
q179302 | ParseRequestHeaders | test | func ParseRequestHeaders(h http.Header) *RequestHeaders {
ret := &RequestHeaders{
QueueName: h.Get("X-AppEngine-QueueName"),
TaskName: h.Get("X-AppEngine-TaskName"),
}
ret.TaskRetryCount, _ = strconv.ParseInt(h.Get("X-AppEngine-TaskRetryCount"), 10, 64)
ret.TaskExecutionCount, _ = strconv.ParseInt(h.Get("X-Ap... | go | {
"resource": ""
} |
q179303 | Add | test | func Add(c context.Context, task *Task, queueName string) (*Task, error) {
req, err := newAddReq(c, task, queueName)
if err != nil {
return nil, err
}
res := &pb.TaskQueueAddResponse{}
if err := internal.Call(c, "taskqueue", "Add", req, res); err != nil {
apiErr, ok := err.(*internal.APIError)
if ok && alrea... | go | {
"resource": ""
} |
q179304 | AddMulti | test | func AddMulti(c context.Context, tasks []*Task, queueName string) ([]*Task, error) {
req := &pb.TaskQueueBulkAddRequest{
AddRequest: make([]*pb.TaskQueueAddRequest, len(tasks)),
}
me, any := make(appengine.MultiError, len(tasks)), false
for i, t := range tasks {
req.AddRequest[i], me[i] = newAddReq(c, t, queueN... | go | {
"resource": ""
} |
q179305 | Delete | test | func Delete(c context.Context, task *Task, queueName string) error {
err := DeleteMulti(c, []*Task{task}, queueName)
if me, ok := err.(appengine.MultiError); ok {
return me[0]
}
return err
} | go | {
"resource": ""
} |
q179306 | DeleteMulti | test | func DeleteMulti(c context.Context, tasks []*Task, queueName string) error {
taskNames := make([][]byte, len(tasks))
for i, t := range tasks {
taskNames[i] = []byte(t.Name)
}
if queueName == "" {
queueName = "default"
}
req := &pb.TaskQueueDeleteRequest{
QueueName: []byte(queueName),
TaskName: taskNames,... | go | {
"resource": ""
} |
q179307 | Lease | test | func Lease(c context.Context, maxTasks int, queueName string, leaseTime int) ([]*Task, error) {
return lease(c, maxTasks, queueName, leaseTime, false, nil)
} | go | {
"resource": ""
} |
q179308 | LeaseByTag | test | func LeaseByTag(c context.Context, maxTasks int, queueName string, leaseTime int, tag string) ([]*Task, error) {
return lease(c, maxTasks, queueName, leaseTime, true, []byte(tag))
} | go | {
"resource": ""
} |
q179309 | Purge | test | func Purge(c context.Context, queueName string) error {
if queueName == "" {
queueName = "default"
}
req := &pb.TaskQueuePurgeQueueRequest{
QueueName: []byte(queueName),
}
res := &pb.TaskQueuePurgeQueueResponse{}
return internal.Call(c, "taskqueue", "PurgeQueue", req, res)
} | go | {
"resource": ""
} |
q179310 | ModifyLease | test | func ModifyLease(c context.Context, task *Task, queueName string, leaseTime int) error {
if queueName == "" {
queueName = "default"
}
req := &pb.TaskQueueModifyTaskLeaseRequest{
QueueName: []byte(queueName),
TaskName: []byte(task.Name),
EtaUsec: proto.Int64(task.ETA.UnixNano() / 1e3), // Used to ... | go | {
"resource": ""
} |
q179311 | QueueStats | test | func QueueStats(c context.Context, queueNames []string) ([]QueueStatistics, error) {
req := &pb.TaskQueueFetchQueueStatsRequest{
QueueName: make([][]byte, len(queueNames)),
}
for i, q := range queueNames {
if q == "" {
q = "default"
}
req.QueueName[i] = []byte(q)
}
res := &pb.TaskQueueFetchQueueStatsRes... | go | {
"resource": ""
} |
q179312 | IsTimeoutError | test | func IsTimeoutError(err error) bool {
if err == context.DeadlineExceeded {
return true
}
if t, ok := err.(interface {
IsTimeout() bool
}); ok {
return t.IsTimeout()
}
return false
} | go | {
"resource": ""
} |
q179313 | Func | test | func Func(key string, i interface{}) *Function {
f := &Function{fv: reflect.ValueOf(i)}
// Derive unique, somewhat stable key for this func.
_, file, _, _ := runtime.Caller(1)
fk, err := fileKey(file)
if err != nil {
// Not fatal, but log the error
stdlog.Printf("delay: %v", err)
}
f.key = fk + ":" + key
... | go | {
"resource": ""
} |
q179314 | Task | test | func (f *Function) Task(args ...interface{}) (*taskqueue.Task, error) {
if f.err != nil {
return nil, fmt.Errorf("delay: func is invalid: %v", f.err)
}
nArgs := len(args) + 1 // +1 for the context.Context
ft := f.fv.Type()
minArgs := ft.NumIn()
if ft.IsVariadic() {
minArgs--
}
if nArgs < minArgs {
return... | go | {
"resource": ""
} |
q179315 | RequestHeaders | test | func RequestHeaders(c context.Context) (*taskqueue.RequestHeaders, error) {
if ret, ok := c.Value(headersContextKey).(*taskqueue.RequestHeaders); ok {
return ret, nil
}
return nil, errOutsideDelayFunc
} | go | {
"resource": ""
} |
q179316 | WithContext | test | func WithContext(parent context.Context, req *http.Request) context.Context {
return internal.WithContext(parent, req)
} | go | {
"resource": ""
} |
q179317 | WithAPICallFunc | test | func WithAPICallFunc(ctx context.Context, f APICallFunc) context.Context {
return internal.WithCallOverride(ctx, internal.CallOverrideFunc(f))
} | go | {
"resource": ""
} |
q179318 | APICall | test | func APICall(ctx context.Context, service, method string, in, out proto.Message) error {
return internal.Call(ctx, service, method, in, out)
} | go | {
"resource": ""
} |
q179319 | ModuleHostname | test | func ModuleHostname(c context.Context, module, version, instance string) (string, error) {
req := &modpb.GetHostnameRequest{}
if module != "" {
req.Module = &module
}
if version != "" {
req.Version = &version
}
if instance != "" {
req.Instance = &instance
}
res := &modpb.GetHostnameResponse{}
if err := i... | go | {
"resource": ""
} |
q179320 | AccessToken | test | func AccessToken(c context.Context, scopes ...string) (token string, expiry time.Time, err error) {
req := &pb.GetAccessTokenRequest{Scope: scopes}
res := &pb.GetAccessTokenResponse{}
err = internal.Call(c, "app_identity_service", "GetAccessToken", req, res)
if err != nil {
return "", time.Time{}, err
}
return... | go | {
"resource": ""
} |
q179321 | PublicCertificates | test | func PublicCertificates(c context.Context) ([]Certificate, error) {
req := &pb.GetPublicCertificateForAppRequest{}
res := &pb.GetPublicCertificateForAppResponse{}
if err := internal.Call(c, "app_identity_service", "GetPublicCertificatesForApp", req, res); err != nil {
return nil, err
}
var cs []Certificate
for ... | go | {
"resource": ""
} |
q179322 | ServiceAccount | test | func ServiceAccount(c context.Context) (string, error) {
req := &pb.GetServiceAccountNameRequest{}
res := &pb.GetServiceAccountNameResponse{}
err := internal.Call(c, "app_identity_service", "GetServiceAccountName", req, res)
if err != nil {
return "", err
}
return res.GetServiceAccountName(), err
} | go | {
"resource": ""
} |
q179323 | SignBytes | test | func SignBytes(c context.Context, bytes []byte) (keyName string, signature []byte, err error) {
req := &pb.SignForAppRequest{BytesToSign: bytes}
res := &pb.SignForAppResponse{}
if err := internal.Call(c, "app_identity_service", "SignForApp", req, res); err != nil {
return "", nil, err
}
return res.GetKeyName(),... | go | {
"resource": ""
} |
q179324 | fetch | test | func (r *reader) fetch(off int64) error {
req := &blobpb.FetchDataRequest{
BlobKey: proto.String(string(r.blobKey)),
StartIndex: proto.Int64(off),
EndIndex: proto.Int64(off + readBufferSize - 1), // EndIndex is inclusive.
}
res := &blobpb.FetchDataResponse{}
if err := internal.Call(r.c, "blobstore", "Fet... | go | {
"resource": ""
} |
q179325 | seek | test | func (r *reader) seek(off int64) (int64, error) {
delta := off - r.off
if delta >= 0 && delta < int64(len(r.buf)) {
r.r = int(delta)
return off, nil
}
r.buf, r.r, r.off = nil, 0, off
return off, nil
} | go | {
"resource": ""
} |
q179326 | multiKeyToProto | test | func multiKeyToProto(appID string, key []*Key) []*pb.Reference {
ret := make([]*pb.Reference, len(key))
for i, k := range key {
ret[i] = keyToProto(appID, k)
}
return ret
} | go | {
"resource": ""
} |
q179327 | referenceValueToKey | test | func referenceValueToKey(r *pb.PropertyValue_ReferenceValue) (k *Key, err error) {
appID := r.GetApp()
namespace := r.GetNameSpace()
for _, e := range r.Pathelement {
k = &Key{
kind: e.GetType(),
stringID: e.GetName(),
intID: e.GetId(),
parent: k,
appID: appID,
namespace: namespa... | go | {
"resource": ""
} |
q179328 | keyToReferenceValue | test | func keyToReferenceValue(defaultAppID string, k *Key) *pb.PropertyValue_ReferenceValue {
ref := keyToProto(defaultAppID, k)
pe := make([]*pb.PropertyValue_ReferenceValue_PathElement, len(ref.Path.Element))
for i, e := range ref.Path.Element {
pe[i] = &pb.PropertyValue_ReferenceValue_PathElement{
Type: e.Type,
... | go | {
"resource": ""
} |
q179329 | Put | test | func Put(c context.Context, key *Key, src interface{}) (*Key, error) {
k, err := PutMulti(c, []*Key{key}, []interface{}{src})
if err != nil {
if me, ok := err.(appengine.MultiError); ok {
return nil, me[0]
}
return nil, err
}
return k[0], nil
} | go | {
"resource": ""
} |
q179330 | PutMulti | test | func PutMulti(c context.Context, key []*Key, src interface{}) ([]*Key, error) {
v := reflect.ValueOf(src)
multiArgType, _ := checkMultiArg(v)
if multiArgType == multiArgTypeInvalid {
return nil, errors.New("datastore: src has invalid type")
}
if len(key) != v.Len() {
return nil, errors.New("datastore: key and ... | go | {
"resource": ""
} |
q179331 | Delete | test | func Delete(c context.Context, key *Key) error {
err := DeleteMulti(c, []*Key{key})
if me, ok := err.(appengine.MultiError); ok {
return me[0]
}
return err
} | go | {
"resource": ""
} |
q179332 | DeleteMulti | test | func DeleteMulti(c context.Context, key []*Key) error {
if len(key) == 0 {
return nil
}
if err := multiValid(key); err != nil {
return err
}
req := &pb.DeleteRequest{
Key: multiKeyToProto(internal.FullyQualifiedAppID(c), key),
}
res := &pb.DeleteResponse{}
return internal.Call(c, "datastore_v3", "Delete",... | go | {
"resource": ""
} |
q179333 | deploy | test | func deploy() error {
vlogf("Running command %v", flag.Args())
cmd := exec.Command(flag.Arg(0), flag.Args()[1:]...)
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("unable to run %q: %v", strings.Join(flag.Args(), " "), err)
}
return nil
} | go | {
"resource": ""
} |
q179334 | Next | test | func (qr *Result) Next() (*Record, error) {
if qr.err != nil {
return nil, qr.err
}
if len(qr.logs) > 0 {
lr := qr.logs[0]
qr.logs = qr.logs[1:]
return lr, nil
}
if qr.request.Offset == nil && qr.resultsSeen {
return nil, Done
}
if err := qr.run(); err != nil {
// Errors here may be retried, so don... | go | {
"resource": ""
} |
q179335 | protoToAppLogs | test | func protoToAppLogs(logLines []*pb.LogLine) []AppLog {
appLogs := make([]AppLog, len(logLines))
for i, line := range logLines {
appLogs[i] = AppLog{
Time: time.Unix(0, *line.Time*1e3),
Level: int(*line.Level),
Message: *line.LogMessage,
}
}
return appLogs
} | go | {
"resource": ""
} |
q179336 | protoToRecord | test | func protoToRecord(rl *pb.RequestLog) *Record {
offset, err := proto.Marshal(rl.Offset)
if err != nil {
offset = nil
}
return &Record{
AppID: *rl.AppId,
ModuleID: rl.GetModuleId(),
VersionID: *rl.VersionId,
RequestID: rl.RequestId,
Offset: offset,
IP: ... | go | {
"resource": ""
} |
q179337 | Run | test | func (params *Query) Run(c context.Context) *Result {
req, err := makeRequest(params, internal.FullyQualifiedAppID(c), appengine.VersionID(c))
return &Result{
context: c,
request: req,
err: err,
}
} | go | {
"resource": ""
} |
q179338 | run | test | func (r *Result) run() error {
res := &pb.LogReadResponse{}
if err := internal.Call(r.context, "logservice", "Read", r.request, res); err != nil {
return err
}
r.logs = make([]*Record, len(res.Log))
r.request.Offset = res.Offset
r.resultsSeen = true
for i, log := range res.Log {
r.logs[i] = protoToRecord(l... | go | {
"resource": ""
} |
q179339 | Current | test | func Current(c context.Context) *User {
h := internal.IncomingHeaders(c)
u := &User{
Email: h.Get("X-AppEngine-User-Email"),
AuthDomain: h.Get("X-AppEngine-Auth-Domain"),
ID: h.Get("X-AppEngine-User-Id"),
Admin: h.Get("X-AppEngine-User-Is-Admin") == "1",
Federat... | go | {
"resource": ""
} |
q179340 | IsAdmin | test | func IsAdmin(c context.Context) bool {
h := internal.IncomingHeaders(c)
return h.Get("X-AppEngine-User-Is-Admin") == "1"
} | go | {
"resource": ""
} |
q179341 | isErrFieldMismatch | test | func isErrFieldMismatch(err error) bool {
_, ok := err.(*datastore.ErrFieldMismatch)
return ok
} | go | {
"resource": ""
} |
q179342 | Stat | test | func Stat(c context.Context, blobKey appengine.BlobKey) (*BlobInfo, error) {
c, _ = appengine.Namespace(c, "") // Blobstore is always in the empty string namespace
dskey := datastore.NewKey(c, blobInfoKind, string(blobKey), 0, nil)
bi := &BlobInfo{
BlobKey: blobKey,
}
if err := datastore.Get(c, dskey, bi); err !... | go | {
"resource": ""
} |
q179343 | Send | test | func Send(response http.ResponseWriter, blobKey appengine.BlobKey) {
hdr := response.Header()
hdr.Set("X-AppEngine-BlobKey", string(blobKey))
if hdr.Get("Content-Type") == "" {
// This value is known to dev_appserver to mean automatic.
// In production this is remapped to the empty value which
// means automa... | go | {
"resource": ""
} |
q179344 | UploadURL | test | func UploadURL(c context.Context, successPath string, opts *UploadURLOptions) (*url.URL, error) {
req := &blobpb.CreateUploadURLRequest{
SuccessPath: proto.String(successPath),
}
if opts != nil {
if n := opts.MaxUploadBytes; n != 0 {
req.MaxUploadSizeBytes = &n
}
if n := opts.MaxUploadBytesPerBlob; n != 0... | go | {
"resource": ""
} |
q179345 | Delete | test | func Delete(c context.Context, blobKey appengine.BlobKey) error {
return DeleteMulti(c, []appengine.BlobKey{blobKey})
} | go | {
"resource": ""
} |
q179346 | DeleteMulti | test | func DeleteMulti(c context.Context, blobKey []appengine.BlobKey) error {
s := make([]string, len(blobKey))
for i, b := range blobKey {
s[i] = string(b)
}
req := &blobpb.DeleteBlobRequest{
BlobKey: s,
}
res := &basepb.VoidProto{}
if err := internal.Call(c, "blobstore", "DeleteBlob", req, res); err != nil {
... | go | {
"resource": ""
} |
q179347 | NewReader | test | func NewReader(c context.Context, blobKey appengine.BlobKey) Reader {
return openBlob(c, blobKey)
} | go | {
"resource": ""
} |
q179348 | Handle | test | func Handle(f func(c context.Context, m *Message)) {
http.HandleFunc("/_ah/xmpp/message/chat/", func(_ http.ResponseWriter, r *http.Request) {
f(appengine.NewContext(r), &Message{
Sender: r.FormValue("from"),
To: []string{r.FormValue("to")},
Body: r.FormValue("body"),
})
})
} | go | {
"resource": ""
} |
q179349 | Send | test | func (m *Message) Send(c context.Context) error {
req := &pb.XmppMessageRequest{
Jid: m.To,
Body: &m.Body,
RawXml: &m.RawXML,
}
if m.Type != "" && m.Type != "chat" {
req.Type = &m.Type
}
if m.Sender != "" {
req.FromJid = &m.Sender
}
res := &pb.XmppMessageResponse{}
if err := internal.Call(c, "xmp... | go | {
"resource": ""
} |
q179350 | Invite | test | func Invite(c context.Context, to, from string) error {
req := &pb.XmppInviteRequest{
Jid: &to,
}
if from != "" {
req.FromJid = &from
}
res := &pb.XmppInviteResponse{}
return internal.Call(c, "xmpp", "SendInvite", req, res)
} | go | {
"resource": ""
} |
q179351 | Send | test | func (p *Presence) Send(c context.Context) error {
req := &pb.XmppSendPresenceRequest{
Jid: &p.To,
}
if p.State != "" {
req.Show = &p.State
}
if p.Type != "" {
req.Type = &p.Type
}
if p.Sender != "" {
req.FromJid = &p.Sender
}
if p.Status != "" {
req.Status = &p.Status
}
res := &pb.XmppSendPresence... | go | {
"resource": ""
} |
q179352 | GetPresence | test | func GetPresence(c context.Context, to string, from string) (string, error) {
req := &pb.PresenceRequest{
Jid: &to,
}
if from != "" {
req.FromJid = &from
}
res := &pb.PresenceResponse{}
if err := internal.Call(c, "xmpp", "GetPresence", req, res); err != nil {
return "", err
}
if !*res.IsAvailable || res.P... | go | {
"resource": ""
} |
q179353 | GetPresenceMulti | test | func GetPresenceMulti(c context.Context, to []string, from string) ([]string, error) {
req := &pb.BulkPresenceRequest{
Jid: to,
}
if from != "" {
req.FromJid = &from
}
res := &pb.BulkPresenceResponse{}
if err := internal.Call(c, "xmpp", "BulkGetPresence", req, res); err != nil {
return nil, err
}
presen... | go | {
"resource": ""
} |
q179354 | newStructFLS | test | func newStructFLS(p interface{}) (FieldLoadSaver, error) {
v := reflect.ValueOf(p)
if v.Kind() != reflect.Ptr || v.IsNil() || v.Elem().Kind() != reflect.Struct {
return nil, ErrInvalidDocumentType
}
codec, err := loadCodec(v.Elem().Type())
if err != nil {
return nil, err
}
return structFLS{v.Elem(), codec}, ... | go | {
"resource": ""
} |
q179355 | SaveStruct | test | func SaveStruct(src interface{}) ([]Field, error) {
f, _, err := saveStructWithMeta(src)
return f, err
} | go | {
"resource": ""
} |
q179356 | Namespaces | test | func Namespaces(ctx context.Context) ([]string, error) {
// TODO(djd): Support range queries.
q := NewQuery(namespaceKind).KeysOnly()
keys, err := q.GetAll(ctx, nil)
if err != nil {
return nil, err
}
// The empty namespace key uses a numeric ID (==1), but luckily
// the string ID defaults to "" for numeric IDs... | go | {
"resource": ""
} |
q179357 | Kinds | test | func Kinds(ctx context.Context) ([]string, error) {
// TODO(djd): Support range queries.
q := NewQuery(kindKind).KeysOnly()
keys, err := q.GetAll(ctx, nil)
if err != nil {
return nil, err
}
return keyNames(keys), nil
} | go | {
"resource": ""
} |
q179358 | RunInTransaction | test | func RunInTransaction(c context.Context, f func(tc context.Context) error, opts *TransactionOptions) error {
xg := false
if opts != nil {
xg = opts.XG
}
readOnly := false
if opts != nil {
readOnly = opts.ReadOnly
}
attempts := 3
if opts != nil && opts.Attempts > 0 {
attempts = opts.Attempts
}
var t *pb.... | go | {
"resource": ""
} |
q179359 | imports | test | func imports(f *ast.File, path string) bool {
return importSpec(f, path) != nil
} | go | {
"resource": ""
} |
q179360 | importSpec | test | func importSpec(f *ast.File, path string) *ast.ImportSpec {
for _, s := range f.Imports {
if importPath(s) == path {
return s
}
}
return nil
} | go | {
"resource": ""
} |
q179361 | declImports | test | func declImports(gen *ast.GenDecl, path string) bool {
if gen.Tok != token.IMPORT {
return false
}
for _, spec := range gen.Specs {
impspec := spec.(*ast.ImportSpec)
if importPath(impspec) == path {
return true
}
}
return false
} | go | {
"resource": ""
} |
q179362 | isPkgDot | test | func isPkgDot(t ast.Expr, pkg, name string) bool {
sel, ok := t.(*ast.SelectorExpr)
return ok && isTopName(sel.X, pkg) && sel.Sel.String() == name
} | go | {
"resource": ""
} |
q179363 | isTopName | test | func isTopName(n ast.Expr, name string) bool {
id, ok := n.(*ast.Ident)
return ok && id.Name == name && id.Obj == nil
} | go | {
"resource": ""
} |
q179364 | isName | test | func isName(n ast.Expr, name string) bool {
id, ok := n.(*ast.Ident)
return ok && id.String() == name
} | go | {
"resource": ""
} |
q179365 | isCall | test | func isCall(t ast.Expr, pkg, name string) bool {
call, ok := t.(*ast.CallExpr)
return ok && isPkgDot(call.Fun, pkg, name)
} | go | {
"resource": ""
} |
q179366 | refersTo | test | func refersTo(n ast.Node, x *ast.Ident) bool {
id, ok := n.(*ast.Ident)
// The test of id.Name == x.Name handles top-level unresolved
// identifiers, which all have Obj == nil.
return ok && id.Obj == x.Obj && id.Name == x.Name
} | go | {
"resource": ""
} |
q179367 | isEmptyString | test | func isEmptyString(n ast.Expr) bool {
lit, ok := n.(*ast.BasicLit)
return ok && lit.Kind == token.STRING && len(lit.Value) == 2
} | go | {
"resource": ""
} |
q179368 | countUses | test | func countUses(x *ast.Ident, scope []ast.Stmt) int {
count := 0
ff := func(n interface{}) {
if n, ok := n.(ast.Node); ok && refersTo(n, x) {
count++
}
}
for _, n := range scope {
walk(n, ff)
}
return count
} | go | {
"resource": ""
} |
q179369 | assignsTo | test | func assignsTo(x *ast.Ident, scope []ast.Stmt) bool {
assigned := false
ff := func(n interface{}) {
if assigned {
return
}
switch n := n.(type) {
case *ast.UnaryExpr:
// use of &x
if n.Op == token.AND && refersTo(n.X, x) {
assigned = true
return
}
case *ast.AssignStmt:
for _, l := ran... | go | {
"resource": ""
} |
q179370 | newPkgDot | test | func newPkgDot(pos token.Pos, pkg, name string) ast.Expr {
return &ast.SelectorExpr{
X: &ast.Ident{
NamePos: pos,
Name: pkg,
},
Sel: &ast.Ident{
NamePos: pos,
Name: name,
},
}
} | go | {
"resource": ""
} |
q179371 | renameTop | test | func renameTop(f *ast.File, old, new string) bool {
var fixed bool
// Rename any conflicting imports
// (assuming package name is last element of path).
for _, s := range f.Imports {
if s.Name != nil {
if s.Name.Name == old {
s.Name.Name = new
fixed = true
}
} else {
_, thisName := path.Split(... | go | {
"resource": ""
} |
q179372 | matchLen | test | func matchLen(x, y string) int {
i := 0
for i < len(x) && i < len(y) && x[i] == y[i] {
i++
}
return i
} | go | {
"resource": ""
} |
q179373 | deleteImport | test | func deleteImport(f *ast.File, path string) (deleted bool) {
oldImport := importSpec(f, path)
// Find the import node that imports path, if any.
for i, decl := range f.Decls {
gen, ok := decl.(*ast.GenDecl)
if !ok || gen.Tok != token.IMPORT {
continue
}
for j, spec := range gen.Specs {
impspec := spec... | go | {
"resource": ""
} |
q179374 | rewriteImport | test | func rewriteImport(f *ast.File, oldPath, newPath string) (rewrote bool) {
for _, imp := range f.Imports {
if importPath(imp) == oldPath {
rewrote = true
// record old End, because the default is to compute
// it using the length of imp.Path.Value.
imp.EndPos = imp.End()
imp.Path.Value = strconv.Quote(... | go | {
"resource": ""
} |
q179375 | DefaultTicket | test | func DefaultTicket() string {
defaultTicketOnce.Do(func() {
if IsDevAppServer() {
defaultTicket = "testapp" + defaultTicketSuffix
return
}
appID := partitionlessAppID()
escAppID := strings.Replace(strings.Replace(appID, ":", "_", -1), ".", "_", -1)
majVersion := VersionID(nil)
if i := strings.Index(m... | go | {
"resource": ""
} |
q179376 | flushLog | test | func (c *context) flushLog(force bool) (flushed bool) {
c.pendingLogs.Lock()
// Grab up to 30 MB. We can get away with up to 32 MB, but let's be cautious.
n, rem := 0, 30<<20
for ; n < len(c.pendingLogs.lines); n++ {
ll := c.pendingLogs.lines[n]
// Each log line will require about 3 bytes of overhead.
nb := p... | go | {
"resource": ""
} |
q179377 | withDeadline | test | func withDeadline(parent context.Context, deadline time.Time) (context.Context, context.CancelFunc) {
if deadline.IsZero() {
return parent, func() {}
}
return context.WithDeadline(parent, deadline)
} | go | {
"resource": ""
} |
q179378 | KeepAlive | test | func (cn *Conn) KeepAlive() error {
req := &pb.GetSocketNameRequest{
SocketDescriptor: &cn.desc,
}
res := &pb.GetSocketNameReply{}
return internal.Call(cn.ctx, "remote_socket", "GetSocketName", req, res)
} | go | {
"resource": ""
} |
q179379 | applyTransaction | test | func applyTransaction(pb proto.Message, t *pb.Transaction) {
v := reflect.ValueOf(pb)
if f, ok := transactionSetters[v.Type()]; ok {
f.Call([]reflect.Value{v, reflect.ValueOf(t)})
}
} | go | {
"resource": ""
} |
q179380 | analyze | test | func analyze(tags []string) (*app, error) {
ctxt := buildContext(tags)
hasMain, appFiles, err := checkMain(ctxt)
if err != nil {
return nil, err
}
gopath := filepath.SplitList(ctxt.GOPATH)
im, err := imports(ctxt, *rootDir, gopath)
return &app{
hasMain: hasMain,
appFiles: appFiles,
imports: im,
}, err... | go | {
"resource": ""
} |
q179381 | buildContext | test | func buildContext(tags []string) *build.Context {
return &build.Context{
GOARCH: build.Default.GOARCH,
GOOS: build.Default.GOOS,
GOROOT: build.Default.GOROOT,
GOPATH: build.Default.GOPATH,
Compiler: build.Default.Compiler,
BuildTags: append(build.Default.BuildTags, tags...),
}
} | go | {
"resource": ""
} |
q179382 | synthesizeMain | test | func synthesizeMain(tw *tar.Writer, appFiles []string) error {
appMap := make(map[string]bool)
for _, f := range appFiles {
appMap[f] = true
}
var f string
for i := 0; i < 100; i++ {
f = fmt.Sprintf("app_main%d.go", i)
if !appMap[filepath.Join(*rootDir, f)] {
break
}
}
if appMap[filepath.Join(*rootDir... | go | {
"resource": ""
} |
q179383 | findInGopath | test | func findInGopath(dir string, gopath []string) (string, error) {
for _, v := range gopath {
dst := filepath.Join(v, "src", dir)
if _, err := os.Stat(dst); err == nil {
return dst, nil
}
}
return "", fmt.Errorf("unable to find package %v in gopath %v", dir, gopath)
} | go | {
"resource": ""
} |
q179384 | copyTree | test | func copyTree(tw *tar.Writer, dstDir, srcDir string) error {
entries, err := ioutil.ReadDir(srcDir)
if err != nil {
return fmt.Errorf("unable to read dir %v: %v", srcDir, err)
}
for _, entry := range entries {
n := entry.Name()
if skipFiles[n] {
continue
}
s := filepath.Join(srcDir, n)
d := filepath.... | go | {
"resource": ""
} |
q179385 | copyFile | test | func copyFile(tw *tar.Writer, dst, src string) error {
s, err := os.Open(src)
if err != nil {
return fmt.Errorf("unable to open %v: %v", src, err)
}
defer s.Close()
fi, err := s.Stat()
if err != nil {
return fmt.Errorf("unable to stat %v: %v", src, err)
}
hdr, err := tar.FileInfoHeader(fi, dst)
if err != ... | go | {
"resource": ""
} |
q179386 | checkMain | test | func checkMain(ctxt *build.Context) (bool, []string, error) {
pkg, err := ctxt.ImportDir(*rootDir, 0)
if err != nil {
return false, nil, fmt.Errorf("unable to analyze source: %v", err)
}
if !pkg.IsCommand() {
errorf("Your app's package needs to be changed from %q to \"main\".\n", pkg.Name)
}
// Search for a "... | go | {
"resource": ""
} |
q179387 | isMain | test | func isMain(f *ast.FuncDecl) bool {
ft := f.Type
return f.Name.Name == "main" && f.Recv == nil && ft.Params.NumFields() == 0 && ft.Results.NumFields() == 0
} | go | {
"resource": ""
} |
q179388 | readFile | test | func readFile(filename string) (hasMain bool, err error) {
var src []byte
src, err = ioutil.ReadFile(filename)
if err != nil {
return
}
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, filename, src, 0)
for _, decl := range file.Decls {
funcDecl, ok := decl.(*ast.FuncDecl)
if !ok {
continu... | go | {
"resource": ""
} |
q179389 | initField | test | func initField(val reflect.Value, index []int) reflect.Value {
for _, i := range index[:len(index)-1] {
val = val.Field(i)
if val.Kind() == reflect.Ptr {
if val.IsNil() {
val.Set(reflect.New(val.Type().Elem()))
}
val = val.Elem()
}
}
return val.Field(index[len(index)-1])
} | go | {
"resource": ""
} |
q179390 | loadEntity | test | func loadEntity(dst interface{}, src *pb.EntityProto) (err error) {
ent, err := protoToEntity(src)
if err != nil {
return err
}
if e, ok := dst.(PropertyLoadSaver); ok {
return e.Load(ent.Properties)
}
return LoadStruct(dst, ent.Properties)
} | go | {
"resource": ""
} |
q179391 | validIndexNameOrDocID | test | func validIndexNameOrDocID(s string) bool {
if strings.HasPrefix(s, "!") {
return false
}
for _, c := range s {
if c < 0x21 || 0x7f <= c {
return false
}
}
return true
} | go | {
"resource": ""
} |
q179392 | Open | test | func Open(name string) (*Index, error) {
if !validIndexNameOrDocID(name) {
return nil, fmt.Errorf("search: invalid index name %q", name)
}
return &Index{
spec: pb.IndexSpec{
Name: &name,
},
}, nil
} | go | {
"resource": ""
} |
q179393 | Put | test | func (x *Index) Put(c context.Context, id string, src interface{}) (string, error) {
ids, err := x.PutMulti(c, []string{id}, []interface{}{src})
if err != nil {
return "", err
}
return ids[0], nil
} | go | {
"resource": ""
} |
q179394 | Get | test | func (x *Index) Get(c context.Context, id string, dst interface{}) error {
if id == "" || !validIndexNameOrDocID(id) {
return fmt.Errorf("search: invalid ID %q", id)
}
req := &pb.ListDocumentsRequest{
Params: &pb.ListDocumentsParams{
IndexSpec: &x.spec,
StartDocId: proto.String(id),
Limit: proto.I... | go | {
"resource": ""
} |
q179395 | Delete | test | func (x *Index) Delete(c context.Context, id string) error {
return x.DeleteMulti(c, []string{id})
} | go | {
"resource": ""
} |
q179396 | DeleteMulti | test | func (x *Index) DeleteMulti(c context.Context, ids []string) error {
if len(ids) > maxDocumentsPerPutDelete {
return ErrTooManyDocuments
}
req := &pb.DeleteDocumentRequest{
Params: &pb.DeleteDocumentParams{
DocId: ids,
IndexSpec: &x.spec,
},
}
res := &pb.DeleteDocumentResponse{}
if err := interna... | go | {
"resource": ""
} |
q179397 | Search | test | func (x *Index) Search(c context.Context, query string, opts *SearchOptions) *Iterator {
t := &Iterator{
c: c,
index: x,
searchQuery: query,
more: moreSearch,
}
if opts != nil {
if opts.Cursor != "" {
if opts.Offset != 0 {
return errIter("at most one of Cursor and Offset may b... | go | {
"resource": ""
} |
q179398 | fetchMore | test | func (t *Iterator) fetchMore() {
if t.err == nil && len(t.listRes)+len(t.searchRes) == 0 && t.more != nil {
t.err = t.more(t)
}
} | go | {
"resource": ""
} |
q179399 | Next | test | func (t *Iterator) Next(dst interface{}) (string, error) {
t.fetchMore()
if t.err != nil {
return "", t.err
}
var doc *pb.Document
var exprs []*pb.Field
switch {
case len(t.listRes) != 0:
doc = t.listRes[0]
t.listRes = t.listRes[1:]
case len(t.searchRes) != 0:
doc = t.searchRes[0].Document
exprs = t.... | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.