id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,600 | xyproto/cookie | cookie.go | SetHeader | func SetHeader(w http.ResponseWriter, hdr, val string, unique bool) {
if unique {
w.Header().Set(hdr, val)
} else {
w.Header().Add(hdr, val)
}
} | go | func SetHeader(w http.ResponseWriter, hdr, val string, unique bool) {
if unique {
w.Header().Set(hdr, val)
} else {
w.Header().Add(hdr, val)
}
} | [
"func",
"SetHeader",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"hdr",
",",
"val",
"string",
",",
"unique",
"bool",
")",
"{",
"if",
"unique",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"hdr",
",",
"val",
")",
"\n",
"}",
"else",
"{",
... | // SetHeader sets cookies in the HTTP header | [
"SetHeader",
"sets",
"cookies",
"in",
"the",
"HTTP",
"header"
] | f4de411f45ff7eb4e4b9310f783951c35cf01711 | https://github.com/xyproto/cookie/blob/f4de411f45ff7eb4e4b9310f783951c35cf01711/cookie.go#L137-L143 |
149,601 | kylemcc/twitter-text-go | extract/extract.go | ExtractEntities | func ExtractEntities(text string) []*TwitterEntity {
var result entitiesT
result = ExtractUrls(text)
result = append(result, ExtractHashtags(text)...)
result = append(result, ExtractMentionsOrLists(text)...)
result = append(result, ExtractCashtags(text)...)
sort.Sort(result)
result.removeOverlappingEntities()
... | go | func ExtractEntities(text string) []*TwitterEntity {
var result entitiesT
result = ExtractUrls(text)
result = append(result, ExtractHashtags(text)...)
result = append(result, ExtractMentionsOrLists(text)...)
result = append(result, ExtractCashtags(text)...)
sort.Sort(result)
result.removeOverlappingEntities()
... | [
"func",
"ExtractEntities",
"(",
"text",
"string",
")",
"[",
"]",
"*",
"TwitterEntity",
"{",
"var",
"result",
"entitiesT",
"\n",
"result",
"=",
"ExtractUrls",
"(",
"text",
")",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"ExtractHashtags",
"(",
"text... | // Extract all usernames, lists, hashtags, and URLs from the
// given text - returned in the order they appear within the
// input string | [
"Extract",
"all",
"usernames",
"lists",
"hashtags",
"and",
"URLs",
"from",
"the",
"given",
"text",
"-",
"returned",
"in",
"the",
"order",
"they",
"appear",
"within",
"the",
"input",
"string"
] | 7f582f6736ec1777a4725aaae652edfd2c28470a | https://github.com/kylemcc/twitter-text-go/blob/7f582f6736ec1777a4725aaae652edfd2c28470a/extract/extract.go#L164-L174 |
149,602 | yudai/umutex | umutex.go | TryLock | func (m UnblockingMutex) TryLock() (result bool) {
select {
case m.C <- true:
return true
default:
return false
}
} | go | func (m UnblockingMutex) TryLock() (result bool) {
select {
case m.C <- true:
return true
default:
return false
}
} | [
"func",
"(",
"m",
"UnblockingMutex",
")",
"TryLock",
"(",
")",
"(",
"result",
"bool",
")",
"{",
"select",
"{",
"case",
"m",
".",
"C",
"<-",
"true",
":",
"return",
"true",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}"
] | // TryLock tries to lock the mutex.
// When the mutex is free at the time, the function locks the mutex and return
// true. Otherwise false will be returned. In the both cases, this function
// doens't block and return the result immediately. | [
"TryLock",
"tries",
"to",
"lock",
"the",
"mutex",
".",
"When",
"the",
"mutex",
"is",
"free",
"at",
"the",
"time",
"the",
"function",
"locks",
"the",
"mutex",
"and",
"return",
"true",
".",
"Otherwise",
"false",
"will",
"be",
"returned",
".",
"In",
"the",
... | 18216d265c6bc72c3bb0ad9c8103d47d530b7003 | https://github.com/yudai/umutex/blob/18216d265c6bc72c3bb0ad9c8103d47d530b7003/umutex.go#L21-L28 |
149,603 | gravitational/form | form.go | Time | func Time(name string, out *time.Time, predicates ...Predicate) Param {
return func(r *http.Request) error {
for _, p := range predicates {
if err := p.Pass(name, r); err != nil {
return err
}
}
v := r.Form.Get(name)
if v == "" {
return nil
}
var t time.Time
if err := t.UnmarshalText([]byte(... | go | func Time(name string, out *time.Time, predicates ...Predicate) Param {
return func(r *http.Request) error {
for _, p := range predicates {
if err := p.Pass(name, r); err != nil {
return err
}
}
v := r.Form.Get(name)
if v == "" {
return nil
}
var t time.Time
if err := t.UnmarshalText([]byte(... | [
"func",
"Time",
"(",
"name",
"string",
",",
"out",
"*",
"time",
".",
"Time",
",",
"predicates",
"...",
"Predicate",
")",
"Param",
"{",
"return",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"for",
"_",
",",
"p",
":=",
"range",
... | // Time extracts duration expressed as in RFC 3339 format | [
"Time",
"extracts",
"duration",
"expressed",
"as",
"in",
"RFC",
"3339",
"format"
] | c4048f792f70d207e6d8b9c1bf52319247f202b8 | https://github.com/gravitational/form/blob/c4048f792f70d207e6d8b9c1bf52319247f202b8/form.go#L95-L113 |
149,604 | gravitational/form | form.go | String | func String(name string, out *string, predicates ...Predicate) Param {
return func(r *http.Request) error {
for _, p := range predicates {
if err := p.Pass(name, r); err != nil {
return err
}
}
*out = r.Form.Get(name)
return nil
}
} | go | func String(name string, out *string, predicates ...Predicate) Param {
return func(r *http.Request) error {
for _, p := range predicates {
if err := p.Pass(name, r); err != nil {
return err
}
}
*out = r.Form.Get(name)
return nil
}
} | [
"func",
"String",
"(",
"name",
"string",
",",
"out",
"*",
"string",
",",
"predicates",
"...",
"Predicate",
")",
"Param",
"{",
"return",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"predicates... | // String extracts the argument by name as is without any changes | [
"String",
"extracts",
"the",
"argument",
"by",
"name",
"as",
"is",
"without",
"any",
"changes"
] | c4048f792f70d207e6d8b9c1bf52319247f202b8 | https://github.com/gravitational/form/blob/c4048f792f70d207e6d8b9c1bf52319247f202b8/form.go#L116-L126 |
149,605 | gravitational/form | form.go | StringSlice | func StringSlice(name string, out *[]string, predicates ...Predicate) Param {
return func(r *http.Request) error {
for _, p := range predicates {
if err := p.Pass(name, r); err != nil {
return err
}
}
*out = make([]string, len(r.Form[name]))
copy(*out, r.Form[name])
return nil
}
} | go | func StringSlice(name string, out *[]string, predicates ...Predicate) Param {
return func(r *http.Request) error {
for _, p := range predicates {
if err := p.Pass(name, r); err != nil {
return err
}
}
*out = make([]string, len(r.Form[name]))
copy(*out, r.Form[name])
return nil
}
} | [
"func",
"StringSlice",
"(",
"name",
"string",
",",
"out",
"*",
"[",
"]",
"string",
",",
"predicates",
"...",
"Predicate",
")",
"Param",
"{",
"return",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"for",
"_",
",",
"p",
":=",
"ra... | // StringSlice extracts the string slice of arguments by name | [
"StringSlice",
"extracts",
"the",
"string",
"slice",
"of",
"arguments",
"by",
"name"
] | c4048f792f70d207e6d8b9c1bf52319247f202b8 | https://github.com/gravitational/form/blob/c4048f792f70d207e6d8b9c1bf52319247f202b8/form.go#L150-L161 |
149,606 | gravitational/form | form.go | Required | func Required() Predicate {
return PredicateFunc(func(param string, r *http.Request) error {
if r.Form.Get(param) == "" {
return &MissingParameterError{Param: param}
}
return nil
})
} | go | func Required() Predicate {
return PredicateFunc(func(param string, r *http.Request) error {
if r.Form.Get(param) == "" {
return &MissingParameterError{Param: param}
}
return nil
})
} | [
"func",
"Required",
"(",
")",
"Predicate",
"{",
"return",
"PredicateFunc",
"(",
"func",
"(",
"param",
"string",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"if",
"r",
".",
"Form",
".",
"Get",
"(",
"param",
")",
"==",
"\"",
"\"",
"{",
... | // Required checker parameter ensures that the parameter is indeed supplied by user
// it returns MissingParameterError when parameter is not present | [
"Required",
"checker",
"parameter",
"ensures",
"that",
"the",
"parameter",
"is",
"indeed",
"supplied",
"by",
"user",
"it",
"returns",
"MissingParameterError",
"when",
"parameter",
"is",
"not",
"present"
] | c4048f792f70d207e6d8b9c1bf52319247f202b8 | https://github.com/gravitational/form/blob/c4048f792f70d207e6d8b9c1bf52319247f202b8/form.go#L216-L223 |
149,607 | janeczku/go-ipset | ipset/ipset.go | Refresh | func (s *IPSet) Refresh(entries []string) error {
tempName := s.Name + "-temp"
err := s.createHashSet(tempName)
if err != nil {
return err
}
for _, entry := range entries {
out, err := exec.Command(ipsetPath, "add", tempName, entry, "-exist").CombinedOutput()
if err != nil {
log.Errorf("error adding entry... | go | func (s *IPSet) Refresh(entries []string) error {
tempName := s.Name + "-temp"
err := s.createHashSet(tempName)
if err != nil {
return err
}
for _, entry := range entries {
out, err := exec.Command(ipsetPath, "add", tempName, entry, "-exist").CombinedOutput()
if err != nil {
log.Errorf("error adding entry... | [
"func",
"(",
"s",
"*",
"IPSet",
")",
"Refresh",
"(",
"entries",
"[",
"]",
"string",
")",
"error",
"{",
"tempName",
":=",
"s",
".",
"Name",
"+",
"\"",
"\"",
"\n",
"err",
":=",
"s",
".",
"createHashSet",
"(",
"tempName",
")",
"\n",
"if",
"err",
"!=... | // Refresh is used to to overwrite the set with the specified entries.
// The ipset is updated on the fly by hot swapping it with a temporary set. | [
"Refresh",
"is",
"used",
"to",
"to",
"overwrite",
"the",
"set",
"with",
"the",
"specified",
"entries",
".",
"The",
"ipset",
"is",
"updated",
"on",
"the",
"fly",
"by",
"hot",
"swapping",
"it",
"with",
"a",
"temporary",
"set",
"."
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L130-L151 |
149,608 | janeczku/go-ipset | ipset/ipset.go | Add | func (s *IPSet) Add(entry string, timeout int) error {
out, err := exec.Command(ipsetPath, "add", s.Name, entry, "timeout", strconv.Itoa(timeout), "-exist").CombinedOutput()
if err != nil {
return fmt.Errorf("error adding entry %s: %v (%s)", entry, err, out)
}
return nil
} | go | func (s *IPSet) Add(entry string, timeout int) error {
out, err := exec.Command(ipsetPath, "add", s.Name, entry, "timeout", strconv.Itoa(timeout), "-exist").CombinedOutput()
if err != nil {
return fmt.Errorf("error adding entry %s: %v (%s)", entry, err, out)
}
return nil
} | [
"func",
"(",
"s",
"*",
"IPSet",
")",
"Add",
"(",
"entry",
"string",
",",
"timeout",
"int",
")",
"error",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"ipsetPath",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"entry",
",",
"\"",
"\... | // Add is used to add the specified entry to the set.
// A timeout of 0 means that the entry will be stored permanently in the set. | [
"Add",
"is",
"used",
"to",
"add",
"the",
"specified",
"entry",
"to",
"the",
"set",
".",
"A",
"timeout",
"of",
"0",
"means",
"that",
"the",
"entry",
"will",
"be",
"stored",
"permanently",
"in",
"the",
"set",
"."
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L172-L178 |
149,609 | janeczku/go-ipset | ipset/ipset.go | Del | func (s *IPSet) Del(entry string) error {
out, err := exec.Command(ipsetPath, "del", s.Name, entry, "-exist").CombinedOutput()
if err != nil {
return fmt.Errorf("error deleting entry %s: %v (%s)", entry, err, out)
}
return nil
} | go | func (s *IPSet) Del(entry string) error {
out, err := exec.Command(ipsetPath, "del", s.Name, entry, "-exist").CombinedOutput()
if err != nil {
return fmt.Errorf("error deleting entry %s: %v (%s)", entry, err, out)
}
return nil
} | [
"func",
"(",
"s",
"*",
"IPSet",
")",
"Del",
"(",
"entry",
"string",
")",
"error",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"ipsetPath",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
",",
"entry",
",",
"\"",
"\"",
")",
".",
"Combined... | // Del is used to delete the specified entry from the set. | [
"Del",
"is",
"used",
"to",
"delete",
"the",
"specified",
"entry",
"from",
"the",
"set",
"."
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L191-L197 |
149,610 | janeczku/go-ipset | ipset/ipset.go | Flush | func (s *IPSet) Flush() error {
out, err := exec.Command(ipsetPath, "flush", s.Name).CombinedOutput()
if err != nil {
return fmt.Errorf("error flushing set %s: %v (%s)", s.Name, err, out)
}
return nil
} | go | func (s *IPSet) Flush() error {
out, err := exec.Command(ipsetPath, "flush", s.Name).CombinedOutput()
if err != nil {
return fmt.Errorf("error flushing set %s: %v (%s)", s.Name, err, out)
}
return nil
} | [
"func",
"(",
"s",
"*",
"IPSet",
")",
"Flush",
"(",
")",
"error",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"ipsetPath",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil... | // Flush is used to flush all entries in the set. | [
"Flush",
"is",
"used",
"to",
"flush",
"all",
"entries",
"in",
"the",
"set",
"."
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L200-L206 |
149,611 | janeczku/go-ipset | ipset/ipset.go | List | func (s *IPSet) List() ([]string, error) {
out, err := exec.Command(ipsetPath, "list", s.Name).CombinedOutput()
if err != nil {
return []string{}, fmt.Errorf("error listing set %s: %v (%s)", s.Name, err, out)
}
r := regexp.MustCompile("(?m)^(.*\n)*Members:\n")
list := r.ReplaceAllString(string(out[:]), "")
retu... | go | func (s *IPSet) List() ([]string, error) {
out, err := exec.Command(ipsetPath, "list", s.Name).CombinedOutput()
if err != nil {
return []string{}, fmt.Errorf("error listing set %s: %v (%s)", s.Name, err, out)
}
r := regexp.MustCompile("(?m)^(.*\n)*Members:\n")
list := r.ReplaceAllString(string(out[:]), "")
retu... | [
"func",
"(",
"s",
"*",
"IPSet",
")",
"List",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"ipsetPath",
",",
"\"",
"\"",
",",
"s",
".",
"Name",
")",
".",
"CombinedOutput",
"(",
... | // List is used to show the contents of a set | [
"List",
"is",
"used",
"to",
"show",
"the",
"contents",
"of",
"a",
"set"
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L209-L217 |
149,612 | janeczku/go-ipset | ipset/ipset.go | DestroyAll | func DestroyAll() error {
initCheck()
out, err := exec.Command(ipsetPath, "destroy").CombinedOutput()
if err != nil {
return fmt.Errorf("error destroying set %s (%s)", err, out)
}
return nil
} | go | func DestroyAll() error {
initCheck()
out, err := exec.Command(ipsetPath, "destroy").CombinedOutput()
if err != nil {
return fmt.Errorf("error destroying set %s (%s)", err, out)
}
return nil
} | [
"func",
"DestroyAll",
"(",
")",
"error",
"{",
"initCheck",
"(",
")",
"\n",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"ipsetPath",
",",
"\"",
"\"",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt... | // DestroyAll is used to destroy the set. | [
"DestroyAll",
"is",
"used",
"to",
"destroy",
"the",
"set",
"."
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L229-L236 |
149,613 | janeczku/go-ipset | ipset/ipset.go | Swap | func Swap(from, to string) error {
out, err := exec.Command(ipsetPath, "swap", from, to).Output()
if err != nil {
return fmt.Errorf("error swapping ipset %s to %s: %v (%s)", from, to, err, out)
}
return nil
} | go | func Swap(from, to string) error {
out, err := exec.Command(ipsetPath, "swap", from, to).Output()
if err != nil {
return fmt.Errorf("error swapping ipset %s to %s: %v (%s)", from, to, err, out)
}
return nil
} | [
"func",
"Swap",
"(",
"from",
",",
"to",
"string",
")",
"error",
"{",
"out",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"ipsetPath",
",",
"\"",
"\"",
",",
"from",
",",
"to",
")",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // Swap is used to hot swap two sets on-the-fly. Use with names of existing sets of the same type. | [
"Swap",
"is",
"used",
"to",
"hot",
"swap",
"two",
"sets",
"on",
"-",
"the",
"-",
"fly",
".",
"Use",
"with",
"names",
"of",
"existing",
"sets",
"of",
"the",
"same",
"type",
"."
] | 499ed3217c4b5a39b31c483b0151aea724adb933 | https://github.com/janeczku/go-ipset/blob/499ed3217c4b5a39b31c483b0151aea724adb933/ipset/ipset.go#L239-L245 |
149,614 | lestrrat-go/tcputil | tcputil.go | EmptyPort | func EmptyPort() (int, error) {
for p := 50000 + rand.Intn(1000); p < 60000; p++ {
l, e := net.Listen("tcp", fmt.Sprintf(":%d", p))
if e == nil {
// yey!
l.Close()
return p, nil
}
}
return 0, errors.New("error: Could not find an available port")
} | go | func EmptyPort() (int, error) {
for p := 50000 + rand.Intn(1000); p < 60000; p++ {
l, e := net.Listen("tcp", fmt.Sprintf(":%d", p))
if e == nil {
// yey!
l.Close()
return p, nil
}
}
return 0, errors.New("error: Could not find an available port")
} | [
"func",
"EmptyPort",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"for",
"p",
":=",
"50000",
"+",
"rand",
".",
"Intn",
"(",
"1000",
")",
";",
"p",
"<",
"60000",
";",
"p",
"++",
"{",
"l",
",",
"e",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"... | // EmptyPort looks for an empty port to listen on local interface. | [
"EmptyPort",
"looks",
"for",
"an",
"empty",
"port",
"to",
"listen",
"on",
"local",
"interface",
"."
] | d3c7f98154fbd76b67d9a534c5032fb60a546803 | https://github.com/lestrrat-go/tcputil/blob/d3c7f98154fbd76b67d9a534c5032fb60a546803/tcputil.go#L12-L23 |
149,615 | lestrrat-go/tcputil | tcputil.go | WaitPort | func WaitPort(addr string, dur time.Duration) error {
timeout := time.Now().Add(dur)
for time.Now().Before(timeout) {
c, e := net.Dial("tcp", addr)
if e == nil {
c.Close()
return nil
}
time.Sleep(500 * time.Millisecond)
}
return fmt.Errorf("error: Could not connect to '%s'", addr)
} | go | func WaitPort(addr string, dur time.Duration) error {
timeout := time.Now().Add(dur)
for time.Now().Before(timeout) {
c, e := net.Dial("tcp", addr)
if e == nil {
c.Close()
return nil
}
time.Sleep(500 * time.Millisecond)
}
return fmt.Errorf("error: Could not connect to '%s'", addr)
} | [
"func",
"WaitPort",
"(",
"addr",
"string",
",",
"dur",
"time",
".",
"Duration",
")",
"error",
"{",
"timeout",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"dur",
")",
"\n",
"for",
"time",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"timeout... | // WaitPort waits until you can connect to `addr`, up to `dur` amount of time | [
"WaitPort",
"waits",
"until",
"you",
"can",
"connect",
"to",
"addr",
"up",
"to",
"dur",
"amount",
"of",
"time"
] | d3c7f98154fbd76b67d9a534c5032fb60a546803 | https://github.com/lestrrat-go/tcputil/blob/d3c7f98154fbd76b67d9a534c5032fb60a546803/tcputil.go#L26-L37 |
149,616 | lestrrat-go/tcputil | tcputil.go | WaitLocalPort | func WaitLocalPort(port int, dur time.Duration) error {
return WaitPort(fmt.Sprintf(":%d", port), dur)
} | go | func WaitLocalPort(port int, dur time.Duration) error {
return WaitPort(fmt.Sprintf(":%d", port), dur)
} | [
"func",
"WaitLocalPort",
"(",
"port",
"int",
",",
"dur",
"time",
".",
"Duration",
")",
"error",
"{",
"return",
"WaitPort",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"port",
")",
",",
"dur",
")",
"\n",
"}"
] | // WaitLocalPort until you can connect to `port` on localhost, up to `dur` amount of time | [
"WaitLocalPort",
"until",
"you",
"can",
"connect",
"to",
"port",
"on",
"localhost",
"up",
"to",
"dur",
"amount",
"of",
"time"
] | d3c7f98154fbd76b67d9a534c5032fb60a546803 | https://github.com/lestrrat-go/tcputil/blob/d3c7f98154fbd76b67d9a534c5032fb60a546803/tcputil.go#L40-L42 |
149,617 | mailgun/minheap | minheap.go | UpdateEl | func (mh *MinHeap) UpdateEl(el *Element, priority int) {
heap.Remove(mh, el.index)
el.Priority = priority
heap.Push(mh, el)
} | go | func (mh *MinHeap) UpdateEl(el *Element, priority int) {
heap.Remove(mh, el.index)
el.Priority = priority
heap.Push(mh, el)
} | [
"func",
"(",
"mh",
"*",
"MinHeap",
")",
"UpdateEl",
"(",
"el",
"*",
"Element",
",",
"priority",
"int",
")",
"{",
"heap",
".",
"Remove",
"(",
"mh",
",",
"el",
".",
"index",
")",
"\n",
"el",
".",
"Priority",
"=",
"priority",
"\n",
"heap",
".",
"Pus... | // update modifies the priority and value of an Item in the queue. | [
"update",
"modifies",
"the",
"priority",
"and",
"value",
"of",
"an",
"Item",
"in",
"the",
"queue",
"."
] | 3dbe6c6bf55f94c5efcf460dc7f86830c21a90b2 | https://github.com/mailgun/minheap/blob/3dbe6c6bf55f94c5efcf460dc7f86830c21a90b2/minheap.go#L67-L71 |
149,618 | efritz/watchdog | watcher.go | BlockUntilSuccess | func BlockUntilSuccess(ctx context.Context, retry Retry, backoff backoff.Backoff) bool {
watcher := NewWatcher(retry, backoff)
defer watcher.Stop()
select {
case <-watcher.Start():
return true
case <-ctx.Done():
return false
}
} | go | func BlockUntilSuccess(ctx context.Context, retry Retry, backoff backoff.Backoff) bool {
watcher := NewWatcher(retry, backoff)
defer watcher.Stop()
select {
case <-watcher.Start():
return true
case <-ctx.Done():
return false
}
} | [
"func",
"BlockUntilSuccess",
"(",
"ctx",
"context",
".",
"Context",
",",
"retry",
"Retry",
",",
"backoff",
"backoff",
".",
"Backoff",
")",
"bool",
"{",
"watcher",
":=",
"NewWatcher",
"(",
"retry",
",",
"backoff",
")",
"\n",
"defer",
"watcher",
".",
"Stop",... | // BlockUntilSuccess creates a transient watcher that fires the given retry
// function until success. This method takes a context object which will,
// if canceled, will stop the watcher. Returns if the function succeeds and
// false if the method was canceled. | [
"BlockUntilSuccess",
"creates",
"a",
"transient",
"watcher",
"that",
"fires",
"the",
"given",
"retry",
"function",
"until",
"success",
".",
"This",
"method",
"takes",
"a",
"context",
"object",
"which",
"will",
"if",
"canceled",
"will",
"stop",
"the",
"watcher",
... | 84cf7cb746565c0215dbb138181dd4ac6269194f | https://github.com/efritz/watchdog/blob/84cf7cb746565c0215dbb138181dd4ac6269194f/watcher.go#L70-L80 |
149,619 | efritz/watchdog | watcher.go | NewWatcher | func NewWatcher(retry Retry, backoff backoff.Backoff) Watcher {
return newWatcherWithClock(retry, backoff, glock.NewRealClock())
} | go | func NewWatcher(retry Retry, backoff backoff.Backoff) Watcher {
return newWatcherWithClock(retry, backoff, glock.NewRealClock())
} | [
"func",
"NewWatcher",
"(",
"retry",
"Retry",
",",
"backoff",
"backoff",
".",
"Backoff",
")",
"Watcher",
"{",
"return",
"newWatcherWithClock",
"(",
"retry",
",",
"backoff",
",",
"glock",
".",
"NewRealClock",
"(",
")",
")",
"\n",
"}"
] | // NewWatcher creates a new watcher with the given retry function and
// interval generator. | [
"NewWatcher",
"creates",
"a",
"new",
"watcher",
"with",
"the",
"given",
"retry",
"function",
"and",
"interval",
"generator",
"."
] | 84cf7cb746565c0215dbb138181dd4ac6269194f | https://github.com/efritz/watchdog/blob/84cf7cb746565c0215dbb138181dd4ac6269194f/watcher.go#L84-L86 |
149,620 | monochromegane/conflag | conflag.go | ArgsFrom | func ArgsFrom(conf string, positions ...string) ([]string, error) {
if _, err := os.Stat(conf); err != nil {
return nil, err
}
return parse(conf, positions...)
} | go | func ArgsFrom(conf string, positions ...string) ([]string, error) {
if _, err := os.Stat(conf); err != nil {
return nil, err
}
return parse(conf, positions...)
} | [
"func",
"ArgsFrom",
"(",
"conf",
"string",
",",
"positions",
"...",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"conf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // ArgsFrom make arguments for command-line flag from configuration file. | [
"ArgsFrom",
"make",
"arguments",
"for",
"command",
"-",
"line",
"flag",
"from",
"configuration",
"file",
"."
] | 6d68c9aa4183844ddc1655481798fe4d90d483e9 | https://github.com/monochromegane/conflag/blob/6d68c9aa4183844ddc1655481798fe4d90d483e9/conflag.go#L17-L22 |
149,621 | martini-contrib/oauth2 | oauth2.go | Expired | func (t *token) Expired() bool {
if t == nil {
return true
}
return !t.Token.Valid()
} | go | func (t *token) Expired() bool {
if t == nil {
return true
}
return !t.Token.Valid()
} | [
"func",
"(",
"t",
"*",
"token",
")",
"Expired",
"(",
")",
"bool",
"{",
"if",
"t",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"!",
"t",
".",
"Token",
".",
"Valid",
"(",
")",
"\n",
"}"
] | // Expired returns whether the access token is expired or not. | [
"Expired",
"returns",
"whether",
"the",
"access",
"token",
"is",
"expired",
"or",
"not",
"."
] | 383220cdf3349109f5ced723c921d4d76478176c | https://github.com/martini-contrib/oauth2/blob/383220cdf3349109f5ced723c921d4d76478176c/oauth2.go#L73-L78 |
149,622 | martini-contrib/oauth2 | oauth2.go | Google | func Google(conf *oauth2.Config) martini.Handler {
conf.Endpoint = google.Endpoint
return NewOAuth2Provider(conf)
} | go | func Google(conf *oauth2.Config) martini.Handler {
conf.Endpoint = google.Endpoint
return NewOAuth2Provider(conf)
} | [
"func",
"Google",
"(",
"conf",
"*",
"oauth2",
".",
"Config",
")",
"martini",
".",
"Handler",
"{",
"conf",
".",
"Endpoint",
"=",
"google",
".",
"Endpoint",
"\n",
"return",
"NewOAuth2Provider",
"(",
"conf",
")",
"\n",
"}"
] | // Google returns a new Google OAuth 2.0 backend endpoint. | [
"Google",
"returns",
"a",
"new",
"Google",
"OAuth",
"2",
".",
"0",
"backend",
"endpoint",
"."
] | 383220cdf3349109f5ced723c921d4d76478176c | https://github.com/martini-contrib/oauth2/blob/383220cdf3349109f5ced723c921d4d76478176c/oauth2.go#L91-L94 |
149,623 | plimble/sessions | session.go | GetString | func (s *Session) GetString(key string, def string) string {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(string)
} | go | func (s *Session) GetString(key string, def string) string {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(string)
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetString",
"(",
"key",
"string",
",",
"def",
"string",
")",
"string",
"{",
"v",
",",
"ok",
":=",
"s",
".",
"Values",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"def",
"\n",
"}",
"\n\n",
"retu... | //GetString return string value | [
"GetString",
"return",
"string",
"value"
] | 7047d39da9ad8cbde35a735bb11f68dc69604106 | https://github.com/plimble/sessions/blob/7047d39da9ad8cbde35a735bb11f68dc69604106/session.go#L50-L57 |
149,624 | plimble/sessions | session.go | GetStrings | func (s *Session) GetStrings(key string, def []string) []string {
v, ok := s.Values[key]
if !ok {
return def
}
valinf := v.([]interface{})
vals := make([]string, len(valinf))
for i := 0; i < len(valinf); i++ {
vals[i] = valinf[i].(string)
}
return vals
} | go | func (s *Session) GetStrings(key string, def []string) []string {
v, ok := s.Values[key]
if !ok {
return def
}
valinf := v.([]interface{})
vals := make([]string, len(valinf))
for i := 0; i < len(valinf); i++ {
vals[i] = valinf[i].(string)
}
return vals
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetStrings",
"(",
"key",
"string",
",",
"def",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"v",
",",
"ok",
":=",
"s",
".",
"Values",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"def",
"... | //GetStrings return array string value | [
"GetStrings",
"return",
"array",
"string",
"value"
] | 7047d39da9ad8cbde35a735bb11f68dc69604106 | https://github.com/plimble/sessions/blob/7047d39da9ad8cbde35a735bb11f68dc69604106/session.go#L60-L73 |
149,625 | plimble/sessions | session.go | GetInt | func (s *Session) GetInt(key string, def int64) int64 {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(int64)
} | go | func (s *Session) GetInt(key string, def int64) int64 {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(int64)
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetInt",
"(",
"key",
"string",
",",
"def",
"int64",
")",
"int64",
"{",
"v",
",",
"ok",
":=",
"s",
".",
"Values",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"def",
"\n",
"}",
"\n\n",
"return",
... | //GetInt return int64 value | [
"GetInt",
"return",
"int64",
"value"
] | 7047d39da9ad8cbde35a735bb11f68dc69604106 | https://github.com/plimble/sessions/blob/7047d39da9ad8cbde35a735bb11f68dc69604106/session.go#L76-L83 |
149,626 | plimble/sessions | session.go | GetFloat | func (s *Session) GetFloat(key string, def float64) float64 {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(float64)
} | go | func (s *Session) GetFloat(key string, def float64) float64 {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(float64)
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetFloat",
"(",
"key",
"string",
",",
"def",
"float64",
")",
"float64",
"{",
"v",
",",
"ok",
":=",
"s",
".",
"Values",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"def",
"\n",
"}",
"\n\n",
"ret... | //GetFloat return float64 value | [
"GetFloat",
"return",
"float64",
"value"
] | 7047d39da9ad8cbde35a735bb11f68dc69604106 | https://github.com/plimble/sessions/blob/7047d39da9ad8cbde35a735bb11f68dc69604106/session.go#L102-L109 |
149,627 | plimble/sessions | session.go | GetBool | func (s *Session) GetBool(key string, def bool) bool {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(bool)
} | go | func (s *Session) GetBool(key string, def bool) bool {
v, ok := s.Values[key]
if !ok {
return def
}
return v.(bool)
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"GetBool",
"(",
"key",
"string",
",",
"def",
"bool",
")",
"bool",
"{",
"v",
",",
"ok",
":=",
"s",
".",
"Values",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"def",
"\n",
"}",
"\n\n",
"return",
... | //GetBool return bool value | [
"GetBool",
"return",
"bool",
"value"
] | 7047d39da9ad8cbde35a735bb11f68dc69604106 | https://github.com/plimble/sessions/blob/7047d39da9ad8cbde35a735bb11f68dc69604106/session.go#L128-L135 |
149,628 | gobs/args | args.go | NewScanner | func NewScanner(r io.Reader) *Scanner {
sc := Scanner{in: bufio.NewReader(r)}
return &sc
} | go | func NewScanner(r io.Reader) *Scanner {
sc := Scanner{in: bufio.NewReader(r)}
return &sc
} | [
"func",
"NewScanner",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"Scanner",
"{",
"sc",
":=",
"Scanner",
"{",
"in",
":",
"bufio",
".",
"NewReader",
"(",
"r",
")",
"}",
"\n",
"return",
"&",
"sc",
"\n",
"}"
] | // Creates a new Scanner with io.Reader as input source | [
"Creates",
"a",
"new",
"Scanner",
"with",
"io",
".",
"Reader",
"as",
"input",
"source"
] | 86002b4df18c1c4919c97bd7b7bd46e216fc69c3 | https://github.com/gobs/args/blob/86002b4df18c1c4919c97bd7b7bd46e216fc69c3/args.go#L44-L47 |
149,629 | gobs/args | args.go | NewScannerString | func NewScannerString(s string) *Scanner {
sc := Scanner{in: bufio.NewReader(strings.NewReader(s))}
return &sc
} | go | func NewScannerString(s string) *Scanner {
sc := Scanner{in: bufio.NewReader(strings.NewReader(s))}
return &sc
} | [
"func",
"NewScannerString",
"(",
"s",
"string",
")",
"*",
"Scanner",
"{",
"sc",
":=",
"Scanner",
"{",
"in",
":",
"bufio",
".",
"NewReader",
"(",
"strings",
".",
"NewReader",
"(",
"s",
")",
")",
"}",
"\n",
"return",
"&",
"sc",
"\n",
"}"
] | // Creates a new Scanner with a string as input source | [
"Creates",
"a",
"new",
"Scanner",
"with",
"a",
"string",
"as",
"input",
"source"
] | 86002b4df18c1c4919c97bd7b7bd46e216fc69c3 | https://github.com/gobs/args/blob/86002b4df18c1c4919c97bd7b7bd46e216fc69c3/args.go#L50-L53 |
149,630 | gobs/args | args.go | GetTokens | func (scanner *Scanner) GetTokens() (tokens []string, err error) {
tokens, _, err = scanner.getTokens(0)
return
} | go | func (scanner *Scanner) GetTokens() (tokens []string, err error) {
tokens, _, err = scanner.getTokens(0)
return
} | [
"func",
"(",
"scanner",
"*",
"Scanner",
")",
"GetTokens",
"(",
")",
"(",
"tokens",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"tokens",
",",
"_",
",",
"err",
"=",
"scanner",
".",
"getTokens",
"(",
"0",
")",
"\n",
"return",
"\n",
"}"
] | // Return all tokens as an array of strings | [
"Return",
"all",
"tokens",
"as",
"an",
"array",
"of",
"strings"
] | 86002b4df18c1c4919c97bd7b7bd46e216fc69c3 | https://github.com/gobs/args/blob/86002b4df18c1c4919c97bd7b7bd46e216fc69c3/args.go#L230-L233 |
149,631 | gobs/args | args.go | GetArgs | func GetArgs(line string, options ...GetArgsOption) (args []string) {
scanner := getScanner(line, options...)
args, _, _ = scanner.GetTokensN(0)
return
} | go | func GetArgs(line string, options ...GetArgsOption) (args []string) {
scanner := getScanner(line, options...)
args, _, _ = scanner.GetTokensN(0)
return
} | [
"func",
"GetArgs",
"(",
"line",
"string",
",",
"options",
"...",
"GetArgsOption",
")",
"(",
"args",
"[",
"]",
"string",
")",
"{",
"scanner",
":=",
"getScanner",
"(",
"line",
",",
"options",
"...",
")",
"\n",
"args",
",",
"_",
",",
"_",
"=",
"scanner"... | // Parse the input line into an array of arguments | [
"Parse",
"the",
"input",
"line",
"into",
"an",
"array",
"of",
"arguments"
] | 86002b4df18c1c4919c97bd7b7bd46e216fc69c3 | https://github.com/gobs/args/blob/86002b4df18c1c4919c97bd7b7bd46e216fc69c3/args.go#L323-L327 |
149,632 | gobs/args | args.go | GetArgsN | func GetArgsN(line string, n int, options ...GetArgsOption) []string {
scanner := getScanner(line, options...)
if n > 0 {
n = n - 1
}
args, rest, _ := scanner.GetTokensN(n)
if rest != "" {
args = append(args, rest)
}
return args
} | go | func GetArgsN(line string, n int, options ...GetArgsOption) []string {
scanner := getScanner(line, options...)
if n > 0 {
n = n - 1
}
args, rest, _ := scanner.GetTokensN(n)
if rest != "" {
args = append(args, rest)
}
return args
} | [
"func",
"GetArgsN",
"(",
"line",
"string",
",",
"n",
"int",
",",
"options",
"...",
"GetArgsOption",
")",
"[",
"]",
"string",
"{",
"scanner",
":=",
"getScanner",
"(",
"line",
",",
"options",
"...",
")",
"\n",
"if",
"n",
">",
"0",
"{",
"n",
"=",
"n",... | // Parse the input line into an array of max n arguments | [
"Parse",
"the",
"input",
"line",
"into",
"an",
"array",
"of",
"max",
"n",
"arguments"
] | 86002b4df18c1c4919c97bd7b7bd46e216fc69c3 | https://github.com/gobs/args/blob/86002b4df18c1c4919c97bd7b7bd46e216fc69c3/args.go#L330-L340 |
149,633 | gobs/args | args.go | NewFlags | func NewFlags(name string) *flag.FlagSet {
flags := flag.NewFlagSet(name, flag.ContinueOnError)
flags.Usage = func() {
fmt.Printf("Usage of %s:\n", name)
flags.PrintDefaults()
}
return flags
} | go | func NewFlags(name string) *flag.FlagSet {
flags := flag.NewFlagSet(name, flag.ContinueOnError)
flags.Usage = func() {
fmt.Printf("Usage of %s:\n", name)
flags.PrintDefaults()
}
return flags
} | [
"func",
"NewFlags",
"(",
"name",
"string",
")",
"*",
"flag",
".",
"FlagSet",
"{",
"flags",
":=",
"flag",
".",
"NewFlagSet",
"(",
"name",
",",
"flag",
".",
"ContinueOnError",
")",
"\n\n",
"flags",
".",
"Usage",
"=",
"func",
"(",
")",
"{",
"fmt",
".",
... | // Create a new FlagSet to be used with ParseFlags | [
"Create",
"a",
"new",
"FlagSet",
"to",
"be",
"used",
"with",
"ParseFlags"
] | 86002b4df18c1c4919c97bd7b7bd46e216fc69c3 | https://github.com/gobs/args/blob/86002b4df18c1c4919c97bd7b7bd46e216fc69c3/args.go#L416-L425 |
149,634 | SermoDigital/helpers | helpers.go | Length | func Length(x uint64) int {
// TODO: use math/bits when it's merged in 1.9
// Loop: for loop
// Log10: math.Log10
// Asm: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// with "IntegerLogBase2(v)" in assembly implemented similar to GCC's
// __builtin_clzll.
// Cond: the switch below
//
/... | go | func Length(x uint64) int {
// TODO: use math/bits when it's merged in 1.9
// Loop: for loop
// Log10: math.Log10
// Asm: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// with "IntegerLogBase2(v)" in assembly implemented similar to GCC's
// __builtin_clzll.
// Cond: the switch below
//
/... | [
"func",
"Length",
"(",
"x",
"uint64",
")",
"int",
"{",
"// TODO: use math/bits when it's merged in 1.9",
"// Loop: for loop",
"// Log10: math.Log10",
"// Asm: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10",
"// \twith \"IntegerLogBase2(v)\" in assembly implemented similar... | // Length finds the number of digits in a uint64. For example, 12 returns 2,
// 100 returns 3, and 1776 returns 4. The minimum width is 1. | [
"Length",
"finds",
"the",
"number",
"of",
"digits",
"in",
"a",
"uint64",
".",
"For",
"example",
"12",
"returns",
"2",
"100",
"returns",
"3",
"and",
"1776",
"returns",
"4",
".",
"The",
"minimum",
"width",
"is",
"1",
"."
] | 8de2321850d4bf9f621014337ba3adc613c9cc25 | https://github.com/SermoDigital/helpers/blob/8de2321850d4bf9f621014337ba3adc613c9cc25/helpers.go#L14-L79 |
149,635 | fluxio/multierror | multierror.go | Push | func (m *Accumulator) Push(err error) {
if err == nil {
return
}
// Check for a Accumulator
if e, ok := err.(_error); ok {
*m = append(*m, e...)
return
}
*m = append(*m, err)
} | go | func (m *Accumulator) Push(err error) {
if err == nil {
return
}
// Check for a Accumulator
if e, ok := err.(_error); ok {
*m = append(*m, e...)
return
}
*m = append(*m, err)
} | [
"func",
"(",
"m",
"*",
"Accumulator",
")",
"Push",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// Check for a Accumulator",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"_error",
")",
";",
"ok",
"{",
... | // Push adds an error to the Accumulator. If err is nil, then Accumulator is
// not affected. | [
"Push",
"adds",
"an",
"error",
"to",
"the",
"Accumulator",
".",
"If",
"err",
"is",
"nil",
"then",
"Accumulator",
"is",
"not",
"affected",
"."
] | 9c68d39025e5c354adb4da3d75f3c8ee6f8c6a02 | https://github.com/fluxio/multierror/blob/9c68d39025e5c354adb4da3d75f3c8ee6f8c6a02/multierror.go#L27-L38 |
149,636 | fluxio/multierror | multierror.go | PushWithf | func (m *Accumulator) PushWithf(fmtstr string, err error, args ...interface{}) {
if err != nil {
m.Pushf(fmtstr, append([]interface{}{err}, args...)...)
}
} | go | func (m *Accumulator) PushWithf(fmtstr string, err error, args ...interface{}) {
if err != nil {
m.Pushf(fmtstr, append([]interface{}{err}, args...)...)
}
} | [
"func",
"(",
"m",
"*",
"Accumulator",
")",
"PushWithf",
"(",
"fmtstr",
"string",
",",
"err",
"error",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"m",
".",
"Pushf",
"(",
"fmtstr",
",",
"append",
"(",
"[",
"... | // PushWithf adds a formatted error string to m if err is non-nil. err is
// passed as the first argument to fmtstr, and any additional arguments in args
// are passed as the remaining arguments. | [
"PushWithf",
"adds",
"a",
"formatted",
"error",
"string",
"to",
"m",
"if",
"err",
"is",
"non",
"-",
"nil",
".",
"err",
"is",
"passed",
"as",
"the",
"first",
"argument",
"to",
"fmtstr",
"and",
"any",
"additional",
"arguments",
"in",
"args",
"are",
"passed... | 9c68d39025e5c354adb4da3d75f3c8ee6f8c6a02 | https://github.com/fluxio/multierror/blob/9c68d39025e5c354adb4da3d75f3c8ee6f8c6a02/multierror.go#L49-L53 |
149,637 | kalafut/imohash | imohash.go | SumFile | func SumFile(filename string) ([Size]byte, error) {
imo := New()
return imo.SumFile(filename)
} | go | func SumFile(filename string) ([Size]byte, error) {
imo := New()
return imo.SumFile(filename)
} | [
"func",
"SumFile",
"(",
"filename",
"string",
")",
"(",
"[",
"Size",
"]",
"byte",
",",
"error",
")",
"{",
"imo",
":=",
"New",
"(",
")",
"\n",
"return",
"imo",
".",
"SumFile",
"(",
"filename",
")",
"\n",
"}"
] | // SumFile hashes a file using default sample parameters. | [
"SumFile",
"hashes",
"a",
"file",
"using",
"default",
"sample",
"parameters",
"."
] | c43c235139744e77138dcd0babbcd694c2c17e3e | https://github.com/kalafut/imohash/blob/c43c235139744e77138dcd0babbcd694c2c17e3e/imohash.go#L51-L54 |
149,638 | kalafut/imohash | imohash.go | Sum | func Sum(data []byte) [Size]byte {
imo := New()
return imo.Sum(data)
} | go | func Sum(data []byte) [Size]byte {
imo := New()
return imo.Sum(data)
} | [
"func",
"Sum",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"Size",
"]",
"byte",
"{",
"imo",
":=",
"New",
"(",
")",
"\n",
"return",
"imo",
".",
"Sum",
"(",
"data",
")",
"\n",
"}"
] | // Sum hashes a byte slice using default sample parameters. | [
"Sum",
"hashes",
"a",
"byte",
"slice",
"using",
"default",
"sample",
"parameters",
"."
] | c43c235139744e77138dcd0babbcd694c2c17e3e | https://github.com/kalafut/imohash/blob/c43c235139744e77138dcd0babbcd694c2c17e3e/imohash.go#L57-L60 |
149,639 | kalafut/imohash | imohash.go | Sum | func (imo *ImoHash) Sum(data []byte) [Size]byte {
sr := io.NewSectionReader(bytes.NewReader(data), 0, int64(len(data)))
return imo.hashCore(sr)
} | go | func (imo *ImoHash) Sum(data []byte) [Size]byte {
sr := io.NewSectionReader(bytes.NewReader(data), 0, int64(len(data)))
return imo.hashCore(sr)
} | [
"func",
"(",
"imo",
"*",
"ImoHash",
")",
"Sum",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"Size",
"]",
"byte",
"{",
"sr",
":=",
"io",
".",
"NewSectionReader",
"(",
"bytes",
".",
"NewReader",
"(",
"data",
")",
",",
"0",
",",
"int64",
"(",
"len",
... | // Sum hashes a byte slice using the ImoHash parameters. | [
"Sum",
"hashes",
"a",
"byte",
"slice",
"using",
"the",
"ImoHash",
"parameters",
"."
] | c43c235139744e77138dcd0babbcd694c2c17e3e | https://github.com/kalafut/imohash/blob/c43c235139744e77138dcd0babbcd694c2c17e3e/imohash.go#L63-L67 |
149,640 | kalafut/imohash | imohash.go | SumFile | func (imo *ImoHash) SumFile(filename string) ([Size]byte, error) {
f, err := os.Open(filename)
defer f.Close()
if err != nil {
return emptyArray, err
}
fi, err := f.Stat()
if err != nil {
return emptyArray, err
}
sr := io.NewSectionReader(f, 0, fi.Size())
return imo.hashCore(sr), nil
} | go | func (imo *ImoHash) SumFile(filename string) ([Size]byte, error) {
f, err := os.Open(filename)
defer f.Close()
if err != nil {
return emptyArray, err
}
fi, err := f.Stat()
if err != nil {
return emptyArray, err
}
sr := io.NewSectionReader(f, 0, fi.Size())
return imo.hashCore(sr), nil
} | [
"func",
"(",
"imo",
"*",
"ImoHash",
")",
"SumFile",
"(",
"filename",
"string",
")",
"(",
"[",
"Size",
"]",
"byte",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"defer",
"f",
".",
"Close",
"(",
")... | // SumFile hashes a file using using the ImoHash parameters. | [
"SumFile",
"hashes",
"a",
"file",
"using",
"using",
"the",
"ImoHash",
"parameters",
"."
] | c43c235139744e77138dcd0babbcd694c2c17e3e | https://github.com/kalafut/imohash/blob/c43c235139744e77138dcd0babbcd694c2c17e3e/imohash.go#L70-L84 |
149,641 | kalafut/imohash | imohash.go | hashCore | func (imo *ImoHash) hashCore(f *io.SectionReader) [Size]byte {
var result [Size]byte
imo.hasher.Reset()
if f.Size() < int64(imo.sampleThreshold) || imo.sampleSize < 1 {
buffer := make([]byte, f.Size())
f.Read(buffer)
imo.hasher.Write(buffer)
} else {
buffer := make([]byte, imo.sampleSize)
f.Read(buffer)... | go | func (imo *ImoHash) hashCore(f *io.SectionReader) [Size]byte {
var result [Size]byte
imo.hasher.Reset()
if f.Size() < int64(imo.sampleThreshold) || imo.sampleSize < 1 {
buffer := make([]byte, f.Size())
f.Read(buffer)
imo.hasher.Write(buffer)
} else {
buffer := make([]byte, imo.sampleSize)
f.Read(buffer)... | [
"func",
"(",
"imo",
"*",
"ImoHash",
")",
"hashCore",
"(",
"f",
"*",
"io",
".",
"SectionReader",
")",
"[",
"Size",
"]",
"byte",
"{",
"var",
"result",
"[",
"Size",
"]",
"byte",
"\n\n",
"imo",
".",
"hasher",
".",
"Reset",
"(",
")",
"\n\n",
"if",
"f"... | // hashCore hashes a SectionReader using the ImoHash parameters. | [
"hashCore",
"hashes",
"a",
"SectionReader",
"using",
"the",
"ImoHash",
"parameters",
"."
] | c43c235139744e77138dcd0babbcd694c2c17e3e | https://github.com/kalafut/imohash/blob/c43c235139744e77138dcd0babbcd694c2c17e3e/imohash.go#L87-L114 |
149,642 | codahale/lunk | event.go | Format | func (id EventID) Format(s string, args ...interface{}) string {
args = append([]interface{}{id.String()}, args...)
return fmt.Sprintf(s, args...)
} | go | func (id EventID) Format(s string, args ...interface{}) string {
args = append([]interface{}{id.String()}, args...)
return fmt.Sprintf(s, args...)
} | [
"func",
"(",
"id",
"EventID",
")",
"Format",
"(",
"s",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"args",
"=",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"id",
".",
"String",
"(",
")",
"}",
",",
"args",
"... | // Format formats according to a format specifier and returns the resulting
// string. The receiver's string representation is the first argument. | [
"Format",
"formats",
"according",
"to",
"a",
"format",
"specifier",
"and",
"returns",
"the",
"resulting",
"string",
".",
"The",
"receiver",
"s",
"string",
"representation",
"is",
"the",
"first",
"argument",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/event.go#L55-L58 |
149,643 | codahale/lunk | event.go | NewEventID | func NewEventID(parent EventID) EventID {
return EventID{
Root: parent.Root,
ID: generateID(),
Parent: parent.ID,
}
} | go | func NewEventID(parent EventID) EventID {
return EventID{
Root: parent.Root,
ID: generateID(),
Parent: parent.ID,
}
} | [
"func",
"NewEventID",
"(",
"parent",
"EventID",
")",
"EventID",
"{",
"return",
"EventID",
"{",
"Root",
":",
"parent",
".",
"Root",
",",
"ID",
":",
"generateID",
"(",
")",
",",
"Parent",
":",
"parent",
".",
"ID",
",",
"}",
"\n",
"}"
] | // NewEventID returns a new ID for an event which is the child of the given
// parent ID. This should be used to track causal relationships between events. | [
"NewEventID",
"returns",
"a",
"new",
"ID",
"for",
"an",
"event",
"which",
"is",
"the",
"child",
"of",
"the",
"given",
"parent",
"ID",
".",
"This",
"should",
"be",
"used",
"to",
"track",
"causal",
"relationships",
"between",
"events",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/event.go#L73-L79 |
149,644 | codahale/lunk | event.go | ParseEventID | func ParseEventID(s string) (*EventID, error) {
parts := strings.Split(s, EventIDDelimiter)
if len(parts) != 2 && len(parts) != 3 {
return nil, ErrBadEventID
}
root, err := ParseID(parts[0])
if err != nil {
return nil, ErrBadEventID
}
id, err := ParseID(parts[1])
if err != nil {
return nil, ErrBadEventI... | go | func ParseEventID(s string) (*EventID, error) {
parts := strings.Split(s, EventIDDelimiter)
if len(parts) != 2 && len(parts) != 3 {
return nil, ErrBadEventID
}
root, err := ParseID(parts[0])
if err != nil {
return nil, ErrBadEventID
}
id, err := ParseID(parts[1])
if err != nil {
return nil, ErrBadEventI... | [
"func",
"ParseEventID",
"(",
"s",
"string",
")",
"(",
"*",
"EventID",
",",
"error",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"EventIDDelimiter",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"&&",
"len",
"(",
"parts"... | // ParseEventID parses the given string as a slash-separated set of parameters. | [
"ParseEventID",
"parses",
"the",
"given",
"string",
"as",
"a",
"slash",
"-",
"separated",
"set",
"of",
"parameters",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/event.go#L88-L118 |
149,645 | codahale/lunk | event.go | NewEntry | func NewEntry(id EventID, e Event) Entry {
props := make(map[string]string, 10)
flattenValue("", reflect.ValueOf(e), func(k, v string) {
props[k] = v
})
return Entry{
EventID: id,
Schema: e.Schema(),
Time: time.Now().In(time.UTC),
Host: host,
Deploy: deploy,
PID: pid,
... | go | func NewEntry(id EventID, e Event) Entry {
props := make(map[string]string, 10)
flattenValue("", reflect.ValueOf(e), func(k, v string) {
props[k] = v
})
return Entry{
EventID: id,
Schema: e.Schema(),
Time: time.Now().In(time.UTC),
Host: host,
Deploy: deploy,
PID: pid,
... | [
"func",
"NewEntry",
"(",
"id",
"EventID",
",",
"e",
"Event",
")",
"Entry",
"{",
"props",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"10",
")",
"\n",
"flattenValue",
"(",
"\"",
"\"",
",",
"reflect",
".",
"ValueOf",
"(",
"e",
")",
... | // NewEntry creates a new entry for the given ID and event. | [
"NewEntry",
"creates",
"a",
"new",
"entry",
"for",
"the",
"given",
"ID",
"and",
"event",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/event.go#L145-L160 |
149,646 | codahale/lunk | logger.go | NewSamplingEventLogger | func NewSamplingEventLogger(l EventLogger) *SamplingEventLogger {
return &SamplingEventLogger{
l: l,
r: rand.New(rand.NewSource(time.Now().UnixNano())),
rates: make(map[string]float64),
rootRates: make(map[ID]float64),
m: new(sync.Mutex),
}
} | go | func NewSamplingEventLogger(l EventLogger) *SamplingEventLogger {
return &SamplingEventLogger{
l: l,
r: rand.New(rand.NewSource(time.Now().UnixNano())),
rates: make(map[string]float64),
rootRates: make(map[ID]float64),
m: new(sync.Mutex),
}
} | [
"func",
"NewSamplingEventLogger",
"(",
"l",
"EventLogger",
")",
"*",
"SamplingEventLogger",
"{",
"return",
"&",
"SamplingEventLogger",
"{",
"l",
":",
"l",
",",
"r",
":",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"time",
".",
"Now",
"(",
")"... | // NewSamplingEventLogger returns a new SamplingEventLogger, passing events
// through to the given EventLogger. | [
"NewSamplingEventLogger",
"returns",
"a",
"new",
"SamplingEventLogger",
"passing",
"events",
"through",
"to",
"the",
"given",
"EventLogger",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/logger.go#L45-L53 |
149,647 | codahale/lunk | logger.go | UnsetRootSampleRate | func (l SamplingEventLogger) UnsetRootSampleRate(root ID) {
l.m.Lock()
defer l.m.Unlock()
delete(l.rootRates, root)
} | go | func (l SamplingEventLogger) UnsetRootSampleRate(root ID) {
l.m.Lock()
defer l.m.Unlock()
delete(l.rootRates, root)
} | [
"func",
"(",
"l",
"SamplingEventLogger",
")",
"UnsetRootSampleRate",
"(",
"root",
"ID",
")",
"{",
"l",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"l",
".",
"rootRates",
",",
"root"... | // UnsetRootSampleRate removes any settings for events with the given root ID. | [
"UnsetRootSampleRate",
"removes",
"any",
"settings",
"for",
"events",
"with",
"the",
"given",
"root",
"ID",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/logger.go#L66-L71 |
149,648 | codahale/lunk | logger.go | UnsetSchemaSampleRate | func (l SamplingEventLogger) UnsetSchemaSampleRate(schema string) {
l.m.Lock()
defer l.m.Unlock()
delete(l.rates, schema)
} | go | func (l SamplingEventLogger) UnsetSchemaSampleRate(schema string) {
l.m.Lock()
defer l.m.Unlock()
delete(l.rates, schema)
} | [
"func",
"(",
"l",
"SamplingEventLogger",
")",
"UnsetSchemaSampleRate",
"(",
"schema",
"string",
")",
"{",
"l",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"l",
".",
"rates",
",",
"s... | // UnsetSchemaSampleRate removes any settings for events with the given root ID. | [
"UnsetSchemaSampleRate",
"removes",
"any",
"settings",
"for",
"events",
"with",
"the",
"given",
"root",
"ID",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/logger.go#L84-L89 |
149,649 | codahale/lunk | logger.go | Log | func (l SamplingEventLogger) Log(id EventID, e Event) {
l.m.Lock()
defer l.m.Unlock()
r, ok := l.rootRates[id.Root]
if !ok {
r, ok = l.rates[e.Schema()]
}
if ok && r < l.r.Float64() {
return
}
l.l.Log(id, e)
} | go | func (l SamplingEventLogger) Log(id EventID, e Event) {
l.m.Lock()
defer l.m.Unlock()
r, ok := l.rootRates[id.Root]
if !ok {
r, ok = l.rates[e.Schema()]
}
if ok && r < l.r.Float64() {
return
}
l.l.Log(id, e)
} | [
"func",
"(",
"l",
"SamplingEventLogger",
")",
"Log",
"(",
"id",
"EventID",
",",
"e",
"Event",
")",
"{",
"l",
".",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"r",
",",
"ok",
":=",
"l",
".",
"root... | // Log passes the event to the underlying EventLogger, probabilistically
// dropping some events. | [
"Log",
"passes",
"the",
"event",
"to",
"the",
"underlying",
"EventLogger",
"probabilistically",
"dropping",
"some",
"events",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/logger.go#L93-L107 |
149,650 | codahale/lunk | id.go | UnmarshalJSON | func (id *ID) UnmarshalJSON(data []byte) error {
i, err := parseJSONString(data)
if err == nil {
*id = i
return nil
}
i, err = parseJSONInt(data)
if err == nil {
*id = i
return nil
}
return fmt.Errorf("%s is not a valid ID", data)
} | go | func (id *ID) UnmarshalJSON(data []byte) error {
i, err := parseJSONString(data)
if err == nil {
*id = i
return nil
}
i, err = parseJSONInt(data)
if err == nil {
*id = i
return nil
}
return fmt.Errorf("%s is not a valid ID", data)
} | [
"func",
"(",
"id",
"*",
"ID",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"i",
",",
"err",
":=",
"parseJSONString",
"(",
"data",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"*",
"id",
"=",
"i",
"\n",
"return",
"nil",
"... | // UnmarshalJSON decodes the given data as either a hexadecimal string or JSON
// integer. | [
"UnmarshalJSON",
"decodes",
"the",
"given",
"data",
"as",
"either",
"a",
"hexadecimal",
"string",
"or",
"JSON",
"integer",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/id.go#L30-L44 |
149,651 | codahale/lunk | id.go | ParseID | func ParseID(s string) (ID, error) {
i, err := strconv.ParseUint(s, 16, 64)
if err != nil {
return 0, err
}
return ID(i), nil
} | go | func ParseID(s string) (ID, error) {
i, err := strconv.ParseUint(s, 16, 64)
if err != nil {
return 0, err
}
return ID(i), nil
} | [
"func",
"ParseID",
"(",
"s",
"string",
")",
"(",
"ID",
",",
"error",
")",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"s",
",",
"16",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",... | // ParseID parses the given string as a hexadecimal string. | [
"ParseID",
"parses",
"the",
"given",
"string",
"as",
"a",
"hexadecimal",
"string",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/id.go#L47-L53 |
149,652 | codahale/lunk | id.go | generateID | func generateID() ID {
m.Lock()
if n == aes.BlockSize {
c.Encrypt(b, ctr)
for i := aes.BlockSize - 1; i >= 0; i-- { // increment ctr
ctr[i]++
if ctr[i] != 0 {
break
}
}
n = 0
}
id := *(*ID)(unsafe.Pointer(&b[n])) // zero-copy b/c we're arch-neutral
n += idSize
m.Unlock()
return id
} | go | func generateID() ID {
m.Lock()
if n == aes.BlockSize {
c.Encrypt(b, ctr)
for i := aes.BlockSize - 1; i >= 0; i-- { // increment ctr
ctr[i]++
if ctr[i] != 0 {
break
}
}
n = 0
}
id := *(*ID)(unsafe.Pointer(&b[n])) // zero-copy b/c we're arch-neutral
n += idSize
m.Unlock()
return id
} | [
"func",
"generateID",
"(",
")",
"ID",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"if",
"n",
"==",
"aes",
".",
"BlockSize",
"{",
"c",
".",
"Encrypt",
"(",
"b",
",",
"ctr",
")",
"\n",
"for",
"i",
":=",
"aes",
".",
"BlockSize",
"-",
"1",
";",
"i",
... | // generateID returns a randomly-generated 64-bit ID. This function is
// thread-safe. IDs are produced by consuming an AES-CTR-128 keystream in
// 64-bit chunks. The AES key is randomly generated on initialization, as is the
// counter's initial state. On machines with AES-NI support, ID generation takes
// ~30ns and... | [
"generateID",
"returns",
"a",
"randomly",
"-",
"generated",
"64",
"-",
"bit",
"ID",
".",
"This",
"function",
"is",
"thread",
"-",
"safe",
".",
"IDs",
"are",
"produced",
"by",
"consuming",
"an",
"AES",
"-",
"CTR",
"-",
"128",
"keystream",
"in",
"64",
"-... | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/id.go#L60-L77 |
149,653 | codahale/lunk | web/http.go | SetRequestEventID | func SetRequestEventID(r *http.Request, e lunk.EventID) {
r.Header.Set(HeaderEventID, e.String())
} | go | func SetRequestEventID(r *http.Request, e lunk.EventID) {
r.Header.Set(HeaderEventID, e.String())
} | [
"func",
"SetRequestEventID",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"e",
"lunk",
".",
"EventID",
")",
"{",
"r",
".",
"Header",
".",
"Set",
"(",
"HeaderEventID",
",",
"e",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // SetRequestEventID sets the Event-ID header on the request. | [
"SetRequestEventID",
"sets",
"the",
"Event",
"-",
"ID",
"header",
"on",
"the",
"request",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/web/http.go#L18-L20 |
149,654 | codahale/lunk | web/http.go | GetRequestEventID | func GetRequestEventID(r *http.Request) (*lunk.EventID, error) {
s := r.Header.Get(HeaderEventID)
if s == "" {
return nil, nil
}
return lunk.ParseEventID(s)
} | go | func GetRequestEventID(r *http.Request) (*lunk.EventID, error) {
s := r.Header.Get(HeaderEventID)
if s == "" {
return nil, nil
}
return lunk.ParseEventID(s)
} | [
"func",
"GetRequestEventID",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"lunk",
".",
"EventID",
",",
"error",
")",
"{",
"s",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"HeaderEventID",
")",
"\n",
"if",
"s",
"==",
"\"",
"\"",
"{",
"retu... | // GetRequestEventID returns the EventID for the request, nil if no Event-ID was
// provided, or an error if the value was unparseable. | [
"GetRequestEventID",
"returns",
"the",
"EventID",
"for",
"the",
"request",
"nil",
"if",
"no",
"Event",
"-",
"ID",
"was",
"provided",
"or",
"an",
"error",
"if",
"the",
"value",
"was",
"unparseable",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/web/http.go#L24-L30 |
149,655 | codahale/lunk | web/http.go | HTTPRequest | func HTTPRequest(r *http.Request) *HTTPRequestEvent {
return &HTTPRequestEvent{
Method: r.Method,
URI: r.RequestURI,
Proto: r.Proto,
Headers: redactHeaders(r),
Host: r.Host,
RemoteAddr: r.RemoteAddr,
ContentLength: r.ContentLength,
}
} | go | func HTTPRequest(r *http.Request) *HTTPRequestEvent {
return &HTTPRequestEvent{
Method: r.Method,
URI: r.RequestURI,
Proto: r.Proto,
Headers: redactHeaders(r),
Host: r.Host,
RemoteAddr: r.RemoteAddr,
ContentLength: r.ContentLength,
}
} | [
"func",
"HTTPRequest",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"HTTPRequestEvent",
"{",
"return",
"&",
"HTTPRequestEvent",
"{",
"Method",
":",
"r",
".",
"Method",
",",
"URI",
":",
"r",
".",
"RequestURI",
",",
"Proto",
":",
"r",
".",
"Proto",
... | // HTTPRequest returns an event which records various aspects of an HTTP request.
// The returned value is incomplete, and should have the response status, size,
// and the elapsed time set before being logged. | [
"HTTPRequest",
"returns",
"an",
"event",
"which",
"records",
"various",
"aspects",
"of",
"an",
"HTTP",
"request",
".",
"The",
"returned",
"value",
"is",
"incomplete",
"and",
"should",
"have",
"the",
"response",
"status",
"size",
"and",
"the",
"elapsed",
"time"... | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/web/http.go#L41-L51 |
149,656 | codahale/lunk | recorder.go | NewNormalizedCSVEntryRecorder | func NewNormalizedCSVEntryRecorder(events, props *csv.Writer) EntryRecorder {
return nCSVRecorder{
events: events,
props: props,
}
} | go | func NewNormalizedCSVEntryRecorder(events, props *csv.Writer) EntryRecorder {
return nCSVRecorder{
events: events,
props: props,
}
} | [
"func",
"NewNormalizedCSVEntryRecorder",
"(",
"events",
",",
"props",
"*",
"csv",
".",
"Writer",
")",
"EntryRecorder",
"{",
"return",
"nCSVRecorder",
"{",
"events",
":",
"events",
",",
"props",
":",
"props",
",",
"}",
"\n",
"}"
] | // NewNormalizedCSVEntryRecorder returns an EntryRecorder which writes events to
// one CSV file and properties to another. | [
"NewNormalizedCSVEntryRecorder",
"returns",
"an",
"EntryRecorder",
"which",
"writes",
"events",
"to",
"one",
"CSV",
"file",
"and",
"properties",
"to",
"another",
"."
] | 3bb9f3be3053e35972e4a0725dd6e44ae203bc99 | https://github.com/codahale/lunk/blob/3bb9f3be3053e35972e4a0725dd6e44ae203bc99/recorder.go#L18-L23 |
149,657 | marcmak/calc | calc/solver.go | SolvePostfix | func SolvePostfix(tokens Stack) float64 {
stack := Stack{}
for _, v := range tokens.Values {
switch v.Type {
case NUMBER:
stack.Push(v)
case FUNCTION:
stack.Push(Token{NUMBER, SolveFunction(v.Value)})
case CONSTANT:
if val, ok := consts[v.Value]; ok {
stack.Push(Token{NUMBER, strconv.FormatFloat(... | go | func SolvePostfix(tokens Stack) float64 {
stack := Stack{}
for _, v := range tokens.Values {
switch v.Type {
case NUMBER:
stack.Push(v)
case FUNCTION:
stack.Push(Token{NUMBER, SolveFunction(v.Value)})
case CONSTANT:
if val, ok := consts[v.Value]; ok {
stack.Push(Token{NUMBER, strconv.FormatFloat(... | [
"func",
"SolvePostfix",
"(",
"tokens",
"Stack",
")",
"float64",
"{",
"stack",
":=",
"Stack",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"tokens",
".",
"Values",
"{",
"switch",
"v",
".",
"Type",
"{",
"case",
"NUMBER",
":",
"stack",
".",
"P... | // SolvePostfix evaluates and returns the answer of the expression converted to postfix | [
"SolvePostfix",
"evaluates",
"and",
"returns",
"the",
"answer",
"of",
"the",
"expression",
"converted",
"to",
"postfix"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/solver.go#L48-L71 |
149,658 | marcmak/calc | calc/solver.go | SolveFunction | func SolveFunction(s string) string {
var fArg float64
fType := s[:strings.Index(s, "(")]
args := s[strings.Index(s, "(")+1 : strings.LastIndex(s, ")")]
if !strings.ContainsAny(args, "+ & * & - & / & ^") && !ContainsLetter(args) {
fArg, _ = strconv.ParseFloat(args, 64)
} else {
stack, _ := NewParser(strings.Ne... | go | func SolveFunction(s string) string {
var fArg float64
fType := s[:strings.Index(s, "(")]
args := s[strings.Index(s, "(")+1 : strings.LastIndex(s, ")")]
if !strings.ContainsAny(args, "+ & * & - & / & ^") && !ContainsLetter(args) {
fArg, _ = strconv.ParseFloat(args, 64)
} else {
stack, _ := NewParser(strings.Ne... | [
"func",
"SolveFunction",
"(",
"s",
"string",
")",
"string",
"{",
"var",
"fArg",
"float64",
"\n",
"fType",
":=",
"s",
"[",
":",
"strings",
".",
"Index",
"(",
"s",
",",
"\"",
"\"",
")",
"]",
"\n",
"args",
":=",
"s",
"[",
"strings",
".",
"Index",
"(... | // SolveFunction returns the answer of a function found within an expression | [
"SolveFunction",
"returns",
"the",
"answer",
"of",
"a",
"function",
"found",
"within",
"an",
"expression"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/solver.go#L74-L86 |
149,659 | marcmak/calc | calc/solver.go | ContainsLetter | func ContainsLetter(s string) bool {
for _, v := range s {
if unicode.IsLetter(v) {
return true
}
}
return false
} | go | func ContainsLetter(s string) bool {
for _, v := range s {
if unicode.IsLetter(v) {
return true
}
}
return false
} | [
"func",
"ContainsLetter",
"(",
"s",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"s",
"{",
"if",
"unicode",
".",
"IsLetter",
"(",
"v",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // ContainsLetter checks if a string contains a letter | [
"ContainsLetter",
"checks",
"if",
"a",
"string",
"contains",
"a",
"letter"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/solver.go#L89-L96 |
149,660 | marcmak/calc | calc/stack.go | Pop | func (self *Stack) Pop() Token {
if len(self.Values) == 0 {
return Token{}
}
token := self.Values[len(self.Values)-1]
self.Values = self.Values[:len(self.Values)-1]
return token
} | go | func (self *Stack) Pop() Token {
if len(self.Values) == 0 {
return Token{}
}
token := self.Values[len(self.Values)-1]
self.Values = self.Values[:len(self.Values)-1]
return token
} | [
"func",
"(",
"self",
"*",
"Stack",
")",
"Pop",
"(",
")",
"Token",
"{",
"if",
"len",
"(",
"self",
".",
"Values",
")",
"==",
"0",
"{",
"return",
"Token",
"{",
"}",
"\n",
"}",
"\n",
"token",
":=",
"self",
".",
"Values",
"[",
"len",
"(",
"self",
... | // Pop removes the token at the top of the stack and returns its value | [
"Pop",
"removes",
"the",
"token",
"at",
"the",
"top",
"of",
"the",
"stack",
"and",
"returns",
"its",
"value"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/stack.go#L9-L16 |
149,661 | marcmak/calc | calc/stack.go | Push | func (self *Stack) Push(i ...Token) {
self.Values = append(self.Values, i...)
} | go | func (self *Stack) Push(i ...Token) {
self.Values = append(self.Values, i...)
} | [
"func",
"(",
"self",
"*",
"Stack",
")",
"Push",
"(",
"i",
"...",
"Token",
")",
"{",
"self",
".",
"Values",
"=",
"append",
"(",
"self",
".",
"Values",
",",
"i",
"...",
")",
"\n",
"}"
] | // Push adds tokens to the top of the stack | [
"Push",
"adds",
"tokens",
"to",
"the",
"top",
"of",
"the",
"stack"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/stack.go#L19-L21 |
149,662 | marcmak/calc | calc/stack.go | Peek | func (self *Stack) Peek() Token {
if len(self.Values) == 0 {
return Token{}
}
return self.Values[len(self.Values)-1]
} | go | func (self *Stack) Peek() Token {
if len(self.Values) == 0 {
return Token{}
}
return self.Values[len(self.Values)-1]
} | [
"func",
"(",
"self",
"*",
"Stack",
")",
"Peek",
"(",
")",
"Token",
"{",
"if",
"len",
"(",
"self",
".",
"Values",
")",
"==",
"0",
"{",
"return",
"Token",
"{",
"}",
"\n",
"}",
"\n",
"return",
"self",
".",
"Values",
"[",
"len",
"(",
"self",
".",
... | // Peek returns the token at the top of the stack | [
"Peek",
"returns",
"the",
"token",
"at",
"the",
"top",
"of",
"the",
"stack"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/stack.go#L24-L29 |
149,663 | marcmak/calc | calc/stack.go | EmptyInto | func (self *Stack) EmptyInto(s *Stack) {
if !self.IsEmpty() {
for i := self.Length() - 1; i >= 0; i-- {
s.Push(self.Pop())
}
}
} | go | func (self *Stack) EmptyInto(s *Stack) {
if !self.IsEmpty() {
for i := self.Length() - 1; i >= 0; i-- {
s.Push(self.Pop())
}
}
} | [
"func",
"(",
"self",
"*",
"Stack",
")",
"EmptyInto",
"(",
"s",
"*",
"Stack",
")",
"{",
"if",
"!",
"self",
".",
"IsEmpty",
"(",
")",
"{",
"for",
"i",
":=",
"self",
".",
"Length",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
... | // EmptyInto dumps all tokens from one stack to another | [
"EmptyInto",
"dumps",
"all",
"tokens",
"from",
"one",
"stack",
"to",
"another"
] | 5bbbfc3b3149741fda5147a18568a62f6cd3fec1 | https://github.com/marcmak/calc/blob/5bbbfc3b3149741fda5147a18568a62f6cd3fec1/calc/stack.go#L32-L38 |
149,664 | NebulousLabs/entropy-mnemonics | mnemonics.go | phraseToInt | func phraseToInt(p Phrase, did DictionaryID) (*big.Int, error) {
// Determine which dictionary to use based on the input language.
var dict Dictionary
var prefixLen int
switch {
case did == English:
dict = englishDictionary
prefixLen = EnglishUniquePrefixLen
case did == German:
dict = germanDictionary
pre... | go | func phraseToInt(p Phrase, did DictionaryID) (*big.Int, error) {
// Determine which dictionary to use based on the input language.
var dict Dictionary
var prefixLen int
switch {
case did == English:
dict = englishDictionary
prefixLen = EnglishUniquePrefixLen
case did == German:
dict = germanDictionary
pre... | [
"func",
"phraseToInt",
"(",
"p",
"Phrase",
",",
"did",
"DictionaryID",
")",
"(",
"*",
"big",
".",
"Int",
",",
"error",
")",
"{",
"// Determine which dictionary to use based on the input language.",
"var",
"dict",
"Dictionary",
"\n",
"var",
"prefixLen",
"int",
"\n"... | // phraseToInt coverts a phrase into a big.Int, using logic similar to
// bytesToInt. | [
"phraseToInt",
"coverts",
"a",
"phrase",
"into",
"a",
"big",
".",
"Int",
"using",
"logic",
"similar",
"to",
"bytesToInt",
"."
] | bc7e13c5ccd82d4715222a0dc2b4b60e881dd462 | https://github.com/NebulousLabs/entropy-mnemonics/blob/bc7e13c5ccd82d4715222a0dc2b4b60e881dd462/mnemonics.go#L112-L172 |
149,665 | NebulousLabs/entropy-mnemonics | mnemonics.go | intToPhrase | func intToPhrase(bi *big.Int, did DictionaryID) (p Phrase, err error) {
// Determine which dictionary to use based on the input language.
var dict Dictionary
switch {
case did == English:
dict = englishDictionary
case did == German:
dict = germanDictionary
case did == Japanese:
dict = japaneseDictionary
de... | go | func intToPhrase(bi *big.Int, did DictionaryID) (p Phrase, err error) {
// Determine which dictionary to use based on the input language.
var dict Dictionary
switch {
case did == English:
dict = englishDictionary
case did == German:
dict = germanDictionary
case did == Japanese:
dict = japaneseDictionary
de... | [
"func",
"intToPhrase",
"(",
"bi",
"*",
"big",
".",
"Int",
",",
"did",
"DictionaryID",
")",
"(",
"p",
"Phrase",
",",
"err",
"error",
")",
"{",
"// Determine which dictionary to use based on the input language.",
"var",
"dict",
"Dictionary",
"\n",
"switch",
"{",
"... | // intToPhrase converts a phrase into a big.Int, working in a fashion similar
// to bytesToInt. | [
"intToPhrase",
"converts",
"a",
"phrase",
"into",
"a",
"big",
".",
"Int",
"working",
"in",
"a",
"fashion",
"similar",
"to",
"bytesToInt",
"."
] | bc7e13c5ccd82d4715222a0dc2b4b60e881dd462 | https://github.com/NebulousLabs/entropy-mnemonics/blob/bc7e13c5ccd82d4715222a0dc2b4b60e881dd462/mnemonics.go#L176-L199 |
149,666 | NebulousLabs/entropy-mnemonics | mnemonics.go | FromString | func FromString(str string, did DictionaryID) ([]byte, error) {
phrase := Phrase(strings.Split(str, " "))
return FromPhrase(phrase, did)
} | go | func FromString(str string, did DictionaryID) ([]byte, error) {
phrase := Phrase(strings.Split(str, " "))
return FromPhrase(phrase, did)
} | [
"func",
"FromString",
"(",
"str",
"string",
",",
"did",
"DictionaryID",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"phrase",
":=",
"Phrase",
"(",
"strings",
".",
"Split",
"(",
"str",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"FromPhrase",
... | // FromString converts an input string into a phrase, and then calls
// 'FromPhrase'. | [
"FromString",
"converts",
"an",
"input",
"string",
"into",
"a",
"phrase",
"and",
"then",
"calls",
"FromPhrase",
"."
] | bc7e13c5ccd82d4715222a0dc2b4b60e881dd462 | https://github.com/NebulousLabs/entropy-mnemonics/blob/bc7e13c5ccd82d4715222a0dc2b4b60e881dd462/mnemonics.go#L226-L229 |
149,667 | felixge/pidctrl | pidctrl.go | NewPIDController | func NewPIDController(p, i, d float64) *PIDController {
return &PIDController{p: p, i: i, d: d, outMin: math.Inf(-1), outMax: math.Inf(0)}
} | go | func NewPIDController(p, i, d float64) *PIDController {
return &PIDController{p: p, i: i, d: d, outMin: math.Inf(-1), outMax: math.Inf(0)}
} | [
"func",
"NewPIDController",
"(",
"p",
",",
"i",
",",
"d",
"float64",
")",
"*",
"PIDController",
"{",
"return",
"&",
"PIDController",
"{",
"p",
":",
"p",
",",
"i",
":",
"i",
",",
"d",
":",
"d",
",",
"outMin",
":",
"math",
".",
"Inf",
"(",
"-",
"... | // NewPIDController returns a new PIDController using the given gain values. | [
"NewPIDController",
"returns",
"a",
"new",
"PIDController",
"using",
"the",
"given",
"gain",
"values",
"."
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L21-L23 |
149,668 | felixge/pidctrl | pidctrl.go | Set | func (c *PIDController) Set(setpoint float64) *PIDController {
c.setpoint = setpoint
return c
} | go | func (c *PIDController) Set(setpoint float64) *PIDController {
c.setpoint = setpoint
return c
} | [
"func",
"(",
"c",
"*",
"PIDController",
")",
"Set",
"(",
"setpoint",
"float64",
")",
"*",
"PIDController",
"{",
"c",
".",
"setpoint",
"=",
"setpoint",
"\n",
"return",
"c",
"\n",
"}"
] | // Set changes the setpoint of the controller. | [
"Set",
"changes",
"the",
"setpoint",
"of",
"the",
"controller",
"."
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L39-L42 |
149,669 | felixge/pidctrl | pidctrl.go | SetPID | func (c *PIDController) SetPID(p, i, d float64) *PIDController {
c.p = p
c.i = i
c.d = d
return c
} | go | func (c *PIDController) SetPID(p, i, d float64) *PIDController {
c.p = p
c.i = i
c.d = d
return c
} | [
"func",
"(",
"c",
"*",
"PIDController",
")",
"SetPID",
"(",
"p",
",",
"i",
",",
"d",
"float64",
")",
"*",
"PIDController",
"{",
"c",
".",
"p",
"=",
"p",
"\n",
"c",
".",
"i",
"=",
"i",
"\n",
"c",
".",
"d",
"=",
"d",
"\n",
"return",
"c",
"\n"... | // SetPID changes the P, I, and D constants | [
"SetPID",
"changes",
"the",
"P",
"I",
"and",
"D",
"constants"
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L50-L55 |
149,670 | felixge/pidctrl | pidctrl.go | PID | func (c *PIDController) PID() (p, i, d float64) {
return c.p, c.i, c.d
} | go | func (c *PIDController) PID() (p, i, d float64) {
return c.p, c.i, c.d
} | [
"func",
"(",
"c",
"*",
"PIDController",
")",
"PID",
"(",
")",
"(",
"p",
",",
"i",
",",
"d",
"float64",
")",
"{",
"return",
"c",
".",
"p",
",",
"c",
".",
"i",
",",
"c",
".",
"d",
"\n",
"}"
] | // PID returns the P, I, and D constants | [
"PID",
"returns",
"the",
"P",
"I",
"and",
"D",
"constants"
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L58-L60 |
149,671 | felixge/pidctrl | pidctrl.go | SetOutputLimits | func (c *PIDController) SetOutputLimits(min, max float64) *PIDController {
if min > max {
panic(MinMaxError{min, max})
}
c.outMin = min
c.outMax = max
if c.integral > c.outMax {
c.integral = c.outMax
} else if c.integral < c.outMin {
c.integral = c.outMin
}
return c
} | go | func (c *PIDController) SetOutputLimits(min, max float64) *PIDController {
if min > max {
panic(MinMaxError{min, max})
}
c.outMin = min
c.outMax = max
if c.integral > c.outMax {
c.integral = c.outMax
} else if c.integral < c.outMin {
c.integral = c.outMin
}
return c
} | [
"func",
"(",
"c",
"*",
"PIDController",
")",
"SetOutputLimits",
"(",
"min",
",",
"max",
"float64",
")",
"*",
"PIDController",
"{",
"if",
"min",
">",
"max",
"{",
"panic",
"(",
"MinMaxError",
"{",
"min",
",",
"max",
"}",
")",
"\n",
"}",
"\n",
"c",
".... | // SetOutputLimits sets the min and max output values | [
"SetOutputLimits",
"sets",
"the",
"min",
"and",
"max",
"output",
"values"
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L63-L76 |
149,672 | felixge/pidctrl | pidctrl.go | OutputLimits | func (c *PIDController) OutputLimits() (min, max float64) {
return c.outMin, c.outMax
} | go | func (c *PIDController) OutputLimits() (min, max float64) {
return c.outMin, c.outMax
} | [
"func",
"(",
"c",
"*",
"PIDController",
")",
"OutputLimits",
"(",
")",
"(",
"min",
",",
"max",
"float64",
")",
"{",
"return",
"c",
".",
"outMin",
",",
"c",
".",
"outMax",
"\n",
"}"
] | // OutputLimits returns the min and max output values | [
"OutputLimits",
"returns",
"the",
"min",
"and",
"max",
"output",
"values"
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L79-L81 |
149,673 | felixge/pidctrl | pidctrl.go | Update | func (c *PIDController) Update(value float64) float64 {
var duration time.Duration
if !c.lastUpdate.IsZero() {
duration = time.Since(c.lastUpdate)
}
c.lastUpdate = time.Now()
return c.UpdateDuration(value, duration)
} | go | func (c *PIDController) Update(value float64) float64 {
var duration time.Duration
if !c.lastUpdate.IsZero() {
duration = time.Since(c.lastUpdate)
}
c.lastUpdate = time.Now()
return c.UpdateDuration(value, duration)
} | [
"func",
"(",
"c",
"*",
"PIDController",
")",
"Update",
"(",
"value",
"float64",
")",
"float64",
"{",
"var",
"duration",
"time",
".",
"Duration",
"\n",
"if",
"!",
"c",
".",
"lastUpdate",
".",
"IsZero",
"(",
")",
"{",
"duration",
"=",
"time",
".",
"Sin... | // Update is identical to UpdateDuration, but automatically keeps track of the
// durations between updates. | [
"Update",
"is",
"identical",
"to",
"UpdateDuration",
"but",
"automatically",
"keeps",
"track",
"of",
"the",
"durations",
"between",
"updates",
"."
] | 7b13bcae7243fe17bbeb7dd5cd8b26675c8db048 | https://github.com/felixge/pidctrl/blob/7b13bcae7243fe17bbeb7dd5cd8b26675c8db048/pidctrl.go#L85-L92 |
149,674 | widuu/gojson | gojson.go | Json | func Json(data string) *Js {
j := new(Js)
var f interface{}
err := json.Unmarshal([]byte(data), &f)
if err != nil {
return j
}
j.data = f
return j
} | go | func Json(data string) *Js {
j := new(Js)
var f interface{}
err := json.Unmarshal([]byte(data), &f)
if err != nil {
return j
}
j.data = f
return j
} | [
"func",
"Json",
"(",
"data",
"string",
")",
"*",
"Js",
"{",
"j",
":=",
"new",
"(",
"Js",
")",
"\n",
"var",
"f",
"interface",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"data",
")",
",",
"&",
"f",
")",
... | //Initialize the json configruation | [
"Initialize",
"the",
"json",
"configruation"
] | 7da9d2cd949b3f1b4e3039dd985773df8cf68a99 | https://github.com/widuu/gojson/blob/7da9d2cd949b3f1b4e3039dd985773df8cf68a99/gojson.go#L22-L31 |
149,675 | widuu/gojson | gojson.go | Get | func (j *Js) Get(key string) *Js {
m := j.Getdata()
if v, ok := m[key]; ok {
j.data = v
return j
}
j.data = nil
return j
} | go | func (j *Js) Get(key string) *Js {
m := j.Getdata()
if v, ok := m[key]; ok {
j.data = v
return j
}
j.data = nil
return j
} | [
"func",
"(",
"j",
"*",
"Js",
")",
"Get",
"(",
"key",
"string",
")",
"*",
"Js",
"{",
"m",
":=",
"j",
".",
"Getdata",
"(",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"m",
"[",
"key",
"]",
";",
"ok",
"{",
"j",
".",
"data",
"=",
"v",
"\n",
"ret... | //According to the key of the returned data information,return js.data | [
"According",
"to",
"the",
"key",
"of",
"the",
"returned",
"data",
"information",
"return",
"js",
".",
"data"
] | 7da9d2cd949b3f1b4e3039dd985773df8cf68a99 | https://github.com/widuu/gojson/blob/7da9d2cd949b3f1b4e3039dd985773df8cf68a99/gojson.go#L34-L42 |
149,676 | widuu/gojson | gojson.go | Getdata | func (j *Js) Getdata() map[string]interface{} {
if m, ok := (j.data).(map[string]interface{}); ok {
return m
}
return nil
} | go | func (j *Js) Getdata() map[string]interface{} {
if m, ok := (j.data).(map[string]interface{}); ok {
return m
}
return nil
} | [
"func",
"(",
"j",
"*",
"Js",
")",
"Getdata",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"if",
"m",
",",
"ok",
":=",
"(",
"j",
".",
"data",
")",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok"... | //return json data | [
"return",
"json",
"data"
] | 7da9d2cd949b3f1b4e3039dd985773df8cf68a99 | https://github.com/widuu/gojson/blob/7da9d2cd949b3f1b4e3039dd985773df8cf68a99/gojson.go#L54-L59 |
149,677 | widuu/gojson | gojson.go | Getpath | func (j *Js) Getpath(args ...string) *Js {
d := j
for i := range args {
m := d.Getdata()
if val, ok := m[args[i]]; ok {
d.data = val
} else {
d.data = nil
return d
}
}
return d
} | go | func (j *Js) Getpath(args ...string) *Js {
d := j
for i := range args {
m := d.Getdata()
if val, ok := m[args[i]]; ok {
d.data = val
} else {
d.data = nil
return d
}
}
return d
} | [
"func",
"(",
"j",
"*",
"Js",
")",
"Getpath",
"(",
"args",
"...",
"string",
")",
"*",
"Js",
"{",
"d",
":=",
"j",
"\n",
"for",
"i",
":=",
"range",
"args",
"{",
"m",
":=",
"d",
".",
"Getdata",
"(",
")",
"\n\n",
"if",
"val",
",",
"ok",
":=",
"m... | //According to the custom of the PATH to find the PATH | [
"According",
"to",
"the",
"custom",
"of",
"the",
"PATH",
"to",
"find",
"the",
"PATH"
] | 7da9d2cd949b3f1b4e3039dd985773df8cf68a99 | https://github.com/widuu/gojson/blob/7da9d2cd949b3f1b4e3039dd985773df8cf68a99/gojson.go#L150-L163 |
149,678 | ahmetb/go-httpbin | handlers.go | HomeHandler | func HomeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `<!DOCTYPE html>
<html lang="en">
<head>
<title>go-httpbin</title>
<head>
<body>
<h1>go-httpbin</h1>
<p>
<a href="https://github.com/ahmetb/go-httpbin">
Read documentation →
</a>
</body>
</html>`)
} | go | func HomeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `<!DOCTYPE html>
<html lang="en">
<head>
<title>go-httpbin</title>
<head>
<body>
<h1>go-httpbin</h1>
<p>
<a href="https://github.com/ahmetb/go-httpbin">
Read documentation →
</a>
</body>
</html>`)
} | [
"func",
"HomeHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"w",
",",
"`<!DOCTYPE html>\n\t<html lang=\"en\">\n\t<head>\n\t\t<title>go-httpbin</title>\n\t<head>\n\t<body>\n\t\t<h1>go-httpbin</h... | // HomeHandler serves static HTML content for the index page. | [
"HomeHandler",
"serves",
"static",
"HTML",
"content",
"for",
"the",
"index",
"page",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L81-L95 |
149,679 | ahmetb/go-httpbin | handlers.go | IPHandler | func IPHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
if err := writeJSON(w, ipResponse{h}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json")) // TODO handle this error in writeJSON(w,v)
}
} | go | func IPHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
if err := writeJSON(w, ipResponse{h}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json")) // TODO handle this error in writeJSON(w,v)
}
} | [
"func",
"IPHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
",",
"_",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"r",
".",
"RemoteAddr",
")",
"\n",
"if",
"err",
":=",
"writeJSON",
"(",
... | // IPHandler returns Origin IP. | [
"IPHandler",
"returns",
"Origin",
"IP",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L98-L103 |
149,680 | ahmetb/go-httpbin | handlers.go | UserAgentHandler | func UserAgentHandler(w http.ResponseWriter, r *http.Request) {
if err := writeJSON(w, userAgentResponse{r.UserAgent()}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
}
} | go | func UserAgentHandler(w http.ResponseWriter, r *http.Request) {
if err := writeJSON(w, userAgentResponse{r.UserAgent()}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
}
} | [
"func",
"UserAgentHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"writeJSON",
"(",
"w",
",",
"userAgentResponse",
"{",
"r",
".",
"UserAgent",
"(",
")",
"}",
")",
";",
"err",
"!="... | // UserAgentHandler returns user agent. | [
"UserAgentHandler",
"returns",
"user",
"agent",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L106-L110 |
149,681 | ahmetb/go-httpbin | handlers.go | HeadersHandler | func HeadersHandler(w http.ResponseWriter, r *http.Request) {
if err := writeJSON(w, headersResponse{getHeaders(r)}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
}
} | go | func HeadersHandler(w http.ResponseWriter, r *http.Request) {
if err := writeJSON(w, headersResponse{getHeaders(r)}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
}
} | [
"func",
"HeadersHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"writeJSON",
"(",
"w",
",",
"headersResponse",
"{",
"getHeaders",
"(",
"r",
")",
"}",
")",
";",
"err",
"!=",
"nil",... | // HeadersHandler returns user agent. | [
"HeadersHandler",
"returns",
"user",
"agent",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L113-L117 |
149,682 | ahmetb/go-httpbin | handlers.go | GetHandler | func GetHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
v := getResponse{
headersResponse: headersResponse{getHeaders(r)},
ipResponse: ipResponse{h},
Args: flattenValues(r.URL.Query()),
}
if err := writeJSON(w, v); err != nil {
writeErrorJSON(w,... | go | func GetHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
v := getResponse{
headersResponse: headersResponse{getHeaders(r)},
ipResponse: ipResponse{h},
Args: flattenValues(r.URL.Query()),
}
if err := writeJSON(w, v); err != nil {
writeErrorJSON(w,... | [
"func",
"GetHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
",",
"_",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"r",
".",
"RemoteAddr",
")",
"\n\n",
"v",
":=",
"getResponse",
"{",
"he... | // GetHandler returns user agent. | [
"GetHandler",
"returns",
"user",
"agent",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L120-L132 |
149,683 | ahmetb/go-httpbin | handlers.go | PostHandler | func PostHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
data, err := parseData(r)
if err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to read body"))
return
}
var jsonPayload interface{}
if strings.Contains(r.Header.Get("Content-Type"), "json") {
err :=... | go | func PostHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
data, err := parseData(r)
if err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to read body"))
return
}
var jsonPayload interface{}
if strings.Contains(r.Header.Get("Content-Type"), "json") {
err :=... | [
"func",
"PostHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
",",
"_",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"r",
".",
"RemoteAddr",
")",
"\n\n",
"data",
",",
"err",
":=",
"parseD... | // PostHandler accept a post and echo its data back | [
"PostHandler",
"accept",
"a",
"post",
"and",
"echo",
"its",
"data",
"back"
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L135-L164 |
149,684 | ahmetb/go-httpbin | handlers.go | RedirectToHandler | func RedirectToHandler(w http.ResponseWriter, r *http.Request) {
u := mux.Vars(r)["url"]
w.Header().Set("Location", u)
w.WriteHeader(http.StatusFound)
} | go | func RedirectToHandler(w http.ResponseWriter, r *http.Request) {
u := mux.Vars(r)["url"]
w.Header().Set("Location", u)
w.WriteHeader(http.StatusFound)
} | [
"func",
"RedirectToHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"u",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\""... | // RedirectToHandler returns a 302 Found response pointing to
// the url query parameter | [
"RedirectToHandler",
"returns",
"a",
"302",
"Found",
"response",
"pointing",
"to",
"the",
"url",
"query",
"parameter"
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L201-L205 |
149,685 | ahmetb/go-httpbin | handlers.go | StatusHandler | func StatusHandler(w http.ResponseWriter, r *http.Request) {
code, _ := strconv.Atoi(mux.Vars(r)["code"])
statusWritten := false
switch code {
case http.StatusMovedPermanently,
http.StatusFound,
http.StatusSeeOther,
http.StatusUseProxy,
http.StatusTemporaryRedirect:
w.Header().Set("Location", "/redirect/... | go | func StatusHandler(w http.ResponseWriter, r *http.Request) {
code, _ := strconv.Atoi(mux.Vars(r)["code"])
statusWritten := false
switch code {
case http.StatusMovedPermanently,
http.StatusFound,
http.StatusSeeOther,
http.StatusUseProxy,
http.StatusTemporaryRedirect:
w.Header().Set("Location", "/redirect/... | [
"func",
"StatusHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"code",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
")",
"\n\n",
"statusW... | // StatusHandler returns a proper response for provided status code | [
"StatusHandler",
"returns",
"a",
"proper",
"response",
"for",
"provided",
"status",
"code"
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L208-L249 |
149,686 | ahmetb/go-httpbin | handlers.go | BytesHandler | func BytesHandler(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(mux.Vars(r)["n"]) // shouldn't fail due to route pattern
seedStr := r.URL.Query().Get("seed")
if seedStr == "" {
seedStr = fmt.Sprintf("%d", time.Now().UnixNano())
}
seed, _ := strconv.ParseInt(seedStr, 10, 64) // shouldn't fail d... | go | func BytesHandler(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(mux.Vars(r)["n"]) // shouldn't fail due to route pattern
seedStr := r.URL.Query().Get("seed")
if seedStr == "" {
seedStr = fmt.Sprintf("%d", time.Now().UnixNano())
}
seed, _ := strconv.ParseInt(seedStr, 10, 64) // shouldn't fail d... | [
"func",
"BytesHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"n",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
")",
"// shouldn't fail due... | // BytesHandler returns n random bytes of binary data and accepts an
// optional 'seed' integer query parameter. | [
"BytesHandler",
"returns",
"n",
"random",
"bytes",
"of",
"binary",
"data",
"and",
"accepts",
"an",
"optional",
"seed",
"integer",
"query",
"parameter",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L253-L275 |
149,687 | ahmetb/go-httpbin | handlers.go | StreamHandler | func StreamHandler(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(mux.Vars(r)["n"]) // shouldn't fail due to route pattern
nl := []byte{'\n'}
// allow only millisecond precision
for i := 0; i < n; i++ {
time.Sleep(StreamInterval)
b, _ := json.Marshal(struct {
N int `json:"n"`
Time... | go | func StreamHandler(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(mux.Vars(r)["n"]) // shouldn't fail due to route pattern
nl := []byte{'\n'}
// allow only millisecond precision
for i := 0; i < n; i++ {
time.Sleep(StreamInterval)
b, _ := json.Marshal(struct {
N int `json:"n"`
Time... | [
"func",
"StreamHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"n",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
")",
"// shouldn't fail du... | // StreamHandler writes a json object to a new line every second. | [
"StreamHandler",
"writes",
"a",
"json",
"object",
"to",
"a",
"new",
"line",
"every",
"second",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L292-L308 |
149,688 | ahmetb/go-httpbin | handlers.go | CookiesHandler | func CookiesHandler(w http.ResponseWriter, r *http.Request) {
if err := writeJSON(w, cookiesResponse{getCookies(r.Cookies())}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
}
} | go | func CookiesHandler(w http.ResponseWriter, r *http.Request) {
if err := writeJSON(w, cookiesResponse{getCookies(r.Cookies())}); err != nil {
writeErrorJSON(w, errors.Wrap(err, "failed to write json"))
}
} | [
"func",
"CookiesHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"err",
":=",
"writeJSON",
"(",
"w",
",",
"cookiesResponse",
"{",
"getCookies",
"(",
"r",
".",
"Cookies",
"(",
")",
")",
"}",
")"... | // CookiesHandler returns the cookies provided in the request. | [
"CookiesHandler",
"returns",
"the",
"cookies",
"provided",
"in",
"the",
"request",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L311-L315 |
149,689 | ahmetb/go-httpbin | handlers.go | DripHandler | func DripHandler(w http.ResponseWriter, r *http.Request) {
var retCode int
retCodeStr := r.URL.Query().Get("code")
delayStr := r.URL.Query().Get("delay")
durationSec, _ := strconv.ParseFloat(mux.Vars(r)["duration"], 32) // shouldn't fail due to route pattern
numBytes, _ := strconv.Atoi(mux.Vars(r)["numbytes"]) ... | go | func DripHandler(w http.ResponseWriter, r *http.Request) {
var retCode int
retCodeStr := r.URL.Query().Get("code")
delayStr := r.URL.Query().Get("delay")
durationSec, _ := strconv.ParseFloat(mux.Vars(r)["duration"], 32) // shouldn't fail due to route pattern
numBytes, _ := strconv.Atoi(mux.Vars(r)["numbytes"]) ... | [
"func",
"DripHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"retCode",
"int",
"\n\n",
"retCodeStr",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
... | // DripHandler drips data over a duration after an optional initial delay,
// then optionally returns with the given status code. | [
"DripHandler",
"drips",
"data",
"over",
"a",
"duration",
"after",
"an",
"optional",
"initial",
"delay",
"then",
"optionally",
"returns",
"with",
"the",
"given",
"status",
"code",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L351-L387 |
149,690 | ahmetb/go-httpbin | handlers.go | GZIPHandler | func GZIPHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
v := gzipResponse{
headersResponse: headersResponse{getHeaders(r)},
ipResponse: ipResponse{h},
Gzipped: true,
}
w.Header().Set("Content-Type", "application/json")
w.Header().Add("Content-Encod... | go | func GZIPHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
v := gzipResponse{
headersResponse: headersResponse{getHeaders(r)},
ipResponse: ipResponse{h},
Gzipped: true,
}
w.Header().Set("Content-Type", "application/json")
w.Header().Add("Content-Encod... | [
"func",
"GZIPHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
",",
"_",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"r",
".",
"RemoteAddr",
")",
"\n\n",
"v",
":=",
"gzipResponse",
"{",
"... | // GZIPHandler returns a GZIP-encoded response | [
"GZIPHandler",
"returns",
"a",
"GZIP",
"-",
"encoded",
"response"
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L408-L424 |
149,691 | ahmetb/go-httpbin | handlers.go | DeflateHandler | func DeflateHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
v := deflateResponse{
headersResponse: headersResponse{getHeaders(r)},
ipResponse: ipResponse{h},
Deflated: true,
}
w.Header().Set("Content-Encoding", "deflate")
ww, _ := flate.NewWriter(w, ... | go | func DeflateHandler(w http.ResponseWriter, r *http.Request) {
h, _, _ := net.SplitHostPort(r.RemoteAddr)
v := deflateResponse{
headersResponse: headersResponse{getHeaders(r)},
ipResponse: ipResponse{h},
Deflated: true,
}
w.Header().Set("Content-Encoding", "deflate")
ww, _ := flate.NewWriter(w, ... | [
"func",
"DeflateHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"h",
",",
"_",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"r",
".",
"RemoteAddr",
")",
"\n\n",
"v",
":=",
"deflateResponse",
"{... | // DeflateHandler returns a DEFLATE-encoded response. | [
"DeflateHandler",
"returns",
"a",
"DEFLATE",
"-",
"encoded",
"response",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L427-L442 |
149,692 | ahmetb/go-httpbin | handlers.go | RobotsTXTHandler | func RobotsTXTHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprint(w, "User-agent: *\nDisallow: /deny\n")
} | go | func RobotsTXTHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
fmt.Fprint(w, "User-agent: *\nDisallow: /deny\n")
} | [
"func",
"RobotsTXTHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"\... | // RobotsTXTHandler returns a robots.txt response. | [
"RobotsTXTHandler",
"returns",
"a",
"robots",
".",
"txt",
"response",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L445-L448 |
149,693 | ahmetb/go-httpbin | handlers.go | BasicAuthHandler | func BasicAuthHandler(w http.ResponseWriter, r *http.Request) {
basicAuthHandler(w, r, http.StatusUnauthorized)
} | go | func BasicAuthHandler(w http.ResponseWriter, r *http.Request) {
basicAuthHandler(w, r, http.StatusUnauthorized)
} | [
"func",
"BasicAuthHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"basicAuthHandler",
"(",
"w",
",",
"r",
",",
"http",
".",
"StatusUnauthorized",
")",
"\n",
"}"
] | // BasicAuthHandler challenges with given username and password. | [
"BasicAuthHandler",
"challenges",
"with",
"given",
"username",
"and",
"password",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L468-L470 |
149,694 | ahmetb/go-httpbin | handlers.go | HiddenBasicAuthHandler | func HiddenBasicAuthHandler(w http.ResponseWriter, r *http.Request) {
basicAuthHandler(w, r, http.StatusNotFound)
} | go | func HiddenBasicAuthHandler(w http.ResponseWriter, r *http.Request) {
basicAuthHandler(w, r, http.StatusNotFound)
} | [
"func",
"HiddenBasicAuthHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"basicAuthHandler",
"(",
"w",
",",
"r",
",",
"http",
".",
"StatusNotFound",
")",
"\n",
"}"
] | // HiddenBasicAuthHandler challenges with given username and password and
// returns 404 if authentication fails. | [
"HiddenBasicAuthHandler",
"challenges",
"with",
"given",
"username",
"and",
"password",
"and",
"returns",
"404",
"if",
"authentication",
"fails",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L474-L476 |
149,695 | ahmetb/go-httpbin | handlers.go | HTMLHandler | func HTMLHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, htmlData)
} | go | func HTMLHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, htmlData)
} | [
"func",
"HTMLHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"htmlDa... | // HTMLHandler returns some HTML response. | [
"HTMLHandler",
"returns",
"some",
"HTML",
"response",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L497-L500 |
149,696 | ahmetb/go-httpbin | handlers.go | XMLHandler | func XMLHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/xml")
fmt.Fprint(w, xmlData)
} | go | func XMLHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/xml")
fmt.Fprint(w, xmlData)
} | [
"func",
"XMLHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"xmlData... | // XMLHandler returns some XML response. | [
"XMLHandler",
"returns",
"some",
"XML",
"response",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L503-L506 |
149,697 | ahmetb/go-httpbin | handlers.go | JPEGHandler | func JPEGHandler(w http.ResponseWriter, r *http.Request) {
jpeg.Encode(w, getImg(), nil)
} | go | func JPEGHandler(w http.ResponseWriter, r *http.Request) {
jpeg.Encode(w, getImg(), nil)
} | [
"func",
"JPEGHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"jpeg",
".",
"Encode",
"(",
"w",
",",
"getImg",
"(",
")",
",",
"nil",
")",
"\n",
"}"
] | // JPEGHandler returns a JPEG image. | [
"JPEGHandler",
"returns",
"a",
"JPEG",
"image",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L574-L576 |
149,698 | ahmetb/go-httpbin | handlers.go | PNGHandler | func PNGHandler(w http.ResponseWriter, r *http.Request) {
png.Encode(w, getImg())
} | go | func PNGHandler(w http.ResponseWriter, r *http.Request) {
png.Encode(w, getImg())
} | [
"func",
"PNGHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"png",
".",
"Encode",
"(",
"w",
",",
"getImg",
"(",
")",
")",
"\n",
"}"
] | // PNGHandler returns a PNG image. | [
"PNGHandler",
"returns",
"a",
"PNG",
"image",
"."
] | 7758ad7b11c5d3d5990b76b4be85e74dffe97bb4 | https://github.com/ahmetb/go-httpbin/blob/7758ad7b11c5d3d5990b76b4be85e74dffe97bb4/handlers.go#L579-L581 |
149,699 | heroku/instruments | reporter/log.go | Log | func Log(source string, r *Registry, d time.Duration) {
for range time.Tick(d) {
var parts []string
for k, m := range r.Instruments() {
switch i := m.(type) {
case instruments.Discrete:
s := i.Snapshot()
parts = append(parts, fmt.Sprintf("sample#%s=%d", k, s))
case instruments.Sample:
s := ins... | go | func Log(source string, r *Registry, d time.Duration) {
for range time.Tick(d) {
var parts []string
for k, m := range r.Instruments() {
switch i := m.(type) {
case instruments.Discrete:
s := i.Snapshot()
parts = append(parts, fmt.Sprintf("sample#%s=%d", k, s))
case instruments.Sample:
s := ins... | [
"func",
"Log",
"(",
"source",
"string",
",",
"r",
"*",
"Registry",
",",
"d",
"time",
".",
"Duration",
")",
"{",
"for",
"range",
"time",
".",
"Tick",
"(",
"d",
")",
"{",
"var",
"parts",
"[",
"]",
"string",
"\n",
"for",
"k",
",",
"m",
":=",
"rang... | // Log logs metrics using logfmt every given duration. | [
"Log",
"logs",
"metrics",
"using",
"logfmt",
"every",
"given",
"duration",
"."
] | 74dbde589dbcd98ace6bcd823ef39720819d816b | https://github.com/heroku/instruments/blob/74dbde589dbcd98ace6bcd823ef39720819d816b/reporter/log.go#L14-L29 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.