id stringlengths 2 7 | text stringlengths 17 51.2k | title stringclasses 1 value |
|---|---|---|
c181600 |
}
if b == false {
panic((&ValidationError{}).New(fieldName + "值的长度应该在" + strings.Replace(strings.Trim(fmt.Sprint(l), "[]"), " ", ",", -1) + "中"))
}
return v
} | |
c181601 |
if b == false {
panic((&ValidationError{}).New(fieldName + "值应该在" + strings.Replace(strings.Trim(fmt.Sprint(l), "[]"), " ", ",", -1) + "中"))
}
return v
} | |
c181602 |
}
b := c.Validate.Email(v)
if b == false {
panic((&ValidationError{}).New(fieldName + "格式错误"))
}
return v
} | |
c181603 |
if err != nil {
return "", err
}
return sorted[len(sorted)-1], nil
} | |
c181604 | typeToCheck)
parentType := ParentType(typeToCheck)
if parentType != "" {
typeToCheck = parentType
} else {
return TypeURIs(typeHierarchy)
}
}
} | |
c181605 | len(types))}
copy(ts.types, types)
sort.Sort(ts)
if ts.invalid {
return types, ErrNotHierarchy
}
return ts.types, nil
} | |
c181606 | {
delete(rs.Values, key)
err := provider.refresh(rs)
return err
} | |
c181607 | error) {
rs := &redisStore{SID: key, Values: values}
err := provider.refresh(rs)
return rs, err
} | |
c181608 |
err = c.HMSet(rs.SID, rs.Values).Err()
if err != nil {
return
}
err = c.Expire(rs.SID, sessExpire).Err()
})
return nil
} | |
c181609 | val, err = c.HGetAll(sid).Result()
rs.Values = val
})
return rs, err
} | |
c181610 | {
err = c.Del(sid).Err()
})
return err
} | |
c181611 |
redisPool.Exec(func(c *redis.Client) {
err = c.Expire(sid, sessExpire).Err()
})
return err
} | |
c181612 | {
hs.Handlers = append(hs.Handlers, h)
} | |
c181613 | "X-Requested-With")
c.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
// Always recover form panics.
defer c.Recover()
// Enter the handlers stack.
c.Next()
// Respnose data
// if c.written == false {
// c.Fail(errors.New("not written"))
// }
// Put the context to ctxPool
putContext(c)
} | |
c181614 | append(group.Handlers, middleware...)
return group.returnObj()
} | |
c181615 | &RouterGroup{
Handlers: group.combineHandlers(handlers),
basePath: group.calculateAbsolutePath(relativePath),
engine: group.engine,
}
} | |
c181616 | state
},
Server: &http.Server{
Addr: Address,
Handler: defaultHandlersStack,
ReadTimeout: ReadTimeout,
WriteTimeout: WriteTimeout,
IdleTimeout: IdleTimeout,
MaxHeaderBytes: MaxHeaderBytes,
},
}
err := srv.ListenAndServe()
if err != nil {
log.Fatalln(err)
}
log.Warnln("Server stoped.")
} | |
c181617 | trees: make(methodTrees, 0, 9),
}
engine.RouterGroup.engine = engine
return engine
} | |
c181618 | int) {
http.Redirect(ctx.ResponseWriter, ctx.Request, url, code)
} | |
c181619 | b, _ := json.Marshal(&ResFormat{Ok: true, Data: data})
ctx.ResponseWriter.WriteHeader(http.StatusOK)
ctx.ResponseWriter.Write(b)
} | |
c181620 | == true {
log.WithFields(log.Fields{"path": ctx.Request.URL.Path}).Warnln(err.Error())
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
b, _ := json.Marshal(&ResFormat{Ok: false, Message: err.Error(), Errno: errno})
coreErr, ok := err.(ICoreError)
if ok == true {
ctx.ResponseWriter.WriteHeader(coreErr.GetHTTPCode())
} else {
ctx.ResponseWriter.WriteHeader(http.StatusInternalServerError)
}
ctx.ResponseWriter.Write(b)
} | |
c181621 | true
ctx.ResponseWriter.WriteHeader(code)
return fmt.Fprint(ctx.ResponseWriter, http.StatusText(code))
} | |
c181622 | been written.
if !ctx.Written() && ctx.index < len(ctx.handlersStack.Handlers)-1 {
ctx.index++
ctx.handlersStack.Handlers[ctx.index](ctx)
}
} | |
c181623 | if store == nil {
return nil
}
st, ok := store.(IStore)
if ok == false {
return nil
}
return st
} | |
c181624 | := strings.Split(reqStr, "&")
for _, v := range reqArr {
param := strings.Split(v, "=")
reqJSON[param[0]], _ = url.QueryUnescape(param[1])
}
} else {
json.Unmarshal(body, &reqJSON)
}
ctx.BodyJSON = reqJSON
} | |
c181625 | provider.Set(sid, values)
if err != nil {
return err
}
cookie := httpCookie
cookie.Value = sid
ctx.Data["session"] = store
respCookie := ctx.ResponseWriter.Header().Get("Set-Cookie")
if strings.HasPrefix(respCookie, cookie.Name) {
ctx.ResponseWriter.Header().Del("Set-Cookie")
}
http.SetCookie(ctx.ResponseWriter, &cookie)
return nil
} | |
c181626 |
err := provider.UpExpire(key)
if err != nil {
return err
}
return nil
} | |
c181627 | cookie.MaxAge = -1
http.SetCookie(ctx.ResponseWriter, &cookie)
return nil
} | |
c181628 | true
return w.ResponseWriter.Write(p)
} | |
c181629 | true
w.ResponseWriter.WriteHeader(code)
} | |
c181630 |
for _, option := range options {
err := option(&c)
if err != nil {
return nil
}
}
return &c
} | |
c181631 | bool) error {
c.allowLargeResults = shouldAllow
c.tempTableName = tempTableName
c.flattenResults = flattenResults
return nil
} | |
c181632 | pemKeyBytes,
"https://www.googleapis.com/auth/bigquery")
//t := jwt.NewToken(c.accountEmailAddress, bigquery.BigqueryScope, pemKeyBytes)
client := t.Client(oauth2.NoContext)
service, err := bigquery.New(client)
if err != nil {
return nil, err
}
c.service = service
return service, nil
} | |
c181633 |
result, err := service.Tabledata.InsertAll(projectID, datasetID, tableID, insertRequest).Do()
if err != nil {
c.printDebug("Error inserting row: ", err)
return err
}
if len(result.InsertErrors) > 0 {
return errors.New("Error inserting row")
}
return nil
} | |
c181634 | {
c.pagedQuery(pageSize, dataset, project, queryStr, dataChan)
} | |
c181635 | return c.pagedQuery(defaultPageSize, dataset, project, queryStr, nil)
} | |
c181636 | int64(pageSize),
Kind: "json",
Query: queryStr,
}
qr, err := service.Jobs.Query(project, query).Do()
// extract the initial rows that have already been returned with the Query
headers, rows := c.headersAndRows(qr.Schema, qr.Rows)
if err != nil {
c.printDebug("Error loading query: ", err)
if dataChan != nil {
dataChan <- Data{Err: err}
}
return nil, nil, err
}
return c.processPagedQuery(qr.JobReference, qr.PageToken, dataChan, headers, rows)
} | |
c181637 | := bigquery.Job{}
job.Configuration = &jobConfig
jobInsert := service.Jobs.Insert(project, &job)
runningJob, jerr := jobInsert.Do()
if jerr != nil {
c.printDebug("Error inserting job!", jerr)
if dataChan != nil {
dataChan <- Data{Err: jerr}
}
return nil, nil, jerr
}
var qr *bigquery.GetQueryResultsResponse
var rows [][]interface{}
var headers []string
var err error
// Periodically, job references are not created, but errors are also not thrown.
// In this scenario, retry up to 5 times to get a job reference before giving up.
for i := 1; ; i++ {
r := service.Jobs.GetQueryResults(project, runningJob.JobReference.JobId)
r.TimeoutMs(c.RequestTimeout)
qr, err = r.Do()
headers, rows = c.headersAndRows(qr.Schema, qr.Rows)
if i >= maxRequestRetry || qr.JobReference != nil || err != nil {
if i > 1 {
c.printDebug("Took %v tries to get a job reference", i)
}
break
}
}
if err == nil && qr.JobReference == nil {
err = fmt.Errorf("missing job reference")
}
if err != nil {
c.printDebug("Error loading query: ", err)
if dataChan != nil {
dataChan <- Data{Err: err}
}
return nil, nil, err
}
rows, headers, err = c.processPagedQuery(qr.JobReference, qr.PageToken, dataChan, headers, rows)
c.printDebug("largeDataPagedQuery completed in ", time.Now().Sub(ts).Seconds(), "s")
return rows, headers, err
} | |
c181638 | nil {
dataChan <- Data{Err: err}
}
return nil, nil, err
}
if c.allowLargeResults && len(c.tempTableName) > 0 {
return c.largeDataPagedQuery(service, pageSize, dataset, project, queryStr, dataChan)
}
return c.stdPagedQuery(service, pageSize, dataset, project, queryStr, dataChan)
} | |
c181639 |
if qr.JobComplete {
c.printDebug("qr.JobComplete")
headers, rows := c.headersAndRows(qr.Schema, qr.Rows)
if headersChan != nil {
headersChan <- headers
close(headersChan)
}
// send back the rows we got
c.printDebug("sending rows")
resultChan <- rows
rowCount = rowCount + len(rows)
c.printDebug("Total rows: ", rowCount)
}
if qr.TotalRows > uint64(rowCount) || !qr.JobComplete {
c.printDebug("!qr.JobComplete")
if qr.JobReference == nil {
c.pageOverJob(rowCount, jobRef, pageToken, resultChan, headersChan)
} else {
c.pageOverJob(rowCount, qr.JobReference, qr.PageToken, resultChan, nil)
}
} else {
close(resultChan)
return nil
}
return nil
} | |
c181640 | > 0 {
val, _ := strconv.ParseInt(res[0][0].(string), 10, 64)
return val
}
}
return 0
} | |
c181641 | args[2].(Fetcher)
if depth <= 0 {
return crawlResult{}
}
body, urls, err := fetcher.Fetch(url)
return crawlResult{body, urls, err}
} | |
c181642 | nil
job.Err = fmt.Errorf(err.(string))
}
}()
job.Result = job.F(job.Args...)
} | |
c181643 | pool.subworker(job)
pool.done_pipe <- job
}
select {
case <-pool.worker_kill_pipe:
break WORKER_LOOP
default:
}
}
pool.worker_wg.Done()
} | |
c181644 | }
if close_pipe {
close(result_pipe)
} else {
result_pipe <- job
}
// is the pool working or just lazing on a Sunday afternoon?
case working_pipe := <-pool.working_wanted_pipe:
working := true
if pool.jobs_ready_to_run.Len() == 0 && pool.num_jobs_running == 0 {
working = false
}
working_pipe <- working
// stats
case stats_pipe := <-pool.stats_wanted_pipe:
pool_stats := stats{pool.num_jobs_submitted, pool.num_jobs_running, pool.num_jobs_completed}
stats_pipe <- pool_stats
// stopping
case <-pool.supervisor_kill_pipe:
break SUPERVISOR_LOOP
}
}
pool.supervisor_wg.Done()
} | |
c181645 | < uint(pool.num_workers); i++ {
pool.worker_wg.Add(1)
go pool.worker(i)
}
pool.workers_started = true
// handle the supervisor
if !pool.supervisor_started {
pool.startSupervisor()
}
} | |
c181646 | bool), 0, pool.getNextJobId()}
pool.add_pipe <- job
<-job.added
} | |
c181647 | break
}
time.Sleep(pool.interval * time.Millisecond)
}
} | |
c181648 | = e.Next() {
res[i] = e.Value.(*Job)
i++
}
pool.jobs_completed = list.New()
return
} | |
c181649 | if !ok {
// no more results available
return nil
}
if job == (*Job)(nil) {
// no result available right now but there are jobs running
time.Sleep(pool.interval * time.Millisecond)
} else {
break
}
}
return job
} | |
c181650 | }
// the supervisor wasn't started so we return a zeroed structure
return stats{}
} | |
c181651 | := func(ctx *Context) error {
f(ctx.Response, ctx.Request)
return nil
}
return newF
} | |
c181652 | websocket.Handler(f)
return WrapHTTPHandlerFunc(h.ServeHTTP)
} | |
c181653 | header.Set("Content-Type", contentType)
return staticFile{filename, header}
} | |
c181654 |
}
if contentType == "" {
contentType = mime.TypeByExtension(path.Ext(filename))
}
header := make(http.Header)
header.Set("Content-Type", contentType)
return preloadFile{body, header}, nil
} | |
c181655 | = html.ParseGlob(pattern)
return
} | |
c181656 | = text.ParseGlob(pattern)
return nil
} | |
c181657 | charSet = CharSetUTF8
}
header := make(http.Header)
header.Set("Content-Type",
fmt.Sprintf("%s; charset=%s", contentType, charSet))
return template{&htmlTemp, name, header}
} | |
c181658 | charSet = CharSetUTF8
}
header := make(http.Header)
header.Set("Content-Type",
fmt.Sprintf("%s; charset=%s", contentType, charSet))
return template{&textTemp, name, header}
} | |
c181659 | {
select {
case <-watcher.Events:
if err := f(pattern); err != nil {
ef(err)
}
case err := <-watcher.Errors:
if ef != nil {
ef(err)
}
case <-watcher.closer:
break
}
}
}()
var matches []string
matches, err = filepath.Glob(pattern)
if err != nil {
return
}
for _, v := range matches {
if err = watcher.Add(v); err != nil {
return
}
}
return
} | |
c181660 |
watcher.closer <- true
}
return watcher.Close()
} | |
c181661 | }
for e := rs.l.Front(); e != nil; e = e.Next() {
s := e.Value.(struct {
r router.Router
v view.View
h HandlerFunc
})
if params, ok := s.r.Match(path); ok {
return params, s.h, s.v
}
}
return nil, nil, nil
} | |
c181662 | path
if sr, ok := r.(*router.Base); ok {
rs.s[sr.Path] = s
return
}
rs.l.PushFront(s)
} | |
c181663 | v view.View
h HandlerFunc
}),
l: list.New(),
}
} | |
c181664 |
}{view.Simple(view.ContentTypePlain, view.CharSetUTF8), defaultNotFound}
return &ServerMux{NewRouters(), nil, nil, nil, nf}
} | |
c181665 | nil {
mux.ErrorHandle(err)
}
} | |
c181666 | h HandlerFunc, v view.View) {
mux.routers.Add(r, h, v)
} | |
c181667 | {
ctx.Response.Status = http.StatusInternalServerError
}
ctx.Response.Data = err.Error()
mux.err(err)
return true
} | |
c181668 | = code
ctx.Response.Data = url
} | |
c181669 | WrapHTTPHandlerFunc(http.HandlerFunc(pprof.Profile)), nil)
mux.HandleFunc(router.Simple(fmt.Sprintf("%s/symbol", prefix)),
WrapHTTPHandlerFunc(http.HandlerFunc(pprof.Symbol)), nil)
} | |
c181670 | (err error) {
ctx.Session, err = f(ctx.Response, ctx.Request)
return
} | |
c181671 | for sub_comb := range combinations(list[i+1:], select_num-1, buf) {
c <- append([]int{list[i]}, sub_comb...)
}
}
}
}()
return
} | |
c181672 | for sub_comb := range repeated_combinations(list[i:], select_num-1, buf) {
c <- append([]int{list[i]}, sub_comb...)
}
}
}()
return
} | |
c181673 | c <- append([]int{top}, perm...)
}
}
default:
for comb := range combinations(list, select_num, buf) {
for perm := range permutations(comb, select_num, buf) {
c <- perm
}
}
}
}()
return
} | |
c181674 | {
for perm := range repeated_permutations(list, select_num-1, buf) {
c <- append([]int{list[i]}, perm...)
}
}
}
}()
return
} | |
c181675 |
}
// reset format args for new iteration
current_args_runes = current_args_runes[0:0]
}
var name string
if len(current_name_runes) == 0 {
name = "EMPTY_PLACEHOLDER"
} else {
name = string(current_name_runes)
}
// reset name runes for next iteration
current_name_runes = current_name_runes[0:0]
// get value from provided args and append it to new_format_args
val, ok := args[name]
if !ok {
val = fmt.Sprintf("%%MISSING=%s", name)
}
new_format_params = append(new_format_params, val)
// reset flags
in_format = false
in_args = false
case ':':
if in_format {
in_args = true
}
default:
if in_format {
if in_args {
current_args_runes = append(current_args_runes, ch)
} else {
current_name_runes = append(current_name_runes, ch)
}
} else {
new_format = append(new_format, ch)
}
}
}
return string(new_format), new_format_params
} | |
c181676 | a := gformat(format, args)
return fmt.Errorf(f, a...)
} | |
c181677 | gformat(format, args)
return fmt.Fprintf(w, f, a...)
} | |
c181678 | gformat(format, args)
return fmt.Printf(f, a...)
} | |
c181679 | a := gformat(format, args)
return fmt.Sprintf(f, a...)
} | |
c181680 | {
return false, "password is too short"
}
if reqs.Digits < p.Digits {
return false, "password has too few digits"
}
if reqs.Punctuation < p.Punctuation {
return false, "password has too few punctuation characters"
}
if reqs.Uppercase < p.Uppercase {
return false, "password has too few uppercase characters"
}
return true, ""
} | |
c181681 | reqs.Digits++
case unicode.IsUpper(rune(pwd[i])):
reqs.Uppercase++
case unicode.IsPunct(rune(pwd[i])):
reqs.Punctuation++
}
}
return reqs
} | |
c181682 | return false, "maximum required uppercase characters is more than maximum total length"
}
if p.MaximumTotalLength < p.Digits+p.Uppercase+p.Punctuation {
return false, "maximum required digits + uppercase + punctuation is more than maximum total length"
}
return true, ""
} | |
c181683 | req.Punctuation
mustGarble = req.Digits
case req.MinimumTotalLength > req.Digits+req.Punctuation+6:
letters = req.MinimumTotalLength - req.Digits - req.Punctuation
default:
letters = req.MinimumTotalLength
}
if req.Uppercase > letters {
letters = req.Uppercase
}
password := g.garbledSequence(letters, mustGarble)
password = g.uppercase(password, req.Uppercase)
password = g.addNums(password, req.Digits-mustGarble)
password = g.punctuate(password, req.Punctuation)
return password, nil
} | |
c181684 | return "", errors.New("requirements failed validation: " + problems)
}
e := Garbler{}
return e.password(*reqs)
} | |
c181685 |
passes := make([]string, n, n)
for i := 0; i < n; i++ {
passes[i], err = e.password(*reqs)
if err != nil {
return nil, err
}
}
return passes, nil
} | |
c181686 | }
ret += fmt.Sprintf("%d", pow(10, remaining-1)+randInt(pow(10, remaining)-pow(10, remaining-1)))
return ret
} | |
c181687 | else {
ret = string(Punctuation[randInt(len(Punctuation))]) + ret
}
}
return ret
} | |
c181688 | Stdin = NewParamSet(buf)
return
}
}
// else use the first variable in the list
if len(os.Args) > 1 {
buf := bytes.NewBufferString(os.Args[1])
Stdin = NewParamSet(buf)
}
} | |
c181689 | p.params[name] = value
} | |
c181690 |
for key, val := range p.params {
data, ok := raw[key]
if !ok {
continue
}
err := json.Unmarshal(data, val)
if err != nil {
return fmt.Errorf("Unable to unarmshal %s. %s", key, err)
}
}
return nil
} | |
c181691 | json.NewDecoder(p.reader).Decode(v)
} | |
c181692 | {
client := http.Client{
Timeout: timeout,
}
return IHTTPClient(&client)
} | |
c181693 | info *DeviceInfo
err := get(p.httpClient, url, &info, &errResponse)
return info, errResponse, err
} | |
c181694 |
err := post(p.httpClient, url, DevicePresenceRequest{Tokens: deviceID}, &devicePresenceResponse, &pushyErr)
return devicePresenceResponse, pushyErr, err
} | |
c181695 | status *NotificationStatus
err := get(p.httpClient, url, &status, &errResponse)
return status, errResponse, err
} | |
c181696 | pushyErr *Error
err := del(p.httpClient, url, &success, &pushyErr)
return success, pushyErr, err
} | |
c181697 | *Error
err := post(p.httpClient, url, request, &success, &pushyErr)
return success, pushyErr, err
} | |
c181698 | line)
if len(message) > 0 {
error_string += fmt.Sprintf("\n\r\tInfo: %+v", message)
}
t.Errorf(error_string)
t.FailNow()
}
} | |
c181699 | }
// Write the buffer
_, err = fp.Write(buf)
// Cleanup
fp.Close()
return err
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.