query
stringlengths
7
3.85k
document
stringlengths
11
430k
metadata
dict
negatives
listlengths
0
101
negative_scores
listlengths
0
101
document_score
stringlengths
3
10
document_rank
stringclasses
102 values
Your code here RPC handlers for the worker to call. Example an example RPC handler. the RPC argument and reply types are defined in rpc.go.
func (m *Master) Example(args *ExampleArgs, reply *ExampleReply) error { fmt.Println("I'm in example ", args.X) reply.Y = args.X + 1 return nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func callWorker(worker, name string, args interface{}, reply interface{}) bool {\n\treturn call(worker, \"RPCWorker.\"+name, args, reply)\n}", "func (cl *Client) DoRPC(functionName string, args interface{}) (response interface{}, err error) {\n\t/*\n\t\tDoes a remote procedure call using the msgpack2 protocol fo...
[ "0.7160002", "0.6427018", "0.6401158", "0.6393349", "0.6337075", "0.6300134", "0.6243808", "0.62327254", "0.62239456", "0.6219964", "0.6070592", "0.60639507", "0.6063026", "0.60481477", "0.6038316", "0.6027173", "0.60211265", "0.60112995", "0.60013", "0.59859306", "0.59594935...
0.0
-1
UpdateTaskStatus change task status when task done or error
func (m *Master) UpdateMapTaskStatus(args *UpdateStatusRequest, reply *UpdateStatusReply) error { defer func() { if err := recover(); err != nil { log.Println("work failed:", err) reply.Err = fmt.Sprintf("%s", err) } }() m.mu.Lock() defer m.mu.Unlock() if args.Status == SUCCESS { for _, record := range m.tasks[args.TaskID] { record.status = SUCCESS m.successCounter++ } if m.successCounter >= len(m.files) { m.phase = TaskReduceType log.Println("All Map task have done , let we entry reduce phase!") } } else if args.Status == FAILED { //TODO add to failed list } else { return &argError{args.Status, "map task just return success or failed"} } return nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (context Context) UpdateTaskStatus(id string, status string, statusMessage string) (err error) {\n\t_, err = context.UpdateTask(id, F{\"status\": status, \"status-message\": statusMessage})\n\treturn\n}", "func (s *Service) UpdateTaskStatus(c context.Context, date string, typ int, status int) (err error) {\...
[ "0.80603653", "0.7995561", "0.79425794", "0.7895905", "0.7725359", "0.75573677", "0.7514321", "0.73935276", "0.7366755", "0.7346412", "0.7342435", "0.72824836", "0.7030268", "0.6976509", "0.685103", "0.6832641", "0.6811408", "0.67838687", "0.673875", "0.66078985", "0.6592641"...
0.7315912
11
start a thread that listens for RPCs from worker.go
func (m *Master) server() { rpc.Register(m) rpc.HandleHTTP() //l, e := net.Listen("tcp", ":1234") sockname := masterSock() os.Remove(sockname) l, e := net.Listen("unix", sockname) if e != nil { log.Fatal("listen error:", e) } go http.Serve(l, nil) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (wk *Worker) startRPCServer() {\n\t// TODO: implement me\n\t// Hint: Refer to how the driver's startRPCServer is implemented.\n\t// TODO TODO TODO\n\t//\n\n\t//\n\t// Once shutdown is closed, should the following statement be\n\t// called, meaning the worker RPC server is existing.\n\tserverless.Debug(\"Worke...
[ "0.6423443", "0.6312183", "0.6110611", "0.60416585", "0.58672446", "0.58397245", "0.5838455", "0.5836735", "0.58064723", "0.5799099", "0.57792133", "0.5770807", "0.57646734", "0.5764245", "0.5761796", "0.57543683", "0.5745381", "0.5742795", "0.5734523", "0.5725471", "0.571950...
0.0
-1
Done check whether it can stop. main/mrmaster.go calls Done() periodically to find out if the entire job has finished.
func (m *Master) Done() bool { // ret := (JobDown == m.phase) // Your code here. return JobDown == m.phase }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (m *Master) Done() bool {\n\t// Your code here.\n\treturn m.jobs.empty(ReduceJob)\n}", "func (m *Master) Done() bool {\n\tret := false\n\tfmt.Printf(\"MapTasks: %v\\n\", m.mapTasks)\n\tfmt.Printf(\"RedTasks: %v\\n\", m.reduceTasks)\n\tfmt.Printf(\"nReduce: %d, nMap: %d\\n\", m.nReduce, m.nMap)\n\t// Your co...
[ "0.7996627", "0.7941394", "0.7888764", "0.77940726", "0.77649367", "0.77086526", "0.76372457", "0.76169884", "0.7613166", "0.7599608", "0.7595551", "0.7579391", "0.7575501", "0.75663006", "0.7555578", "0.75244766", "0.74878955", "0.74781144", "0.7467091", "0.7411585", "0.7405...
0.77588177
5
MakeMaster as the name create a Master. main/mrmaster.go calls this function. nReduce is the number of reduce tasks to use.
func MakeMaster(files []string, nReduce int) *Master { m := Master{} m.files = files m.record = map[string]*record{} m.tasks = map[int][]*record{} m.reduceTasks = map[int]*record{} m.nReduce = nReduce m.phase = TaskMapType // Your code here. m.server() return &m }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func MakeMaster(files []string, nReduce int) *Master {\n\tfmt.Printf(\"Making Master. nReduce = %d\\n\", nReduce)\n\n\tm := Master{}\n\tm.nReduce = nReduce\n\tm.mapDone = false\n\tm.reduceDone = false\n\n\t// Create map tasks from files\n\tfor i, filename := range files {\n\t\tfmt.Printf(\"Creating task for file %...
[ "0.8261484", "0.8238458", "0.8148093", "0.80947137", "0.8092807", "0.8089421", "0.80650294", "0.80432916", "0.8039373", "0.8032846", "0.8027626", "0.79940253", "0.7988203", "0.79579335", "0.79458636", "0.7905601", "0.7896114", "0.78781605", "0.7851", "0.78498274", "0.7843989"...
0.77630055
27
check if current time is during day
func isBright() bool { now := time.Now() if now.After(sunriseTime) && now.Before(sunsetTime) { return true } return false }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func whichPartOfDayIsNow() {\n\tswitch {\n\tcase time.Now().Hour() < 12:\n\t\tfmt.Println(\"Good morning!\")\n\tcase time.Now().Hour() < 17:\n\t\tfmt.Println(\"Good afternoon!\")\n\tdefault:\n\t\tfmt.Println(\"Good evening!\")\n\n\t}\n}", "func IsAfternoon() bool {\n localTime := time.Now()\n return local...
[ "0.6837422", "0.68246526", "0.66332364", "0.6369505", "0.59788275", "0.58758134", "0.5860154", "0.58266675", "0.5822932", "0.5798924", "0.57924026", "0.578373", "0.5771897", "0.5766363", "0.5752725", "0.56679946", "0.55978906", "0.5531325", "0.55143285", "0.550681", "0.550473...
0.53761876
32
/ the mian enter of algorithm of quicksort
func (idx *IndexBuf)quickSort(s, t int) { if t < 0 {return} m := idx.split(s, t) for s > t { idx.quickSort(s, m-1) idx.quickSort(m+1, t) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func qsort(a []int, start, end int) {\n\tif start >= end {\n\t\treturn\n\t}\n\tif end >= len(a) {\n\t\tend = len(a) - 1\n\t}\n\tpivot := a[(start+end)/2]\n\n\ti := start\n\tj := end\n\tfor {\n\t\tfor ; i <= end && a[i] < pivot; i++ {\n\t\t}\n\t\tfor ; j >= start && a[j] > pivot; j-- {\n\t\t}\n\t\tif i >= j {\n\t\t...
[ "0.7434971", "0.7427814", "0.71793103", "0.7163517", "0.71632874", "0.7137938", "0.71337104", "0.70999765", "0.70314693", "0.7029114", "0.7027174", "0.7010988", "0.70097184", "0.7002579", "0.6967433", "0.6962324", "0.6962127", "0.69464695", "0.6884501", "0.6869758", "0.686356...
0.6535588
42
/ the split part of algorithm of quicksort
func (idx *IndexBuf)split(s, t int) int { var i, j int for i, j = s, s; i < t; i++ { if idx.less(i, t) { idx.swap(i, j) j++ } } idx.swap(j, t) return j }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (s *quicksort) partition(slice []int, low, high int) int {\n\tpivotIdx := s.FindPivotIndex(slice, low, high)\n\n\tpivot := slice[pivotIdx]\n\ti := low\n\tj := high\n\n\tfor {\n\t\tfor ; slice[i] < pivot; i++ {\n\n\t\t}\n\t\tfor ; slice[j] > pivot; j-- {\n\n\t\t}\n\t\tif i >= j {\n\t\t\treturn j\n\t\t}\n\t\t//...
[ "0.7229065", "0.7190257", "0.707405", "0.706499", "0.7031688", "0.6961537", "0.6913219", "0.6912623", "0.6788063", "0.6781634", "0.67755073", "0.6756104", "0.67342824", "0.67150515", "0.6709114", "0.6702981", "0.6681376", "0.6680446", "0.66566795", "0.66553825", "0.66483855",...
0.5829982
84
GetAwsSession Returns an AWS session for the specified server cfguration
func GetAwsSession(cfg config.ServerConfig) (*session.Session, error) { var providers []credentials.Provider customResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) { if service == endpoints.RdsServiceID && cfg.AwsEndpointRdsURL != "" { return endpoints.ResolvedEndpoint{ URL: cfg.AwsEndpointRdsURL, SigningRegion: cfg.AwsEndpointSigningRegion, }, nil } if service == endpoints.Ec2ServiceID && cfg.AwsEndpointEc2URL != "" { return endpoints.ResolvedEndpoint{ URL: cfg.AwsEndpointEc2URL, SigningRegion: cfg.AwsEndpointSigningRegion, }, nil } if service == endpoints.MonitoringServiceID && cfg.AwsEndpointCloudwatchURL != "" { return endpoints.ResolvedEndpoint{ URL: cfg.AwsEndpointCloudwatchURL, SigningRegion: cfg.AwsEndpointSigningRegion, }, nil } if service == endpoints.LogsServiceID && cfg.AwsEndpointCloudwatchLogsURL != "" { return endpoints.ResolvedEndpoint{ URL: cfg.AwsEndpointCloudwatchLogsURL, SigningRegion: cfg.AwsEndpointSigningRegion, }, nil } return endpoints.DefaultResolver().EndpointFor(service, region, optFns...) } if cfg.AwsAccessKeyID != "" { providers = append(providers, &credentials.StaticProvider{ Value: credentials.Value{ AccessKeyID: cfg.AwsAccessKeyID, SecretAccessKey: cfg.AwsSecretAccessKey, SessionToken: "", }, }) } // add default providers providers = append(providers, &credentials.EnvProvider{}) providers = append(providers, &credentials.SharedCredentialsProvider{Filename: "", Profile: ""}) // add the metadata service def := defaults.Get() def.Config.HTTPClient = config.CreateEC2IMDSHTTPClient(cfg) def.Config.MaxRetries = aws.Int(2) providers = append(providers, defaults.RemoteCredProvider(*def.Config, def.Handlers)) creds := credentials.NewChainCredentials(providers) if cfg.AwsAssumeRole != "" || (cfg.AwsWebIdentityTokenFile != "" && cfg.AwsRoleArn != "") { sess, err := session.NewSession(&aws.Config{ Credentials: creds, CredentialsChainVerboseErrors: aws.Bool(true), Region: aws.String(cfg.AwsRegion), HTTPClient: cfg.HTTPClient, EndpointResolver: endpoints.ResolverFunc(customResolver), }) if err != nil { return nil, err } if cfg.AwsAssumeRole != "" { creds = stscreds.NewCredentials(sess, cfg.AwsAssumeRole) } else if cfg.AwsWebIdentityTokenFile != "" && cfg.AwsRoleArn != "" { creds = stscreds.NewWebIdentityCredentials(sess, cfg.AwsRoleArn, "", cfg.AwsWebIdentityTokenFile) } } return session.NewSession(&aws.Config{ Credentials: creds, CredentialsChainVerboseErrors: aws.Bool(true), Region: aws.String(cfg.AwsRegion), HTTPClient: cfg.HTTPClient, EndpointResolver: endpoints.ResolverFunc(customResolver), }) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func GetAwsSession(region string, awsAccessKeyID string, awsSecretAccessKey string) (*session.Session, error) {\n\tif awsAccessKeyID == \"\" || awsSecretAccessKey == \"\" {\n\t\tconfig := aws.Config{\n\t\t\tRegion: aws.String(region),\n\t\t\tMaxRetries: aws.Int(awsSdkMaxRetries),\n\t\t}\n\n\t\tsess, err := ses...
[ "0.7475091", "0.7309152", "0.7308612", "0.7059727", "0.6873469", "0.6860654", "0.676002", "0.671794", "0.6665601", "0.66074514", "0.6492171", "0.6449359", "0.64330184", "0.64273876", "0.62588125", "0.6234018", "0.61775804", "0.61309797", "0.61003613", "0.6086228", "0.6027008"...
0.7961176
0
NewAuthorizer registers a new resource with the given unique name, arguments, and options.
func NewAuthorizer(ctx *pulumi.Context, name string, args *AuthorizerArgs, opts ...pulumi.ResourceOpt) (*Authorizer, error) { if args == nil || args.RestApi == nil { return nil, errors.New("missing required argument 'RestApi'") } inputs := make(map[string]interface{}) if args == nil { inputs["authorizerCredentials"] = nil inputs["authorizerResultTtlInSeconds"] = nil inputs["authorizerUri"] = nil inputs["identitySource"] = nil inputs["identityValidationExpression"] = nil inputs["name"] = nil inputs["providerArns"] = nil inputs["restApi"] = nil inputs["type"] = nil } else { inputs["authorizerCredentials"] = args.AuthorizerCredentials inputs["authorizerResultTtlInSeconds"] = args.AuthorizerResultTtlInSeconds inputs["authorizerUri"] = args.AuthorizerUri inputs["identitySource"] = args.IdentitySource inputs["identityValidationExpression"] = args.IdentityValidationExpression inputs["name"] = args.Name inputs["providerArns"] = args.ProviderArns inputs["restApi"] = args.RestApi inputs["type"] = args.Type } s, err := ctx.RegisterResource("aws:apigateway/authorizer:Authorizer", name, true, inputs, opts...) if err != nil { return nil, err } return &Authorizer{s: s}, nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (c *APIGateway) CreateAuthorizerRequest(input *CreateAuthorizerInput) (req *request.Request, output *Authorizer) {\n\top := &request.Operation{\n\t\tName: opCreateAuthorizer,\n\t\tHTTPMethod: \"POST\",\n\t\tHTTPPath: \"/restapis/{restapi_id}/authorizers\",\n\t}\n\n\tif input == nil {\n\t\tinput = &Cre...
[ "0.52188647", "0.5108134", "0.5086522", "0.5000285", "0.4891315", "0.48323616", "0.47788405", "0.4774721", "0.47684354", "0.47625926", "0.47625926", "0.47579473", "0.47527245", "0.47505093", "0.47407386", "0.47402185", "0.4731808", "0.4727103", "0.47142524", "0.4701625", "0.4...
0.65082943
0
GetAuthorizer gets an existing Authorizer resource's state with the given name, ID, and optional state properties that are used to uniquely qualify the lookup (nil if not required).
func GetAuthorizer(ctx *pulumi.Context, name string, id pulumi.ID, state *AuthorizerState, opts ...pulumi.ResourceOpt) (*Authorizer, error) { inputs := make(map[string]interface{}) if state != nil { inputs["authorizerCredentials"] = state.AuthorizerCredentials inputs["authorizerResultTtlInSeconds"] = state.AuthorizerResultTtlInSeconds inputs["authorizerUri"] = state.AuthorizerUri inputs["identitySource"] = state.IdentitySource inputs["identityValidationExpression"] = state.IdentityValidationExpression inputs["name"] = state.Name inputs["providerArns"] = state.ProviderArns inputs["restApi"] = state.RestApi inputs["type"] = state.Type } s, err := ctx.ReadResource("aws:apigateway/authorizer:Authorizer", name, id, inputs, opts...) if err != nil { return nil, err } return &Authorizer{s: s}, nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (c *APIGateway) GetAuthorizer(input *GetAuthorizerInput) (*Authorizer, error) {\n\treq, out := c.GetAuthorizerRequest(input)\n\terr := req.Send()\n\treturn out, err\n}", "func GetAuthorizer(sp *ServicePrincipal, env *azure.Environment) (autorest.Authorizer, error) {\n\toauthConfig, err := adal.NewOAuthConfi...
[ "0.6288236", "0.61128867", "0.600631", "0.5912986", "0.56904894", "0.55917406", "0.55573034", "0.54324085", "0.5352838", "0.52806234", "0.51653206", "0.51357406", "0.5128047", "0.50898623", "0.5068182", "0.5052384", "0.50460017", "0.4977039", "0.4974712", "0.49660113", "0.495...
0.8224552
0
URN is this resource's unique name assigned by Pulumi.
func (r *Authorizer) URN() pulumi.URNOutput { return r.s.URN() }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (e *ExternalService) URN() string {\n\treturn \"extsvc:\" + strings.ToLower(e.Kind) + \":\" + strconv.FormatInt(e.ID, 10)\n}", "func (r *ResourceGroup) URN() pulumi.URNOutput {\n\treturn r.s.URN()\n}", "func (r *Template) URN() pulumi.URNOutput {\n\treturn r.s.URN()\n}", "func (r *Policy) URN() pulumi.U...
[ "0.6310668", "0.6242247", "0.62268686", "0.6194743", "0.615504", "0.6015328", "0.5991877", "0.5970723", "0.58543295", "0.5854269", "0.581078", "0.57991636", "0.57965666", "0.57886875", "0.5758153", "0.5749012", "0.5738039", "0.5725185", "0.5713738", "0.57052803", "0.57030535"...
0.58101857
11
ID is this resource's unique identifier assigned by its provider.
func (r *Authorizer) ID() pulumi.IDOutput { return r.s.ID() }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (id ResourceGroupProviderId) ID() string {\n\tfmtString := \"/subscriptions/%s/resourceGroups/%s/providers/%s/%s/%s/%s/%s\"\n\treturn fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProviderName, id.ResourceParentType, id.ResourceParentName, id.ResourceType, id.ResourceName)\n}", "func (r...
[ "0.77244645", "0.7674558", "0.72857183", "0.7220597", "0.7069998", "0.68257725", "0.68159103", "0.67238456", "0.6696106", "0.6684843", "0.668004", "0.6648919", "0.66450715", "0.6630396", "0.6594919", "0.65727526", "0.65727526", "0.65422493", "0.6540629", "0.6530791", "0.65282...
0.63920933
30
The credentials required for the authorizer. To specify an IAM Role for API Gateway to assume, use the IAM Role ARN.
func (r *Authorizer) AuthorizerCredentials() pulumi.StringOutput { return (pulumi.StringOutput)(r.s.State["authorizerCredentials"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (ccc ClientCredentialsConfig) Authorizer() (autorest.Authorizer, error) {\n\toauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tspToken, err := adal.NewServicePrincipalToken(*oauthConfig, ccc.ClientID, ccc.ClientSecret, ccc.Resource)\n\tif ...
[ "0.6120914", "0.57939726", "0.57908136", "0.57908136", "0.57615143", "0.57037455", "0.56405944", "0.55967647", "0.5563223", "0.55153674", "0.54845834", "0.52695364", "0.52332366", "0.5226719", "0.52190316", "0.5182857", "0.51811236", "0.51581323", "0.5140233", "0.5134174", "0...
0.6042423
1
The TTL of cached authorizer results in seconds. Defaults to `300`.
func (r *Authorizer) AuthorizerResultTtlInSeconds() pulumi.IntOutput { return (pulumi.IntOutput)(r.s.State["authorizerResultTtlInSeconds"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (f *lazyCallReq) TTL() time.Duration {\n\tttl := binary.BigEndian.Uint32(f.Payload[_ttlIndex : _ttlIndex+_ttlLen])\n\treturn time.Duration(ttl) * time.Millisecond\n}", "func (i *Incarnation) TTL() time.Duration {\n\tr := time.Duration(0)\n\tif i.status != nil {\n\t\tr = time.Duration(i.status.TTL) * time.Se...
[ "0.5827483", "0.5766706", "0.567723", "0.5667254", "0.562132", "0.56082237", "0.5564176", "0.5538723", "0.5526179", "0.55230135", "0.54945475", "0.54936993", "0.54185873", "0.5330114", "0.5329961", "0.52914006", "0.52701855", "0.5223752", "0.51707166", "0.51675946", "0.516506...
0.5272764
16
The source of the identity in an incoming request. Defaults to `method.request.header.Authorization`. For `REQUEST` type, this may be a commaseparated list of values, including headers, query string parameters and stage variables e.g. `"method.request.header.SomeHeaderName,method.request.querystring.SomeQueryStringName,stageVariables.SomeStageVariableName"`
func (r *Authorizer) IdentitySource() pulumi.StringOutput { return (pulumi.StringOutput)(r.s.State["identitySource"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func caller(req *http.Request) string {\n\treturn req.Header.Get(_httpHeaderUser)\n}", "func (r *Request) Authorization() string {\n\treturn r.request.Header.Get(\"Authorization\")\n}", "func (o LookupAuthorizerResultOutput) IdentitySource() pulumi.StringOutput {\n\treturn o.ApplyT(func(v LookupAuthorizerResul...
[ "0.6037237", "0.56057835", "0.54971004", "0.5475506", "0.54306847", "0.53429914", "0.53171206", "0.53134394", "0.5294382", "0.52697986", "0.5243935", "0.5189092", "0.5154368", "0.5136604", "0.5135017", "0.5102016", "0.50762564", "0.5061965", "0.50589633", "0.5055378", "0.5050...
0.5468022
4
A validation expression for the incoming identity. For `TOKEN` type, this value should be a regular expression. The incoming token from the client is matched against this expression, and will proceed if the token matches. If the token doesn't match, the client receives a 401 Unauthorized response.
func (r *Authorizer) IdentityValidationExpression() pulumi.StringOutput { return (pulumi.StringOutput)(r.s.State["identityValidationExpression"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TokenValidationMiddleware(context *gin.Context) {\n\tpayload := context.MustGet(SHORT_USER_INFO_KEY)\n\tshortUser := payload.(*entity.ShortUser)\n\terr := mongo.ValidateAuthToken(shortUser.Email, shortUser.Nickname, shortUser.Token)\n\tif err != nil {\n\t\tmessage := *INVALID_TOKEN_MESSAGE\n\t\tmessage.Payloa...
[ "0.5470086", "0.538882", "0.53538656", "0.52855575", "0.5248191", "0.52401423", "0.52155536", "0.51719457", "0.51408523", "0.51288927", "0.5112652", "0.5105326", "0.504248", "0.5032163", "0.5024669", "0.5000452", "0.49955586", "0.4995149", "0.49716762", "0.4967016", "0.493642...
0.5086416
12
The name of the authorizer
func (r *Authorizer) Name() pulumi.StringOutput { return (pulumi.StringOutput)(r.s.State["name"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (c *authorizer) Name() string {\n\treturn c.config.Name\n}", "func (this *BaseHandler) Authorizer(key string) string {\n\tvalue, ok := this.RequestVO.Request.RequestContext.Authorizer[key].(string)\n\tif ok {\n\t\treturn value\n\t}\n\tlogs.Error(\"BaseHandler : Authorizer : unable to get \", key, ok, this.R...
[ "0.77056956", "0.671004", "0.6626713", "0.6626713", "0.63819623", "0.6372522", "0.62091225", "0.61002564", "0.5986317", "0.59525335", "0.5937197", "0.59172904", "0.5893463", "0.5838321", "0.58199275", "0.58056426", "0.5800984", "0.5775594", "0.5717718", "0.5717718", "0.571771...
0.60424936
8
The ID of the associated REST API
func (r *Authorizer) RestApi() pulumi.StringOutput { return (pulumi.StringOutput)(r.s.State["restApi"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (r *Request) ID() string { return string(r.id) }", "func (r *Request) ID() string { return string(r.id) }", "func (r *Response) ID() string { return r.id }", "func (r *Response) ID() string { return r.id }", "func (i *Resource) Id() string {\n\treturn i.data.Id\n}", "func (this *RouterEntry) Id() st...
[ "0.68417984", "0.68417984", "0.664459", "0.664459", "0.646249", "0.63702404", "0.6350375", "0.62945896", "0.6247671", "0.6209772", "0.6209526", "0.6188234", "0.61318105", "0.61301976", "0.61273354", "0.61212593", "0.60999155", "0.5993974", "0.5949995", "0.5914038", "0.5902934...
0.0
-1
The type of the authorizer. Possible values are `TOKEN` for a Lambda function using a single authorization token submitted in a custom header, `REQUEST` for a Lambda function using incoming request parameters, or `COGNITO_USER_POOLS` for using an Amazon Cognito user pool. Defaults to `TOKEN`.
func (r *Authorizer) Type() pulumi.StringOutput { return (pulumi.StringOutput)(r.s.State["type"]) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func Authorizer(ctx workflow.Context, evt events.APIGatewayCustomAuthorizerRequest) (err error) {\n\tauthService := new(services.AuthService)\n\tres, err := authService.GetAuthorizerResponse(evt)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tctx.SetRawResponse(res)\n\treturn nil\n}", "func Authorizer(userService ...
[ "0.61980224", "0.6126441", "0.61207795", "0.59648436", "0.5938632", "0.58868974", "0.5796655", "0.5790644", "0.5787622", "0.57243574", "0.5690847", "0.56687355", "0.5521617", "0.54964364", "0.5460831", "0.5450241", "0.5394661", "0.53943145", "0.53929675", "0.53923756", "0.538...
0.56096715
12
Search performs a symbol search on the symbols service.
func (c *Client) Search(ctx context.Context, args search.SymbolsParameters) (symbols result.Symbols, err error) { span, ctx := ot.StartSpanFromContext(ctx, "symbols.Client.Search") defer func() { if err != nil { ext.Error.Set(span, true) span.LogFields(otlog.Error(err)) } span.Finish() }() span.SetTag("Repo", string(args.Repo)) span.SetTag("CommitID", string(args.CommitID)) resp, err := c.httpPost(ctx, "search", args.Repo, args) if err != nil { return nil, err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { // best-effort inclusion of body in error message body, _ := io.ReadAll(io.LimitReader(resp.Body, 200)) return nil, errors.Errorf( "Symbol.Search http status %d: %s", resp.StatusCode, string(body), ) } var response search.SymbolsResponse err = json.NewDecoder(resp.Body).Decode(&response) if err != nil { return nil, err } if response.Err != "" { return nil, errors.New(response.Err) } symbols = response.Symbols // 🚨 SECURITY: We have valid results, so we need to apply sub-repo permissions // filtering. if c.SubRepoPermsChecker == nil { return symbols, err } checker := c.SubRepoPermsChecker() if !authz.SubRepoEnabled(checker) { return symbols, err } a := actor.FromContext(ctx) // Filter in place filtered := symbols[:0] for _, r := range symbols { rc := authz.RepoContent{ Repo: args.Repo, Path: r.Path, } perm, err := authz.ActorPermissions(ctx, checker, a, rc) if err != nil { return nil, errors.Wrap(err, "checking sub-repo permissions") } if perm.Include(authz.Read) { filtered = append(filtered, r) } } return filtered, nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (s *svc) Search(ctx context.Context, req *api.SearchRequest) (*api.SearchResponse, error) {\n\tvar resp api.SearchResponse\n\tresp.Results = &api.Series{\n\t\tKey: req.Key,\n\t}\n\n\telts, err := s.searcher.Search(req.Key, req.Oldest, req.Newest)\n\tswitch err.(type) {\n\tcase storage.KeyNotFound:\n\t\tresp.S...
[ "0.6486218", "0.6482556", "0.6436115", "0.63494456", "0.63310945", "0.6226671", "0.62113196", "0.62071586", "0.6191202", "0.6155028", "0.61464447", "0.6116039", "0.60901916", "0.60784996", "0.6064667", "0.6061123", "0.6048405", "0.60473895", "0.60432905", "0.6012252", "0.6011...
0.75943005
0
ValidateNetwork validates a Network object.
func ValidateNetwork(network *extensionsv1alpha1.Network) field.ErrorList { allErrs := field.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&network.ObjectMeta, true, apivalidation.NameIsDNSSubdomain, field.NewPath("metadata"))...) allErrs = append(allErrs, ValidateNetworkSpec(&network.Spec, field.NewPath("spec"))...) return allErrs }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (m *Network) Validate(formats strfmt.Registry) error {\n\tvar res []error\n\n\tif err := m.validateID(formats); err != nil {\n\t\tres = append(res, err)\n\t}\n\n\tif err := m.validateMasterInterface(formats); err != nil {\n\t\tres = append(res, err)\n\t}\n\n\tif err := m.validateType(formats); err != nil {\n\...
[ "0.73155195", "0.7186104", "0.6923285", "0.6841164", "0.6532549", "0.6366392", "0.6291432", "0.6251806", "0.6238205", "0.62232083", "0.6216633", "0.6098777", "0.60969937", "0.6080908", "0.60757625", "0.60336506", "0.59988767", "0.59749514", "0.5909168", "0.59000635", "0.58446...
0.722179
1
ValidateNetworkUpdate validates a Network object before an update.
func ValidateNetworkUpdate(new, old *extensionsv1alpha1.Network) field.ErrorList { allErrs := field.ErrorList{} allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&new.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata"))...) allErrs = append(allErrs, ValidateNetworkSpecUpdate(&new.Spec, &old.Spec, new.DeletionTimestamp != nil, field.NewPath("spec"))...) allErrs = append(allErrs, ValidateNetwork(new)...) return allErrs }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (n *Network) ValidateUpdate(old runtime.Object) error {\n\tvar allErrors field.ErrorList\n\toldNetwork := old.(*Network)\n\n\tnetworklog.Info(\"validate update\", \"name\", n.Name)\n\n\t// shared validation rules with create\n\tallErrors = append(allErrors, n.Validate()...)\n\n\t// shared validation rules wit...
[ "0.75814086", "0.7003011", "0.69270676", "0.66921806", "0.65416247", "0.6206754", "0.61542016", "0.6152612", "0.6117212", "0.6075632", "0.6073497", "0.6065042", "0.6044899", "0.60341346", "0.5975376", "0.59118503", "0.5901321", "0.58906287", "0.5874365", "0.5820233", "0.58181...
0.81501204
0
ValidateNetworkSpec validates the specification of a Network object.
func ValidateNetworkSpec(spec *extensionsv1alpha1.NetworkSpec, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if len(spec.Type) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("type"), "field is required")) } var cidrs []cidrvalidation.CIDR if len(spec.PodCIDR) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("podCIDR"), "field is required")) } else { cidrs = append(cidrs, cidrvalidation.NewCIDR(spec.PodCIDR, fldPath.Child("podCIDR"))) } if len(spec.ServiceCIDR) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("serviceCIDR"), "field is required")) } else { cidrs = append(cidrs, cidrvalidation.NewCIDR(spec.ServiceCIDR, fldPath.Child("serviceCIDR"))) } allErrs = append(allErrs, cidrvalidation.ValidateCIDRParse(cidrs...)...) allErrs = append(allErrs, cidrvalidation.ValidateCIDROverlap(cidrs, cidrs, false)...) return allErrs }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (m *Network) Validate(formats strfmt.Registry) error {\n\tvar res []error\n\n\tif err := m.validateID(formats); err != nil {\n\t\tres = append(res, err)\n\t}\n\n\tif err := m.validateMasterInterface(formats); err != nil {\n\t\tres = append(res, err)\n\t}\n\n\tif err := m.validateType(formats); err != nil {\n\...
[ "0.67122936", "0.6589741", "0.65722126", "0.6494365", "0.6392701", "0.6391177", "0.6070578", "0.5993474", "0.59743595", "0.5910308", "0.5891103", "0.58672804", "0.5779491", "0.57532775", "0.574947", "0.5687439", "0.56747395", "0.5661901", "0.5616588", "0.5615219", "0.5526241"...
0.7853857
0
ValidateNetworkSpecUpdate validates the spec of a Network object before an update.
func ValidateNetworkSpecUpdate(new, old *extensionsv1alpha1.NetworkSpec, deletionTimestampSet bool, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if deletionTimestampSet && !apiequality.Semantic.DeepEqual(new, old) { allErrs = append(allErrs, apivalidation.ValidateImmutableField(new, old, fldPath)...) return allErrs } allErrs = append(allErrs, apivalidation.ValidateImmutableField(new.Type, old.Type, fldPath.Child("type"))...) allErrs = append(allErrs, apivalidation.ValidateImmutableField(new.PodCIDR, old.PodCIDR, fldPath.Child("podCIDR"))...) allErrs = append(allErrs, apivalidation.ValidateImmutableField(new.ServiceCIDR, old.ServiceCIDR, fldPath.Child("serviceCIDR"))...) return allErrs }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func ValidateNetworkUpdate(new, old *extensionsv1alpha1.Network) field.ErrorList {\n\tallErrs := field.ErrorList{}\n\n\tallErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&new.ObjectMeta, &old.ObjectMeta, field.NewPath(\"metadata\"))...)\n\tallErrs = append(allErrs, ValidateNetworkSpecUpdate(&new.Spe...
[ "0.7803706", "0.7432386", "0.6940642", "0.6773171", "0.65616477", "0.62644356", "0.6179208", "0.61404437", "0.60304904", "0.5948759", "0.5853366", "0.5791877", "0.5764017", "0.5707987", "0.5648009", "0.561715", "0.56039965", "0.560212", "0.55983096", "0.55652076", "0.5551288"...
0.84096605
0
ValidateNetworkStatus validates the status of a Network object.
func ValidateNetworkStatus(spec *extensionsv1alpha1.NetworkStatus, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} return allErrs }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func ValidateNetworkStatusUpdate(newStatus, oldStatus extensionsv1alpha1.NetworkStatus) field.ErrorList {\n\tallErrs := field.ErrorList{}\n\n\treturn allErrs\n}", "func (m *PVMInstanceNetwork) Validate(formats strfmt.Registry) error {\n\treturn nil\n}", "func (m *Network) Validate(formats strfmt.Registry) erro...
[ "0.66972476", "0.6420284", "0.6402876", "0.623381", "0.6194095", "0.6179858", "0.59234226", "0.59146374", "0.5855416", "0.5853569", "0.5832253", "0.5828169", "0.5795385", "0.5792761", "0.5747493", "0.5727989", "0.56904906", "0.5665054", "0.55920434", "0.55584145", "0.5537664"...
0.78875095
0
ValidateNetworkStatusUpdate validates the status field of a Network object.
func ValidateNetworkStatusUpdate(newStatus, oldStatus extensionsv1alpha1.NetworkStatus) field.ErrorList { allErrs := field.ErrorList{} return allErrs }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func ValidateNetworkUpdate(new, old *extensionsv1alpha1.Network) field.ErrorList {\n\tallErrs := field.ErrorList{}\n\n\tallErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&new.ObjectMeta, &old.ObjectMeta, field.NewPath(\"metadata\"))...)\n\tallErrs = append(allErrs, ValidateNetworkSpecUpdate(&new.Spe...
[ "0.7406666", "0.68307406", "0.64648366", "0.64205205", "0.63305455", "0.615615", "0.57889855", "0.5749044", "0.56802106", "0.56731206", "0.56397283", "0.5616703", "0.5597998", "0.552378", "0.55079824", "0.550207", "0.55003566", "0.5485629", "0.54382426", "0.54291725", "0.5423...
0.8169572
0
Your code here RPC handlers for the worker to call. an example RPC handler. the RPC argument and reply types are defined in rpc.go.
func (m *Master) Example(args *ExampleArgs, reply *ExampleReply) error { reply.Y = args.X + 1 return nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func callWorker(worker, name string, args interface{}, reply interface{}) bool {\n\treturn call(worker, \"RPCWorker.\"+name, args, reply)\n}", "func (rm *REKTManager) worker(req http.Request) Response {\n\tresp, err := rm.client.Do(&req)\n\tif err != nil {\n\t\treturn Response{make([]byte, 0), err}\n\t}\n\tdefer...
[ "0.7302178", "0.6500732", "0.64542025", "0.6361744", "0.6355909", "0.63264745", "0.6268335", "0.62581736", "0.61935055", "0.61914307", "0.61727107", "0.6134238", "0.6127644", "0.6121213", "0.610963", "0.61064565", "0.60991734", "0.60874856", "0.60695577", "0.60539484", "0.602...
0.0
-1
start a thread that listens for RPCs from worker.go
func (m *Master) server() { rpc.Register(m) rpc.HandleHTTP() //l, e := net.Listen("tcp", ":1234") sockname := masterSock() os.Remove(sockname) l, e := net.Listen("unix", sockname) if e != nil { log.Fatal("listen error:", e) } go http.Serve(l, nil) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (wk *Worker) startRPCServer() {\n\t// TODO: implement me\n\t// Hint: Refer to how the driver's startRPCServer is implemented.\n\t// TODO TODO TODO\n\t//\n\n\t//\n\t// Once shutdown is closed, should the following statement be\n\t// called, meaning the worker RPC server is existing.\n\tserverless.Debug(\"Worke...
[ "0.64237857", "0.63124293", "0.6109769", "0.60422313", "0.5865199", "0.58389354", "0.583757", "0.5834663", "0.58046454", "0.5800697", "0.5778423", "0.5769884", "0.57659143", "0.5764688", "0.57607377", "0.5753001", "0.5745076", "0.5744342", "0.57366085", "0.5727261", "0.571949...
0.0
-1
/ should hold lock before enter this func
func (m *Master) mapfinished() bool { t := time.Now().Unix() ret := true j := 0 for j < len(m.mapTasks) { if m.mapTasks[j].state == 1 { if t-m.mapTasks[j].emittime >= TIMEOUT { m.mapTasks[j].state = 0 } } j++ } i := 0 for i < len(m.mapTasks) { if m.mapTasks[i].state == 0 { m.nextmaptask = i break } i++ } for _, mapTask := range m.mapTasks { if mapTask.state != 2 { ret = false break } } return ret }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (e *Enumerate) lock() {\n\te.u.m.Lock()\n}", "func (heap *SkewHeap) lock() { heap.mutex.Lock() }", "func (r *Radix) lock() {\n\tif r.ts {\n\t\tr.mu.Lock()\n\t}\n}", "func (q *RxQueue) lock() {\n\tq.pendingMutex.Lock()\n}", "func (self *Map) lock() {\n\tif self.atomic == nil {\n\t\tself.atomic = new(...
[ "0.64919794", "0.6400804", "0.6357743", "0.61221063", "0.60903263", "0.6075487", "0.6074046", "0.5973512", "0.5962571", "0.593107", "0.5918071", "0.58903503", "0.5859525", "0.5784371", "0.5672075", "0.564242", "0.5573499", "0.55710864", "0.5566131", "0.5564282", "0.5564187", ...
0.0
-1
/ should hold lock before enter this func
func (m *Master) haveDone() bool { ret := true t := time.Now().Unix() j := 0 for j < len(m.reduceTasks) { if m.reduceTasks[j].state == 1 { if t-m.reduceTasks[j].emittime >= TIMEOUT { m.reduceTasks[j].state = 0 } } j++ } i := 0 for _, reduceTask := range m.reduceTasks { if reduceTask.state == 0 { m.nextreducetask = i break } i++ } for _, reduceTask := range m.reduceTasks { if reduceTask.state != 2 { ret = false break } } if ret { m.done = true } return ret }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (e *Enumerate) lock() {\n\te.u.m.Lock()\n}", "func (heap *SkewHeap) lock() { heap.mutex.Lock() }", "func (r *Radix) lock() {\n\tif r.ts {\n\t\tr.mu.Lock()\n\t}\n}", "func (q *RxQueue) lock() {\n\tq.pendingMutex.Lock()\n}", "func (self *Map) lock() {\n\tif self.atomic == nil {\n\t\tself.atomic = new(...
[ "0.64920616", "0.63997245", "0.63581294", "0.61224926", "0.60899276", "0.6075556", "0.6073647", "0.5971925", "0.59608155", "0.59295136", "0.5917507", "0.5889608", "0.5857709", "0.5783735", "0.56712055", "0.5640408", "0.5573369", "0.55703145", "0.5564623", "0.5563278", "0.5562...
0.0
-1
main/mrmaster.go calls Done() periodically to find out if the entire job has finished.
func (m *Master) Done() bool { ret := false m.mu.Lock() defer m.mu.Unlock() ret = m.haveDone() return ret }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (m *Master) Done() bool {\n\tret := false\n\tfmt.Printf(\"MapTasks: %v\\n\", m.mapTasks)\n\tfmt.Printf(\"RedTasks: %v\\n\", m.reduceTasks)\n\tfmt.Printf(\"nReduce: %d, nMap: %d\\n\", m.nReduce, m.nMap)\n\t// Your code here.\n\t// all tasks have finished\n\tif m.hasGenerateReduceTasks && m.nReduce <= 0 && m.nM...
[ "0.7823017", "0.76430684", "0.761561", "0.74849814", "0.7421957", "0.7361364", "0.73418754", "0.7336742", "0.730617", "0.7304654", "0.72612065", "0.72489536", "0.7237784", "0.7212441", "0.7203896", "0.71987164", "0.7190169", "0.7184905", "0.71776134", "0.71732163", "0.7136540...
0.6820809
30
create a Master. main/mrmaster.go calls this function. nReduce is the number of reduce tasks to use.
func MakeMaster(files []string, nReduce int) *Master { m := Master{} // Your code here. //record each file as a task mapTasks := []MapTask{} j := 0 for _, filename := range files { mapTasks = append(mapTasks, MapTask{filename, j, 0, 0}) j++ } m.mapTasks = mapTasks m.nextmaptask = 0 //generate nReduce reduce tasks each in an intermediate file reduceTasks := []ReduceTask{} i := 0 for i < nReduce { reduceTasks = append(reduceTasks, ReduceTask{INTERPREFIX + strconv.Itoa(i), i, 0, 0}) i++ } m.reduceTasks = reduceTasks m.nextreducetask = 0 m.nReduce = nReduce m.done = false m.server() return &m }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func MakeMaster(files []string, nReduce int) *Master {\n\t// TODO: figure out better place to setup log flags\n\tlog.SetFlags(log.Ltime) // | log.Lshortfile)\n\n\tm := Master{nReduce: nReduce}\n\n\t// Your code here.\n\t// Generating Map tasks\n\tlogger.Debug(\"Generating Map tasks...\")\n\tfor i, fn := range file...
[ "0.8002119", "0.7995797", "0.7962175", "0.7938654", "0.7938438", "0.7934938", "0.7905836", "0.7880066", "0.7851733", "0.7834671", "0.77987695", "0.77802426", "0.7772365", "0.7745725", "0.77451676", "0.76724774", "0.76557", "0.76477695", "0.7533418", "0.752726", "0.7493959", ...
0.7983713
2
TestRejectStaleTermMessage tests that if a server receives a request with a stale term number, it rejects the request. Our implementation ignores the request instead. Reference: section 5.1
func TestRejectStaleTermMessage(t *testing.T) { called := false fakeStep := func(r *raft, m pb.Message) bool { called = true return false } r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) r.step = fakeStep r.loadState(pb.HardState{Term: 2}) r.Step(pb.Message{Type: pb.MsgApp, Term: r.Term - 1}) if called { t.Errorf("stepFunc called = %v, want %v", called, false) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (r *Raft) handleStaleTerm(replication *followerReplication) {\n\tklog.Errorf(fmt.Sprintf(\"peer:%s/%s has newer term, stopping replication\", replication.peer.ID, replication.peer.Address))\n\treplication.notifyAll(false) // No longer leader\n\tselect {\n\tcase replication.stepDown <- struct{}{}:\n\tdefault:\...
[ "0.56858855", "0.53210557", "0.52441114", "0.5125209", "0.5098463", "0.50712526", "0.5064494", "0.5052523", "0.5047018", "0.5040143", "0.50186044", "0.49960944", "0.49875304", "0.49849272", "0.48978335", "0.48863882", "0.4785406", "0.4753413", "0.47414866", "0.47414866", "0.4...
0.78242046
0
TestStartAsFollower tests that when servers start up, they begin as followers. Reference: section 5.2
func TestStartAsFollower(t *testing.T) { r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) if r.state != StateFollower { t.Errorf("state = %s, want %s", r.state, StateFollower) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestSubscribeStreamNotLeader(t *testing.T) {\n\tdefer cleanupStorage(t)\n\n\t// Use a central NATS server.\n\tns := natsdTest.RunDefaultServer()\n\tdefer ns.Shutdown()\n\n\t// Configure first server.\n\ts1Config := getTestConfig(\"a\", true, 5050)\n\ts1 := runServerWithConfig(t, s1Config)\n\tdefer s1.Stop()\n...
[ "0.595199", "0.58877313", "0.58543223", "0.5852667", "0.58501625", "0.57495034", "0.5743804", "0.57330644", "0.57233655", "0.5692679", "0.5688954", "0.56840384", "0.5670661", "0.5664961", "0.5647548", "0.5643796", "0.5638572", "0.55047965", "0.5490936", "0.5486376", "0.548137...
0.81484336
0
TestLeaderBcastBeat tests that if the leader receives a heartbeat tick, it will send a msgApp with m.Index = 0, m.LogTerm=0 and empty entries as heartbeat to all followers. Reference: section 5.2
func TestLeaderBcastBeat(t *testing.T) { // heartbeat interval hi := 1 r := newTestRaft(1, []uint64{1, 2, 3}, 10, hi, NewMemoryStorage()) defer closeAndFreeRaft(r) r.becomeCandidate() r.becomeLeader() for i := 0; i < 10; i++ { r.appendEntry(pb.Entry{Index: uint64(i) + 1}) } for i := 0; i < hi; i++ { r.tick() } msgs := r.readMessages() sort.Sort(messageSlice(msgs)) wmsgs := []pb.Message{ {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 2, ToGroup: pb.Group{NodeId: 2, GroupId: 1, RaftReplicaId: 2}, Term: 1, Type: pb.MsgHeartbeat}, {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 3, ToGroup: pb.Group{NodeId: 3, GroupId: 1, RaftReplicaId: 3}, Term: 1, Type: pb.MsgHeartbeat}, } if !reflect.DeepEqual(msgs, wmsgs) { t.Errorf("msgs = %v, want %v", msgs, wmsgs) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestBcastBeat(t *testing.T) {\n\toffset := uint64(1000)\n\t// make a state machine with log.offset = 1000\n\tpeerGrps := make([]*pb.Group, 0)\n\tfor _, pid := range []uint64{1, 2, 3} {\n\t\tgrp := pb.Group{\n\t\t\tNodeId: pid,\n\t\t\tRaftReplicaId: pid,\n\t\t\tGroupId: 1,\n\t\t}\n\t\tpeerGrps = a...
[ "0.71547526", "0.70240164", "0.63609374", "0.62657857", "0.62503654", "0.62429494", "0.61554277", "0.60415953", "0.6011709", "0.59536695", "0.58787113", "0.5639564", "0.56021845", "0.55552447", "0.54215586", "0.5409809", "0.5384751", "0.5377757", "0.53510165", "0.532129", "0....
0.8377475
0
testNonleaderStartElection tests that if a follower receives no communication over election timeout, it begins an election to choose a new leader. It increments its current term and transitions to candidate state. It then votes for itself and issues RequestVote RPCs in parallel to each of the other servers in the cluster. Reference: section 5.2 Also if a candidate fails to obtain a majority, it will time out and start a new election by incrementing its term and initiating another round of RequestVote RPCs. Reference: section 5.2
func testNonleaderStartElection(t *testing.T, state StateType) { // election timeout et := 10 r := newTestRaft(1, []uint64{1, 2, 3}, et, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) switch state { case StateFollower: r.becomeFollower(1, 2) case StateCandidate: r.becomeCandidate() } for i := 1; i < 2*et; i++ { r.tick() } if r.Term != 2 { t.Errorf("term = %d, want 2", r.Term) } if r.state != StateCandidate { t.Errorf("state = %s, want %s", r.state, StateCandidate) } if !r.votes[r.id] { t.Errorf("vote for self = false, want true") } msgs := r.readMessages() sort.Sort(messageSlice(msgs)) wmsgs := []pb.Message{ {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 2, ToGroup: pb.Group{NodeId: 2, GroupId: 1, RaftReplicaId: 2}, Term: 2, Type: pb.MsgVote}, {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 3, ToGroup: pb.Group{NodeId: 3, GroupId: 1, RaftReplicaId: 3}, Term: 2, Type: pb.MsgVote}, } if !reflect.DeepEqual(msgs, wmsgs) { t.Errorf("msgs = %v, want %v", msgs, wmsgs) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestLeaderElectionInOneRoundRPC(t *testing.T) {\n\ttests := []struct {\n\t\tsize int\n\t\tvotes map[uint64]bool\n\t\tstate StateType\n\t}{\n\t\t// win the election when receiving votes from a majority of the servers\n\t\t{1, map[uint64]bool{}, StateLeader},\n\t\t{3, map[uint64]bool{2: true, 3: true}, StateLe...
[ "0.69972724", "0.6816061", "0.6698817", "0.6691727", "0.6545872", "0.6444551", "0.6347674", "0.6304992", "0.6195448", "0.61766136", "0.6131735", "0.6121858", "0.6079972", "0.60769695", "0.6027061", "0.6016548", "0.6013733", "0.60108995", "0.59614134", "0.5916561", "0.59080714...
0.8241493
0
TestLeaderElectionInOneRoundRPC tests all cases that may happen in leader election during one round of RequestVote RPC: a) it wins the election b) it loses the election c) it is unclear about the result Reference: section 5.2
func TestLeaderElectionInOneRoundRPC(t *testing.T) { tests := []struct { size int votes map[uint64]bool state StateType }{ // win the election when receiving votes from a majority of the servers {1, map[uint64]bool{}, StateLeader}, {3, map[uint64]bool{2: true, 3: true}, StateLeader}, {3, map[uint64]bool{2: true}, StateLeader}, {5, map[uint64]bool{2: true, 3: true, 4: true, 5: true}, StateLeader}, {5, map[uint64]bool{2: true, 3: true, 4: true}, StateLeader}, {5, map[uint64]bool{2: true, 3: true}, StateLeader}, // return to follower state if it receives vote denial from a majority {3, map[uint64]bool{2: false, 3: false}, StateFollower}, {5, map[uint64]bool{2: false, 3: false, 4: false, 5: false}, StateFollower}, {5, map[uint64]bool{2: true, 3: false, 4: false, 5: false}, StateFollower}, // stay in candidate if it does not obtain the majority {3, map[uint64]bool{}, StateCandidate}, {5, map[uint64]bool{2: true}, StateCandidate}, {5, map[uint64]bool{2: false, 3: false}, StateCandidate}, {5, map[uint64]bool{}, StateCandidate}, } for i, tt := range tests { r := newTestRaft(1, idsBySize(tt.size), 10, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgHup}) for id, vote := range tt.votes { r.Step(pb.Message{From: id, To: 1, Term: r.Term, Type: pb.MsgVoteResp, Reject: !vote}) } if r.state != tt.state { t.Errorf("#%d: state = %s, want %s", i, r.state, tt.state) } if g := r.Term; g != 1 { t.Errorf("#%d: term = %d, want %d", i, g, 1) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func testNonleaderStartElection(t *testing.T, state StateType) {\n\t// election timeout\n\tet := 10\n\tr := newTestRaft(1, []uint64{1, 2, 3}, et, 1, NewMemoryStorage())\n\tdefer closeAndFreeRaft(r)\n\tswitch state {\n\tcase StateFollower:\n\t\tr.becomeFollower(1, 2)\n\tcase StateCandidate:\n\t\tr.becomeCandidate()...
[ "0.712777", "0.6818168", "0.65368366", "0.64485717", "0.6448258", "0.64238167", "0.6404896", "0.63321364", "0.6317073", "0.6308467", "0.62964714", "0.62061626", "0.61874914", "0.61642045", "0.6135719", "0.61182326", "0.6116993", "0.61055106", "0.6050055", "0.6028388", "0.6019...
0.83975685
0
TestFollowerVote tests that each follower will vote for at most one candidate in a given term, on a firstcomefirstserved basis. Reference: section 5.2
func TestFollowerVote(t *testing.T) { tests := []struct { vote uint64 nvote uint64 wreject bool }{ {None, 1, false}, {None, 2, false}, {1, 1, false}, {2, 2, false}, {1, 2, true}, {2, 1, true}, } for i, tt := range tests { r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) r.loadState(pb.HardState{Term: 1, Vote: tt.vote}) r.Step(pb.Message{From: tt.nvote, FromGroup: pb.Group{NodeId: tt.nvote, GroupId: 1, RaftReplicaId: tt.nvote}, To: 1, ToGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, Term: 1, Type: pb.MsgVote}) msgs := r.readMessages() wmsgs := []pb.Message{ {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: tt.nvote, ToGroup: pb.Group{NodeId: tt.nvote, GroupId: 1, RaftReplicaId: tt.nvote}, Term: 1, Type: pb.MsgVoteResp, Reject: tt.wreject}, } if !reflect.DeepEqual(msgs, wmsgs) { t.Errorf("#%d: msgs = %v, want %v", i, msgs, wmsgs) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestPreVoteWithSplitVote(t *testing.T) {\n\tn1 := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage())\n\tn2 := newTestRaft(2, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage())\n\tn3 := newTestRaft(3, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage())\n\tdefer closeAndFreeRaft(n1)\n\tdefer closeAndFreeRaft(n2)...
[ "0.65611714", "0.60730743", "0.59893113", "0.5856957", "0.5796058", "0.578427", "0.57096905", "0.5693165", "0.5662607", "0.5610894", "0.5576574", "0.5562577", "0.5519122", "0.54921544", "0.54869354", "0.54458255", "0.54402566", "0.5409583", "0.53818727", "0.5380176", "0.53773...
0.7265358
0
TestCandidateFallback tests that while waiting for votes, if a candidate receives an AppendEntries RPC from another server claiming to be leader whose term is at least as large as the candidate's current term, it recognizes the leader as legitimate and returns to follower state. Reference: section 5.2
func TestCandidateFallback(t *testing.T) { tests := []pb.Message{ {From: 2, To: 1, Term: 1, Type: pb.MsgApp}, {From: 2, To: 1, Term: 2, Type: pb.MsgApp}, } for i, tt := range tests { r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgHup}) if r.state != StateCandidate { t.Fatalf("unexpected state = %s, want %s", r.state, StateCandidate) } r.Step(tt) if g := r.state; g != StateFollower { t.Errorf("#%d: state = %s, want %s", i, g, StateFollower) } if g := r.Term; g != tt.Term { t.Errorf("#%d: term = %d, want %d", i, g, tt.Term) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func testNonleaderStartElection(t *testing.T, state StateType) {\n\t// election timeout\n\tet := 10\n\tr := newTestRaft(1, []uint64{1, 2, 3}, et, 1, NewMemoryStorage())\n\tdefer closeAndFreeRaft(r)\n\tswitch state {\n\tcase StateFollower:\n\t\tr.becomeFollower(1, 2)\n\tcase StateCandidate:\n\t\tr.becomeCandidate()...
[ "0.6167525", "0.6163571", "0.58222115", "0.57729566", "0.5765619", "0.57036155", "0.5693399", "0.5582176", "0.55365545", "0.54777724", "0.5464581", "0.539433", "0.5368451", "0.53509605", "0.5331513", "0.53258264", "0.5297152", "0.5295841", "0.5238286", "0.52340853", "0.523113...
0.77985966
0
testNonleaderElectionTimeoutRandomized tests that election timeout for follower or candidate is randomized. Reference: section 5.2
func testNonleaderElectionTimeoutRandomized(t *testing.T, state StateType) { et := 10 r := newTestRaft(1, []uint64{1, 2, 3}, et, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) timeouts := make(map[int]bool) for round := 0; round < 50*et; round++ { switch state { case StateFollower: r.becomeFollower(r.Term+1, 2) case StateCandidate: r.becomeCandidate() } time := 0 for len(r.readMessages()) == 0 { r.tick() time++ } timeouts[time] = true } for d := et + 1; d < 2*et; d++ { if !timeouts[d] { t.Errorf("timeout in %d ticks should happen", d) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (node *Node) randElectionTimeout() time.Duration {\n\treturn time.Duration(150+rand.Intn(150)) * time.Millisecond\n}", "func TestLearnerElectionTimeout(t *testing.T) {\n\tn1 := newTestLearnerRaft(1, []uint64{1}, []uint64{2}, 10, 1, NewMemoryStorage())\n\tn2 := newTestLearnerRaft(2, []uint64{1}, []uint64{2},...
[ "0.7392285", "0.7258269", "0.7240653", "0.71084785", "0.70563203", "0.6986426", "0.6932368", "0.6688159", "0.6592933", "0.6393019", "0.5969358", "0.5868286", "0.5805566", "0.5655917", "0.562618", "0.5552523", "0.54569644", "0.5443769", "0.54374623", "0.54012024", "0.53832304"...
0.84037805
0
testNonleadersElectionTimeoutNonconflict tests that in most cases only a single server(follower or candidate) will time out, which reduces the likelihood of split vote in the new election. Reference: section 5.2
func testNonleadersElectionTimeoutNonconflict(t *testing.T, state StateType) { et := 10 size := 5 rs := make([]*raft, size) ids := idsBySize(size) for k := range rs { rs[k] = newTestRaft(ids[k], ids, et, 1, NewMemoryStorage()) } defer func() { for k := range rs { closeAndFreeRaft(rs[k]) } }() conflicts := 0 for round := 0; round < 1000; round++ { for _, r := range rs { switch state { case StateFollower: r.becomeFollower(r.Term+1, None) case StateCandidate: r.becomeCandidate() } } timeoutNum := 0 for timeoutNum == 0 { for _, r := range rs { r.tick() if len(r.readMessages()) > 0 { timeoutNum++ } } } // several rafts time out at the same tick if timeoutNum > 1 { conflicts++ } } if g := float64(conflicts) / 1000; g > 0.3 { t.Errorf("probability of conflicts = %v, want <= 0.3", g) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestLearnerElectionTimeout(t *testing.T) {\n\tn1 := newTestLearnerRaft(1, []uint64{1}, []uint64{2}, 10, 1, NewMemoryStorage())\n\tn2 := newTestLearnerRaft(2, []uint64{1}, []uint64{2}, 10, 1, NewMemoryStorage())\n\tdefer closeAndFreeRaft(n1)\n\tdefer closeAndFreeRaft(n2)\n\n\tn1.becomeFollower(1, None)\n\tn2.b...
[ "0.75048506", "0.74821985", "0.67603856", "0.6744892", "0.64194924", "0.6378772", "0.62738466", "0.6143999", "0.61402524", "0.61349475", "0.6042316", "0.59706557", "0.5956589", "0.5952429", "0.59391177", "0.59348154", "0.5842057", "0.58403885", "0.58317566", "0.5827153", "0.5...
0.81604284
0
TestLeaderStartReplication tests that when receiving client proposals, the leader appends the proposal to its log as a new entry, then issues AppendEntries RPCs in parallel to each of the other servers to replicate the entry. Also, when sending an AppendEntries RPC, the leader includes the index and term of the entry in its log that immediately precedes the new entries. Also, it writes the new entry into stable storage. Reference: section 5.3
func TestLeaderStartReplication(t *testing.T) { s := NewMemoryStorage() r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, s) defer closeAndFreeRaft(r) r.becomeCandidate() r.becomeLeader() commitNoopEntry(r, s) li := r.raftLog.lastIndex() ents := []pb.Entry{{Data: []byte("some data")}} r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: ents}) if g := r.raftLog.lastIndex(); g != li+1 { t.Errorf("lastIndex = %d, want %d", g, li+1) } if g := r.raftLog.committed; g != li { t.Errorf("committed = %d, want %d", g, li) } msgs := r.readMessages() sort.Sort(messageSlice(msgs)) wents := []pb.Entry{{Index: li + 1, Term: 1, Data: []byte("some data")}} wmsgs := []pb.Message{ {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 2, ToGroup: pb.Group{NodeId: 2, GroupId: 1, RaftReplicaId: 2}, Term: 1, Type: pb.MsgApp, Index: li, LogTerm: 1, Entries: wents, Commit: li}, {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 3, ToGroup: pb.Group{NodeId: 3, GroupId: 1, RaftReplicaId: 3}, Term: 1, Type: pb.MsgApp, Index: li, LogTerm: 1, Entries: wents, Commit: li}, } if !reflect.DeepEqual(msgs, wmsgs) { t.Errorf("msgs = %+v, want %+v", msgs, wmsgs) } if g := r.raftLog.unstableEntries(); !reflect.DeepEqual(g, wents) { t.Errorf("ents = %+v, want %+v", g, wents) } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestLogReplication1(t *testing.T) {\n\n\tack := make(chan bool)\n\n\t//Get leader\n\tleaderId := raft.GetLeaderId()\n\n\t//Append a log entry to leader as client\n\traft.InsertFakeLogEntry(leaderId)\n\n\tleaderLog := raft.GetLogAsString(leaderId)\n\t// log.Println(leaderLog)\n\n\ttime.AfterFunc(1*time.Second,...
[ "0.6864116", "0.640381", "0.6347351", "0.62488306", "0.6234333", "0.6037683", "0.60331476", "0.5993272", "0.58315694", "0.57851213", "0.578263", "0.57710594", "0.57250357", "0.5723692", "0.56953937", "0.56943995", "0.562664", "0.55386865", "0.5529624", "0.5525888", "0.5491838...
0.7907163
0
TestLeaderCommitEntry tests that when the entry has been safely replicated, the leader gives out the applied entries, which can be applied to its state machine. Also, the leader keeps track of the highest index it knows to be committed, and it includes that index in future AppendEntries RPCs so that the other servers eventually find out. Reference: section 5.3
func TestLeaderCommitEntry(t *testing.T) { s := NewMemoryStorage() r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, s) defer closeAndFreeRaft(r) r.becomeCandidate() r.becomeLeader() commitNoopEntry(r, s) li := r.raftLog.lastIndex() r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("some data")}}}) for _, m := range r.readMessages() { r.Step(acceptAndReply(m)) } if g := r.raftLog.committed; g != li+1 { t.Errorf("committed = %d, want %d", g, li+1) } wents := []pb.Entry{{Index: li + 1, Term: 1, Data: []byte("some data")}} if g := r.raftLog.nextEnts(); !reflect.DeepEqual(g, wents) { t.Errorf("nextEnts = %+v, want %+v", g, wents) } msgs := r.readMessages() sort.Sort(messageSlice(msgs)) for i, m := range msgs { if w := uint64(i + 2); m.To != w { t.Errorf("to = %x, want %x", m.To, w) } if m.Type != pb.MsgApp { t.Errorf("type = %v, want %v", m.Type, pb.MsgApp) } if m.Commit != li+1 { t.Errorf("commit = %d, want %d", m.Commit, li+1) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestFollowerCommitEntry(t *testing.T) {\n\ttests := []struct {\n\t\tents []pb.Entry\n\t\tcommit uint64\n\t}{\n\t\t{\n\t\t\t[]pb.Entry{\n\t\t\t\t{Term: 1, Index: 1, Data: []byte(\"some data\")},\n\t\t\t},\n\t\t\t1,\n\t\t},\n\t\t{\n\t\t\t[]pb.Entry{\n\t\t\t\t{Term: 1, Index: 1, Data: []byte(\"some data\")},\n...
[ "0.6883694", "0.67447805", "0.66522014", "0.652149", "0.61476606", "0.6147621", "0.5985899", "0.59405583", "0.58946085", "0.5710116", "0.56795913", "0.56135434", "0.5583243", "0.5540832", "0.552765", "0.5499955", "0.54635894", "0.54535663", "0.5443962", "0.5425161", "0.540683...
0.8186935
0
TestLeaderAcknowledgeCommit tests that a log entry is committed once the leader that created the entry has replicated it on a majority of the servers. Reference: section 5.3
func TestLeaderAcknowledgeCommit(t *testing.T) { tests := []struct { size int acceptors map[uint64]bool wack bool }{ {1, nil, true}, {3, nil, false}, {3, map[uint64]bool{2: true}, true}, {3, map[uint64]bool{2: true, 3: true}, true}, {5, nil, false}, {5, map[uint64]bool{2: true}, false}, {5, map[uint64]bool{2: true, 3: true}, true}, {5, map[uint64]bool{2: true, 3: true, 4: true}, true}, {5, map[uint64]bool{2: true, 3: true, 4: true, 5: true}, true}, } for i, tt := range tests { s := NewMemoryStorage() r := newTestRaft(1, idsBySize(tt.size), 10, 1, s) defer closeAndFreeRaft(r) r.becomeCandidate() r.becomeLeader() commitNoopEntry(r, s) li := r.raftLog.lastIndex() r.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{Data: []byte("some data")}}}) for _, m := range r.readMessages() { if tt.acceptors[m.To] { r.Step(acceptAndReply(m)) } } if g := r.raftLog.committed > li; g != tt.wack { t.Errorf("#%d: ack commit = %v, want %v", i, g, tt.wack) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestLeaderCommitEntry(t *testing.T) {\n\ts := NewMemoryStorage()\n\tr := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, s)\n\tdefer closeAndFreeRaft(r)\n\tr.becomeCandidate()\n\tr.becomeLeader()\n\tcommitNoopEntry(r, s)\n\tli := r.raftLog.lastIndex()\n\tr.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: [...
[ "0.6636693", "0.6383855", "0.6223964", "0.61065626", "0.6075896", "0.60401034", "0.60329896", "0.6028253", "0.59614366", "0.59245425", "0.58974385", "0.5846647", "0.5833662", "0.58287334", "0.57737565", "0.57682055", "0.57222724", "0.57091546", "0.570812", "0.5635217", "0.562...
0.8480067
0
TestFollowerCommitEntry tests that once a follower learns that a log entry is committed, it applies the entry to its local state machine (in log order). Reference: section 5.3
func TestFollowerCommitEntry(t *testing.T) { tests := []struct { ents []pb.Entry commit uint64 }{ { []pb.Entry{ {Term: 1, Index: 1, Data: []byte("some data")}, }, 1, }, { []pb.Entry{ {Term: 1, Index: 1, Data: []byte("some data")}, {Term: 1, Index: 2, Data: []byte("some data2")}, }, 2, }, { []pb.Entry{ {Term: 1, Index: 1, Data: []byte("some data2")}, {Term: 1, Index: 2, Data: []byte("some data")}, }, 2, }, { []pb.Entry{ {Term: 1, Index: 1, Data: []byte("some data")}, {Term: 1, Index: 2, Data: []byte("some data2")}, }, 1, }, } for i, tt := range tests { r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, NewMemoryStorage()) defer closeAndFreeRaft(r) r.becomeFollower(1, 2) r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgApp, Term: 1, Entries: tt.ents, Commit: tt.commit}) if g := r.raftLog.committed; g != tt.commit { t.Errorf("#%d: committed = %d, want %d", i, g, tt.commit) } wents := tt.ents[:int(tt.commit)] if g := r.raftLog.nextEnts(); !reflect.DeepEqual(g, wents) { t.Errorf("#%d: nextEnts = %v, want %v", i, g, wents) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestLeaderCommitEntry(t *testing.T) {\n\ts := NewMemoryStorage()\n\tr := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, s)\n\tdefer closeAndFreeRaft(r)\n\tr.becomeCandidate()\n\tr.becomeLeader()\n\tcommitNoopEntry(r, s)\n\tli := r.raftLog.lastIndex()\n\tr.Step(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: [...
[ "0.7963243", "0.7106544", "0.64706445", "0.637154", "0.62599796", "0.6237348", "0.6076704", "0.60045826", "0.58949214", "0.58655334", "0.5726599", "0.56900215", "0.5676556", "0.5592769", "0.5567174", "0.5552651", "0.5539082", "0.5505763", "0.5505618", "0.54969454", "0.5466882...
0.85471386
0
TestFollowerCheckMsgApp tests that if the follower does not find an entry in its log with the same index and term as the one in AppendEntries RPC, then it refuses the new entries. Otherwise it replies that it accepts the append entries. Reference: section 5.3
func TestFollowerCheckMsgApp(t *testing.T) { ents := []pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}} tests := []struct { term uint64 index uint64 windex uint64 wreject bool wrejectHint uint64 }{ // match with committed entries {0, 0, 1, false, 0}, {ents[0].Term, ents[0].Index, 1, false, 0}, // match with uncommitted entries {ents[1].Term, ents[1].Index, 2, false, 0}, // unmatch with existing entry {ents[0].Term, ents[1].Index, ents[1].Index, true, 2}, // unexisting entry {ents[1].Term + 1, ents[1].Index + 1, ents[1].Index + 1, true, 2}, } for i, tt := range tests { storage := NewMemoryStorage() storage.Append(ents) r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, storage) defer closeAndFreeRaft(r) r.loadState(pb.HardState{Commit: 1}) r.becomeFollower(2, 2) r.Step(pb.Message{From: 2, FromGroup: pb.Group{NodeId: 2, GroupId: 1, RaftReplicaId: 2}, To: 1, ToGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, Type: pb.MsgApp, Term: 2, LogTerm: tt.term, Index: tt.index}) msgs := r.readMessages() wmsgs := []pb.Message{ {From: 1, FromGroup: pb.Group{NodeId: 1, GroupId: 1, RaftReplicaId: 1}, To: 2, ToGroup: pb.Group{NodeId: 2, GroupId: 1, RaftReplicaId: 2}, Type: pb.MsgAppResp, Term: 2, Index: tt.windex, Reject: tt.wreject, RejectHint: tt.wrejectHint}, } if !reflect.DeepEqual(msgs, wmsgs) { t.Errorf("#%d: msgs = %+v, want %+v", i, msgs, wmsgs) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestFollowerAppendEntries(t *testing.T) {\n\ttests := []struct {\n\t\tindex, term uint64\n\t\tents []pb.Entry\n\t\twents []pb.Entry\n\t\twunstable []pb.Entry\n\t}{\n\t\t{\n\t\t\t2, 2,\n\t\t\t[]pb.Entry{{Term: 3, Index: 3}},\n\t\t\t[]pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}, {Term: 3, I...
[ "0.68868625", "0.67104995", "0.60897493", "0.607411", "0.59460866", "0.5896438", "0.5842949", "0.58197165", "0.57796806", "0.57522064", "0.5702428", "0.56857294", "0.56728303", "0.56607705", "0.5658912", "0.5633639", "0.56321836", "0.5629746", "0.56050974", "0.5597355", "0.55...
0.8075628
0
TestFollowerAppendEntries tests that when AppendEntries RPC is valid, the follower will delete the existing conflict entry and all that follow it, and append any new entries not already in the log. Also, it writes the new entry into stable storage. Reference: section 5.3
func TestFollowerAppendEntries(t *testing.T) { tests := []struct { index, term uint64 ents []pb.Entry wents []pb.Entry wunstable []pb.Entry }{ { 2, 2, []pb.Entry{{Term: 3, Index: 3}}, []pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}, {Term: 3, Index: 3}}, []pb.Entry{{Term: 3, Index: 3}}, }, { 1, 1, []pb.Entry{{Term: 3, Index: 2}, {Term: 4, Index: 3}}, []pb.Entry{{Term: 1, Index: 1}, {Term: 3, Index: 2}, {Term: 4, Index: 3}}, []pb.Entry{{Term: 3, Index: 2}, {Term: 4, Index: 3}}, }, { 0, 0, []pb.Entry{{Term: 1, Index: 1}}, []pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}}, nil, }, { 0, 0, []pb.Entry{{Term: 3, Index: 1}}, []pb.Entry{{Term: 3, Index: 1}}, []pb.Entry{{Term: 3, Index: 1}}, }, } for i, tt := range tests { storage := NewMemoryStorage() storage.Append([]pb.Entry{{Term: 1, Index: 1}, {Term: 2, Index: 2}}) r := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, storage) defer closeAndFreeRaft(r) r.becomeFollower(2, 2) r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgApp, Term: 2, LogTerm: tt.term, Index: tt.index, Entries: tt.ents}) if g := r.raftLog.allEntries(); !reflect.DeepEqual(g, tt.wents) { t.Errorf("#%d: ents = %+v, want %+v", i, g, tt.wents) } if g := r.raftLog.unstableEntries(); !reflect.DeepEqual(g, tt.wunstable) { t.Errorf("#%d: unstableEnts = %+v, want %+v", i, g, tt.wunstable) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (rf *Raft) AppendEntries(args AppendEntriesArgs, reply *AppendEntriesReply) error {\n\trf.mu.Lock()\n\tdefer rf.mu.Unlock()\n\tif rf.state == Down {\n\t\treturn nil\n\t}\n\n\tlog.Printf(\"[%v] received AppendEntries RPC call: Args%+v\", rf.me, args)\n\tif args.Term > rf.currentTerm {\n\t\tlog.Printf(\"[%v] cu...
[ "0.7225577", "0.7173168", "0.7102185", "0.7074297", "0.6984191", "0.69528997", "0.6949836", "0.69274294", "0.6906517", "0.69037604", "0.687655", "0.6865381", "0.6854907", "0.6832888", "0.6794146", "0.67904896", "0.6753549", "0.67144686", "0.6712799", "0.6691537", "0.6635659",...
0.82861537
0
TestLeaderSyncFollowerLog tests that the leader could bring a follower's log into consistency with its own. Reference: section 5.3, figure 7
func TestLeaderSyncFollowerLog(t *testing.T) { ents := []pb.Entry{ {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 4, Index: 4}, {Term: 4, Index: 5}, {Term: 5, Index: 6}, {Term: 5, Index: 7}, {Term: 6, Index: 8}, {Term: 6, Index: 9}, {Term: 6, Index: 10}, } term := uint64(8) tests := [][]pb.Entry{ { {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 4, Index: 4}, {Term: 4, Index: 5}, {Term: 5, Index: 6}, {Term: 5, Index: 7}, {Term: 6, Index: 8}, {Term: 6, Index: 9}, }, { {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 4, Index: 4}, }, { {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 4, Index: 4}, {Term: 4, Index: 5}, {Term: 5, Index: 6}, {Term: 5, Index: 7}, {Term: 6, Index: 8}, {Term: 6, Index: 9}, {Term: 6, Index: 10}, {Term: 6, Index: 11}, }, { {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 4, Index: 4}, {Term: 4, Index: 5}, {Term: 5, Index: 6}, {Term: 5, Index: 7}, {Term: 6, Index: 8}, {Term: 6, Index: 9}, {Term: 6, Index: 10}, {Term: 7, Index: 11}, {Term: 7, Index: 12}, }, { {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 4, Index: 4}, {Term: 4, Index: 5}, {Term: 4, Index: 6}, {Term: 4, Index: 7}, }, { {}, {Term: 1, Index: 1}, {Term: 1, Index: 2}, {Term: 1, Index: 3}, {Term: 2, Index: 4}, {Term: 2, Index: 5}, {Term: 2, Index: 6}, {Term: 3, Index: 7}, {Term: 3, Index: 8}, {Term: 3, Index: 9}, {Term: 3, Index: 10}, {Term: 3, Index: 11}, }, } for i, tt := range tests { leadStorage := NewMemoryStorage() defer leadStorage.Close() leadStorage.Append(ents) lead := newTestRaft(1, []uint64{1, 2, 3}, 10, 1, leadStorage) lead.loadState(pb.HardState{Commit: lead.raftLog.lastIndex(), Term: term}) followerStorage := NewMemoryStorage() defer followerStorage.Close() followerStorage.Append(tt) follower := newTestRaft(2, []uint64{1, 2, 3}, 10, 1, followerStorage) follower.loadState(pb.HardState{Term: term - 1}) // It is necessary to have a three-node cluster. // The second may have more up-to-date log than the first one, so the // first node needs the vote from the third node to become the leader. n := newNetwork(lead, follower, nopStepper) n.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup}) // The election occurs in the term after the one we loaded with // lead.loadState above. n.send(pb.Message{From: 3, To: 1, Type: pb.MsgVoteResp, Term: term + 1}) n.send(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{}}}) if g := diffu(ltoa(lead.raftLog), ltoa(follower.raftLog)); g != "" { t.Errorf("#%d: log diff:\n%s", i, g) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestFollowerCommitEntry(t *testing.T) {\n\ttests := []struct {\n\t\tents []pb.Entry\n\t\tcommit uint64\n\t}{\n\t\t{\n\t\t\t[]pb.Entry{\n\t\t\t\t{Term: 1, Index: 1, Data: []byte(\"some data\")},\n\t\t\t},\n\t\t\t1,\n\t\t},\n\t\t{\n\t\t\t[]pb.Entry{\n\t\t\t\t{Term: 1, Index: 1, Data: []byte(\"some data\")},\n...
[ "0.66216356", "0.642609", "0.642562", "0.6424496", "0.63664854", "0.62123907", "0.614392", "0.6084621", "0.59841955", "0.58548945", "0.581514", "0.573651", "0.57138723", "0.57014894", "0.5697903", "0.56343067", "0.55782557", "0.55703485", "0.55664957", "0.55110955", "0.544706...
0.7571284
0
TestVoter tests the voter denies its vote if its own log is more uptodate than that of the candidate. Reference: section 5.4.1
func TestVoter(t *testing.T) { tests := []struct { ents []pb.Entry logterm uint64 index uint64 wreject bool }{ // same logterm {[]pb.Entry{{Term: 1, Index: 1}}, 1, 1, false}, {[]pb.Entry{{Term: 1, Index: 1}}, 1, 2, false}, {[]pb.Entry{{Term: 1, Index: 1}, {Term: 1, Index: 2}}, 1, 1, true}, // candidate higher logterm {[]pb.Entry{{Term: 1, Index: 1}}, 2, 1, false}, {[]pb.Entry{{Term: 1, Index: 1}}, 2, 2, false}, {[]pb.Entry{{Term: 1, Index: 1}, {Term: 1, Index: 2}}, 2, 1, false}, // voter higher logterm {[]pb.Entry{{Term: 2, Index: 1}}, 1, 1, true}, {[]pb.Entry{{Term: 2, Index: 1}}, 1, 2, true}, {[]pb.Entry{{Term: 2, Index: 1}, {Term: 1, Index: 2}}, 1, 1, true}, } for i, tt := range tests { storage := NewMemoryStorage() storage.Append(tt.ents) r := newTestRaft(1, []uint64{1, 2}, 10, 1, storage) defer closeAndFreeRaft(r) r.Step(pb.Message{From: 2, To: 1, Type: pb.MsgVote, Term: 3, LogTerm: tt.logterm, Index: tt.index}) msgs := r.readMessages() if len(msgs) != 1 { t.Fatalf("#%d: len(msg) = %d, want %d", i, len(msgs), 1) } m := msgs[0] if m.Type != pb.MsgVoteResp { t.Errorf("#%d: msgType = %d, want %d", i, m.Type, pb.MsgVoteResp) } if m.Reject != tt.wreject { t.Errorf("#%d: reject = %t, want %t", i, m.Reject, tt.wreject) } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestVoter_Vote(t *testing.T) {\n\tallia := sdk.NewOntologySdk()\n\tallia.NewRpcClient().SetAddress(RpcAddr)\n\tvoting := make(chan *btc.BtcProof, 10)\n\n\tacct, err := GetAccountByPassword(allia, \"../cmd/lightcli/wallet.dat\", \"passwordtest\")\n\tif err != nil {\n\t\tt.Fatalf(\"Failed to get acct: %v\", err...
[ "0.64001024", "0.6056834", "0.6027904", "0.5626672", "0.56244373", "0.5542475", "0.5518413", "0.5512789", "0.54705715", "0.54133296", "0.5404219", "0.5358423", "0.5338186", "0.53258735", "0.531703", "0.5274945", "0.5258293", "0.5252841", "0.5242921", "0.5231294", "0.52267873"...
0.7073056
0
Free decrements the reference count on a message, and releases its resources if no further references remain. While this is not strictly necessary thanks to GC, doing so allows for the resources to be recycled without engaging GC. This can have rather substantial benefits for performance.
func (m *Message) Free() { var ch chan *Message if v := atomic.AddInt32(&m.refcnt, -1); v > 0 { return } for i := range messageCache { if m.bsize == messageCache[i].maxbody { ch = messageCache[i].cache break } } m.Port = nil select { case ch <- m: default: } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (m *Message) Free() {\n\tC.nlmsg_free(m.nlm)\n\tm.nlm = nil\n}", "func (m *Message) Release() {\n\tif m != nil {\n\t\tm.Text = nil\n\t\tfor i := len(m.List) - 1; i >= 0; i-- {\n\t\t\tm.List[i] = nil\n\t\t}\n\t\tm.List = m.List[:0]\n\t\tif m.used > 0 {\n\t\t\tcopy(m.buf[:m.used], blankBuf[:m.used])\n\t\t\tm....
[ "0.7511681", "0.7141758", "0.64743555", "0.6416629", "0.61727434", "0.6037461", "0.59808373", "0.5910276", "0.5909302", "0.5899108", "0.5874916", "0.5853634", "0.5834384", "0.583358", "0.58314615", "0.580654", "0.5789198", "0.57745117", "0.5758875", "0.5738124", "0.5727779", ...
0.785433
0
Dup creates a "duplicate" message. What it really does is simply increment the reference count on the message. Note that since the underlying message is actually shared, consumers must take care not to modify the message. (We might revise this API in the future to add a copyonwrite facility, but for now modification is neither needed nor supported.) Applications should NOT make use of this function it is intended for Protocol, Transport and internal use only.
func (m *Message) Dup() *Message { atomic.AddInt32(&m.refcnt, 1) return m }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (pkt *Packet) Dup() {\n\tpkt.mtx.Lock()\n\tif *pkt.refCount <= 0 {\n\t\tpanic(\"cannot reference freed packet\")\n\t}\n\t*pkt.refCount++\n\tpkt.mtx.Unlock()\n}", "func (c *Clac) DupN() error {\n\tnum, err := c.popCount()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn c.dup(0, num)\n}", "func Duplicate(...
[ "0.6534085", "0.54666907", "0.5392197", "0.5277368", "0.5169085", "0.5128281", "0.50643915", "0.5006668", "0.50032216", "0.49683774", "0.49560294", "0.48899946", "0.4889048", "0.48835996", "0.48802045", "0.4869459", "0.4795192", "0.47699422", "0.47657543", "0.47597653", "0.47...
0.72607046
0
Expired returns true if the message has "expired". This is used by transport implementations to discard messages that have been stuck in the write queue for too long, and should be discarded rather than delivered across the transport. This is only used on the TX path, there is no sense of "expiration" on the RX path.
func (m *Message) Expired() bool { if m.expire.IsZero() { return false } if m.expire.After(time.Now()) { return false } return true }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (m *Attachment) HasExpired() bool {\n\tvar validTime = m.SigningTime.Add(time.Duration(m.SigningMinutes) * time.Minute)\n\treturn validTime.Unix() < time.Now().Unix()\n}", "func (q *queueData) expired() bool {\n\treturn q.ExpireAt < time.Now().Unix()\n}", "func (r *Record) IsExpired() bool {\n\treturn IsE...
[ "0.7090891", "0.70129126", "0.696582", "0.69188714", "0.6754564", "0.66905755", "0.6583698", "0.6581767", "0.65576303", "0.6547072", "0.6530696", "0.65154415", "0.65109485", "0.6510724", "0.6507026", "0.65001976", "0.64995795", "0.64461267", "0.64384156", "0.6424752", "0.6424...
0.7297898
0
NewMessage is the supported way to obtain a new Message. This makes use of a "cache" which greatly reduces the load on the garbage collector.
func NewMessage(sz int) *Message { var m *Message var ch chan *Message for i := range messageCache { if sz < messageCache[i].maxbody { ch = messageCache[i].cache sz = messageCache[i].maxbody break } } select { case m = <-ch: default: m = &Message{} m.bbuf = make([]byte, 0, sz) m.hbuf = make([]byte, 0, 32) m.bsize = sz } m.refcnt = 1 m.Body = m.bbuf m.Header = m.hbuf return m }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (s *Store) NewMessage(_ context.Context, req *meta.StoreNewMessageRequest) (*meta.StoreNewMessageResponse, error) {\n\tlog.Debugf(\"Store NewMessage, msg:%v\", req.Msg)\n\t// add消息到db\n\tif err := s.message.add(*req.Msg); err != nil {\n\t\treturn &meta.StoreNewMessageResponse{Header: &meta.ResponseHeader{Code...
[ "0.76747173", "0.75967216", "0.7573609", "0.7450602", "0.7434523", "0.7382211", "0.7325671", "0.7325356", "0.7283416", "0.727642", "0.7223555", "0.7203074", "0.7185232", "0.7172994", "0.71674216", "0.71535164", "0.71507347", "0.7118813", "0.7068694", "0.70560145", "0.7037355"...
0.7645472
1
Your KthLargest object will be instantiated and called as such: obj := Constructor(k, nums); param_1 := obj.Add(val);
func main() { k := 3 arr := []int{4,5,8,2} obj := Constructor(k, arr) fmt.Println(obj.Add(3)) fmt.Println(obj.Add(5)) fmt.Println(obj.Add(10)) fmt.Println(obj.Add(9)) fmt.Println(obj.Add(4)) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func main() {\n\th := &IntHeap{2, 1, 5}\n\theap.Init(h)\n\theap.Push(h, 3)\n\tfmt.Printf(\"minimum: %d\\n\", (*h)[0])\n\tfor h.Len() > 0 {\n\t\tfmt.Printf(\"%d \", heap.Pop(h))\n\t}\n\n\tfmt.Println()\n\ttempKthLargest := Constructor(3, []int{1000, 4,5,8,2,9, 10, 100})\n\t//for tempKthLargest.MyHeap.Len() > 0 {\n\...
[ "0.68705994", "0.5936624", "0.5897099", "0.58373976", "0.5735787", "0.5687011", "0.5647957", "0.55208284", "0.5458464", "0.5372213", "0.5371416", "0.5321578", "0.5310426", "0.5263591", "0.5253384", "0.52368516", "0.52337337", "0.51977116", "0.51825726", "0.5176275", "0.516835...
0.693237
0
AddGigasecond returns a time (10^9 seconds) past the given time.
func AddGigasecond(t time.Time) time.Time { gigasecond := time.Duration(1000000000) * time.Second return t.Add(gigasecond) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func AddGigasecond(t time.Time) time.Time {\n\treturn t.Add(time.Duration(time.Duration(math.Pow(10, 9)) * time.Second))\n}", "func AddGigasecond(t time.Time) time.Time {\n\tvar result time.Time\n\tseconds := t.Unix()\n\tseconds += 1000000000\n\tresult = time.Unix(seconds, 0)\n\treturn result\n}", "func AddGig...
[ "0.8909693", "0.8903045", "0.88976306", "0.8885725", "0.8846816", "0.8846816", "0.88360655", "0.88360655", "0.8815402", "0.8815402", "0.8815402", "0.8815402", "0.8773541", "0.8761344", "0.87517613", "0.87358516", "0.8727222", "0.87032026", "0.8683116", "0.86745614", "0.865222...
0.87901026
12
Initialize sets up necessary googleprovided sdks and other local data
func (d *DNS) Initialize(credentials string, log logger.Interface) error { var err error ctx := context.Background() d.log = log d.PendingWaitSeconds = 5 d.Calls = &Calls{ ChangesCreate: &calls.ChangesCreateCall{}, ResourceRecordSetsList: &calls.ResourceRecordSetsListCall{}, } if credentials != "" { if d.V1, err = v1.NewService(ctx, option.WithCredentialsJSON([]byte(credentials))); err != nil { return err } } else { if d.V1, err = v1.NewService(ctx); err != nil { return err } } return nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func init() {\n\tconfigDir := \"\"\n\tdataDir := \"\"\n\tcacheDir := \"\"\n\n\th := \"\"\n\tu, e := user.Current()\n\tif nil == e {\n\t\th = u.HomeDir\n\n\t\tconfigDir = os.Getenv(\"XDG_CONFIG_HOME\")\n\t\tdataDir = os.Getenv(\"XDG_DATA_HOME\")\n\t\tcacheDir = os.Getenv(\"XDG_CACHE_HOME\")\n\n\t\tif \"\" == config...
[ "0.6706975", "0.6563391", "0.6534072", "0.6531327", "0.65187436", "0.6465373", "0.6455937", "0.6430652", "0.6427519", "0.6399086", "0.63725406", "0.6368758", "0.63631004", "0.6351088", "0.63325745", "0.62966895", "0.62871706", "0.62633616", "0.6257511", "0.6252291", "0.625033...
0.0
-1
GetResourceRecordSets will return all resource record sets for a managed zone
func (d *DNS) GetResourceRecordSets(projectID string, managedZone string) ([]*v1.ResourceRecordSet, error) { ctx := context.Background() rrsService := v1.NewResourceRecordSetsService(d.V1) rrsListCall := rrsService.List(projectID, managedZone).Context(ctx) rrsList, err := d.Calls.ResourceRecordSetsList.Do(rrsListCall) if err != nil { return nil, err } return rrsList.Rrsets, nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (s *cloudDNSService) getResourceRecordSets(dnsZone string) ([]*dns.ResourceRecordSet, error) {\n\ttimer := pkg.NewTimer(prometheus.ObserverFunc(func(v float64) {\n\t\trequestRecordsTimeSummary.WithLabelValues(dnsZone).Observe(v)\n\t}))\n\tdefer timer.ObserveDuration()\n\n\tpageToken := \"\"\n\n\tresourceRecor...
[ "0.7884958", "0.71977293", "0.690012", "0.667474", "0.6506424", "0.65049356", "0.6426561", "0.62984467", "0.6185397", "0.61584216", "0.6146449", "0.60125625", "0.6006893", "0.5978852", "0.596062", "0.5958101", "0.59567195", "0.59504706", "0.59106505", "0.5834692", "0.58345544...
0.749032
1
GetResourceRecordSet will search for an existing record set by the resourcer record set name
func (d *DNS) GetResourceRecordSet(projectID string, managedZone string, name string) (*v1.ResourceRecordSet, error) { ctx := context.Background() rrsService := v1.NewResourceRecordSetsService(d.V1) rrsListCall := rrsService.List(projectID, managedZone).Context(ctx).Name(name) rrsList, err := d.Calls.ResourceRecordSetsList.Do(rrsListCall) if err != nil { return nil, err } if len(rrsList.Rrsets) == 0 { return nil, nil } return rrsList.Rrsets[0], nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func GetResourceRecordSet(ctx *pulumi.Context,\n\tname string, id pulumi.IDInput, state *ResourceRecordSetState, opts ...pulumi.ResourceOption) (*ResourceRecordSet, error) {\n\tvar resource ResourceRecordSet\n\terr := ctx.ReadResource(\"google-native:dns/v1beta2:ResourceRecordSet\", name, id, state, &resource, opt...
[ "0.6996784", "0.69788545", "0.69788545", "0.6760038", "0.6608798", "0.6574195", "0.62507427", "0.6177412", "0.61474234", "0.6131648", "0.5973977", "0.5969924", "0.5915531", "0.58928186", "0.5730913", "0.569206", "0.56689787", "0.55815643", "0.553899", "0.55002767", "0.5467366...
0.70044184
0
SetResourceRecordSets will create or update a DNS zone with one or more record sets
func (d *DNS) SetResourceRecordSets(projectID string, managedZone string, records []*v1.ResourceRecordSet) error { var deletions []*v1.ResourceRecordSet var additions []*v1.ResourceRecordSet var change *v1.Change logItems := []string{} for _, record := range records { existing, err := d.GetResourceRecordSet(projectID, managedZone, record.Name) if err != nil { return fmt.Errorf("Error trying to get existing resource record set: %s", err) } action := "creating" if existing != nil { deletions = append(deletions, existing) action = "recreating" } logItems = append(logItems, fmt.Sprintf("====> %s %s => %s %s", action, record.Name, record.Type, strings.Join(record.Rrdatas, ","))) additions = append(additions, record) } d.log.Info("Ensuring the DNS zone %s has the following records:", managedZone) for _, item := range logItems { d.log.ListItem(item) } if len(deletions) > 0 { change = &v1.Change{ Deletions: deletions, } if err := d.executeChange(projectID, managedZone, change); err != nil { return err } } change = &v1.Change{ Additions: additions, } if err := d.executeChange(projectID, managedZone, change); err != nil { return err } return nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {\n\tp.mutex.Lock()\n\tdefer p.mutex.Unlock()\n\n\tclient := &http.Client{}\n\n\tvar updatedRecords []libdns.Record\n\n\tvar resourceRecordSets []LeasewebRecordSet\n\n\tfor _, record := range records {...
[ "0.7518115", "0.6707654", "0.6628259", "0.6497489", "0.61840737", "0.61539745", "0.6116657", "0.6111992", "0.6105293", "0.6021211", "0.5987698", "0.5978222", "0.58855504", "0.58805597", "0.58334905", "0.5816443", "0.5797787", "0.5787811", "0.5784792", "0.5780214", "0.5722433"...
0.81879765
0
DeleteResourceRecordSets will remove all resource record sets from a managed zone
func (d *DNS) DeleteResourceRecordSets(projectID string, managedZone string) error { var deletions []*v1.ResourceRecordSet resourceRecordSets, err := d.GetResourceRecordSets(projectID, managedZone) if err != nil { return err } d.log.Info("Deleting all records from DNS zone %s:", managedZone) for _, resourceRecordSet := range resourceRecordSets { if resourceRecordSet.Type == "SOA" || resourceRecordSet.Type == "NS" { continue } deletions = append(deletions, resourceRecordSet) d.log.ListItem("%s %s", resourceRecordSet.Type, resourceRecordSet.Name) } change := &v1.Change{ Deletions: deletions, } if err := d.executeChange(projectID, managedZone, change); err != nil { return err } return nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (s *Synk) deleteResourceSets(ctx context.Context, name string, version int32) error {\n\tc := s.client.Resource(resourceSetGVR)\n\n\tlist, err := c.List(ctx, metav1.ListOptions{})\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"list existing resources\")\n\t}\n\tfor _, r := range list.Items {\n\t\tn, v, ok ...
[ "0.7039469", "0.6500067", "0.6473653", "0.6403441", "0.63773626", "0.60974884", "0.60132223", "0.5994559", "0.5870117", "0.58634305", "0.5807364", "0.5782578", "0.5775964", "0.57438874", "0.57385606", "0.56440526", "0.56085396", "0.5581031", "0.5575552", "0.5569227", "0.55610...
0.81050515
0
Meta sets the meta data to be included in the aggregation response.
func (a *ChildrenAggregation) Meta(metaData map[string]interface{}) *ChildrenAggregation { a.meta = metaData return a }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (a *FilterAggregation) Meta(metaData map[string]interface{}) *FilterAggregation {\n\ta.meta = metaData\n\treturn a\n}", "func (a *AdjacencyMatrixAggregation) Meta(metaData map[string]interface{}) *AdjacencyMatrixAggregation {\n\ta.meta = metaData\n\treturn a\n}", "func (o *GetRecipeInformation200ResponseE...
[ "0.7573695", "0.7172021", "0.63159454", "0.6203084", "0.60634434", "0.6045212", "0.6020982", "0.6007781", "0.5971997", "0.59656334", "0.5953286", "0.5938713", "0.5897168", "0.5880866", "0.58364844", "0.58214897", "0.5801138", "0.57809526", "0.57665086", "0.57444215", "0.57327...
0.7300219
1
NewCreateSubCategoryCreated creates CreateSubCategoryCreated with default headers values
func NewCreateSubCategoryCreated() *CreateSubCategoryCreated { return &CreateSubCategoryCreated{} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func NewSubCategoryTemplate()(*SubCategoryTemplate) {\n m := &SubCategoryTemplate{\n FilePlanDescriptorTemplate: *NewFilePlanDescriptorTemplate(),\n }\n return m\n}", "func CreateCategory (w http.ResponseWriter, r *http.Request) {\n\tvar newCategory Category\n\n\t//get the information containing ...
[ "0.66819435", "0.5615386", "0.54907864", "0.52989936", "0.52907383", "0.5224993", "0.5219203", "0.5214657", "0.5207687", "0.51817536", "0.5170403", "0.50995934", "0.5090224", "0.5088297", "0.5087905", "0.50834537", "0.505557", "0.4943674", "0.4890234", "0.4861894", "0.4855793...
0.561965
1
WithPayload adds the payload to the create sub category created response
func (o *CreateSubCategoryCreated) WithPayload(payload *models.SubCategory) *CreateSubCategoryCreated { o.Payload = payload return o }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (o *CreateSubCategoryCreated) SetPayload(payload *models.SubCategory) {\n\to.Payload = payload\n}", "func CreateCategory (w http.ResponseWriter, r *http.Request) {\n\tvar newCategory Category\n\n\t//get the information containing in request's body\n\t//or report an error\n\treqBody, err := ioutil.ReadAll(r....
[ "0.65292084", "0.5659147", "0.5402749", "0.5291293", "0.5193651", "0.51259524", "0.5121756", "0.5048872", "0.4986674", "0.49802187", "0.49666917", "0.49362504", "0.49362025", "0.49071783", "0.48970366", "0.48712412", "0.48694733", "0.48630476", "0.48542443", "0.4837587", "0.4...
0.730311
0
SetPayload sets the payload to the create sub category created response
func (o *CreateSubCategoryCreated) SetPayload(payload *models.SubCategory) { o.Payload = payload }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (o *PutSlideSuperlikeCreated) SetPayload(payload models.Success) {\n\to.Payload = payload\n}", "func (o *CreateSubCategoryCreated) WithPayload(payload *models.SubCategory) *CreateSubCategoryCreated {\n\to.Payload = payload\n\treturn o\n}", "func (o *ClientPermissionCreateInternalServerError) SetPayload(pa...
[ "0.6328343", "0.6283681", "0.62103945", "0.6195887", "0.61484605", "0.6141625", "0.60756665", "0.607248", "0.60694844", "0.6023221", "0.6005432", "0.597998", "0.59690493", "0.5965882", "0.5945944", "0.5940896", "0.5934345", "0.59289837", "0.5923078", "0.59091187", "0.5885831"...
0.73931634
0
WriteResponse to the client
func (o *CreateSubCategoryCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { rw.WriteHeader(201) if o.Payload != nil { payload := o.Payload if err := producer.Produce(rw, payload); err != nil { panic(err) // let the recovery middleware deal with this } } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (r *Response) Write(w io.Writer) error", "func (c *Operation) writeResponse(rw http.ResponseWriter, status int, data []byte) { // nolint: unparam\n\trw.WriteHeader(status)\n\n\tif _, err := rw.Write(data); err != nil {\n\t\tlogger.Errorf(\"Unable to send error message, %s\", err)\n\t}\n}", "func WriteResp...
[ "0.81304365", "0.78822106", "0.7772603", "0.77724785", "0.7753003", "0.7741224", "0.76676315", "0.7638531", "0.7610215", "0.7580745", "0.75792986", "0.75681144", "0.7560947", "0.7558793", "0.75451237", "0.7542909", "0.7541853", "0.75351036", "0.75317055", "0.7520023", "0.7519...
0.0
-1
NewCreateSubCategoryBadRequest creates CreateSubCategoryBadRequest with default headers values
func NewCreateSubCategoryBadRequest() *CreateSubCategoryBadRequest { return &CreateSubCategoryBadRequest{} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func NewCreateCategoryBadRequest() *CreateCategoryBadRequest {\n\treturn &CreateCategoryBadRequest{}\n}", "func TestCreateCategoryEmptyBody (t *testing.T) {\n\t//initial length of []Categories\n\tinitialLen := len(Categories)\n\t//empty body\n\trequestBody := &Category{}\n\tjsonCategory, _ := json.Marshal(reques...
[ "0.5717193", "0.56688726", "0.54354084", "0.5418711", "0.5237581", "0.5216485", "0.518136", "0.5173002", "0.51577747", "0.5135354", "0.5087039", "0.50678825", "0.50366735", "0.50136673", "0.50069875", "0.4961325", "0.49262026", "0.49182692", "0.49142945", "0.4903018", "0.4884...
0.69636065
0
WriteResponse to the client
func (o *CreateSubCategoryBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { rw.WriteHeader(400) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (r *Response) Write(w io.Writer) error", "func (c *Operation) writeResponse(rw http.ResponseWriter, status int, data []byte) { // nolint: unparam\n\trw.WriteHeader(status)\n\n\tif _, err := rw.Write(data); err != nil {\n\t\tlogger.Errorf(\"Unable to send error message, %s\", err)\n\t}\n}", "func WriteResp...
[ "0.81303823", "0.7882039", "0.77722245", "0.7771901", "0.7753117", "0.7740585", "0.76670325", "0.7638451", "0.76095873", "0.75798", "0.7579178", "0.7567389", "0.7560546", "0.75579476", "0.75447774", "0.7542929", "0.75416607", "0.753386", "0.7531158", "0.75192654", "0.75191355...
0.0
-1
New creates processor for k8s Secret resource.
func New() helmify.Processor { return &secret{} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func Create(c *client.Client, i *Instance) error {\n\tsecretType, err := detectSecretType(i.Type)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tsecret := v1.Secret{\n\t\tObjectMeta: metav1.ObjectMeta{\n\t\t\tName: i.Name,\n\t\t\tNamespace: i.Namespace,\n\t\t},\n\t\tData: map[string][]byte{\n\t\t\ti.Key: []byte...
[ "0.66797674", "0.6378324", "0.63245016", "0.631639", "0.6316075", "0.6300446", "0.62829036", "0.611341", "0.6105122", "0.60965884", "0.60490847", "0.6026435", "0.60210687", "0.60203475", "0.59663445", "0.5898095", "0.5892259", "0.5868871", "0.5848825", "0.58468777", "0.584556...
0.73855734
0
Process k8s Secret object into template. Returns false if not capable of processing given resource type.
func (d secret) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured) (bool, helmify.Template, error) { if obj.GroupVersionKind() != configMapGVC { return false, nil, nil } sec := corev1.Secret{} err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &sec) if err != nil { return true, nil, errors.Wrap(err, "unable to cast to secret") } meta, err := processor.ProcessObjMeta(appMeta, obj) if err != nil { return true, nil, err } name := appMeta.TrimName(obj.GetName()) nameCamelCase := strcase.ToLowerCamel(name) secretType := string(sec.Type) if secretType != "" { secretType, err = yamlformat.Marshal(map[string]interface{}{"type": secretType}, 0) if err != nil { return true, nil, err } } values := helmify.Values{} var data, stringData string templatedData := map[string]string{} for key := range sec.Data { keyCamelCase := strcase.ToLowerCamel(key) if key == strings.ToUpper(key) { keyCamelCase = strcase.ToLowerCamel(strings.ToLower(key)) } templatedName, err := values.AddSecret(true, nameCamelCase, keyCamelCase) if err != nil { return true, nil, errors.Wrap(err, "unable add secret to values") } templatedData[key] = templatedName } if len(templatedData) != 0 { data, err = yamlformat.Marshal(map[string]interface{}{"data": templatedData}, 0) if err != nil { return true, nil, err } data = strings.ReplaceAll(data, "'", "") data = format.FixUnterminatedQuotes(data) } templatedData = map[string]string{} for key := range sec.StringData { keyCamelCase := strcase.ToLowerCamel(key) if key == strings.ToUpper(key) { keyCamelCase = strcase.ToLowerCamel(strings.ToLower(key)) } templatedName, err := values.AddSecret(false, nameCamelCase, keyCamelCase) if err != nil { return true, nil, errors.Wrap(err, "unable add secret to values") } templatedData[key] = templatedName } if len(templatedData) != 0 { stringData, err = yamlformat.Marshal(map[string]interface{}{"stringData": templatedData}, 0) if err != nil { return true, nil, err } stringData = strings.ReplaceAll(stringData, "'", "") stringData = format.FixUnterminatedQuotes(stringData) } return true, &result{ name: name + ".yaml", data: struct { Type string Meta string Data string StringData string }{Type: secretType, Meta: meta, Data: data, StringData: stringData}, values: values, }, nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func isSecret(resource v1alpha1.BackingServiceResource) bool {\n\treturn strings.ToLower(resource.Group+\".\"+resource.Version+\".\"+resource.Kind) == \".v1.secret\"\n}", "func (regionEnv *RegionEnv) createSecret(deploymentName string) bool {\n\tgvk := schema.GroupVersionKind{Version: \"v1\", Kind: \"Secret\"}\n...
[ "0.6179236", "0.5799094", "0.52540725", "0.515004", "0.51190156", "0.5062301", "0.50266254", "0.49973863", "0.49073693", "0.489995", "0.48877433", "0.48646992", "0.48484105", "0.4844005", "0.4831506", "0.4827381", "0.48271757", "0.48162967", "0.4793151", "0.47895056", "0.4777...
0.7421397
0
Create provides a mock function with given fields: ctx, in
func (_m *ConstraintReferenceService) Create(ctx context.Context, in *model.FormationTemplateConstraintReference) error { ret := _m.Called(ctx, in) var r0 error if rf, ok := ret.Get(0).(func(context.Context, *model.FormationTemplateConstraintReference) error); ok { r0 = rf(ctx, in) } else { r0 = ret.Error(0) } return r0 }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (_m *MockInterface) Create(ctx context.Context, key string, val string) error {\n\tret := _m.Called(ctx, key, val)\n\n\tvar r0 error\n\tif rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok {\n\t\tr0 = rf(ctx, key, val)\n\t} else {\n\t\tr0 = ret.Error(0)\n\t}\n\n\treturn r0\n}", "func (_...
[ "0.6506049", "0.63336253", "0.6049436", "0.6022087", "0.6017729", "0.59983265", "0.59662163", "0.59630024", "0.59338665", "0.5871227", "0.58698124", "0.58649105", "0.5860727", "0.5797569", "0.5788492", "0.5760916", "0.5745492", "0.5740569", "0.5738385", "0.5718003", "0.571288...
0.5913062
9
Delete provides a mock function with given fields: ctx, constraintID, formationTemplateID
func (_m *ConstraintReferenceService) Delete(ctx context.Context, constraintID string, formationTemplateID string) error { ret := _m.Called(ctx, constraintID, formationTemplateID) var r0 error if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { r0 = rf(ctx, constraintID, formationTemplateID) } else { r0 = ret.Error(0) } return r0 }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (s *service) Delete(ctx context.Context, constraintID, formationTemplateID string) error {\n\tif err := s.repo.Delete(ctx, formationTemplateID, constraintID); err != nil {\n\t\treturn errors.Wrapf(err, \"while deleting Formation Template Constraint Reference for Constraint with ID %q and Formation Template wi...
[ "0.6036101", "0.60064006", "0.5893598", "0.581268", "0.57082725", "0.56985646", "0.5678859", "0.5655733", "0.5650084", "0.56484133", "0.5645776", "0.5601811", "0.55741787", "0.5523782", "0.5514463", "0.5486046", "0.54723054", "0.5457707", "0.5447327", "0.5446301", "0.544352",...
0.6998396
0
NewConstraintReferenceService creates a new instance of ConstraintReferenceService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func NewConstraintReferenceService(t mockConstructorTestingTNewConstraintReferenceService) *ConstraintReferenceService { mock := &ConstraintReferenceService{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) }) return mock }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func NewFormationConstraintSvc(t mockConstructorTestingTNewFormationConstraintSvc) *FormationConstraintSvc {\n\tmock := &FormationConstraintSvc{}\n\tmock.Mock.Test(t)\n\n\tt.Cleanup(func() { mock.AssertExpectations(t) })\n\n\treturn mock\n}", "func NewService(repo formationTemplateConstraintReferenceRepository, ...
[ "0.61277133", "0.5656435", "0.5619453", "0.54407775", "0.5274641", "0.5209439", "0.5191312", "0.5136981", "0.49495593", "0.4917797", "0.48863798", "0.48752347", "0.48572385", "0.47870165", "0.47863263", "0.47311988", "0.47112477", "0.46971738", "0.46850052", "0.46345636", "0....
0.84137696
0
var queryType = "DataType" GET DATA TYPE DETAILS
func control_data_type_details(w http.ResponseWriter, r *http.Request) { //ADMIN checkAdmin(w,r) //PARAMETERS itemID := strings.Split(r.RequestURI,"/") //fmt.Fprintln(w,itemID[5]) //CONTEXT c := appengine.NewContext(r) //DECODE KEY key,err := datastore.DecodeKey(itemID[5]) //KEY ERR if err != nil { fmt.Fprintln(w, "error decoding") return } /*******************************GET**************************/ if r.Method == "GET"{ //QUERY q := datastore.NewQuery("DataType").Filter("__key__ =", key).Limit(1).Limit(100) //DB GET ALL var db []*DataType _,err := q.GetAll(c,&db) //DB ERR if err != nil { fmt.Fprint(w,"error getting items") return } //VAR dbData := []DataType{} //FOR LOOP 1 DB ITEMS for i := range db { //KEYS ENCODE //k := keys[i].Encode() TheFields := []FieldType {} //DEBUG //fmt.Fprintln(w,k) //fmt.Fprintln(w,db[i].Fields[0].Name) //fmt.Fprintln(w,len(db[i].Fields)-1) //FOR LOOP 2 FIELDS for j := 0; j <= (len(db[i].Fields)-1); j++ { TheFields = append(TheFields, FieldType { Name: db[i].Fields[j].Name , UI: db[i].Fields[j].UI , }) //END FOR 2 } //APPEND dbData = append(dbData, DataType { Title: db[i].Title, URL: db[i].URL, //"key": k, Fields: TheFields, }, ) //END FOR 1 } //fmt.Fprintln(w,data) //fmt.Fprintln(w,dbData) //fmt.Fprintln(w,r.Header.Get("X-Requested-With")) //"X-Requested-With" if r.Header.Get("X-Requested-With") != "" { //MARSHAL JSON j,errJSON := json.Marshal(dbData) if errJSON != nil { fmt.Fprintln(w,"error with JSON") } //SET CONTENT-TYPE w.Header().Set("Content-Type", "application/json") //DISPLAY JSON fmt.Fprint(w,string(j)) } //END GET } //END FUNC }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (c *QueryDescriptor) QueryType() string {\n\treturn typeOf(c.query)\n}", "func QueryType(typeName string) QueryBuilder {\n\treturn Query(TypeFn(typeName))\n}", "func getQueryType(db *pg.DB, modelType *graphql.Object) *graphql.Object {\n\treturn graphql.NewObject(graphql.ObjectConfig{\n\t\tName: \"Query\",...
[ "0.66651064", "0.6497343", "0.64160186", "0.6286393", "0.62545264", "0.6123289", "0.61106265", "0.61101663", "0.59699", "0.5967814", "0.5966449", "0.5934342", "0.59213394", "0.59168285", "0.58997035", "0.5895523", "0.5870778", "0.5852317", "0.5852317", "0.58443254", "0.584224...
0.6284614
4
GET LIST PAGES/POST ADD PAGES
func control_data_type(w http.ResponseWriter, r *http.Request) { //ADMIN checkAdmin(w,r) //CONTEXT c := appengine.NewContext(r) /*******************************GET LIST/ADD**************************/ if r.Method == "GET"{ //DATA data := map[string]string{ "get":"true", "title": "Data", } //QUERY q := datastore.NewQuery("DataType").Limit(100) //DB GET ALL var db []*DataType keys,err := q.GetAll(c,&db) //DB ERR if err != nil { fmt.Fprint(w,"error getting items") return } //VAR var dbData []map[string]string //FOR DB ITEMS for i := range db { //KEYS ENCODE k := keys[i].Encode() dbData = append(dbData, map[string]string { "title": db[i].Title, "key": k, //"fieldNames": db[i].Fields[1].Name, //"fieldUI":db[i].UI, /*Fields: map[string]string{ "Name":"text", "Email":"text", "Phone":"text", "Message":"textarea", },*/ }, ) } //fmt.Fprintln(w,data) //fmt.Fprintln(w,dbData) //fmt.Fprintln(w,r.Header.Get("X-Requested-With")) //"X-Requested-With" if r.Header.Get("X-Requested-With") != "" { //MARSHAL JSON j,errJSON := json.Marshal(dbData) if errJSON != nil { fmt.Fprintln(w,"error with JSON") } //SET CONTENT-TYPE w.Header().Set("Content-Type", "application/json") //DISPLAY JSON fmt.Fprint(w,string(j)) } else { renderControl(w, r, "/control/data.html", data, dbData) } /********************************POST ADD*********************************/ } else { //GET FORM VALS formVal := func(val string)string{ return r.FormValue(val) } //newFields := map[string]string {} //fmt.Fprintln(w,r) TheFields := []FieldType {} FieldCount,_ := strconv.Atoi(formVal("field_count")) FieldCount = FieldCount - 1 for i := 0; i <= FieldCount; i++ { iCount := strconv.Itoa(i) TheFields = append(TheFields, FieldType { Name: formVal("fieldName" + iCount), Order: formVal("fieldOrder" + iCount), UI: formVal("fieldUI" + iCount), //Errors: formVal("fieldErrors" + iCount), }) //fmt.Fprintln(w,formVal("fieldName" + iCount)) //fmt.Fprintln(w,formVal("fieldName0")) //fmt.Fprintln(w, FieldCount) //fmt.Fprintln(w,iCount) } /* { Name: formVal("fieldName1"), Label: formVal("fieldLabel1"), UI: formVal("fieldUI1"), Errors: formVal("fieldErrors1"), }, { Name: formVal("fieldName2"), Label: formVal("fieldLabel2"), UI: formVal("fieldUI2"), Errors: formVal("fieldErrors2"), }, }*/ //PRETTIFY URL reg, err := regexp.Compile("[^A-Za-z0-9]+") if err != nil { fmt.Fprintln(w,"error with RegX") } prettyurl := reg.ReplaceAllString(formVal("slug"), "-") prettyurl = strings.ToLower(strings.Trim(prettyurl, "-")) //fmt.Fprintln(w,prettyurl) //MAP FORM VALS newType := DataType { Title: formVal("typeName"), TemplateList: formVal("data_type_template_list"), TemplateItem: formVal("data_type_template_item"), Description: formVal("description"), Keywords: formVal("keywords"), URL: prettyurl, Fields: TheFields, } //fmt.Fprintln(w,newType) //DB PUT key, err := datastore.Put(c, datastore.NewIncompleteKey(c, "DataType", nil), &newType) //IF ERRORS if err != nil { fmt.Fprint(w,"error adding") return //NO ERRORS } else { cacheFlush("types",r) //DEBUG //fmt.Fprintln(w,"added successfully") //fmt.Fprintln(w,"key: " + key.Encode()) //PREP JSON m := map[string]string{ "message":"new type added", "key":key.Encode(), "title":newType.Title, "adminSlug":AdminSlug, } //MARSHAL JSON j,errJSON := json.Marshal(m) if errJSON != nil { fmt.Fprintln(w,"error with JSON") } //DISPLAY JSON w.Header().Set("Content-Type", "application/json") fmt.Fprint(w,string(j)) return //END ERRORS } //END POST } //END FUNC }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func TestListPage(t *testing.T) {\n\n\t// Get all pages (we should have at least one)\n\tresults, err := FindAll(Query())\n\tif err != nil {\n\t\tt.Fatalf(\"pages: List no page found :%s\", err)\n\t}\n\n\tif len(results) < 1 {\n\t\tt.Fatalf(\"pages: List no pages found :%s\", err)\n\t}\n\n}", "func (h *PageHandl...
[ "0.64121014", "0.6053224", "0.5971785", "0.59450006", "0.58816975", "0.5828093", "0.5775039", "0.575437", "0.5751406", "0.5750042", "0.57327384", "0.5730634", "0.57283455", "0.57073927", "0.5698735", "0.56935793", "0.56563675", "0.5623424", "0.56171405", "0.5606726", "0.56065...
0.0
-1
idDistance calculates the distance of a and b accounting for wraparound using max. Wraparound means that a may be closer to b if they traveled through max. The lowest value of the following is returned: |a b| max a + b + 1 max b + a + 1 Expressions that evaluate to be larger than max are ignored to prevent overflowing.
func idDistance(a, b id.ID, max id.ID) id.ID { // Wrap distance will always be smaller when a > b so // swap the two if that doesn't hold. if id.Compare(a, b) < 0 { return idDistance(b, a, max) } var ( one = id.ID{Low: 1} directDist = absSub(b, a) maxDist = idSub(max, a) ) // Don't wrap around if b+1 or (max-a)+b+1 would overflow. if addOverflows(b, one, max) || addOverflows(maxDist, idAdd(b, one), max) { return directDist } wraparoundDist := idAdd(maxDist, idAdd(b, one)) // Return the smaller of direct and wraparound distance. if id.Compare(wraparoundDist, directDist) < 0 { return wraparoundDist } return directDist }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (id ID) Distance(other ID) (result ID) {\n\tdistance := new(big.Int)\n\tdistance = distance.Xor(id.Int(), other.Int())\n\tresult, _ = NewID(distance.Bytes())\n\treturn\n}", "func (kademliaID KademliaID) CalcDistance(target *KademliaID) *KademliaID {\n\tresult := KademliaID{}\n\tfor i := 0; i < ID_LEN; i++ {...
[ "0.59706086", "0.5848006", "0.5799961", "0.5799961", "0.57304907", "0.5343803", "0.51886135", "0.5186379", "0.5079502", "0.50471145", "0.49845216", "0.4917509", "0.49031368", "0.490295", "0.487796", "0.4873442", "0.4847311", "0.4836192", "0.48251015", "0.48215413", "0.4791891...
0.8380889
0
absSub :: | a b |
func absSub(a, b id.ID) id.ID { cmp := id.Compare(a, b) switch { case cmp < 0: // a < b return idSub(b, a) case cmp == 0: // a == b return id.Zero case cmp > 0: // a > b return idSub(a, b) default: panic("impossible case") } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (v Vec) AbsSub(other Vec) Vec {\n\treturn v.Copy().AbsSubBy(other)\n}", "func (a Vec2) Sub(b Vec2) Vec2 {\n\treturn Vec2{a.X - b.X, a.Y - b.Y}\n}", "func (t Torus) Sub(a, b Point) Point {\n\ta, b = t.normPair(a, b)\n\treturn a.Sub(b)\n}", "func (a ImpactAmount) sub(b ImpactAmount) ImpactAmount {\n\tif b...
[ "0.7009983", "0.6930586", "0.6803725", "0.66169053", "0.65832865", "0.65832865", "0.65832865", "0.6508825", "0.6508825", "0.6508825", "0.6458546", "0.6458546", "0.6458546", "0.6440195", "0.64367706", "0.6427443", "0.6413858", "0.64080596", "0.6405884", "0.637051", "0.634558",...
0.7613036
0
Returns true when v + o would overflow max.
func addOverflows(v, o, max id.ID) bool { // o overflows when (max - v) < o maxDist := idSub(max, v) return id.Compare(maxDist, o) < 0 }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func bounded(n ir.Node, max int64) bool {\n\tif n.Type() == nil || !n.Type().IsInteger() {\n\t\treturn false\n\t}\n\n\tsign := n.Type().IsSigned()\n\tbits := int32(8 * n.Type().Size())\n\n\tif ir.IsSmallIntConst(n) {\n\t\tv := ir.Int64Val(n)\n\t\treturn 0 <= v && v < max\n\t}\n\n\tswitch n.Op() {\n\tcase ir.OAND, ...
[ "0.59384793", "0.58904886", "0.58642787", "0.584234", "0.5744652", "0.56927615", "0.5617862", "0.5560207", "0.550647", "0.5500962", "0.54567045", "0.5416046", "0.5390327", "0.53597915", "0.5351312", "0.5327792", "0.5325286", "0.5323421", "0.5316553", "0.5291704", "0.5264823",...
0.7086862
0
sub :: v o
func idSub(v, o id.ID) id.ID { low, borrow := bits.Sub64(v.Low, o.Low, 0) high, borrow := bits.Sub64(v.High, o.High, borrow) return id.ID{High: high, Low: low} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (v Vector) Sub(o Vector) *Vector {\n\treturn &Vector{v[0] - o[0], v[1] - o[1], v[2] - o[2]}\n}", "func (u Vec) Sub(v Vec) Vec {\n\treturn Vec{\n\t\tu.X - v.X,\n\t\tu.Y - v.Y,\n\t}\n}", "func (v Vec2) Sub(x Vec2) Vec2 {\n\treturn Vec2{v[0] - x[0], v[1] - x[1]}\n}", "func (v Vec2) Sub(other Vec2) Vec2 {\n...
[ "0.7930486", "0.75865024", "0.7481174", "0.7398153", "0.73943275", "0.73667604", "0.73144025", "0.7308492", "0.7287318", "0.72847265", "0.72703105", "0.7236882", "0.72253644", "0.72095793", "0.7167069", "0.7157974", "0.71352875", "0.7106701", "0.70946306", "0.70377123", "0.69...
0.6274007
88
idAdd :: v + o
func idAdd(v, o id.ID) id.ID { low, borrow := bits.Add64(v.Low, o.Low, 0) high, _ := bits.Add64(v.High, o.High, borrow) return id.ID{High: high, Low: low} }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func add(this js.Value, i []js.Value) interface{} {\n\tin1, in2 := getInputValues(i)\n\tsetValueById(i[2].String(), in1+in2)\n\treturn nil\n}", "func _cgoexp_e93fccc2f088_add(a *struct {\n\t\tp0 _Ctype_int\n\t\tp1 _Ctype_int\n\t\tr0 _Ctype_int\n\t}) {\n\ta.r0 = add(a.p0, a.p1)\n}", "func add(x, y int) int", ...
[ "0.67529297", "0.6540365", "0.64769065", "0.64463145", "0.64110214", "0.63479173", "0.63165194", "0.6288132", "0.6288132", "0.6288132", "0.6288132", "0.6288132", "0.6288132", "0.6288132", "0.6278636", "0.6243417", "0.6243417", "0.6243417", "0.6243417", "0.62226516", "0.621912...
0.774656
0
control the terminal mode Set a tty terminal to raw mode.
func setRawMode(fd int) (*raw.Termios, error) { // make sure this is a tty if !isatty.IsTerminal(uintptr(fd)) { return nil, fmt.Errorf("fd %d is not a tty", fd) } // get the terminal IO mode originalMode, err := raw.TcGetAttr(uintptr(fd)) if err != nil { return nil, err } // modify the original mode newMode := *originalMode newMode.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON) newMode.Oflag &^= syscall.OPOST newMode.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN) newMode.Cflag &^= (syscall.CSIZE | syscall.PARENB) newMode.Cflag |= syscall.CS8 newMode.Cc[syscall.VMIN] = 1 newMode.Cc[syscall.VTIME] = 0 err = raw.TcSetAttr(uintptr(fd), &newMode) if err != nil { return nil, err } return originalMode, nil }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (i *In) SetRawTerminal() (err error) {\n\tif !i.isTerminal || os.Getenv(\"NORAW\") != \"\" {\n\t\treturn nil\n\t}\n\ti.state, err = term.SetRawTerminal(i.fd)\n\treturn err\n}", "func SetRawTerminal(fd FileDescriptor) (state *TerminalState, err error) {\n\tvar s *mobyterm.State\n\ts, err = mobyterm.SetRawTer...
[ "0.75425404", "0.7029126", "0.66933656", "0.61317337", "0.5962113", "0.58300453", "0.57845724", "0.5764185", "0.5763176", "0.5722855", "0.5571576", "0.5564034", "0.553365", "0.5418981", "0.5362698", "0.53572845", "0.5330058", "0.5295675", "0.5278407", "0.52701086", "0.526473"...
0.7128382
1
Restore the terminal mode.
func restoreMode(fd int, mode *raw.Termios) error { return raw.TcSetAttr(uintptr(fd), mode) }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func RestoreTerminal(fd uintptr, state *State) error {\n\treturn SetConsoleMode(fd, state.mode)\n}", "func restoreTerminal() {\n\tif !stdoutIsTerminal() {\n\t\treturn\n\t}\n\n\tfd := int(os.Stdout.Fd())\n\tstate, err := terminal.GetState(fd)\n\tif err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"unable to get terminal...
[ "0.77427965", "0.7543272", "0.74539554", "0.71161926", "0.6849582", "0.67580074", "0.6674304", "0.6480208", "0.6445519", "0.6392272", "0.63900316", "0.6365112", "0.6365112", "0.63387257", "0.62861365", "0.6114559", "0.5983823", "0.5850905", "0.58457255", "0.5747718", "0.57414...
0.6962825
4
Add a byte to a utf8 decode. Return the rune and it's size in bytes.
func (u *utf8) add(c byte) (r rune, size int) { switch u.state { case getByte0: if c&0x80 == 0 { // 1 byte return rune(c), 1 } else if c&0xe0 == 0xc0 { // 2 byte u.val = int32(c&0x1f) << 6 u.count = 2 u.state = get1More return KeycodeNull, 0 } else if c&0xf0 == 0xe0 { // 3 bytes u.val = int32(c&0x0f) << 6 u.count = 3 u.state = get2More return KeycodeNull, 0 } else if c&0xf8 == 0xf0 { // 4 bytes u.val = int32(c&0x07) << 6 u.count = 4 u.state = get3More return KeycodeNull, 0 } case get3More: if c&0xc0 == 0x80 { u.state = get2More u.val |= int32(c & 0x3f) u.val <<= 6 return KeycodeNull, 0 } case get2More: if c&0xc0 == 0x80 { u.state = get1More u.val |= int32(c & 0x3f) u.val <<= 6 return KeycodeNull, 0 } case get1More: if c&0xc0 == 0x80 { u.state = getByte0 u.val |= int32(c & 0x3f) return rune(u.val), u.count } } // Error u.state = getByte0 return unicode.ReplacementChar, 1 }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (UTF8Decoder) DecodeRune(p []byte) (rune, int) { return utf8.DecodeRune(p) }", "func (s *scratch) addRune(r rune) int {\n\tif s.fill+utf8.UTFMax >= cap(s.data) {\n\t\ts.grow()\n\t}\n\n\tn := utf8.EncodeRune(s.data[s.fill:], r)\n\ts.fill += n\n\treturn n\n}", "func (t *TelWindow) AddByte(b byte) {\n \n}...
[ "0.62522995", "0.6023888", "0.575294", "0.5561606", "0.55129707", "0.5300394", "0.52845013", "0.52588093", "0.5219854", "0.5210699", "0.5197407", "0.5191365", "0.5188205", "0.5158537", "0.5146117", "0.50871277", "0.5043505", "0.5022171", "0.49819675", "0.49794295", "0.4960473...
0.7119522
0
read a single rune from a file descriptor (with timeout) timeout >= 0 : wait for timeout seconds timeout = nil : return immediately
func (u *utf8) getRune(fd int, timeout *syscall.Timeval) rune { // use select() for the timeout if timeout != nil { for true { rd := syscall.FdSet{} fdset.Set(fd, &rd) n, err := syscall.Select(fd+1, &rd, nil, nil, timeout) if err != nil { continue } if n == 0 { // nothing is readable return KeycodeNull } break } } // Read the file descriptor buf := make([]byte, 1) _, err := syscall.Read(fd, buf) if err != nil { panic(fmt.Sprintf("read error %s\n", err)) } // decode the utf8 r, size := u.add(buf[0]) if size == 0 { // incomplete utf8 code point return KeycodeNull } if size == 1 && r == unicode.ReplacementChar { // utf8 decode error return KeycodeNull } return r }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (r *timeoutReadCloser) Read(b []byte) (int, error) {\n\ttimer := time.NewTimer(r.duration)\n\tc := make(chan readResult, 1)\n\n\tgo func() {\n\t\tn, err := r.reader.Read(b)\n\t\ttimer.Stop()\n\t\tc <- readResult{n: n, err: err}\n\t}()\n\n\tselect {\n\tcase data := <-c:\n\t\treturn data.n, data.err\n\tcase <-t...
[ "0.6527407", "0.6354455", "0.62314177", "0.60235244", "0.59406394", "0.5750943", "0.56235766", "0.56235766", "0.5595832", "0.5575077", "0.55733573", "0.5528142", "0.55023915", "0.5498631", "0.54959285", "0.5492799", "0.54909766", "0.5408234", "0.5406413", "0.53877175", "0.537...
0.66135055
0
If fd is not readable within the timeout period return true.
func wouldBlock(fd int, timeout *syscall.Timeval) bool { rd := syscall.FdSet{} fdset.Set(fd, &rd) n, err := syscall.Select(fd+1, &rd, nil, nil, timeout) if err != nil { log.Printf("select error %s\n", err) return false } return n == 0 }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func IsTimeout(err error) bool", "func (c *connection) locked_readOperationTimedOut(tq *timerQueue, cd *connectionData) bool {\n\treturn !c.readData.timeout.IsZero() && tq.Now().After(c.readData.timeout)\n}", "func (o *Content) HasReadTimeout() bool {\n\tif o != nil && o.ReadTimeout.IsSet() {\n\t\treturn true\...
[ "0.6929368", "0.65608245", "0.6201191", "0.6042862", "0.5884998", "0.58426654", "0.5810461", "0.5719689", "0.57021224", "0.56685066", "0.56480896", "0.56158537", "0.55566245", "0.55403715", "0.55130386", "0.5479078", "0.5474698", "0.5410281", "0.5392653", "0.53810465", "0.531...
0.59510916
4
Write a string to the file descriptor, return the number of bytes written.
func puts(fd int, s string) int { n, err := syscall.Write(fd, []byte(s)) if err != nil { panic(fmt.Sprintf("puts error %s\n", err)) } return n }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (fs *Fs) WriteString(file *os.File, string string) (int, error) {\n\treturn file.WriteString(string) // #nosec G304\n}", "func (a ReverseHttpFile) WriteString(s string) (int, error) {\n\treturn 0, syscall.EPERM\n}", "func (r *RingBuffer) WriteString(s string) (n int, err error) {\n\tbs := String2Bytes(s)\...
[ "0.65339494", "0.6443635", "0.6394321", "0.63284874", "0.62357426", "0.62231046", "0.6221263", "0.6219123", "0.6129166", "0.611008", "0.6103962", "0.602641", "0.6001503", "0.5954072", "0.5947781", "0.58849305", "0.5862734", "0.58547515", "0.58542186", "0.5849421", "0.58125377...
0.6710511
0
Get the horizontal cursor position
func getCursorPosition(ifd, ofd int) int { // query the cursor location if puts(ofd, "\x1b[6n") != 4 { return -1 } // read the response: ESC [ rows ; cols R // rows/cols are decimal number strings buf := make([]rune, 0, 32) u := utf8{} for len(buf) < 32 { r := u.getRune(ifd, &timeout20ms) if r == KeycodeNull { break } buf = append(buf, r) if r == 'R' { break } } // parse it: esc [ number ; number R (at least 6 characters) if len(buf) < 6 || buf[0] != KeycodeESC || buf[1] != '[' || buf[len(buf)-1] != 'R' { return -1 } // should have 2 number fields x := strings.Split(string(buf[2:len(buf)-1]), ";") if len(x) != 2 { return -1 } // return the cols cols, err := strconv.Atoi(x[1]) if err != nil { return -1 } return cols }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (b *Buffer) getCursorMinXPos() int {\n return b.getLineMetaChars() + 1\n}", "func (tb *Textbox) Cursor() (x, y int) {\n\treturn tb.cursor % len(tb.canvas[0]), tb.cursor / len(tb.canvas[0])\n}", "func CursorPosX(x int) string {\n\treturn Esc + strconv.Itoa(x+1) + \"G\"\n}", "func CursorPos(x, y int) str...
[ "0.73878413", "0.712756", "0.7014254", "0.6883936", "0.6776131", "0.6621112", "0.6584309", "0.6405177", "0.6345664", "0.6337626", "0.62170935", "0.6178933", "0.6144976", "0.6053561", "0.60182124", "0.59999216", "0.59960705", "0.5993182", "0.59289753", "0.591452", "0.5882976",...
0.0
-1
Get the number of columns for the terminal. Assume defaultCols if it fails.
func getColumns(ifd, ofd int) int { // try using the ioctl to get the number of cols var winsize [4]uint16 _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdout), syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&winsize))) if err == 0 { return int(winsize[1]) } // the ioctl failed - try using the terminal itself start := getCursorPosition(ifd, ofd) if start < 0 { return defaultCols } // Go to right margin and get position if puts(ofd, "\x1b[999C") != 6 { return defaultCols } cols := getCursorPosition(ifd, ofd) if cols < 0 { return defaultCols } // restore the position if cols > start { puts(ofd, fmt.Sprintf("\x1b[%dD", cols-start)) } return cols }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (b Board) NumCols() int {\n\treturn b.ncols\n}", "func (v Chunk) NCols() int {\n\treturn len(v.buf.Columns)\n}", "func (fw *Writer) NumColumns() int { return fw.Schema.NumColumns() }", "func (A *Matrix64) Ncols() int {\n\treturn A.ncols\n}", "func (reader *Reader) GetNColumnIn() int {\n\treturn len(re...
[ "0.65468746", "0.6216222", "0.6080732", "0.6039732", "0.59775245", "0.5952306", "0.5922178", "0.59129816", "0.58751225", "0.58284223", "0.58216983", "0.5815894", "0.57869226", "0.5776121", "0.5771894", "0.57390213", "0.5737454", "0.57297176", "0.5712563", "0.57088536", "0.568...
0.6874037
0
Return true if we know we don't support this terminal.
func unsupportedTerm() bool { _, ok := unsupported[os.Getenv("TERM")] return ok }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func IsTerminal(fd uintptr) bool {\r\n\treturn false\r\n}", "func isTerminal(f *os.File) bool {\n\tlog.Fatalf(\"hyperkit: Function not supported on your OS\")\n\treturn false\n}", "func terminalIsDumb() bool {\n var term = os.Getenv(\"TERM\")\n\n if term == \"\" || term == \"dumb\" {\n return true...
[ "0.6745055", "0.66499245", "0.6545055", "0.6524213", "0.64737916", "0.6460544", "0.64597934", "0.62575334", "0.6241871", "0.62060475", "0.6071826", "0.6039111", "0.60130143", "0.6007517", "0.59933984", "0.5969025", "0.59652334", "0.59541774", "0.59541774", "0.5943652", "0.584...
0.7082624
0
show hints to the right of the cursor
func (ls *linestate) refreshShowHints() []string { // do we have a hints callback? if ls.ts.hintsCallback == nil { // no hints return nil } // How many columns do we have for the hint? hintCols := ls.cols - ls.promptWidth - runewidth.StringWidth(string(ls.buf)) if hintCols <= 0 { // no space to display hints return nil } // get the hint h := ls.ts.hintsCallback(string(ls.buf)) if h == nil || len(h.Hint) == 0 { // no hints return nil } // trim the hint until it fits hEnd := len(h.Hint) for runewidth.StringWidth(h.Hint[:hEnd]) > hintCols { hEnd-- } // color fixup if h.Bold && h.Color < 0 { h.Color = 37 } // build the output string seq := make([]string, 0, 3) if h.Color >= 0 || h.Bold { seq = append(seq, fmt.Sprintf("\033[%d;%d;49m", btoi(h.Bold), h.Color)) } seq = append(seq, h.Hint[:hEnd]) if h.Color >= 0 || h.Bold { seq = append(seq, "\033[0m") } return seq }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func setCursorLoc(x, y int) {\n\tfmt.Printf(\"\\033[%v;%vH\", y, x)\n}", "func printHint() {\n\tprint(\"orbi - Embeddable Interactive ORuby Shell\\n\\n\")\n}", "func (d *Display) CursorRight() error {\n\t_, err := d.port.Write([]byte(CursorRight))\n\treturn err\n}", "func (w *VT100Writer) ShowCursor() {\n\tw...
[ "0.6077438", "0.60423", "0.60144335", "0.5872064", "0.57536685", "0.56957555", "0.5690847", "0.5627629", "0.556421", "0.556421", "0.5455736", "0.5433945", "0.5396354", "0.53862804", "0.5341166", "0.5299029", "0.52494884", "0.5230935", "0.51621526", "0.51560223", "0.5151575", ...
0.5885805
3
refresh the edit line
func (ls *linestate) refreshLine() { if ls.ts.mlmode { ls.refreshMultiline() } else { ls.refreshSingleline() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func Edit(defval, prompt string, refresh func(int, int)) string {\n\treturn EditDynamicWithCallback(defval, prompt, refresh, nil)\n}", "func (ls *linestate) editDelete() {\n\tif len(ls.buf) > 0 && ls.pos < len(ls.buf) {\n\t\tls.buf = append(ls.buf[:ls.pos], ls.buf[ls.pos+1:]...)\n\t\tls.refreshLine()\n\t}\n}", ...
[ "0.6306653", "0.6266596", "0.61689687", "0.6149421", "0.5967917", "0.5826063", "0.58000565", "0.57523245", "0.5705781", "0.5584211", "0.5578572", "0.5550107", "0.54992044", "0.54992044", "0.5471874", "0.5461494", "0.54481226", "0.5432281", "0.5408312", "0.52952456", "0.529086...
0.6496335
0
delete the character at the current cursor position
func (ls *linestate) editDelete() { if len(ls.buf) > 0 && ls.pos < len(ls.buf) { ls.buf = append(ls.buf[:ls.pos], ls.buf[ls.pos+1:]...) ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (e *LineEditor) DelChar() {\n\n\t// different handling for at the beginning of the line or middle of line\n\tif e.Cx > 0 {\n\t\trow := e.Row\n\t\tcopy(row[e.Cx-1:], row[e.Cx:])\n\t\trow = row[:len(row)-1]\n\t\te.Row = row\n\t\te.Cx--\n\t}\n}", "func (tv *TextView) CursorDelete(steps int) {\n\twupdt := tv.To...
[ "0.75402987", "0.6650366", "0.6263558", "0.6129098", "0.60061044", "0.58697176", "0.58670366", "0.58643687", "0.5804483", "0.57899517", "0.57389545", "0.57170504", "0.57014334", "0.5661418", "0.56473815", "0.5607732", "0.5556907", "0.5527127", "0.5519712", "0.55096525", "0.55...
0.5917855
5
delete the character to the left of the current cursor position
func (ls *linestate) editBackspace() { if ls.pos > 0 && len(ls.buf) > 0 { ls.buf = append(ls.buf[:ls.pos-1], ls.buf[ls.pos:]...) ls.pos-- ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (e *LineEditor) DelChar() {\n\n\t// different handling for at the beginning of the line or middle of line\n\tif e.Cx > 0 {\n\t\trow := e.Row\n\t\tcopy(row[e.Cx-1:], row[e.Cx:])\n\t\trow = row[:len(row)-1]\n\t\te.Row = row\n\t\te.Cx--\n\t}\n}", "func (m *Model) deleteWordLeft() bool {\n\tif m.pos == 0 || len...
[ "0.6931943", "0.6675788", "0.63332933", "0.63267565", "0.62952375", "0.6169678", "0.6126563", "0.60828185", "0.5912601", "0.5898569", "0.5814333", "0.5758422", "0.5742485", "0.57424265", "0.5734684", "0.57340974", "0.57005805", "0.56671005", "0.56294894", "0.56037384", "0.559...
0.55979943
20
insert a character at the current cursor position
func (ls *linestate) editInsert(r rune) { ls.buf = append(ls.buf[:ls.pos], append([]rune{r}, ls.buf[ls.pos:]...)...) ls.pos++ ls.refreshLine() }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (i *Input) Insert(r rune) {\n\ti.Buffer.InsertRune(r, i.Pos)\n\ti.Pos++\n}", "func (r *Row) insertChar (char string, index int) {\n content := r.content.Bytes()\n newBuffer := bytes.NewBuffer(nil)\n\n newBuffer.Write(content[:index])\n newBuffer.Write([]byte(char))\n newBuffer.Write(content[index:])\n\...
[ "0.76106894", "0.7585166", "0.7517167", "0.7278935", "0.7108609", "0.70963687", "0.6521914", "0.64360595", "0.63691735", "0.6232524", "0.62302566", "0.6224099", "0.6085163", "0.6070685", "0.6023234", "0.5956973", "0.5898353", "0.5883555", "0.5878901", "0.58115983", "0.5792886...
0.729633
3
Swap current character with the previous character.
func (ls *linestate) editSwap() { if ls.pos > 0 && ls.pos < len(ls.buf) { tmp := ls.buf[ls.pos-1] ls.buf[ls.pos-1] = ls.buf[ls.pos] ls.buf[ls.pos] = tmp if ls.pos != len(ls.buf)-1 { ls.pos++ } ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (c *Cursor) Previous() {\n\tc.pos--\n}", "func swap(a, b rune, plugboard string) string {\n\tfor i, letter := range plugboard {\n\t\tif letter == a {\n\t\t\tplugboard = plugboard[0:i] + string(b) + plugboard[i+1:]\n\t\t} else if letter == b {\n\t\t\tplugboard = plugboard[0:i] + string(a) + plugboard[i+1:]\n...
[ "0.5779657", "0.537581", "0.5162446", "0.50913924", "0.50529397", "0.4990177", "0.49679735", "0.48747104", "0.48697123", "0.4851855", "0.4823436", "0.47806108", "0.4761153", "0.4752942", "0.47519898", "0.47460264", "0.47025988", "0.4697588", "0.46973363", "0.4685477", "0.4670...
0.54316425
1
Set the line buffer to a string.
func (ls *linestate) editSet(s string) { ls.buf = []rune(s) ls.pos = len(ls.buf) ls.refreshLine() }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func Buffer() string {\n\treturn C.GoString(C.rl_line_buffer)\n}", "func (v *TextView) SetBuffer(buffer *TextBuffer) {\n\tC.gtk_text_view_set_buffer(v.native(), buffer.native())\n}", "func (src *Source) SetBuffer(buf []byte) {\n\tsrc.buf = buf\n}", "func (l *StringLexer) BufferString() string {\n\treturn l.i...
[ "0.6371343", "0.5862435", "0.5831232", "0.5748995", "0.56864643", "0.5641822", "0.56276137", "0.55717295", "0.55606496", "0.5525872", "0.5525364", "0.55208725", "0.5504437", "0.54288745", "0.5415996", "0.54111296", "0.5385222", "0.53531575", "0.5333338", "0.53176993", "0.5314...
0.5652134
5
Move cursor on the left.
func (ls *linestate) editMoveLeft() { if ls.pos > 0 { ls.pos-- ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (e *LineEditor) CursorLeft() {\n\n\tif e.Cx > 0 {\n\t\te.Cx--\n\t}\n}", "func (i *Input) CursorLeft() {\n\tif i.Pos > 0 {\n\t\ti.Pos--\n\t}\n}", "func (d *Display) CursorLeft() error {\n\t_, err := d.port.Write([]byte(CursorLeft))\n\treturn err\n}", "func (c *Camera) MoveLeft() {\n\tc.x -= c.worldWidth ...
[ "0.7997701", "0.7938411", "0.78383493", "0.71686447", "0.7092171", "0.69622624", "0.69529593", "0.68944913", "0.6806713", "0.67822456", "0.6753121", "0.6689498", "0.65439445", "0.6536123", "0.6495173", "0.64557284", "0.641655", "0.6380656", "0.62823004", "0.6266162", "0.62512...
0.7620068
3
Move cursor to the right.
func (ls *linestate) editMoveRight() { if ls.pos != len(ls.buf) { ls.pos++ ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (i *Input) CursorRight() {\n\tif i.Pos < i.Buffer.Len() {\n\t\ti.Pos++\n\t}\n}", "func (e *LineEditor) CursorRight() {\n\t// right moves only if we're within a valid line.\n\t// for past EOF, there's no movement\n\tif e.Cx < len(e.Row) {\n\t\te.Cx++\n\t}\n}", "func (d *Display) CursorRight() error {\n\t_,...
[ "0.7856465", "0.78023463", "0.76541454", "0.699471", "0.693096", "0.6794503", "0.67479396", "0.67300725", "0.6594457", "0.6572439", "0.65516806", "0.64767385", "0.64715546", "0.6293926", "0.625782", "0.6238422", "0.6194988", "0.61666787", "0.6080963", "0.6056318", "0.60210586...
0.75334066
3
Move to the start of the line buffer.
func (ls *linestate) editMoveHome() { if ls.pos > 0 { ls.pos = 0 ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (lexer *Lexer) nextLine() {\n lexer.position.Col = 0\n lexer.position.Row++\n}", "func (e *Editor) prepend(s string) {\n\tif e.singleLine {\n\t\ts = strings.ReplaceAll(s, \"\\n\", \" \")\n\t}\n\te.caret.start.ofs = e.editBuffer.deleteRunes(e.caret.start.ofs,\n\t\te.caret.end.ofs-e.caret.start.ofs) // ...
[ "0.6160869", "0.5816958", "0.5776713", "0.5755481", "0.56894267", "0.5604808", "0.5589513", "0.55494845", "0.55149835", "0.55141646", "0.55054355", "0.54670656", "0.54652417", "0.5444559", "0.5405748", "0.53980356", "0.5392492", "0.53920853", "0.5386621", "0.5339732", "0.5339...
0.54549706
13
Move to the end of the line buffer.
func (ls *linestate) editMoveEnd() { if ls.pos != len(ls.buf) { ls.pos = len(ls.buf) ls.refreshLine() } }
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "func (ls *linestate) deleteToEnd() {\n\tls.buf = ls.buf[:ls.pos]\n\tls.refreshLine()\n}", "func ClearLinePartialForward() {\n\temitEscape(\"K\")\n}", "func (i *Input) backspace() {\n\tcurLine := i.lines[i.cursorLineIndex]\n\t// at the beginning of the buffer, nothing to do\n\tif len(curLine) == 0 && i.cursorLi...
[ "0.7160396", "0.6042775", "0.6032601", "0.5990435", "0.59048235", "0.58782816", "0.5877553", "0.578516", "0.5618679", "0.55800724", "0.5567242", "0.5558867", "0.5543684", "0.55424917", "0.55307984", "0.55307984", "0.5504199", "0.5459268", "0.5456745", "0.5402668", "0.5394385"...
0.6757685
1