id stringlengths 2 7 | text stringlengths 17 51.2k | title stringclasses 1 value |
|---|---|---|
c181700 | = append(f.Errors, e)
} | |
c181701 | {
f.FieldErrors[field] = []string{}
}
f.FieldErrors[field] = append(f.FieldErrors[field], e)
} | |
c181702 | f.FieldErrors {
if len(v) > 0 {
return true
}
}
return false
} | |
c181703 | := FormErrors{}
errors.AddError(e)
return errors
} | |
c181704 |
errors.AddFieldError(field, e)
return errors
} | |
c181705 | 1; i >= 0; i-- {
h = handlers[i](h)
}
return
} | |
c181706 | func(_ http.Handler) http.Handler {
return h
}
} | |
c181707 | s.HashLength {
return "", nil
}
return strings.TrimRight(hex.EncodeToString(h)[:s.HashLength], "="), nil
} | |
c181708 | range h {
found = false
for _, m := range hexChars {
if c == m {
found = true
break
}
}
if !found {
return false
}
}
return true
} | |
c181709 | {
o.fileFindFunc = func(f string) string {
return filepath.Join(dir, f)
}
}
} | |
c181710 | return func(o *Options) { o.fileFindFunc = fn }
} | |
c181711 | func(o *Options) { o.files[name] = files }
} | |
c181712 | := range ts {
o.files[name] = files
}
}
} | |
c181713 | func(o *Options) { o.strings[name] = strings }
} | |
c181714 | range ts {
o.strings[name] = strings
}
}
} | |
c181715 | func(o *Options) { o.functions[name] = fn }
} | |
c181716 | range fns {
o.functions[name] = fn
}
}
} | |
c181717 | o.delimOpen = open
o.delimClose = close
}
} | |
c181718 | tpl, err := parseStrings(template.New("").Funcs(o.functions).Delims(o.delimOpen, o.delimClose), strings...)
if err != nil {
return nil, err
}
t.templates[name] = tpl
}
for name, files := range o.files {
fs := []string{}
for _, f := range files {
fs = append(fs, o.fileFindFunc(f))
}
tpl, err := parseFiles(o.fileReadFunc, template.New("").Funcs(o.functions).Delims(o.delimOpen, o.delimClose), fs...)
if err != nil {
return nil, err
}
t.templates[name] = tpl
}
return
} | |
c181719 | }
if t.contentType != "" {
w.Header().Set("Content-Type", t.contentType)
}
if status > 0 {
w.WriteHeader(status)
}
if _, err := buf.WriteTo(w); err != nil {
t.logf("respond %q: %v", name, err)
}
} | |
c181720 |
t.RespondTemplateWithStatus(w, name, templateName, data, 0)
} | |
c181721 | {
t.RespondWithStatus(w, name, data, 0)
} | |
c181722 | tpl.ExecuteTemplate(&buf, templateName, data); err != nil {
return "", err
}
return buf.String(), nil
} | |
c181723 | &http.Server{
Handler: handler,
TLSConfig: o.tlsConfig,
},
},
}
return
} | |
c181724 | conn.LocalAddr().String()
return s.Server.Serve(conn)
} | |
c181725 | return s.Server.Close()
} | |
c181726 | http.ResponseWriter, r *http.Request) {
s.SetQuicHeaders(w.Header())
h.ServeHTTP(w, r)
})
} | |
c181727 | }
xri := r.Header.Get("X-Real-Ip")
if xri != "" {
ips = append(ips, xri)
}
return strings.Join(ips, ", ")
} | |
c181728 | s = "https"
}
if d == domain && rs == s {
h.ServeHTTP(w, r)
return
}
switch {
case s == "http" && p == "80":
p = ""
case s == "https" && p == "443":
p = ""
case port != "":
p = ":" + port
case p != "":
p = ":" + p
}
if d == altDomain {
http.Redirect(w, r, strings.Join([]string{s, "://", domain, p, r.RequestURI}, ""), http.StatusMovedPermanently)
return
}
http.Redirect(w, r, strings.Join([]string{s, "://", domain, p, r.RequestURI}, ""), http.StatusFound)
})
} | |
c181729 |
for _, opt := range opts {
opt(s)
}
return
} | |
c181730 | name: name,
address: address,
})
s.mu.Unlock()
} | |
c181731 | {
if srv.name == name {
return srv.tcpAddr
}
}
return nil
} | |
c181732 | {
if srv.name == name {
return srv.udpAddr
}
}
return nil
} | |
c181733 | srv.Close(); err != nil {
s.logger.Errorf("%s close: %v", srv.label(), err)
}
}(srv)
}
wg.Wait()
return
} | |
c181734 | err := srv.Shutdown(ctx); err != nil {
s.logger.Errorf("%s shutdown: %v", srv.label(), err)
}
}(srv)
}
wg.Wait()
return
} | |
c181735 | con := &conn{
Conn: c,
b: b[0],
e: err,
f: true,
}
if b[0] == 22 {
return tls.Server(con, l.TLSConfig), nil
}
return con, nil
} | |
c181736 | strings.TrimPrefix(r.URL.Path, prefix)
_, err := fs.Open(filename)
if err != nil {
h.ServeHTTP(w, r)
return
}
fileserver.ServeHTTP(w, r)
})
} | |
c181737 | != nil {
r = rr
}
}
if !valid {
h.unauthorized(w, r)
return
}
if h.Handler != nil {
h.Handler.ServeHTTP(w, r)
}
} | |
c181738 | marshal.Duration(o.RetryTimeMax),
RetrySleepMax: marshal.Duration(o.RetrySleepMax),
RetrySleepBase: marshal.Duration(o.RetrySleepBase),
})
} | |
c181739 | v.TLSSkipVerify,
RetryTimeMax: v.RetryTimeMax.Duration(),
RetrySleepMax: v.RetrySleepMax.Duration(),
RetrySleepBase: v.RetrySleepBase.Duration(),
}
return nil
} | |
c181740 | marshal.Duration(o.RetryTimeMax),
RetrySleepMax: marshal.Duration(o.RetrySleepMax),
RetrySleepBase: marshal.Duration(o.RetrySleepBase),
}, nil
} | |
c181741 |
TLSSkipVerify: v.TLSSkipVerify,
RetryTimeMax: v.RetryTimeMax.Duration(),
RetrySleepMax: v.RetrySleepMax.Duration(),
RetrySleepBase: v.RetrySleepBase.Duration(),
}
return nil
} | |
c181742 | level = logging.ERROR
case rl.status >= 400:
level = logging.WARNING
case rl.status >= 300:
level = logging.INFO
case rl.status >= 200:
level = logging.INFO
default:
level = logging.DEBUG
}
logger.Logf(level, "%s \"%s\" \"%v %s %v\" %d %d %f \"%s\" \"%s\"", r.RemoteAddr, xips, r.Method, r.RequestURI, r.Proto, rl.status, rl.size, time.Since(startTime).Seconds(), referrer, userAgent)
})
} | |
c181743 | return func(o *Handler) {
o.panicBody = body
o.panicContentType = contentType
}
} | |
c181744 | func(o *Handler) { o.panicResponseHandler = h }
} | |
c181745 | log.Printf,
}
for _, option := range options {
option(h)
}
return
} | |
c181746 | h.logf("http recovery handler: notify panic: %v", err)
}
}()
if err := h.notifier.Notify(
fmt.Sprint(
"Panic ",
r.Method,
" ",
r.URL.String(),
": ", err,
),
debugMsg,
); err != nil {
h.logf("http recovery handler: notify: %v", err)
}
}()
}
if h.panicResponseHandler != nil {
h.panicResponseHandler.ServeHTTP(w, r)
return
}
if h.panicContentType != "" {
w.Header().Set("Content-Type", h.panicContentType)
}
w.WriteHeader(http.StatusInternalServerError)
if h.panicBody != "" {
fmt.Fprintln(w, h.panicBody)
}
}
}()
h.handler.ServeHTTP(w, r)
} | |
c181747 | value, ok := m[key]; ok {
return value
}
return nil
}
} | |
c181748 | = map[int]func(body []byte) error{}
}
return &MapErrorRegistry{
errors: errors,
handlers: handlers,
}
} | |
c181749 | ok := r.handlers[code]; ok {
return ErrErrorAlreadyRegistered
}
r.errors[code] = err
return nil
} | |
c181750 | {
return nil, ErrErrorAlreadyRegistered
}
err := &Error{
Message: message,
Code: code,
}
r.errors[code] = err
return err, nil
} | |
c181751 | err error) {
if e := r.AddError(code, err); e != nil {
panic(e)
}
} | |
c181752 | *Error {
err, e := r.AddMessageError(code, message)
if e != nil {
panic(e)
}
return err
} | |
c181753 | if _, ok := r.handlers[code]; ok {
return ErrErrorAlreadyRegistered
}
r.handlers[code] = handler
return nil
} | |
c181754 | []byte) error) {
if err := r.AddHandler(code, handler); err != nil {
panic(err)
}
} | |
c181755 | {
return r.handlers[code]
} | |
c181756 | errorRegistry,
KeyHeader: DefaultKeyHeader,
HTTPClient: http.DefaultClient,
}
} | |
c181757 | accept []string) (resp *http.Response, err error) {
return c.RequestContext(nil, method, path, query, body, accept)
} | |
c181758 | "application/json") {
return fmt.Errorf("unsupported content type: %s", contentType)
}
var body []byte
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return
}
if err = JSONUnmarshal(body, &response); err != nil {
return
}
}
return
} | |
c181759 | c.RequestContext(ctx, method, path, query, body, accept)
if err != nil {
return
}
contentType = resp.Header.Get("Content-Type")
data = resp.Body
return
} | |
c181760 | (data io.ReadCloser, contentType string, err error) {
return c.StreamContext(nil, method, path, query, body, accept)
} | |
c181761 | line, col := getLineColFromOffset(data, e.Offset)
return fmt.Errorf("expected json %s value but got %s, line: %d, column: %d", e.Type, e.Value, line, col)
}
return err
}
return nil
} | |
c181762 |
}
if s.TLSConfig != nil {
ln = tls.NewListener(ln, s.TLSConfig)
}
err = s.Server.Serve(ln)
if err == http.ErrServerClosed {
return nil
}
return
} | |
c181763 | return s.Server.Serve(ln)
} | |
c181764 | s.Server.GracefulStop()
return
} | |
c181765 | w.WriteHeader(http.StatusOK)
} else {
w.Header().Set("Content-Type", contentType)
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintln(w, body)
}
}
} | |
c181766 | := range headers {
w.Header().Set(header, value)
}
h.ServeHTTP(w, r)
})
} | |
c181767 | }
return &Server{
Options: *options,
root: root,
dir: dir,
hashes: map[string]string{},
mu: &sync.RWMutex{},
}
} | |
c181768 | _, err = s.hashFromFilename(p)
}
if err != nil {
return "", err
}
}
return path.Join(s.root, s.hashedPath(p, h)), nil
} | |
c181769 | }
for _, option := range options {
option(s)
}
if s.store == nil {
s.store = NewMemoryStore()
}
return
} | |
c181770 | }
w.Header().Set("Content-Type", HTMLContentType)
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintln(w, s.HTML.Body)
return
}
h.ServeHTTP(w, r)
})
} | |
c181771 | return s.store.Status()
} | |
c181772 | status: %s", err)
jsonInternalServerErrorResponse(w)
return
}
jsonStatusResponse(w, on)
} | |
c181773 |
}
if changed {
s.logger.Infof("maintenance on")
jsonCreatedResponse(w)
return
}
jsonOKResponse(w)
} | |
c181774 | jsonInternalServerErrorResponse(w)
return
}
if changed {
s.logger.Infof("maintenance off")
}
jsonOKResponse(w)
} | |
c181775 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181776 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181777 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181778 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181779 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181780 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181781 |
return errors.New("TriggerHookResponse: UnmarshalJSON on nil pointer")
}
*this = append((*this)[0:0], data...)
return nil
} | |
c181782 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181783 | json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181784 | json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181785 | json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181786 | discussion.
return nil, errors.New("queue.Time.MarshalJSON: year outside of range [0,9999]")
}
return []byte(`"` + t.String() + `"`), nil
} | |
c181787 | err = time.Parse(`"`+time.RFC3339+`"`, string(data))
*t = Time(*x)
return
} | |
c181788 | buf2
}
if minCap > len(rws.buf) {
rws.buf = rws.buf[:minCap]
}
copy(rws.buf[rws.pos:], p)
rws.pos += len(p)
return len(p), nil
} | |
c181789 | = len(rws.buf) + offs
}
if newPos < 0 {
return 0, errors.New("negative result pos")
}
rws.pos = newPos
return int64(newPos), nil
} | |
c181790 | }
n = copy(b, rws.buf[rws.pos:])
rws.pos += n
return
} | |
c181791 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181792 | := json.RawMessage(*this)
return (&x).MarshalJSON()
} | |
c181793 | project,
// making sure that ` + "`${GOPATH}/bin` is in your `PATH`" + `:
//
// go install && go generate
//
// This package was generated from the schema defined at
// ` + apiDefs[i].URL + `
`
content += apiDefs[i].generateAPICode()
sourceFile := filepath.Join(apiDefs[i].PackagePath, apiDefs[i].PackageName+".go")
FormatSourceAndSave(sourceFile, []byte(content))
}
content := "Generated: " + strconv.FormatInt(downloadedTime.Unix(), 10) + "\n"
content += "The following file is an auto-generated static dump of the API models at time of code generation.\n"
content += "It is provided here for reference purposes, but is not used by any code.\n"
content += "\n"
for i := range apiDefs {
content += text.Underline(apiDefs[i].URL)
content += apiDefs[i].Data.String() + "\n\n"
for _, url := range apiDefs[i].schemas.SortedSanitizedURLs() {
content += text.Underline(url)
content += apiDefs[i].schemas.SubSchema(url).String() + "\n\n"
}
}
exitOnFail(ioutil.WriteFile(modelData, []byte(content), 0644))
} | |
c181794 |
entry.OutputURL = tcurls.Schema(tcclient.RootURLFromEnvVars(), entry.Parent.ServiceName, entry.Output)
*x = append(*x, entry.OutputURL)
}
} | |
c181795 | ...string) (tempCreds *Credentials, err error) {
return permaCreds.CreateNamedTemporaryCredentials("", duration, scopes...)
} | |
c181796 | fmt.Errorf("Cannot parse url: '%v', is BaseURL (%v) set correctly?\n%v\n", URL, client.BaseURL, err)
}
if query != nil {
u.RawQuery = query.Encode()
}
return
} | |
c181797 | Key: c.AccessToken,
Hash: sha256.New,
}
reqAuth := hawk.NewRequestAuth(req, credentials, 0)
reqAuth.Ext, err = getExtHeader(c)
if err != nil {
return fmt.Errorf("Internal error: was not able to generate hawk ext header from provided credentials:\n%s\n%s", c, err)
}
req.Header.Set("Authorization", reqAuth.RequestHeader())
return nil
} | |
c181798 | err,
}
}
// if result is passed in as nil, it means the API defines no response body
// json
if reflect.ValueOf(result).IsValid() && !reflect.ValueOf(result).IsNil() {
err = json.Unmarshal([]byte(callSummary.HTTPResponseBody), &result)
}
if err != nil {
return result,
callSummary,
&APICallException{
CallSummary: callSummary,
RootCause: err,
}
}
return result, callSummary, nil
} | |
c181799 | != nil {
return
}
reqAuth.Ext, err = getExtHeader(client.Credentials)
if err != nil {
return
}
bewitSignature := reqAuth.Bewit()
if query == nil {
query = url.Values{}
}
query.Set("bewit", bewitSignature)
u.RawQuery = query.Encode()
return
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.