id stringlengths 2 7 | text stringlengths 17 51.2k | title stringclasses 1 value |
|---|---|---|
c172000 |
ok = true
}
default:
switch {
case l.indent == parent.Base().ln.indent+1:
ok = true
case l.indent > parent.Base().ln.indent+1:
err = fmt.Errorf("the indent is invalid [file: %s][line: %d]", l.fileName(), l.no)
}
}
return ok, err
} | |
c172001 | indent: indent(str),
tokens: strings.Split(strings.TrimLeft(str, space), space),
opts: opts,
file: f,
}
} | |
c172002 | {
break
}
i++
}
return i / 2
} | |
c172003 | }
if opts.NoCloseTagNames == nil {
opts.NoCloseTagNames = make([]string, len(defaultNoCloseTagNames))
copy(opts.NoCloseTagNames, defaultNoCloseTagNames)
}
if opts.Indent != "" {
opts.formatter = newFormatter(opts.Indent)
}
return opts
} | |
c172004 | append(opts.NoCloseTagNames, name)
} | |
c172005 | n := range opts.NoCloseTagNames {
if n != name {
newset = append(newset, n)
}
}
opts.NoCloseTagNames = newset
} | |
c172006 | return nil, fmt.Errorf("Asset %s not found", name)
} | |
c172007 | *Options) *action {
return &action{
elementBase: newElementBase(ln, rslt, src, parent, opts),
}
} | |
c172008 |
// TODO
if err := n.AddTransport(r.Transport()); err != nil {
log.Error("failed to add relay transport:", err)
} else if err := n.Listen(r.Listener().Multiaddr()); err != nil {
log.Error("failed to listen on relay transport:", err)
}
return nil
} | |
c172009 | = true
case OptDiscovery:
r.discovery = true
default:
return nil, fmt.Errorf("unrecognized option: %d", opt)
}
}
h.SetStreamHandler(ProtoID, r.handleNewStream)
if r.discovery {
h.Network().Notify(r.notifiee())
}
return r, nil
} | |
c172010 | json.NewDecoder(r).Decode(&v); err != nil {
return nil, err
}
return v, nil
} | |
c172011 |
// capture environment variables by default
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
r.vars[pair[0]] = parse.ParseValue([]byte(pair[1]))
}
return r
} | |
c172012 | {
for _, group := range groups {
r.runGroup(group)
}
} | |
c172013 | != nil {
return err
}
groups = append(groups, gs...)
return nil
}(file); err != nil {
return nil, err
}
}
return groups, nil
} | |
c172014 | parse the detail now
var d *Detail
if linetype == LineTypeDetail || linetype == LineTypeParam {
var err error
d, err = parseDetail(text, rx)
if err != nil {
return nil, &ErrLine{N: n, Err: err}
}
}
return &Line{
Number: n,
Type: linetype,
Bytes: text,
Regexp: rx,
Comment: comment,
detail: d,
}, nil
} | |
c172015 | len(matches) < 2 {
return ""
}
return string(matches[1])
} | |
c172016 | line.Bytes)
}
return bytes.Join(lines, []byte("\n"))
} | |
c172017 | string
valStr := fmt.Sprintf("%v", val)
if regex.Match([]byte(valStr)) {
return true
}
}
return fmt.Sprintf("%v", v.Data) == fmt.Sprintf("%v", val)
} | |
c172018 |
if isRegex(str) {
return "regex"
}
return "string"
} | |
c172019 |
r.Path("/hello").Methods("GET").HandlerFunc(handleHello)
return r
} | |
c172020 | json.MarshalIndent(input, "", indentStr)
if err != nil {
return err
}
_, err = fmt.Println(string(data))
return err
} | |
c172021 | err := json.MarshalIndent(data, "", indent)
if err != nil {
return ""
}
return string(buffer)
} | |
c172022 |
hash.Write([]byte(data))
return fmt.Sprintf("%x", hash.Sum(nil))
} | |
c172023 | sha1.Sum([]byte(data))
return base64.StdEncoding.EncodeToString(hash[:])
} | |
c172024 | i++ {
if i > 0 {
buffer.WriteString(sep)
}
buffer.WriteString(fmt.Sprintf(format, v.Index(i).Interface()))
}
return buffer.String()
} | |
c172025 | {
if i > 0 {
buffer.WriteString(sep)
}
buffer.WriteString(fmt.Sprint(v.Index(i).Interface()))
}
return buffer.String()
} | |
c172026 | _ := strconv.Atoi(ni)
intj, _ := strconv.Atoi(nj)
return inti < intj
} else {
return len(ni) < len(nj)
}
}
return bi < bj
} | |
c172027 |
s[i], s[j] = s[j], s[i]
} | |
c172028 | := 0; i < size; i++ {
result[i] = f(data[i])
}
return result
} | |
c172029 | {
if f(element) {
result = append(result, element)
}
}
return result
} | |
c172030 |
if end == -1 {
return "", s, false
}
return between[:end], s[begin+len(start)+end+len(stop):], true
} | |
c172031 | -1 {
return s, false
}
return s[i+len(token):], true
} | |
c172032 | io.ReadFull(rand.Reader, iv); err != nil {
panic(err)
}
stream := cipher.NewCFBEncrypter(block, iv)
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)
return ciphertext
} | |
c172033 |
ciphertext = ciphertext[aes.BlockSize:]
stream := cipher.NewCFBDecrypter(block, iv)
// XORKeyStream can work in-place if the two arguments are the same.
stream.XORKeyStream(ciphertext, ciphertext)
return ciphertext
} | |
c172034 | because of error: %s\nAt:\n%s\n", err, StackTrace(2)))
}
}
} | |
c172035 | ok {
return err
}
return fmt.Errorf("%v", r)
} | |
c172036 | nil {
return err
}
}
return nil
} | |
c172037 | i >= 0; i-- {
err := errs[i]
if err != nil {
return err
}
}
return nil
} | |
c172038 | ok := err.(ErrorList); ok {
return list
}
return ErrorList{err}
} | |
c172039 | _, err := range list {
fmt.Fprintln(&b, err)
}
return b.String()
} | |
c172040 | len(list) == 0 {
return nil
}
return list[len(list)-1]
} | |
c172041 | := a.(error); err != nil {
*list = append(*list, err)
}
}
} | |
c172042 |
NewHTTPCompressHandlerFromFunc(handlerFunc).ServeHTTP(response, request)
}
} | |
c172043 | err == nil && (response.StatusCode < 200 || response.StatusCode > 299) {
err = errors.New(response.Status)
}
return err
} | |
c172044 | := http.DefaultClient.Do(request)
if err != nil {
return 0, "", err
}
return response.StatusCode, response.Status, nil
} | |
c172045 | request.Body.Close()
body, err := ioutil.ReadAll(request.Body)
if err != nil {
return err
}
return json.Unmarshal(body, result)
} | |
c172046 | writer, _ = flate.NewWriter(dst, flate.BestCompression)
}
return writer
} | |
c172047 | *flate.Writer) {
writer.Close()
pool.pool.Put(writer)
} | |
c172048 | nil {
writer = w.(*gzip.Writer)
writer.Reset(dst)
} else {
writer, _ = gzip.NewWriterLevel(dst, gzip.BestCompression)
}
return writer
} | |
c172049 | *gzip.Writer) {
writer.Close()
pool.pool.Put(writer)
} | |
c172050 | }
if c == '\n' {
if i != lastR+1 {
l := string(data[lastN+1 : i])
lines = append(lines, l)
}
lastN = i
}
}
l := string(data[lastN+1:])
lines = append(lines, l)
return lines, nil
} | |
c172051 | != nil {
return "", err
}
} else {
file, err := os.Open(filenameOrURL)
if err != nil {
return "", err
}
defer file.Close()
info, err := file.Stat()
if err != nil {
return "", err
}
if start := info.Size() - 64*1024; start > 0 {
file.Seek(start, os.SEEK_SET)
}
data, err = ioutil.ReadAll(file)
if err != nil {
return "", err
}
}
pos := bytes.LastIndex(data, []byte{'\n'})
return string(data[pos+1:]), nil
} | |
c172052 | os.Stat(filename)
if err != nil {
return 0
}
return info.Size()
} | |
c172053 | string(data[begin:end]))
begin = i + 1
if len(lines) == numLines {
break
}
}
}
if len(lines) != numLines {
lines = append(lines, string(data[begin:]))
begin = len(data)
}
return lines, data[begin:]
} | |
c172054 | 0; i < size; i++ {
result[i] = f(data[i])
}
return result
} | |
c172055 | 0)
for _, element := range data {
if f(element) {
result = append(result, element)
}
}
return result
} | |
c172056 | _, err := fmt.Sscan(value, f.Addr().Interface())
if err != nil {
return err
}
}
} else {
return fmt.Errorf("%T has no struct field '%s'", v.Interface(), name)
}
return nil
} | |
c172057 |
countingReader := CountingReader{Reader: r}
err = binary.Read(&countingReader, order, data)
return countingReader.BytesRead, err
} | |
c172058 | n = 0; n < dataSize; {
m, err := writer.Write(data[n:])
n += m
if err != nil {
return n, err
}
}
return dataSize, nil
} | |
c172059 | data := buffer.Bytes()
if len(data) > 0 && data[len(data)-1] == '\r' {
data = data[:len(data)-1]
}
return string(data), err
} | |
c172060 | make([]byte, 1)
os.Stdin.Read(buffer)
return buffer[0]
} | |
c172061 | {
return defaultValue
}
return ret
} | |
c172062 |
}
for _, addr := range addrs {
ip := addr.String()
if ip != "127.0.0.1" {
return ip
}
}
return ""
} | |
c172063 | !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
}
}
}
return ""
} | |
c172064 | loadWithFunc(conf, configPaths, nil, yaml.Unmarshal)
} | |
c172065 | loadWithFunc(conf, configPaths, nil, json.Unmarshal)
} | |
c172066 | loadWithFunc(conf, configPaths, nil, toml.Unmarshal)
} | |
c172067 | loadConfigBytes(conf, src, nil, yaml.Unmarshal)
} | |
c172068 | loadConfigBytes(conf, src, nil, json.Unmarshal)
} | |
c172069 | loadConfigBytes(conf, src, nil, toml.Unmarshal)
} | |
c172070 | loadWithFunc(conf, configPaths, envReplacer, json.Unmarshal)
} | |
c172071 | loadWithFunc(conf, configPaths, envReplacer, toml.Unmarshal)
} | |
c172072 | loadConfigBytes(conf, src, envReplacer, yaml.Unmarshal)
} | |
c172073 | loadConfigBytes(conf, src, envReplacer, json.Unmarshal)
} | |
c172074 | loadConfigBytes(conf, src, envReplacer, toml.Unmarshal)
} | |
c172075 | c.computedCropArea(img.Bounds(), size)
cr = img.Bounds().Intersect(cr)
if c.Options&Copy == Copy {
return cropWithCopy(img, cr)
}
if dImg, ok := img.(subImageSupported); ok {
return dImg.SubImage(cr), nil
}
return cropWithCopy(img, cr)
} | |
c172076 |
if float64(ratio.X)/float64(bounds.Dx()) > float64(ratio.Y)/float64(bounds.Dy()) {
p = image.Point{bounds.Dx(), (bounds.Dx() / ratio.X) * ratio.Y}
} else {
p = image.Point{(bounds.Dy() / ratio.Y) * ratio.X, bounds.Dy()}
}
} else {
p = image.Point{ratio.X, ratio.Y}
}
return
} | |
c172077 | default: // TopLeft
rMin := image.Point{min.X + c.Anchor.X, min.Y + c.Anchor.Y}
r = image.Rect(rMin.X, rMin.Y, rMin.X+size.X, rMin.Y+size.Y)
}
return
} | |
c172078 | &gitCmd{command: command, args: args}
} | |
c172079 | background: true, haltChan: make(chan struct{})}
} | |
c172080 |
return g.command + " " + strings.Join(g.args, " ")
} | |
c172081 | return g.execBackground(dir)
}
return g.exec(dir)
} | |
c172082 | := g.monitoring
g.RUnlock()
if monitoring {
g.haltChan <- struct{}{}
}
} | |
c172083 |
cmd.Stdout(os.Stderr)
cmd.Stderr(os.Stderr)
cmd.Dir(dir)
if err := cmd.Start(); err != nil {
return err
}
return cmd.Wait()
} | |
c172084 | output, err := cmd.Output(); err == nil {
return string(bytes.TrimSpace(output)), nil
}
return "", err
} | |
c172085 | neither is found, return error.
shell = "bash"
if _, err = gos.LookPath("bash"); err != nil {
shell = "sh"
if _, err = gos.LookPath("sh"); err != nil {
return fmt.Errorf("git middleware requires either bash or sh")
}
}
return nil
} | |
c172086 | err
}
if err = file.Chmod(os.FileMode(0755)); err != nil {
return nil, err
}
return file, file.Close()
} | |
c172087 | chmod +x {tmp_dir}/.git_ssh.$$
export GIT_SSH={tmp_dir}/.git_ssh.$$
fi
# in case the git command is repeated
[ "$1" = "git" ] && shift
# Run the git command
{git_binary} "$@"
`
replacer := strings.NewReplacer(
"{shell}", shell,
"{tmp_dir}", strings.TrimSuffix(gos.TempDir(), "/"),
"{git_binary}", gitBinary,
)
return []byte(replacer.Replace(scriptTemplate))
} | |
c172088 | -i {ssh_key_path} {ssh_params};
`
replacer := strings.NewReplacer(
"{shell}", shell,
"{repo_host}", repo.Host,
"{git_ssh_path}", gitSSHPath,
"{ssh_key_path}", repo.KeyPath,
"{ssh_params}", strings.Join(params, " "),
)
return []byte(replacer.Replace(scriptTemplate))
} | |
c172089 |
if token != secret {
return errors.New("Unable to verify request. The token and specified secret do not match!")
}
}
}
return nil
} | |
c172090 | return http.StatusRequestTimeout, errors.New("could not read body from request")
}
err = g.handlePush(body, repo)
if err != nil {
return http.StatusBadRequest, err
}
return http.StatusOK, nil
} | |
c172091 |
mac.Write(body)
expectedMac := hex.EncodeToString(mac.Sum(nil))
if signature[5:] != expectedMac {
return errors.New("could not verify request signature. The signature is invalid")
}
}
}
return nil
} | |
c172092 |
// ensure the functions are executed once per server block
// for cases like server1.com, server2.com { ... }
c.OncePerServerBlock(func() error {
for i := range startupFuncs {
c.OnStartup(startupFuncs[i])
}
return nil
})
// if there are repo(s) with webhook
// return handler
if len(hookRepos) > 0 {
webhook := &WebHook{Repos: hookRepos}
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
webhook.Next = next
return webhook
})
}
return nil
} | |
c172093 | scheme is required", urlParts[0])
default:
if private {
repoURL = "ssh://" + repoURL
} else {
repoURL = "https://" + repoURL
}
}
u, err := url.Parse(repoURL)
if err != nil {
return nil, err
}
return u, nil
} | |
c172094 | if err != nil {
Logger().Println(err)
}
case <-s.halt:
s.ticker.Stop()
return
}
}
}(service)
// add to services to make it stoppable
Services.add(service)
} | |
c172095 |
s.services = append(s.services, r)
} | |
c172096 |
if i < len(g) {
return g[i]
}
return nil
} | |
c172097 | {
return string(r)
}
if u.User != nil {
u.User = url.User(u.User.Username())
}
return u.String()
} | |
c172098 | return strings.TrimPrefix(string(r), "ssh://")
}
return string(r)
} | |
c172099 | break
}
Logger().Println(err)
}
if err != nil {
return err
}
// check if there are new changes,
// then execute post pull command
if r.lastCommit == lastCommit {
Logger().Println("No new changes.")
return nil
}
return r.execThen()
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.