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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
142,600 | grokify/gotilla | math/mathutil/ratio.go | RatioInt | func RatioInt(x1, y1, x2, y2 int) (int, int) {
if x2 > 0 && y2 > 0 {
return x2, y2
} else if x2 <= 0 && y2 <= 0 {
return x1, y1
} else if x2 <= 0 {
return int((float64(x1) / float64(y1)) * float64(y2)), y2
} else if y2 <= 0 {
return x2, int((float64(y1) / float64(x1)) * float64(x2))
}
return x2, y2
} | go | func RatioInt(x1, y1, x2, y2 int) (int, int) {
if x2 > 0 && y2 > 0 {
return x2, y2
} else if x2 <= 0 && y2 <= 0 {
return x1, y1
} else if x2 <= 0 {
return int((float64(x1) / float64(y1)) * float64(y2)), y2
} else if y2 <= 0 {
return x2, int((float64(y1) / float64(x1)) * float64(x2))
}
return x2, y2
} | [
"func",
"RatioInt",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
"int",
")",
"(",
"int",
",",
"int",
")",
"{",
"if",
"x2",
">",
"0",
"&&",
"y2",
">",
"0",
"{",
"return",
"x2",
",",
"y2",
"\n",
"}",
"else",
"if",
"x2",
"<=",
"0",
"&&",
"y2"... | // RatioInt generates the missing value in a ratio calculation. | [
"RatioInt",
"generates",
"the",
"missing",
"value",
"in",
"a",
"ratio",
"calculation",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/math/mathutil/ratio.go#L4-L15 |
142,601 | grokify/gotilla | encoding/base36/base36.go | Encode36 | func Encode36(ba []byte) string {
s16 := hex.EncodeToString(ba)
bi := gmp.NewInt(0)
bi.SetString(s16, 16)
return bi.InBase(36)
} | go | func Encode36(ba []byte) string {
s16 := hex.EncodeToString(ba)
bi := gmp.NewInt(0)
bi.SetString(s16, 16)
return bi.InBase(36)
} | [
"func",
"Encode36",
"(",
"ba",
"[",
"]",
"byte",
")",
"string",
"{",
"s16",
":=",
"hex",
".",
"EncodeToString",
"(",
"ba",
")",
"\n",
"bi",
":=",
"gmp",
".",
"NewInt",
"(",
"0",
")",
"\n",
"bi",
".",
"SetString",
"(",
"s16",
",",
"16",
")",
"\n... | // Encode36String returns an encoded string given a byte array. | [
"Encode36String",
"returns",
"an",
"encoded",
"string",
"given",
"a",
"byte",
"array",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/encoding/base36/base36.go#L14-L19 |
142,602 | grokify/gotilla | encoding/base36/base36.go | Decode36String | func Decode36String(s36 string) ([]byte, error) {
bi := gmp.NewInt(0)
bi.SetString(s36, 36)
s16 := bi.InBase(16)
return hex.DecodeString(s16)
} | go | func Decode36String(s36 string) ([]byte, error) {
bi := gmp.NewInt(0)
bi.SetString(s36, 36)
s16 := bi.InBase(16)
return hex.DecodeString(s16)
} | [
"func",
"Decode36String",
"(",
"s36",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"bi",
":=",
"gmp",
".",
"NewInt",
"(",
"0",
")",
"\n",
"bi",
".",
"SetString",
"(",
"s36",
",",
"36",
")",
"\n",
"s16",
":=",
"bi",
".",
"InBase... | // Decode36String returns a decoded byte array given an encoded string. | [
"Decode36String",
"returns",
"a",
"decoded",
"byte",
"array",
"given",
"an",
"encoded",
"string",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/encoding/base36/base36.go#L32-L37 |
142,603 | grokify/gotilla | encoding/base36/base36.go | Md5Base36 | func Md5Base36(s string) string {
h := md5.New()
io.WriteString(h, s)
s16 := fmt.Sprintf("%x", h.Sum(nil))
bi := gmp.NewInt(0)
bi.SetString(s16, 16)
return fmt.Sprintf("%025s", bi.InBase(36))
} | go | func Md5Base36(s string) string {
h := md5.New()
io.WriteString(h, s)
s16 := fmt.Sprintf("%x", h.Sum(nil))
bi := gmp.NewInt(0)
bi.SetString(s16, 16)
return fmt.Sprintf("%025s", bi.InBase(36))
} | [
"func",
"Md5Base36",
"(",
"s",
"string",
")",
"string",
"{",
"h",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"io",
".",
"WriteString",
"(",
"h",
",",
"s",
")",
"\n",
"s16",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"h",
".",
"Sum",
"("... | // Md5Base36 returns a Base36 encoded MD5 hash of a string. | [
"Md5Base36",
"returns",
"a",
"Base36",
"encoded",
"MD5",
"hash",
"of",
"a",
"string",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/encoding/base36/base36.go#L40-L47 |
142,604 | grokify/gotilla | time/timeutil/quarter_int.go | AnyStringToQuarterTime | func AnyStringToQuarterTime(yyyyqSrcStr string) time.Time {
yyyyqSrcStr = strings.TrimSpace(yyyyqSrcStr)
// If not a string, return now time.
if len(yyyyqSrcStr) != 5 {
return time.Now().UTC()
}
// If not a yyyyq pattern, return now time.
rx := regexp.MustCompile(`^[0-9]{4}[1-4]$`)
m := rx.FindString(strings.T... | go | func AnyStringToQuarterTime(yyyyqSrcStr string) time.Time {
yyyyqSrcStr = strings.TrimSpace(yyyyqSrcStr)
// If not a string, return now time.
if len(yyyyqSrcStr) != 5 {
return time.Now().UTC()
}
// If not a yyyyq pattern, return now time.
rx := regexp.MustCompile(`^[0-9]{4}[1-4]$`)
m := rx.FindString(strings.T... | [
"func",
"AnyStringToQuarterTime",
"(",
"yyyyqSrcStr",
"string",
")",
"time",
".",
"Time",
"{",
"yyyyqSrcStr",
"=",
"strings",
".",
"TrimSpace",
"(",
"yyyyqSrcStr",
")",
"\n",
"// If not a string, return now time.",
"if",
"len",
"(",
"yyyyqSrcStr",
")",
"!=",
"5",
... | // AnyStringToQuarterTime returns the current time if in the
// current quarter or the end of any previous quarter. | [
"AnyStringToQuarterTime",
"returns",
"the",
"current",
"time",
"if",
"in",
"the",
"current",
"quarter",
"or",
"the",
"end",
"of",
"any",
"previous",
"quarter",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/time/timeutil/quarter_int.go#L171-L200 |
142,605 | grokify/gotilla | strconv/phonenumber/phonenumber.go | NewAreaCodeInfoStrings | func NewAreaCodeInfoStrings(ac, lat, lon string) (AreaCodeInfo, error) {
aci := AreaCodeInfo{}
i, err := strconv.Atoi(ac)
if err != nil {
return aci, err
}
if i < 100 || i > 999 {
return aci, fmt.Errorf("Invalid Area Code %v", i)
}
aci.AreaCode = uint16(i)
geo, err := NewPointString(lat, lon)
if err != nil... | go | func NewAreaCodeInfoStrings(ac, lat, lon string) (AreaCodeInfo, error) {
aci := AreaCodeInfo{}
i, err := strconv.Atoi(ac)
if err != nil {
return aci, err
}
if i < 100 || i > 999 {
return aci, fmt.Errorf("Invalid Area Code %v", i)
}
aci.AreaCode = uint16(i)
geo, err := NewPointString(lat, lon)
if err != nil... | [
"func",
"NewAreaCodeInfoStrings",
"(",
"ac",
",",
"lat",
",",
"lon",
"string",
")",
"(",
"AreaCodeInfo",
",",
"error",
")",
"{",
"aci",
":=",
"AreaCodeInfo",
"{",
"}",
"\n",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"ac",
")",
"\n",
"if",
... | // NewAreaCodeInfoStrings returns an AreaCodeInfo based on string area code,
// lat and lon values. | [
"NewAreaCodeInfoStrings",
"returns",
"an",
"AreaCodeInfo",
"based",
"on",
"string",
"area",
"code",
"lat",
"and",
"lon",
"values",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/strconv/phonenumber/phonenumber.go#L26-L42 |
142,606 | grokify/gotilla | os/osutil/osutil.go | EmptyAll | func EmptyAll(name string) error {
aEntries, err := ioutil.ReadDir(name)
if err != nil {
return err
}
for _, f := range aEntries {
if f.Name() == "." || f.Name() == ".." {
continue
}
err = os.Remove(name + "/" + f.Name())
if err != nil {
return err
}
}
return nil
} | go | func EmptyAll(name string) error {
aEntries, err := ioutil.ReadDir(name)
if err != nil {
return err
}
for _, f := range aEntries {
if f.Name() == "." || f.Name() == ".." {
continue
}
err = os.Remove(name + "/" + f.Name())
if err != nil {
return err
}
}
return nil
} | [
"func",
"EmptyAll",
"(",
"name",
"string",
")",
"error",
"{",
"aEntries",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"a... | // EmptyAll will delete all contents of a directory, leaving
// the provided directory. This is different from os.Remove
// which also removes the directory provided. | [
"EmptyAll",
"will",
"delete",
"all",
"contents",
"of",
"a",
"directory",
"leaving",
"the",
"provided",
"directory",
".",
"This",
"is",
"different",
"from",
"os",
".",
"Remove",
"which",
"also",
"removes",
"the",
"directory",
"provided",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/os/osutil/osutil.go#L17-L32 |
142,607 | grokify/gotilla | os/osutil/osutil.go | FileModAgeFromInfo | func FileModAgeFromInfo(fi os.FileInfo) time.Duration {
return time.Now().Sub(fi.ModTime())
} | go | func FileModAgeFromInfo(fi os.FileInfo) time.Duration {
return time.Now().Sub(fi.ModTime())
} | [
"func",
"FileModAgeFromInfo",
"(",
"fi",
"os",
".",
"FileInfo",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"fi",
".",
"ModTime",
"(",
")",
")",
"\n",
"}"
] | // FileModAgeFromInfo returns the file last modification
// age as a time.Duration. | [
"FileModAgeFromInfo",
"returns",
"the",
"file",
"last",
"modification",
"age",
"as",
"a",
"time",
".",
"Duration",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/os/osutil/osutil.go#L60-L62 |
142,608 | grokify/gotilla | os/osutil/osutil.go | GetFileInfo | func GetFileInfo(path string) (os.FileInfo, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return f.Stat()
} | go | func GetFileInfo(path string) (os.FileInfo, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return f.Stat()
} | [
"func",
"GetFileInfo",
"(",
"path",
"string",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n"... | // GetFileInfo returns an os.FileInfo from a filepath. | [
"GetFileInfo",
"returns",
"an",
"os",
".",
"FileInfo",
"from",
"a",
"filepath",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/os/osutil/osutil.go#L65-L72 |
142,609 | grokify/gotilla | regexp/regexputil/regexputil.go | McReplaceAllString | func McReplaceAllString(pattern string, s string, repl string) string {
return regexp.MustCompile(pattern).ReplaceAllString(s, repl)
} | go | func McReplaceAllString(pattern string, s string, repl string) string {
return regexp.MustCompile(pattern).ReplaceAllString(s, repl)
} | [
"func",
"McReplaceAllString",
"(",
"pattern",
"string",
",",
"s",
"string",
",",
"repl",
"string",
")",
"string",
"{",
"return",
"regexp",
".",
"MustCompile",
"(",
"pattern",
")",
".",
"ReplaceAllString",
"(",
"s",
",",
"repl",
")",
"\n",
"}"
] | // McReplaceAllString is a single line MustCompile regexp for ReplaceAllString | [
"McReplaceAllString",
"is",
"a",
"single",
"line",
"MustCompile",
"regexp",
"for",
"ReplaceAllString"
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/regexp/regexputil/regexputil.go#L9-L11 |
142,610 | grokify/gotilla | config/dotenv.go | GetDotEnvVal | func GetDotEnvVal(envPath, varName string) (string, error) {
cmd := fmt.Sprintf("grep %s '%s' | rev | cut -d= -f1 | rev", varName, envPath)
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return "", fmt.Errorf("Failed to execute command: %s", cmd)
}
return string(out), nil
} | go | func GetDotEnvVal(envPath, varName string) (string, error) {
cmd := fmt.Sprintf("grep %s '%s' | rev | cut -d= -f1 | rev", varName, envPath)
out, err := exec.Command("bash", "-c", cmd).Output()
if err != nil {
return "", fmt.Errorf("Failed to execute command: %s", cmd)
}
return string(out), nil
} | [
"func",
"GetDotEnvVal",
"(",
"envPath",
",",
"varName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"cmd",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"varName",
",",
"envPath",
")",
"\n\n",
"out",
",",
"err",
":=",
"exec",
".",
"C... | // GetDotEnvVal retrieves a single var from a `.env` file path | [
"GetDotEnvVal",
"retrieves",
"a",
"single",
"var",
"from",
"a",
".",
"env",
"file",
"path"
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/config/dotenv.go#L66-L74 |
142,611 | grokify/gotilla | type/stringsutil/stringsutil.go | Capitalize | func Capitalize(s1 string) string {
s2 := strings.ToLower(s1)
return ToUpperFirst(s2)
} | go | func Capitalize(s1 string) string {
s2 := strings.ToLower(s1)
return ToUpperFirst(s2)
} | [
"func",
"Capitalize",
"(",
"s1",
"string",
")",
"string",
"{",
"s2",
":=",
"strings",
".",
"ToLower",
"(",
"s1",
")",
"\n",
"return",
"ToUpperFirst",
"(",
"s2",
")",
"\n",
"}"
] | // Capitalize returns a string with the first character
// capitalized and the rest lower cased. | [
"Capitalize",
"returns",
"a",
"string",
"with",
"the",
"first",
"character",
"capitalized",
"and",
"the",
"rest",
"lower",
"cased",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L46-L49 |
142,612 | grokify/gotilla | type/stringsutil/stringsutil.go | ToLowerFirst | func ToLowerFirst(s1 string) string {
a1 := []rune(s1)
a1[0] = unicode.ToLower(a1[0])
return string(a1)
/*
if s == "" {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToLower(r)) + s[n:]
*/
} | go | func ToLowerFirst(s1 string) string {
a1 := []rune(s1)
a1[0] = unicode.ToLower(a1[0])
return string(a1)
/*
if s == "" {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToLower(r)) + s[n:]
*/
} | [
"func",
"ToLowerFirst",
"(",
"s1",
"string",
")",
"string",
"{",
"a1",
":=",
"[",
"]",
"rune",
"(",
"s1",
")",
"\n",
"a1",
"[",
"0",
"]",
"=",
"unicode",
".",
"ToLower",
"(",
"a1",
"[",
"0",
"]",
")",
"\n",
"return",
"string",
"(",
"a1",
")",
... | // ToLowerFirst lower cases the first letter in the string | [
"ToLowerFirst",
"lower",
"cases",
"the",
"first",
"letter",
"in",
"the",
"string"
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L52-L63 |
142,613 | grokify/gotilla | type/stringsutil/stringsutil.go | ToUpperFirst | func ToUpperFirst(s1 string) string {
a1 := []rune(s1)
a1[0] = unicode.ToUpper(a1[0])
return string(a1)
/*
if s == "" {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToUpper(r)) + s[n:]
*/
} | go | func ToUpperFirst(s1 string) string {
a1 := []rune(s1)
a1[0] = unicode.ToUpper(a1[0])
return string(a1)
/*
if s == "" {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToUpper(r)) + s[n:]
*/
} | [
"func",
"ToUpperFirst",
"(",
"s1",
"string",
")",
"string",
"{",
"a1",
":=",
"[",
"]",
"rune",
"(",
"s1",
")",
"\n",
"a1",
"[",
"0",
"]",
"=",
"unicode",
".",
"ToUpper",
"(",
"a1",
"[",
"0",
"]",
")",
"\n",
"return",
"string",
"(",
"a1",
")",
... | // ToUpperFirst upper cases the first letter in the string | [
"ToUpperFirst",
"upper",
"cases",
"the",
"first",
"letter",
"in",
"the",
"string"
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L66-L77 |
142,614 | grokify/gotilla | type/stringsutil/stringsutil.go | ToBool | func ToBool(v string) bool {
if strings.TrimSpace(strings.ToLower(v)) == "true" {
return true
}
return false
} | go | func ToBool(v string) bool {
if strings.TrimSpace(strings.ToLower(v)) == "true" {
return true
}
return false
} | [
"func",
"ToBool",
"(",
"v",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"ToLower",
"(",
"v",
")",
")",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // ToBool converts a string to a boolean value
// looking for the string "true" in any case. | [
"ToBool",
"converts",
"a",
"string",
"to",
"a",
"boolean",
"value",
"looking",
"for",
"the",
"string",
"true",
"in",
"any",
"case",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L81-L86 |
142,615 | grokify/gotilla | type/stringsutil/stringsutil.go | SplitCondenseSpace | func SplitCondenseSpace(s, sep string) []string {
split := strings.Split(s, sep)
strs := []string{}
for _, str := range split {
str = strings.TrimSpace(str)
if len(str) > 0 {
strs = append(strs, str)
}
}
return strs
} | go | func SplitCondenseSpace(s, sep string) []string {
split := strings.Split(s, sep)
strs := []string{}
for _, str := range split {
str = strings.TrimSpace(str)
if len(str) > 0 {
strs = append(strs, str)
}
}
return strs
} | [
"func",
"SplitCondenseSpace",
"(",
"s",
",",
"sep",
"string",
")",
"[",
"]",
"string",
"{",
"split",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"sep",
")",
"\n",
"strs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"str",
":=",
... | // SplitCondenseSpace splits a string and trims spaces on
// remaining elements, removing empty elements. | [
"SplitCondenseSpace",
"splits",
"a",
"string",
"and",
"trims",
"spaces",
"on",
"remaining",
"elements",
"removing",
"empty",
"elements",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L90-L100 |
142,616 | grokify/gotilla | type/stringsutil/stringsutil.go | CondenseString | func CondenseString(content string, join_lines bool) string {
if join_lines {
content = regexp.MustCompile(`\n`).ReplaceAllString(content, " ")
}
// Beginning
content = regexp.MustCompile(`^\s+`).ReplaceAllString(content, "")
// End
content = regexp.MustCompile(`\s+$`).ReplaceAllString(content, "")
// Middle
... | go | func CondenseString(content string, join_lines bool) string {
if join_lines {
content = regexp.MustCompile(`\n`).ReplaceAllString(content, " ")
}
// Beginning
content = regexp.MustCompile(`^\s+`).ReplaceAllString(content, "")
// End
content = regexp.MustCompile(`\s+$`).ReplaceAllString(content, "")
// Middle
... | [
"func",
"CondenseString",
"(",
"content",
"string",
",",
"join_lines",
"bool",
")",
"string",
"{",
"if",
"join_lines",
"{",
"content",
"=",
"regexp",
".",
"MustCompile",
"(",
"`\\n`",
")",
".",
"ReplaceAllString",
"(",
"content",
",",
"\"",
"\"",
")",
"\n"... | // CondenseString trims whitespace at the ends of the string
// as well as in between. | [
"CondenseString",
"trims",
"whitespace",
"at",
"the",
"ends",
"of",
"the",
"string",
"as",
"well",
"as",
"in",
"between",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L104-L119 |
142,617 | grokify/gotilla | type/stringsutil/stringsutil.go | TrimSentenceLength | func TrimSentenceLength(sentenceInput string, maxLength int) string {
if len(sentenceInput) <= maxLength {
return sentenceInput
}
sentenceLen := string(sentenceInput[0:maxLength]) // first350 := string(s[0:350])
rx_end := regexp.MustCompile(`[[:punct:]][^[[:punct:]]]*$`)
sentencePunct := rx_end.ReplaceAllString(... | go | func TrimSentenceLength(sentenceInput string, maxLength int) string {
if len(sentenceInput) <= maxLength {
return sentenceInput
}
sentenceLen := string(sentenceInput[0:maxLength]) // first350 := string(s[0:350])
rx_end := regexp.MustCompile(`[[:punct:]][^[[:punct:]]]*$`)
sentencePunct := rx_end.ReplaceAllString(... | [
"func",
"TrimSentenceLength",
"(",
"sentenceInput",
"string",
",",
"maxLength",
"int",
")",
"string",
"{",
"if",
"len",
"(",
"sentenceInput",
")",
"<=",
"maxLength",
"{",
"return",
"sentenceInput",
"\n",
"}",
"\n",
"sentenceLen",
":=",
"string",
"(",
"sentence... | // TrimSentenceLength trims a string by a max length at word boundaries. | [
"TrimSentenceLength",
"trims",
"a",
"string",
"by",
"a",
"max",
"length",
"at",
"word",
"boundaries",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L124-L135 |
142,618 | grokify/gotilla | type/stringsutil/stringsutil.go | JoinInterface | func JoinInterface(arr []interface{}, sep string, stripRepeatedSep bool, stripEmbeddedSep bool, altSep string) string {
parts := []string{}
rx := regexp.MustCompile(sep)
for _, el := range arr {
part := fmt.Sprintf("%v", el)
if stripEmbeddedSep {
part = rx.ReplaceAllString(part, altSep)
}
parts = append(p... | go | func JoinInterface(arr []interface{}, sep string, stripRepeatedSep bool, stripEmbeddedSep bool, altSep string) string {
parts := []string{}
rx := regexp.MustCompile(sep)
for _, el := range arr {
part := fmt.Sprintf("%v", el)
if stripEmbeddedSep {
part = rx.ReplaceAllString(part, altSep)
}
parts = append(p... | [
"func",
"JoinInterface",
"(",
"arr",
"[",
"]",
"interface",
"{",
"}",
",",
"sep",
"string",
",",
"stripRepeatedSep",
"bool",
",",
"stripEmbeddedSep",
"bool",
",",
"altSep",
"string",
")",
"string",
"{",
"parts",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
... | // JoinInterface joins an interface and returns a string. It takes
// a join separator, boolean to replace the join separator in the
// string parts and a separator alternate. `stripEmbeddedSep` strips
// separator string found within parts. `stripRepeatedSep` strips
// repeating separators. This flexibility is designe... | [
"JoinInterface",
"joins",
"an",
"interface",
"and",
"returns",
"a",
"string",
".",
"It",
"takes",
"a",
"join",
"separator",
"boolean",
"to",
"replace",
"the",
"join",
"separator",
"in",
"the",
"string",
"parts",
"and",
"a",
"separator",
"alternate",
".",
"st... | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L147-L163 |
142,619 | grokify/gotilla | type/stringsutil/stringsutil.go | StringToConstant | func StringToConstant(s string) string {
newParts := []string{}
parts := strings.Split(s, "_")
ciMap := CommonInitialismsMap()
for _, p := range parts {
pUp := strings.ToUpper(p)
if _, ok := ciMap[pUp]; ok {
newParts = append(newParts, pUp)
} else {
newParts = append(newParts, ToUpperFirst(strings.ToLow... | go | func StringToConstant(s string) string {
newParts := []string{}
parts := strings.Split(s, "_")
ciMap := CommonInitialismsMap()
for _, p := range parts {
pUp := strings.ToUpper(p)
if _, ok := ciMap[pUp]; ok {
newParts = append(newParts, pUp)
} else {
newParts = append(newParts, ToUpperFirst(strings.ToLow... | [
"func",
"StringToConstant",
"(",
"s",
"string",
")",
"string",
"{",
"newParts",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"ciMap",
":=",
"CommonInitialismsMap",
"(",
")",
"... | // StringToConstant is used to generate constant names for code generation.
// It uses the commonInitialisms in Go Lint. | [
"StringToConstant",
"is",
"used",
"to",
"generate",
"constant",
"names",
"for",
"code",
"generation",
".",
"It",
"uses",
"the",
"commonInitialisms",
"in",
"Go",
"Lint",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/type/stringsutil/stringsutil.go#L237-L250 |
142,620 | grokify/gotilla | mime/multipartutil/multipartutil.go | NewMultipartBuilder | func NewMultipartBuilder() MultipartBuilder {
builder := MultipartBuilder{}
var b bytes.Buffer
builder.Buffer = &b
builder.Writer = multipart.NewWriter(&b)
return builder
} | go | func NewMultipartBuilder() MultipartBuilder {
builder := MultipartBuilder{}
var b bytes.Buffer
builder.Buffer = &b
builder.Writer = multipart.NewWriter(&b)
return builder
} | [
"func",
"NewMultipartBuilder",
"(",
")",
"MultipartBuilder",
"{",
"builder",
":=",
"MultipartBuilder",
"{",
"}",
"\n",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"builder",
".",
"Buffer",
"=",
"&",
"b",
"\n",
"builder",
".",
"Writer",
"=",
"multipart",
".",... | // NewMultipartBuilder instantiates a new MultipartBuilder. | [
"NewMultipartBuilder",
"instantiates",
"a",
"new",
"MultipartBuilder",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/mime/multipartutil/multipartutil.go#L51-L57 |
142,621 | grokify/gotilla | mime/multipartutil/multipartutil.go | WriteFieldString | func (builder *MultipartBuilder) WriteFieldString(partName string, data string) error {
return builder.Writer.WriteField(partName, data)
} | go | func (builder *MultipartBuilder) WriteFieldString(partName string, data string) error {
return builder.Writer.WriteField(partName, data)
} | [
"func",
"(",
"builder",
"*",
"MultipartBuilder",
")",
"WriteFieldString",
"(",
"partName",
"string",
",",
"data",
"string",
")",
"error",
"{",
"return",
"builder",
".",
"Writer",
".",
"WriteField",
"(",
"partName",
",",
"data",
")",
"\n",
"}"
] | // WriteFieldString adds a text part. | [
"WriteFieldString",
"adds",
"a",
"text",
"part",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/mime/multipartutil/multipartutil.go#L60-L62 |
142,622 | grokify/gotilla | mime/multipartutil/multipartutil.go | WriteFieldAsJSON | func (builder *MultipartBuilder) WriteFieldAsJSON(partName string, data interface{}, base64Encode bool) error {
jsonBytes, err := json.Marshal(data)
if err != nil {
return err
}
header := textproto.MIMEHeader{}
header.Add(hum.HeaderContentDisposition, fmt.Sprintf(`form-data; name="%s"`, partName))
header.Add(h... | go | func (builder *MultipartBuilder) WriteFieldAsJSON(partName string, data interface{}, base64Encode bool) error {
jsonBytes, err := json.Marshal(data)
if err != nil {
return err
}
header := textproto.MIMEHeader{}
header.Add(hum.HeaderContentDisposition, fmt.Sprintf(`form-data; name="%s"`, partName))
header.Add(h... | [
"func",
"(",
"builder",
"*",
"MultipartBuilder",
")",
"WriteFieldAsJSON",
"(",
"partName",
"string",
",",
"data",
"interface",
"{",
"}",
",",
"base64Encode",
"bool",
")",
"error",
"{",
"jsonBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"data",
")"... | // WriteFieldAsJSON adds a JSON part. | [
"WriteFieldAsJSON",
"adds",
"a",
"JSON",
"part",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/mime/multipartutil/multipartutil.go#L65-L90 |
142,623 | grokify/gotilla | mime/multipartutil/multipartutil.go | WriteFilePath | func (builder *MultipartBuilder) WriteFilePath(partName, srcFilepath string) error {
file, err := os.Open(srcFilepath)
if err != nil {
return err
}
defer file.Close()
_, filename := filepath.Split(srcFilepath)
return builder.WriteFileReader(partName, filename, file)
} | go | func (builder *MultipartBuilder) WriteFilePath(partName, srcFilepath string) error {
file, err := os.Open(srcFilepath)
if err != nil {
return err
}
defer file.Close()
_, filename := filepath.Split(srcFilepath)
return builder.WriteFileReader(partName, filename, file)
} | [
"func",
"(",
"builder",
"*",
"MultipartBuilder",
")",
"WriteFilePath",
"(",
"partName",
",",
"srcFilepath",
"string",
")",
"error",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"srcFilepath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // WriteFilePath adds a file part given a filename. | [
"WriteFilePath",
"adds",
"a",
"file",
"part",
"given",
"a",
"filename",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/mime/multipartutil/multipartutil.go#L140-L148 |
142,624 | grokify/gotilla | mime/multipartutil/multipartutil.go | WriteFileReader | func (builder *MultipartBuilder) WriteFileReader(partName, filename string, src io.Reader) error {
fw, err := builder.Writer.CreateFormFile(partName, filename)
if err != nil {
return err
}
_, err = io.Copy(fw, src)
return err
} | go | func (builder *MultipartBuilder) WriteFileReader(partName, filename string, src io.Reader) error {
fw, err := builder.Writer.CreateFormFile(partName, filename)
if err != nil {
return err
}
_, err = io.Copy(fw, src)
return err
} | [
"func",
"(",
"builder",
"*",
"MultipartBuilder",
")",
"WriteFileReader",
"(",
"partName",
",",
"filename",
"string",
",",
"src",
"io",
".",
"Reader",
")",
"error",
"{",
"fw",
",",
"err",
":=",
"builder",
".",
"Writer",
".",
"CreateFormFile",
"(",
"partName... | // WriteFileReader adds a file part given a filename and `io.Reader`. | [
"WriteFileReader",
"adds",
"a",
"file",
"part",
"given",
"a",
"filename",
"and",
"io",
".",
"Reader",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/mime/multipartutil/multipartutil.go#L163-L170 |
142,625 | grokify/gotilla | encoding/guid/guid.go | GuidToBase58 | func GuidToBase58(guid string) (string, error) {
bi, err := GuidToBigInt(guid)
if err != nil {
return "", err
}
return string(bitcoinmath.Big2Base58(bi)), nil
} | go | func GuidToBase58(guid string) (string, error) {
bi, err := GuidToBigInt(guid)
if err != nil {
return "", err
}
return string(bitcoinmath.Big2Base58(bi)), nil
} | [
"func",
"GuidToBase58",
"(",
"guid",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"bi",
",",
"err",
":=",
"GuidToBigInt",
"(",
"guid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
... | // GuidToBase58 converts a GUID string to a Base58 string using the Bitcoin alphabet. | [
"GuidToBase58",
"converts",
"a",
"GUID",
"string",
"to",
"a",
"Base58",
"string",
"using",
"the",
"Bitcoin",
"alphabet",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/encoding/guid/guid.go#L39-L45 |
142,626 | grokify/gotilla | encoding/guid/guid.go | Base58ToGuid | func Base58ToGuid(b58str string, inclHyphen bool) (string, error) {
b58 := bitcoinmath.Base58(b58str)
bi := b58.Base582Big()
guid := fmt.Sprintf("%032s", bi.Text(16))
if len(guid) != 32 {
return "", fmt.Errorf("Error converting base58 string to hex: %v", b58str)
}
if inclHyphen {
guid = rxGuid.ReplaceAllSt... | go | func Base58ToGuid(b58str string, inclHyphen bool) (string, error) {
b58 := bitcoinmath.Base58(b58str)
bi := b58.Base582Big()
guid := fmt.Sprintf("%032s", bi.Text(16))
if len(guid) != 32 {
return "", fmt.Errorf("Error converting base58 string to hex: %v", b58str)
}
if inclHyphen {
guid = rxGuid.ReplaceAllSt... | [
"func",
"Base58ToGuid",
"(",
"b58str",
"string",
",",
"inclHyphen",
"bool",
")",
"(",
"string",
",",
"error",
")",
"{",
"b58",
":=",
"bitcoinmath",
".",
"Base58",
"(",
"b58str",
")",
"\n",
"bi",
":=",
"b58",
".",
"Base582Big",
"(",
")",
"\n\n",
"guid",... | // Base58ToGuid converts a Base58 string to a GUID string, with or without hyphens, using the Bitcoin alphabet. | [
"Base58ToGuid",
"converts",
"a",
"Base58",
"string",
"to",
"a",
"GUID",
"string",
"with",
"or",
"without",
"hyphens",
"using",
"the",
"Bitcoin",
"alphabet",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/encoding/guid/guid.go#L48-L63 |
142,627 | grokify/gotilla | image/convertutil/reformatdir.go | ReformatImages | func ReformatImages(baseSrcDir, baseOutDir string, copyType CopyType) error {
var err error
baseSrcDir, err = filepath.Abs(strings.TrimSpace(baseSrcDir))
if err != nil {
return err
}
baseOutDir, err = filepath.Abs(strings.TrimSpace(baseOutDir))
if err != nil {
return err
}
return reformatImagesSubdir(baseSr... | go | func ReformatImages(baseSrcDir, baseOutDir string, copyType CopyType) error {
var err error
baseSrcDir, err = filepath.Abs(strings.TrimSpace(baseSrcDir))
if err != nil {
return err
}
baseOutDir, err = filepath.Abs(strings.TrimSpace(baseOutDir))
if err != nil {
return err
}
return reformatImagesSubdir(baseSr... | [
"func",
"ReformatImages",
"(",
"baseSrcDir",
",",
"baseOutDir",
"string",
",",
"copyType",
"CopyType",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"baseSrcDir",
",",
"err",
"=",
"filepath",
".",
"Abs",
"(",
"strings",
".",
"TrimSpace",
"(",
"baseSrcDir",... | // ReformatImages converts images in one dir to another using default
// formats for Kindle and PDF. | [
"ReformatImages",
"converts",
"images",
"in",
"one",
"dir",
"to",
"another",
"using",
"default",
"formats",
"for",
"Kindle",
"and",
"PDF",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/image/convertutil/reformatdir.go#L27-L38 |
142,628 | grokify/gotilla | errors/errorsutil/errorsutil.go | Append | func Append(err error, str string) error {
return errors.New(fmt.Sprint(err) + str)
} | go | func Append(err error, str string) error {
return errors.New(fmt.Sprint(err) + str)
} | [
"func",
"Append",
"(",
"err",
"error",
",",
"str",
"string",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"fmt",
".",
"Sprint",
"(",
"err",
")",
"+",
"str",
")",
"\n",
"}"
] | // Append adds additional text to an existing error. | [
"Append",
"adds",
"additional",
"text",
"to",
"an",
"existing",
"error",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/errors/errorsutil/errorsutil.go#L9-L11 |
142,629 | grokify/gotilla | net/httputilmore/http_client.go | DoRequestRateLimited | func DoRequestRateLimited(client *http.Client, req *http.Request, useXrlHyphen bool, fnLog FnLogRateLimitInfo) (*http.Response, error) {
resp, err := client.Do(req)
if err != nil {
return resp, err
}
rlstat := NewResponseRateLimitInfo(resp, useXrlHyphen)
if rlstat.XRateLimitRemaining <= 0 {
fnLog(rlstat)
t... | go | func DoRequestRateLimited(client *http.Client, req *http.Request, useXrlHyphen bool, fnLog FnLogRateLimitInfo) (*http.Response, error) {
resp, err := client.Do(req)
if err != nil {
return resp, err
}
rlstat := NewResponseRateLimitInfo(resp, useXrlHyphen)
if rlstat.XRateLimitRemaining <= 0 {
fnLog(rlstat)
t... | [
"func",
"DoRequestRateLimited",
"(",
"client",
"*",
"http",
".",
"Client",
",",
"req",
"*",
"http",
".",
"Request",
",",
"useXrlHyphen",
"bool",
",",
"fnLog",
"FnLogRateLimitInfo",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"resp",
"... | // DoRequestRateLimited will pause a request for the time specified in the
// HTTP response headers. | [
"DoRequestRateLimited",
"will",
"pause",
"a",
"request",
"for",
"the",
"time",
"specified",
"in",
"the",
"HTTP",
"response",
"headers",
"."
] | a89420864b4d1cc22c57bcc025cc960a91372b37 | https://github.com/grokify/gotilla/blob/a89420864b4d1cc22c57bcc025cc960a91372b37/net/httputilmore/http_client.go#L48-L72 |
142,630 | nbio/hitch | hitch.go | New | func New() *Hitch {
r := httprouter.New()
r.HandleMethodNotAllowed = false // may cause problems otherwise
return &Hitch{
Router: r,
}
} | go | func New() *Hitch {
r := httprouter.New()
r.HandleMethodNotAllowed = false // may cause problems otherwise
return &Hitch{
Router: r,
}
} | [
"func",
"New",
"(",
")",
"*",
"Hitch",
"{",
"r",
":=",
"httprouter",
".",
"New",
"(",
")",
"\n",
"r",
".",
"HandleMethodNotAllowed",
"=",
"false",
"// may cause problems otherwise",
"\n",
"return",
"&",
"Hitch",
"{",
"Router",
":",
"r",
",",
"}",
"\n",
... | // New initializes a new Hitch. | [
"New",
"initializes",
"a",
"new",
"Hitch",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L17-L23 |
142,631 | nbio/hitch | hitch.go | Use | func (h *Hitch) Use(middleware ...func(http.Handler) http.Handler) {
h.middleware = append(h.middleware, middleware...)
} | go | func (h *Hitch) Use(middleware ...func(http.Handler) http.Handler) {
h.middleware = append(h.middleware, middleware...)
} | [
"func",
"(",
"h",
"*",
"Hitch",
")",
"Use",
"(",
"middleware",
"...",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
")",
"{",
"h",
".",
"middleware",
"=",
"append",
"(",
"h",
".",
"middleware",
",",
"middleware",
"...",
")",
"\n... | // Use installs one or more middleware in the Hitch request cycle. | [
"Use",
"installs",
"one",
"or",
"more",
"middleware",
"in",
"the",
"Hitch",
"request",
"cycle",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L26-L28 |
142,632 | nbio/hitch | hitch.go | Handle | func (h *Hitch) Handle(method, path string, handler http.Handler, middleware ...func(http.Handler) http.Handler) {
for i := len(middleware) - 1; i >= 0; i-- {
handler = middleware[i](handler)
}
h.Router.Handle(method, path, wrap(handler))
} | go | func (h *Hitch) Handle(method, path string, handler http.Handler, middleware ...func(http.Handler) http.Handler) {
for i := len(middleware) - 1; i >= 0; i-- {
handler = middleware[i](handler)
}
h.Router.Handle(method, path, wrap(handler))
} | [
"func",
"(",
"h",
"*",
"Hitch",
")",
"Handle",
"(",
"method",
",",
"path",
"string",
",",
"handler",
"http",
".",
"Handler",
",",
"middleware",
"...",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
")",
"{",
"for",
"i",
":=",
"le... | // Handle registers a handler for the given method and path. | [
"Handle",
"registers",
"a",
"handler",
"for",
"the",
"given",
"method",
"and",
"path",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L46-L51 |
142,633 | nbio/hitch | hitch.go | HandleFunc | func (h *Hitch) HandleFunc(method, path string, handler func(http.ResponseWriter, *http.Request), middleware ...func(http.Handler) http.Handler) {
h.Handle(method, path, http.HandlerFunc(handler), middleware...)
} | go | func (h *Hitch) HandleFunc(method, path string, handler func(http.ResponseWriter, *http.Request), middleware ...func(http.Handler) http.Handler) {
h.Handle(method, path, http.HandlerFunc(handler), middleware...)
} | [
"func",
"(",
"h",
"*",
"Hitch",
")",
"HandleFunc",
"(",
"method",
",",
"path",
"string",
",",
"handler",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
",",
"middleware",
"...",
"func",
"(",
"http",
".",
"Handler",
... | // HandleFunc registers a func handler for the given method and path. | [
"HandleFunc",
"registers",
"a",
"func",
"handler",
"for",
"the",
"given",
"method",
"and",
"path",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L54-L56 |
142,634 | nbio/hitch | hitch.go | Put | func (h *Hitch) Put(path string, handler http.Handler, middleware ...func(http.Handler) http.Handler) {
h.Handle("PUT", path, handler, middleware...)
} | go | func (h *Hitch) Put(path string, handler http.Handler, middleware ...func(http.Handler) http.Handler) {
h.Handle("PUT", path, handler, middleware...)
} | [
"func",
"(",
"h",
"*",
"Hitch",
")",
"Put",
"(",
"path",
"string",
",",
"handler",
"http",
".",
"Handler",
",",
"middleware",
"...",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
")",
"{",
"h",
".",
"Handle",
"(",
"\"",
"\"",
... | // Put registers a PUT handler for the given path. | [
"Put",
"registers",
"a",
"PUT",
"handler",
"for",
"the",
"given",
"path",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L64-L66 |
142,635 | nbio/hitch | hitch.go | Handler | func (h *Hitch) Handler() http.Handler {
handler := http.Handler(h.Router)
for i := len(h.middleware) - 1; i >= 0; i-- {
handler = h.middleware[i](handler)
}
return handler
} | go | func (h *Hitch) Handler() http.Handler {
handler := http.Handler(h.Router)
for i := len(h.middleware) - 1; i >= 0; i-- {
handler = h.middleware[i](handler)
}
return handler
} | [
"func",
"(",
"h",
"*",
"Hitch",
")",
"Handler",
"(",
")",
"http",
".",
"Handler",
"{",
"handler",
":=",
"http",
".",
"Handler",
"(",
"h",
".",
"Router",
")",
"\n",
"for",
"i",
":=",
"len",
"(",
"h",
".",
"middleware",
")",
"-",
"1",
";",
"i",
... | // Handler returns an http.Handler for the embedded router and middleware. | [
"Handler",
"returns",
"an",
"http",
".",
"Handler",
"for",
"the",
"embedded",
"router",
"and",
"middleware",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L89-L95 |
142,636 | nbio/hitch | hitch.go | Params | func Params(req *http.Request) httprouter.Params {
if value, ok := httpcontext.GetOk(req, paramsKey); ok {
if params, ok := value.(httprouter.Params); ok {
return params
}
}
return httprouter.Params{}
} | go | func Params(req *http.Request) httprouter.Params {
if value, ok := httpcontext.GetOk(req, paramsKey); ok {
if params, ok := value.(httprouter.Params); ok {
return params
}
}
return httprouter.Params{}
} | [
"func",
"Params",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"httprouter",
".",
"Params",
"{",
"if",
"value",
",",
"ok",
":=",
"httpcontext",
".",
"GetOk",
"(",
"req",
",",
"paramsKey",
")",
";",
"ok",
"{",
"if",
"params",
",",
"ok",
":=",
"valu... | // Params returns the httprouter.Params for req. | [
"Params",
"returns",
"the",
"httprouter",
".",
"Params",
"for",
"req",
"."
] | 242e9e06e69ac1ca48e8b420ed87c21a051e0947 | https://github.com/nbio/hitch/blob/242e9e06e69ac1ca48e8b420ed87c21a051e0947/hitch.go#L109-L116 |
142,637 | fujiwara/shapeio | shapeio.go | NewReader | func NewReader(r io.Reader) *Reader {
return &Reader{
r: r,
ctx: context.Background(),
}
} | go | func NewReader(r io.Reader) *Reader {
return &Reader{
r: r,
ctx: context.Background(),
}
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"Reader",
"{",
"return",
"&",
"Reader",
"{",
"r",
":",
"r",
",",
"ctx",
":",
"context",
".",
"Background",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewReader returns a reader that implements io.Reader with rate limiting. | [
"NewReader",
"returns",
"a",
"reader",
"that",
"implements",
"io",
".",
"Reader",
"with",
"rate",
"limiting",
"."
] | c073257dd7455637a1fa51201a9865a14ecb7f20 | https://github.com/fujiwara/shapeio/blob/c073257dd7455637a1fa51201a9865a14ecb7f20/shapeio.go#L26-L31 |
142,638 | fujiwara/shapeio | shapeio.go | NewReaderWithContext | func NewReaderWithContext(r io.Reader, ctx context.Context) *Reader {
return &Reader{
r: r,
ctx: ctx,
}
} | go | func NewReaderWithContext(r io.Reader, ctx context.Context) *Reader {
return &Reader{
r: r,
ctx: ctx,
}
} | [
"func",
"NewReaderWithContext",
"(",
"r",
"io",
".",
"Reader",
",",
"ctx",
"context",
".",
"Context",
")",
"*",
"Reader",
"{",
"return",
"&",
"Reader",
"{",
"r",
":",
"r",
",",
"ctx",
":",
"ctx",
",",
"}",
"\n",
"}"
] | // NewReaderWithContext returns a reader that implements io.Reader with rate limiting. | [
"NewReaderWithContext",
"returns",
"a",
"reader",
"that",
"implements",
"io",
".",
"Reader",
"with",
"rate",
"limiting",
"."
] | c073257dd7455637a1fa51201a9865a14ecb7f20 | https://github.com/fujiwara/shapeio/blob/c073257dd7455637a1fa51201a9865a14ecb7f20/shapeio.go#L34-L39 |
142,639 | fujiwara/shapeio | shapeio.go | NewWriter | func NewWriter(w io.Writer) *Writer {
return &Writer{
w: w,
ctx: context.Background(),
}
} | go | func NewWriter(w io.Writer) *Writer {
return &Writer{
w: w,
ctx: context.Background(),
}
} | [
"func",
"NewWriter",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Writer",
"{",
"return",
"&",
"Writer",
"{",
"w",
":",
"w",
",",
"ctx",
":",
"context",
".",
"Background",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewWriter returns a writer that implements io.Writer with rate limiting. | [
"NewWriter",
"returns",
"a",
"writer",
"that",
"implements",
"io",
".",
"Writer",
"with",
"rate",
"limiting",
"."
] | c073257dd7455637a1fa51201a9865a14ecb7f20 | https://github.com/fujiwara/shapeio/blob/c073257dd7455637a1fa51201a9865a14ecb7f20/shapeio.go#L42-L47 |
142,640 | fujiwara/shapeio | shapeio.go | NewWriterWithContext | func NewWriterWithContext(w io.Writer, ctx context.Context) *Writer {
return &Writer{
w: w,
ctx: ctx,
}
} | go | func NewWriterWithContext(w io.Writer, ctx context.Context) *Writer {
return &Writer{
w: w,
ctx: ctx,
}
} | [
"func",
"NewWriterWithContext",
"(",
"w",
"io",
".",
"Writer",
",",
"ctx",
"context",
".",
"Context",
")",
"*",
"Writer",
"{",
"return",
"&",
"Writer",
"{",
"w",
":",
"w",
",",
"ctx",
":",
"ctx",
",",
"}",
"\n",
"}"
] | // NewWriterWithContext returns a writer that implements io.Writer with rate limiting. | [
"NewWriterWithContext",
"returns",
"a",
"writer",
"that",
"implements",
"io",
".",
"Writer",
"with",
"rate",
"limiting",
"."
] | c073257dd7455637a1fa51201a9865a14ecb7f20 | https://github.com/fujiwara/shapeio/blob/c073257dd7455637a1fa51201a9865a14ecb7f20/shapeio.go#L50-L55 |
142,641 | fujiwara/shapeio | shapeio.go | Read | func (s *Reader) Read(p []byte) (int, error) {
if s.limiter == nil {
return s.r.Read(p)
}
n, err := s.r.Read(p)
if err != nil {
return n, err
}
if err := s.limiter.WaitN(s.ctx, n); err != nil {
return n, err
}
return n, nil
} | go | func (s *Reader) Read(p []byte) (int, error) {
if s.limiter == nil {
return s.r.Read(p)
}
n, err := s.r.Read(p)
if err != nil {
return n, err
}
if err := s.limiter.WaitN(s.ctx, n); err != nil {
return n, err
}
return n, nil
} | [
"func",
"(",
"s",
"*",
"Reader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"s",
".",
"limiter",
"==",
"nil",
"{",
"return",
"s",
".",
"r",
".",
"Read",
"(",
"p",
")",
"\n",
"}",
"\n",
"n",
","... | // Read reads bytes into p. | [
"Read",
"reads",
"bytes",
"into",
"p",
"."
] | c073257dd7455637a1fa51201a9865a14ecb7f20 | https://github.com/fujiwara/shapeio/blob/c073257dd7455637a1fa51201a9865a14ecb7f20/shapeio.go#L64-L76 |
142,642 | droundy/goopt | goopt.go | Expand | func Expand(x string) string {
for k, v := range Vars {
x = strings.Join(strings.Split(x, k), v)
}
return x
} | go | func Expand(x string) string {
for k, v := range Vars {
x = strings.Join(strings.Split(x, k), v)
}
return x
} | [
"func",
"Expand",
"(",
"x",
"string",
")",
"string",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"Vars",
"{",
"x",
"=",
"strings",
".",
"Join",
"(",
"strings",
".",
"Split",
"(",
"x",
",",
"k",
")",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"x"... | // Expand all variables in Vars within the given string. This does
// not assume any prefix or suffix that sets off a variable from the
// rest of the text, so a var of A set to HI expanded into HAPPY will
// become HHIPPY. | [
"Expand",
"all",
"variables",
"in",
"Vars",
"within",
"the",
"given",
"string",
".",
"This",
"does",
"not",
"assume",
"any",
"prefix",
"or",
"suffix",
"that",
"sets",
"off",
"a",
"variable",
"from",
"the",
"rest",
"of",
"the",
"text",
"so",
"a",
"var",
... | 0b8effe182da161d81b011aba271507324ecb7ab | https://github.com/droundy/goopt/blob/0b8effe182da161d81b011aba271507324ecb7ab/goopt.go#L66-L71 |
142,643 | droundy/goopt | goopt.go | VisitAllNames | func VisitAllNames(f func(string)) {
for _, o := range opts {
for _, n := range o.names {
f(n)
}
}
} | go | func VisitAllNames(f func(string)) {
for _, o := range opts {
for _, n := range o.names {
f(n)
}
}
} | [
"func",
"VisitAllNames",
"(",
"f",
"func",
"(",
"string",
")",
")",
"{",
"for",
"_",
",",
"o",
":=",
"range",
"opts",
"{",
"for",
"_",
",",
"n",
":=",
"range",
"o",
".",
"names",
"{",
"f",
"(",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Execute the given closure on the name of all known arguments | [
"Execute",
"the",
"given",
"closure",
"on",
"the",
"name",
"of",
"all",
"known",
"arguments"
] | 0b8effe182da161d81b011aba271507324ecb7ab | https://github.com/droundy/goopt/blob/0b8effe182da161d81b011aba271507324ecb7ab/goopt.go#L194-L200 |
142,644 | droundy/goopt | slice.go | append | func append(slice *[]string, val string) {
length := len(*slice)
if cap(*slice) == length {
// we need to expand
newsl := make([]string, length, 2*(length+1))
for i, v := range *slice {
newsl[i] = v
}
*slice = newsl
}
*slice = (*slice)[0 : length+1]
(*slice)[length] = val
} | go | func append(slice *[]string, val string) {
length := len(*slice)
if cap(*slice) == length {
// we need to expand
newsl := make([]string, length, 2*(length+1))
for i, v := range *slice {
newsl[i] = v
}
*slice = newsl
}
*slice = (*slice)[0 : length+1]
(*slice)[length] = val
} | [
"func",
"append",
"(",
"slice",
"*",
"[",
"]",
"string",
",",
"val",
"string",
")",
"{",
"length",
":=",
"len",
"(",
"*",
"slice",
")",
"\n",
"if",
"cap",
"(",
"*",
"slice",
")",
"==",
"length",
"{",
"// we need to expand",
"newsl",
":=",
"make",
"... | // Here we have some utility slice routines
// append appends an element to a slice, in-place if possible, and
// expanding if needed. | [
"Here",
"we",
"have",
"some",
"utility",
"slice",
"routines",
"append",
"appends",
"an",
"element",
"to",
"a",
"slice",
"in",
"-",
"place",
"if",
"possible",
"and",
"expanding",
"if",
"needed",
"."
] | 0b8effe182da161d81b011aba271507324ecb7ab | https://github.com/droundy/goopt/blob/0b8effe182da161d81b011aba271507324ecb7ab/slice.go#L7-L19 |
142,645 | droundy/goopt | slice.go | cats | func cats(slices [][]string) []string {
lentot := 0
for _, sl := range slices {
lentot += len(sl)
}
out := make([]string, lentot)
i := 0
for _, sl := range slices {
for _, v := range sl {
out[i] = v
i++
}
}
return out
} | go | func cats(slices [][]string) []string {
lentot := 0
for _, sl := range slices {
lentot += len(sl)
}
out := make([]string, lentot)
i := 0
for _, sl := range slices {
for _, v := range sl {
out[i] = v
i++
}
}
return out
} | [
"func",
"cats",
"(",
"slices",
"[",
"]",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"lentot",
":=",
"0",
"\n",
"for",
"_",
",",
"sl",
":=",
"range",
"slices",
"{",
"lentot",
"+=",
"len",
"(",
"sl",
")",
"\n",
"}",
"\n",
"out",
":=",
"m... | // cats concatenates several slices, expanding if needed. | [
"cats",
"concatenates",
"several",
"slices",
"expanding",
"if",
"needed",
"."
] | 0b8effe182da161d81b011aba271507324ecb7ab | https://github.com/droundy/goopt/blob/0b8effe182da161d81b011aba271507324ecb7ab/slice.go#L27-L41 |
142,646 | djherbis/atime | stat.go | Stat | func Stat(name string) (time.Time, error) {
fi, err := os.Stat(name)
if err != nil {
return time.Time{}, err
}
return atime(fi), nil
} | go | func Stat(name string) (time.Time, error) {
fi, err := os.Stat(name)
if err != nil {
return time.Time{}, err
}
return atime(fi), nil
} | [
"func",
"Stat",
"(",
"name",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err... | // Stat returns the Last Access Time for the given filename | [
"Stat",
"returns",
"the",
"Last",
"Access",
"Time",
"for",
"the",
"given",
"filename"
] | 2d569978378562c466df74eda2d82900f435c5f4 | https://github.com/djherbis/atime/blob/2d569978378562c466df74eda2d82900f435c5f4/stat.go#L15-L21 |
142,647 | gogo/gateway | jsonpb.go | Marshal | func (j *JSONPb) Marshal(v interface{}) ([]byte, error) {
if _, ok := v.(proto.Message); !ok {
return j.marshalNonProtoField(v)
}
var buf bytes.Buffer
if err := j.marshalTo(&buf, v); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func (j *JSONPb) Marshal(v interface{}) ([]byte, error) {
if _, ok := v.(proto.Message); !ok {
return j.marshalNonProtoField(v)
}
var buf bytes.Buffer
if err := j.marshalTo(&buf, v); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"(",
"j",
"*",
"JSONPb",
")",
"Marshal",
"(",
"v",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"v",
".",
"(",
"proto",
".",
"Message",
")",
";",
"!",
"ok",
"{",
"return",
"j... | // Marshal marshals "v" into JSON. | [
"Marshal",
"marshals",
"v",
"into",
"JSON",
"."
] | 817b4cf527e834d7d563b7329355c45801d5e02d | https://github.com/gogo/gateway/blob/817b4cf527e834d7d563b7329355c45801d5e02d/jsonpb.go#L28-L37 |
142,648 | gogo/gateway | jsonpb.go | NewDecoder | func (j *JSONPb) NewDecoder(r io.Reader) runtime.Decoder {
d := json.NewDecoder(r)
return runtime.DecoderFunc(func(v interface{}) error { return decodeJSONPb(d, v) })
} | go | func (j *JSONPb) NewDecoder(r io.Reader) runtime.Decoder {
d := json.NewDecoder(r)
return runtime.DecoderFunc(func(v interface{}) error { return decodeJSONPb(d, v) })
} | [
"func",
"(",
"j",
"*",
"JSONPb",
")",
"NewDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"runtime",
".",
"Decoder",
"{",
"d",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"return",
"runtime",
".",
"DecoderFunc",
"(",
"func",
"(",
"v",
"inte... | // NewDecoder returns a runtime.Decoder which reads JSON stream from "r". | [
"NewDecoder",
"returns",
"a",
"runtime",
".",
"Decoder",
"which",
"reads",
"JSON",
"stream",
"from",
"r",
"."
] | 817b4cf527e834d7d563b7329355c45801d5e02d | https://github.com/gogo/gateway/blob/817b4cf527e834d7d563b7329355c45801d5e02d/jsonpb.go#L93-L96 |
142,649 | rs/xstats | handler_pre17.go | NewContext | func NewContext(ctx context.Context, xs XStater) context.Context {
return context.WithValue(ctx, xstatsKey, xs)
} | go | func NewContext(ctx context.Context, xs XStater) context.Context {
return context.WithValue(ctx, xstatsKey, xs)
} | [
"func",
"NewContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"xs",
"XStater",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"xstatsKey",
",",
"xs",
")",
"\n",
"}"
] | // NewContext returns a copy of the parent context and associates it with passed stats. | [
"NewContext",
"returns",
"a",
"copy",
"of",
"the",
"parent",
"context",
"and",
"associates",
"it",
"with",
"passed",
"stats",
"."
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/handler_pre17.go#L25-L27 |
142,650 | rs/xstats | handler_pre17.go | FromContext | func FromContext(ctx context.Context) XStater {
rc, ok := ctx.Value(xstatsKey).(XStater)
if ok {
return rc
}
return nop
} | go | func FromContext(ctx context.Context) XStater {
rc, ok := ctx.Value(xstatsKey).(XStater)
if ok {
return rc
}
return nop
} | [
"func",
"FromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"XStater",
"{",
"rc",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"xstatsKey",
")",
".",
"(",
"XStater",
")",
"\n",
"if",
"ok",
"{",
"return",
"rc",
"\n",
"}",
"\n",
"return",
"nop",... | // FromContext retreives the request's xstats client from a given context if any.
// If no xstats is embeded in the context, a nop instance is returned so you can
// use it safely without having to test for it's presence. | [
"FromContext",
"retreives",
"the",
"request",
"s",
"xstats",
"client",
"from",
"a",
"given",
"context",
"if",
"any",
".",
"If",
"no",
"xstats",
"is",
"embeded",
"in",
"the",
"context",
"a",
"nop",
"instance",
"is",
"returned",
"so",
"you",
"can",
"use",
... | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/handler_pre17.go#L32-L38 |
142,651 | rs/xstats | dogstatsd/dogstatsd.go | New | func New(w io.Writer, reportInterval time.Duration) xstats.Sender {
return NewMaxPacket(w, reportInterval, defaultMaxPacketLen)
} | go | func New(w io.Writer, reportInterval time.Duration) xstats.Sender {
return NewMaxPacket(w, reportInterval, defaultMaxPacketLen)
} | [
"func",
"New",
"(",
"w",
"io",
".",
"Writer",
",",
"reportInterval",
"time",
".",
"Duration",
")",
"xstats",
".",
"Sender",
"{",
"return",
"NewMaxPacket",
"(",
"w",
",",
"reportInterval",
",",
"defaultMaxPacketLen",
")",
"\n",
"}"
] | // New creates a datadog statsd sender that emits observations in the statsd
// protocol to the passed writer. Observations are buffered for the report
// interval or until the buffer exceeds a max packet size, whichever comes
// first. | [
"New",
"creates",
"a",
"datadog",
"statsd",
"sender",
"that",
"emits",
"observations",
"in",
"the",
"statsd",
"protocol",
"to",
"the",
"passed",
"writer",
".",
"Observations",
"are",
"buffered",
"for",
"the",
"report",
"interval",
"or",
"until",
"the",
"buffer... | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/dogstatsd/dogstatsd.go#L33-L35 |
142,652 | rs/xstats | dogstatsd/dogstatsd.go | NewMaxPacket | func NewMaxPacket(w io.Writer, reportInterval time.Duration, maxPacketLen int) xstats.Sender {
s := &sender{
c: make(chan string),
quit: make(chan struct{}),
done: make(chan struct{}),
}
go s.fwd(w, reportInterval, maxPacketLen)
return s
} | go | func NewMaxPacket(w io.Writer, reportInterval time.Duration, maxPacketLen int) xstats.Sender {
s := &sender{
c: make(chan string),
quit: make(chan struct{}),
done: make(chan struct{}),
}
go s.fwd(w, reportInterval, maxPacketLen)
return s
} | [
"func",
"NewMaxPacket",
"(",
"w",
"io",
".",
"Writer",
",",
"reportInterval",
"time",
".",
"Duration",
",",
"maxPacketLen",
"int",
")",
"xstats",
".",
"Sender",
"{",
"s",
":=",
"&",
"sender",
"{",
"c",
":",
"make",
"(",
"chan",
"string",
")",
",",
"q... | // NewMaxPacket creates a datadog statsd sender that emits observations in the
// statsd protocol to the passed writer. Observations are buffered for the
// report interval or until the buffer exceeds the max packet size, whichever
// comes first. | [
"NewMaxPacket",
"creates",
"a",
"datadog",
"statsd",
"sender",
"that",
"emits",
"observations",
"in",
"the",
"statsd",
"protocol",
"to",
"the",
"passed",
"writer",
".",
"Observations",
"are",
"buffered",
"for",
"the",
"report",
"interval",
"or",
"until",
"the",
... | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/dogstatsd/dogstatsd.go#L41-L49 |
142,653 | rs/xstats | dogstatsd/dogstatsd.go | Close | func (s *sender) Close() error {
close(s.quit)
<-s.done
close(s.c)
return nil
} | go | func (s *sender) Close() error {
close(s.quit)
<-s.done
close(s.c)
return nil
} | [
"func",
"(",
"s",
"*",
"sender",
")",
"Close",
"(",
")",
"error",
"{",
"close",
"(",
"s",
".",
"quit",
")",
"\n",
"<-",
"s",
".",
"done",
"\n",
"close",
"(",
"s",
".",
"c",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close implements xstats.Sender interface | [
"Close",
"implements",
"xstats",
".",
"Sender",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/dogstatsd/dogstatsd.go#L72-L78 |
142,654 | rs/xstats | dogstatsd/dogstatsd.go | t | func t(tags []string) string {
t := ""
if len(tags) > 0 {
t = "|#" + strings.Join(tags, ",")
}
return t
} | go | func t(tags []string) string {
t := ""
if len(tags) > 0 {
t = "|#" + strings.Join(tags, ",")
}
return t
} | [
"func",
"t",
"(",
"tags",
"[",
"]",
"string",
")",
"string",
"{",
"t",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"tags",
")",
">",
"0",
"{",
"t",
"=",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"tags",
",",
"\"",
"\"",
")",
"\n",
"}",
... | // Generate a DogStatsD tag suffix | [
"Generate",
"a",
"DogStatsD",
"tag",
"suffix"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/dogstatsd/dogstatsd.go#L81-L87 |
142,655 | rs/xstats | telegraf/telegraf.go | t | func t(tags []string) string {
for i, v := range tags {
tags[i] = strings.Replace(v, ":", "=", 1)
}
t := ""
if len(tags) > 0 {
t = "" + strings.Join(tags, ",")
}
return t
} | go | func t(tags []string) string {
for i, v := range tags {
tags[i] = strings.Replace(v, ":", "=", 1)
}
t := ""
if len(tags) > 0 {
t = "" + strings.Join(tags, ",")
}
return t
} | [
"func",
"t",
"(",
"tags",
"[",
"]",
"string",
")",
"string",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"tags",
"{",
"tags",
"[",
"i",
"]",
"=",
"strings",
".",
"Replace",
"(",
"v",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",... | // Generate a telegraf tag suffix | [
"Generate",
"a",
"telegraf",
"tag",
"suffix"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/telegraf/telegraf.go#L81-L90 |
142,656 | rs/xstats | xstats.go | NewScoping | func NewScoping(s Sender, delimiter string, scopes ...string) XStater {
var xs *xstats
if DisablePooling {
xs = &xstats{}
} else {
xs = xstatsPool.Get().(*xstats)
}
xs.s = s
if len(scopes) > 0 {
xs.prefix = strings.Join(scopes, delimiter) + delimiter
} else {
xs.prefix = ""
}
xs.delimiter = delimiter
... | go | func NewScoping(s Sender, delimiter string, scopes ...string) XStater {
var xs *xstats
if DisablePooling {
xs = &xstats{}
} else {
xs = xstatsPool.Get().(*xstats)
}
xs.s = s
if len(scopes) > 0 {
xs.prefix = strings.Join(scopes, delimiter) + delimiter
} else {
xs.prefix = ""
}
xs.delimiter = delimiter
... | [
"func",
"NewScoping",
"(",
"s",
"Sender",
",",
"delimiter",
"string",
",",
"scopes",
"...",
"string",
")",
"XStater",
"{",
"var",
"xs",
"*",
"xstats",
"\n",
"if",
"DisablePooling",
"{",
"xs",
"=",
"&",
"xstats",
"{",
"}",
"\n",
"}",
"else",
"{",
"xs"... | // NewScoping returns a new xstats client with the provided backend sender.
// The delimiter is used to delimit scopes. Initial scopes can be provided. | [
"NewScoping",
"returns",
"a",
"new",
"xstats",
"client",
"with",
"the",
"provided",
"backend",
"sender",
".",
"The",
"delimiter",
"is",
"used",
"to",
"delimit",
"scopes",
".",
"Initial",
"scopes",
"can",
"be",
"provided",
"."
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L82-L97 |
142,657 | rs/xstats | xstats.go | Copy | func Copy(xs XStater) XStater {
if c, ok := xs.(Copier); ok {
return c.Copy()
}
return nop
} | go | func Copy(xs XStater) XStater {
if c, ok := xs.(Copier); ok {
return c.Copy()
}
return nop
} | [
"func",
"Copy",
"(",
"xs",
"XStater",
")",
"XStater",
"{",
"if",
"c",
",",
"ok",
":=",
"xs",
".",
"(",
"Copier",
")",
";",
"ok",
"{",
"return",
"c",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"return",
"nop",
"\n",
"}"
] | // Copy makes a copy of the given XStater if it implements the Copier
// interface. Otherwise it returns a nop stats. | [
"Copy",
"makes",
"a",
"copy",
"of",
"the",
"given",
"XStater",
"if",
"it",
"implements",
"the",
"Copier",
"interface",
".",
"Otherwise",
"it",
"returns",
"a",
"nop",
"stats",
"."
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L101-L106 |
142,658 | rs/xstats | xstats.go | Scope | func Scope(xs XStater, scope string, scopes ...string) XStater {
if c, ok := xs.(Scoper); ok {
return c.Scope(scope, scopes...)
}
return nop
} | go | func Scope(xs XStater, scope string, scopes ...string) XStater {
if c, ok := xs.(Scoper); ok {
return c.Scope(scope, scopes...)
}
return nop
} | [
"func",
"Scope",
"(",
"xs",
"XStater",
",",
"scope",
"string",
",",
"scopes",
"...",
"string",
")",
"XStater",
"{",
"if",
"c",
",",
"ok",
":=",
"xs",
".",
"(",
"Scoper",
")",
";",
"ok",
"{",
"return",
"c",
".",
"Scope",
"(",
"scope",
",",
"scopes... | // Scope makes a scoped copy of the given XStater if it implements the Scoper
// interface. Otherwise it returns a nop stats. | [
"Scope",
"makes",
"a",
"scoped",
"copy",
"of",
"the",
"given",
"XStater",
"if",
"it",
"implements",
"the",
"Scoper",
"interface",
".",
"Otherwise",
"it",
"returns",
"a",
"nop",
"stats",
"."
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L110-L115 |
142,659 | rs/xstats | xstats.go | Copy | func (xs *xstats) Copy() XStater {
xs2 := NewScoping(xs.s, xs.delimiter, xs.prefix).(*xstats)
xs2.tags = xs.tags
return xs2
} | go | func (xs *xstats) Copy() XStater {
xs2 := NewScoping(xs.s, xs.delimiter, xs.prefix).(*xstats)
xs2.tags = xs.tags
return xs2
} | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"Copy",
"(",
")",
"XStater",
"{",
"xs2",
":=",
"NewScoping",
"(",
"xs",
".",
"s",
",",
"xs",
".",
"delimiter",
",",
"xs",
".",
"prefix",
")",
".",
"(",
"*",
"xstats",
")",
"\n",
"xs2",
".",
"tags",
"=",
... | // Copy implements the Copier interface | [
"Copy",
"implements",
"the",
"Copier",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L136-L140 |
142,660 | rs/xstats | xstats.go | Scope | func (xs *xstats) Scope(scope string, scopes ...string) XStater {
var scs []string
if xs.prefix == "" {
scs = make([]string, 0, 1+len(scopes))
} else {
scs = make([]string, 0, 2+len(scopes))
scs = append(scs, strings.TrimRight(xs.prefix, xs.delimiter))
}
scs = append(scs, scope)
scs = append(scs, scopes...)... | go | func (xs *xstats) Scope(scope string, scopes ...string) XStater {
var scs []string
if xs.prefix == "" {
scs = make([]string, 0, 1+len(scopes))
} else {
scs = make([]string, 0, 2+len(scopes))
scs = append(scs, strings.TrimRight(xs.prefix, xs.delimiter))
}
scs = append(scs, scope)
scs = append(scs, scopes...)... | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"Scope",
"(",
"scope",
"string",
",",
"scopes",
"...",
"string",
")",
"XStater",
"{",
"var",
"scs",
"[",
"]",
"string",
"\n",
"if",
"xs",
".",
"prefix",
"==",
"\"",
"\"",
"{",
"scs",
"=",
"make",
"(",
"[",
... | // Scope implements Scoper interface | [
"Scope",
"implements",
"Scoper",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L143-L156 |
142,661 | rs/xstats | xstats.go | Close | func (xs *xstats) Close() error {
if !DisablePooling {
xs.s = nil
xs.tags = nil
xs.prefix = ""
xs.delimiter = ""
xstatsPool.Put(xs)
}
return nil
} | go | func (xs *xstats) Close() error {
if !DisablePooling {
xs.s = nil
xs.tags = nil
xs.prefix = ""
xs.delimiter = ""
xstatsPool.Put(xs)
}
return nil
} | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"!",
"DisablePooling",
"{",
"xs",
".",
"s",
"=",
"nil",
"\n",
"xs",
".",
"tags",
"=",
"nil",
"\n",
"xs",
".",
"prefix",
"=",
"\"",
"\"",
"\n",
"xs",
".",
"delimiter",... | // Close returns the xstats to the sync.Pool | [
"Close",
"returns",
"the",
"xstats",
"to",
"the",
"sync",
".",
"Pool"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L159-L168 |
142,662 | rs/xstats | xstats.go | AddTags | func (xs *xstats) AddTags(tags ...string) {
if xs.tags == nil {
xs.tags = tags
} else {
xs.tags = append(xs.tags, tags...)
}
} | go | func (xs *xstats) AddTags(tags ...string) {
if xs.tags == nil {
xs.tags = tags
} else {
xs.tags = append(xs.tags, tags...)
}
} | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"AddTags",
"(",
"tags",
"...",
"string",
")",
"{",
"if",
"xs",
".",
"tags",
"==",
"nil",
"{",
"xs",
".",
"tags",
"=",
"tags",
"\n",
"}",
"else",
"{",
"xs",
".",
"tags",
"=",
"append",
"(",
"xs",
".",
"ta... | // AddTag implements XStater interface | [
"AddTag",
"implements",
"XStater",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L171-L177 |
142,663 | rs/xstats | xstats.go | Gauge | func (xs *xstats) Gauge(stat string, value float64, tags ...string) {
if xs.s == nil {
return
}
tags = append(tags, xs.tags...)
xs.s.Gauge(xs.prefix+stat, value, tags...)
} | go | func (xs *xstats) Gauge(stat string, value float64, tags ...string) {
if xs.s == nil {
return
}
tags = append(tags, xs.tags...)
xs.s.Gauge(xs.prefix+stat, value, tags...)
} | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"Gauge",
"(",
"stat",
"string",
",",
"value",
"float64",
",",
"tags",
"...",
"string",
")",
"{",
"if",
"xs",
".",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"tags",
"=",
"append",
"(",
"tags",
",",
... | // Gauge implements XStater interface | [
"Gauge",
"implements",
"XStater",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L185-L191 |
142,664 | rs/xstats | xstats.go | Count | func (xs *xstats) Count(stat string, count float64, tags ...string) {
if xs.s == nil {
return
}
tags = append(tags, xs.tags...)
xs.s.Count(xs.prefix+stat, count, tags...)
} | go | func (xs *xstats) Count(stat string, count float64, tags ...string) {
if xs.s == nil {
return
}
tags = append(tags, xs.tags...)
xs.s.Count(xs.prefix+stat, count, tags...)
} | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"Count",
"(",
"stat",
"string",
",",
"count",
"float64",
",",
"tags",
"...",
"string",
")",
"{",
"if",
"xs",
".",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"tags",
"=",
"append",
"(",
"tags",
",",
... | // Count implements XStater interface | [
"Count",
"implements",
"XStater",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L194-L200 |
142,665 | rs/xstats | xstats.go | Timing | func (xs *xstats) Timing(stat string, duration time.Duration, tags ...string) {
if xs.s == nil {
return
}
tags = append(tags, xs.tags...)
xs.s.Timing(xs.prefix+stat, duration, tags...)
} | go | func (xs *xstats) Timing(stat string, duration time.Duration, tags ...string) {
if xs.s == nil {
return
}
tags = append(tags, xs.tags...)
xs.s.Timing(xs.prefix+stat, duration, tags...)
} | [
"func",
"(",
"xs",
"*",
"xstats",
")",
"Timing",
"(",
"stat",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"tags",
"...",
"string",
")",
"{",
"if",
"xs",
".",
"s",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"tags",
"=",
"append",
"(... | // Timing implements XStater interface | [
"Timing",
"implements",
"XStater",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/xstats.go#L212-L218 |
142,666 | rs/xstats | sender.go | Gauge | func (s MultiSender) Gauge(stat string, value float64, tags ...string) {
for _, ss := range s {
ss.Gauge(stat, value, tags...)
}
} | go | func (s MultiSender) Gauge(stat string, value float64, tags ...string) {
for _, ss := range s {
ss.Gauge(stat, value, tags...)
}
} | [
"func",
"(",
"s",
"MultiSender",
")",
"Gauge",
"(",
"stat",
"string",
",",
"value",
"float64",
",",
"tags",
"...",
"string",
")",
"{",
"for",
"_",
",",
"ss",
":=",
"range",
"s",
"{",
"ss",
".",
"Gauge",
"(",
"stat",
",",
"value",
",",
"tags",
"..... | // Gauge implements the xstats.Sender interface | [
"Gauge",
"implements",
"the",
"xstats",
".",
"Sender",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/sender.go#L43-L47 |
142,667 | rs/xstats | sender.go | Count | func (s MultiSender) Count(stat string, count float64, tags ...string) {
for _, ss := range s {
ss.Count(stat, count, tags...)
}
} | go | func (s MultiSender) Count(stat string, count float64, tags ...string) {
for _, ss := range s {
ss.Count(stat, count, tags...)
}
} | [
"func",
"(",
"s",
"MultiSender",
")",
"Count",
"(",
"stat",
"string",
",",
"count",
"float64",
",",
"tags",
"...",
"string",
")",
"{",
"for",
"_",
",",
"ss",
":=",
"range",
"s",
"{",
"ss",
".",
"Count",
"(",
"stat",
",",
"count",
",",
"tags",
"..... | // Count implements the xstats.Sender interface | [
"Count",
"implements",
"the",
"xstats",
".",
"Sender",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/sender.go#L50-L54 |
142,668 | rs/xstats | sender.go | Timing | func (s MultiSender) Timing(stat string, duration time.Duration, tags ...string) {
for _, ss := range s {
ss.Timing(stat, duration, tags...)
}
} | go | func (s MultiSender) Timing(stat string, duration time.Duration, tags ...string) {
for _, ss := range s {
ss.Timing(stat, duration, tags...)
}
} | [
"func",
"(",
"s",
"MultiSender",
")",
"Timing",
"(",
"stat",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"tags",
"...",
"string",
")",
"{",
"for",
"_",
",",
"ss",
":=",
"range",
"s",
"{",
"ss",
".",
"Timing",
"(",
"stat",
",",
"duratio... | // Timing implements the xstats.Sender interface | [
"Timing",
"implements",
"the",
"xstats",
".",
"Sender",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/sender.go#L64-L68 |
142,669 | rs/xstats | prometheus/prometheus.go | New | func New(addr string) xstats.Sender {
s := NewHandler()
go func() {
http.ListenAndServe(addr, s)
}()
return s
} | go | func New(addr string) xstats.Sender {
s := NewHandler()
go func() {
http.ListenAndServe(addr, s)
}()
return s
} | [
"func",
"New",
"(",
"addr",
"string",
")",
"xstats",
".",
"Sender",
"{",
"s",
":=",
"NewHandler",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"http",
".",
"ListenAndServe",
"(",
"addr",
",",
"s",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"s",
... | // New creates a prometheus publisher at the given HTTP address. | [
"New",
"creates",
"a",
"prometheus",
"publisher",
"at",
"the",
"given",
"HTTP",
"address",
"."
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/prometheus/prometheus.go#L23-L29 |
142,670 | rs/xstats | prometheus/prometheus.go | NewHandler | func NewHandler() *sender {
return &sender{
Handler: prometheus.Handler(),
counters: make(map[string]*prometheus.CounterVec),
gauges: make(map[string]*prometheus.GaugeVec),
histograms: make(map[string]*prometheus.HistogramVec),
}
} | go | func NewHandler() *sender {
return &sender{
Handler: prometheus.Handler(),
counters: make(map[string]*prometheus.CounterVec),
gauges: make(map[string]*prometheus.GaugeVec),
histograms: make(map[string]*prometheus.HistogramVec),
}
} | [
"func",
"NewHandler",
"(",
")",
"*",
"sender",
"{",
"return",
"&",
"sender",
"{",
"Handler",
":",
"prometheus",
".",
"Handler",
"(",
")",
",",
"counters",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"prometheus",
".",
"CounterVec",
")",
",",
"g... | // NewHandler creates a prometheus publisher - a http.Handler and an xstats.Sender. | [
"NewHandler",
"creates",
"a",
"prometheus",
"publisher",
"-",
"a",
"http",
".",
"Handler",
"and",
"an",
"xstats",
".",
"Sender",
"."
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/prometheus/prometheus.go#L32-L39 |
142,671 | rs/xstats | mock/mock.go | Histogram | func (s *sender) Histogram(stat string, value float64, tags ...string) {
s.Called(stat, value, tags)
} | go | func (s *sender) Histogram(stat string, value float64, tags ...string) {
s.Called(stat, value, tags)
} | [
"func",
"(",
"s",
"*",
"sender",
")",
"Histogram",
"(",
"stat",
"string",
",",
"value",
"float64",
",",
"tags",
"...",
"string",
")",
"{",
"s",
".",
"Called",
"(",
"stat",
",",
"value",
",",
"tags",
")",
"\n",
"}"
] | // Histogram implements xstats.Sender interface | [
"Histogram",
"implements",
"xstats",
".",
"Sender",
"interface"
] | c67367528e160e557423e4d87059614d8c31a582 | https://github.com/rs/xstats/blob/c67367528e160e557423e4d87059614d8c31a582/mock/mock.go#L31-L33 |
142,672 | polds/imgbase64 | images.go | FromRemote | func FromRemote(url string) string {
image, mime := get(cleanUrl(url))
enc := encode(image)
out := format(enc, mime)
return out
} | go | func FromRemote(url string) string {
image, mime := get(cleanUrl(url))
enc := encode(image)
out := format(enc, mime)
return out
} | [
"func",
"FromRemote",
"(",
"url",
"string",
")",
"string",
"{",
"image",
",",
"mime",
":=",
"get",
"(",
"cleanUrl",
"(",
"url",
")",
")",
"\n",
"enc",
":=",
"encode",
"(",
"image",
")",
"\n\n",
"out",
":=",
"format",
"(",
"enc",
",",
"mime",
")",
... | // FromRemote is a better named function that
// presently calls NewImage which will be deprecated.
// Function accepts an RFC compliant URL and returns
// a base64 encoded result. | [
"FromRemote",
"is",
"a",
"better",
"named",
"function",
"that",
"presently",
"calls",
"NewImage",
"which",
"will",
"be",
"deprecated",
".",
"Function",
"accepts",
"an",
"RFC",
"compliant",
"URL",
"and",
"returns",
"a",
"base64",
"encoded",
"result",
"."
] | cb7bf37298b7c2d13bd2451f51674d6bbdb46e44 | https://github.com/polds/imgbase64/blob/cb7bf37298b7c2d13bd2451f51674d6bbdb46e44/images.go#L78-L84 |
142,673 | polds/imgbase64 | images.go | FromBuffer | func FromBuffer(buf bytes.Buffer) string {
enc := encode(buf.Bytes())
mime := http.DetectContentType(buf.Bytes())
return format(enc, mime)
} | go | func FromBuffer(buf bytes.Buffer) string {
enc := encode(buf.Bytes())
mime := http.DetectContentType(buf.Bytes())
return format(enc, mime)
} | [
"func",
"FromBuffer",
"(",
"buf",
"bytes",
".",
"Buffer",
")",
"string",
"{",
"enc",
":=",
"encode",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"mime",
":=",
"http",
".",
"DetectContentType",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"re... | // FromBuffer accepts a buffer and returns a
// base64 encoded string. | [
"FromBuffer",
"accepts",
"a",
"buffer",
"and",
"returns",
"a",
"base64",
"encoded",
"string",
"."
] | cb7bf37298b7c2d13bd2451f51674d6bbdb46e44 | https://github.com/polds/imgbase64/blob/cb7bf37298b7c2d13bd2451f51674d6bbdb46e44/images.go#L88-L93 |
142,674 | polds/imgbase64 | images.go | FromLocal | func FromLocal(fname string) (string, error) {
var b bytes.Buffer
fileExists, _ := exists(fname)
if !fileExists {
return "", fmt.Errorf("File does not exist\n")
}
file, err := os.Open(fname)
if err != nil {
return "", fmt.Errorf("Error opening file\n")
}
_, err = b.ReadFrom(file)
if err != nil {
retur... | go | func FromLocal(fname string) (string, error) {
var b bytes.Buffer
fileExists, _ := exists(fname)
if !fileExists {
return "", fmt.Errorf("File does not exist\n")
}
file, err := os.Open(fname)
if err != nil {
return "", fmt.Errorf("Error opening file\n")
}
_, err = b.ReadFrom(file)
if err != nil {
retur... | [
"func",
"FromLocal",
"(",
"fname",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n\n",
"fileExists",
",",
"_",
":=",
"exists",
"(",
"fname",
")",
"\n",
"if",
"!",
"fileExists",
"{",
"return",
"\"",
"\"",
... | // FromLocal reads a local file and returns
// the base64 encoded version. | [
"FromLocal",
"reads",
"a",
"local",
"file",
"and",
"returns",
"the",
"base64",
"encoded",
"version",
"."
] | cb7bf37298b7c2d13bd2451f51674d6bbdb46e44 | https://github.com/polds/imgbase64/blob/cb7bf37298b7c2d13bd2451f51674d6bbdb46e44/images.go#L97-L116 |
142,675 | polds/imgbase64 | images.go | format | func format(enc []byte, mime string) string {
switch mime {
case "image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/tiff":
return fmt.Sprintf("data:%s;base64,%s", mime, enc)
default:
}
return fmt.Sprintf("data:image/png;base64,%s", enc)
} | go | func format(enc []byte, mime string) string {
switch mime {
case "image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/tiff":
return fmt.Sprintf("data:%s;base64,%s", mime, enc)
default:
}
return fmt.Sprintf("data:image/png;base64,%s", enc)
} | [
"func",
"format",
"(",
"enc",
"[",
"]",
"byte",
",",
"mime",
"string",
")",
"string",
"{",
"switch",
"mime",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"fmt",
".",
"Sprintf",
"(",... | // format is an abstraction of the mime switch to create the
// acceptable base64 string needed for browsers. | [
"format",
"is",
"an",
"abstraction",
"of",
"the",
"mime",
"switch",
"to",
"create",
"the",
"acceptable",
"base64",
"string",
"needed",
"for",
"browsers",
"."
] | cb7bf37298b7c2d13bd2451f51674d6bbdb46e44 | https://github.com/polds/imgbase64/blob/cb7bf37298b7c2d13bd2451f51674d6bbdb46e44/images.go#L120-L128 |
142,676 | caio/go-tdigest | tdigest.go | newWithoutSummary | func newWithoutSummary(options ...tdigestOption) (*TDigest, error) {
tdigest := &TDigest{
compression: 100,
count: 0,
rng: globalRNG{},
}
for _, option := range options {
err := option(tdigest)
if err != nil {
return nil, err
}
}
return tdigest, nil
} | go | func newWithoutSummary(options ...tdigestOption) (*TDigest, error) {
tdigest := &TDigest{
compression: 100,
count: 0,
rng: globalRNG{},
}
for _, option := range options {
err := option(tdigest)
if err != nil {
return nil, err
}
}
return tdigest, nil
} | [
"func",
"newWithoutSummary",
"(",
"options",
"...",
"tdigestOption",
")",
"(",
"*",
"TDigest",
",",
"error",
")",
"{",
"tdigest",
":=",
"&",
"TDigest",
"{",
"compression",
":",
"100",
",",
"count",
":",
"0",
",",
"rng",
":",
"globalRNG",
"{",
"}",
",",... | // Creates a tdigest instance without allocating a summary. | [
"Creates",
"a",
"tdigest",
"instance",
"without",
"allocating",
"a",
"summary",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L54-L69 |
142,677 | caio/go-tdigest | tdigest.go | AddWeighted | func (t *TDigest) AddWeighted(value float64, count uint32) (err error) {
if count == 0 {
return fmt.Errorf("Illegal datapoint <value: %.4f, count: %d>", value, count)
}
if t.summary.Len() == 0 {
err = t.summary.Add(value, count)
t.count = uint64(count)
return err
}
begin := t.summary.Floor(value)
if be... | go | func (t *TDigest) AddWeighted(value float64, count uint32) (err error) {
if count == 0 {
return fmt.Errorf("Illegal datapoint <value: %.4f, count: %d>", value, count)
}
if t.summary.Len() == 0 {
err = t.summary.Add(value, count)
t.count = uint64(count)
return err
}
begin := t.summary.Floor(value)
if be... | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"AddWeighted",
"(",
"value",
"float64",
",",
"count",
"uint32",
")",
"(",
"err",
"error",
")",
"{",
"if",
"count",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
",",
"count",
... | // AddWeighted registers a new sample in the digest.
//
// It's the main entry point for the digest and very likely the only
// method to be used for collecting samples. The count parameter is for
// when you are registering a sample that occurred multiple times - the
// most common value for this is 1.
//
// This will... | [
"AddWeighted",
"registers",
"a",
"new",
"sample",
"in",
"the",
"digest",
".",
"It",
"s",
"the",
"main",
"entry",
"point",
"for",
"the",
"digest",
"and",
"very",
"likely",
"the",
"only",
"method",
"to",
"be",
"used",
"for",
"collecting",
"samples",
".",
"... | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L156-L194 |
142,678 | caio/go-tdigest | tdigest.go | Compress | func (t *TDigest) Compress() (err error) {
if t.summary.Len() <= 1 {
return nil
}
oldTree := t.summary
t.summary = newSummary(estimateCapacity(t.compression))
t.count = 0
oldTree.shuffle(t.rng)
oldTree.ForEach(func(mean float64, count uint32) bool {
err = t.AddWeighted(mean, count)
return err == nil
})
... | go | func (t *TDigest) Compress() (err error) {
if t.summary.Len() <= 1 {
return nil
}
oldTree := t.summary
t.summary = newSummary(estimateCapacity(t.compression))
t.count = 0
oldTree.shuffle(t.rng)
oldTree.ForEach(func(mean float64, count uint32) bool {
err = t.AddWeighted(mean, count)
return err == nil
})
... | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"Compress",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"t",
".",
"summary",
".",
"Len",
"(",
")",
"<=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"oldTree",
":=",
"t",
".",
"summary",
"\n",
"t",
... | // Compress tries to reduce the number of individual centroids stored
// in the digest.
//
// Compression trades off accuracy for performance and happens
// automatically after a certain amount of distinct samples have been
// stored.
//
// At any point in time you may call Compress on a digest, but you
// may complete... | [
"Compress",
"tries",
"to",
"reduce",
"the",
"number",
"of",
"individual",
"centroids",
"stored",
"in",
"the",
"digest",
".",
"Compression",
"trades",
"off",
"accuracy",
"for",
"performance",
"and",
"happens",
"automatically",
"after",
"a",
"certain",
"amount",
"... | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L233-L248 |
142,679 | caio/go-tdigest | tdigest.go | MergeDestructive | func (t *TDigest) MergeDestructive(other *TDigest) (err error) {
if other.summary.Len() == 0 {
return nil
}
other.summary.shuffle(t.rng)
other.summary.ForEach(func(mean float64, count uint32) bool {
err = t.AddWeighted(mean, count)
return err == nil
})
return err
} | go | func (t *TDigest) MergeDestructive(other *TDigest) (err error) {
if other.summary.Len() == 0 {
return nil
}
other.summary.shuffle(t.rng)
other.summary.ForEach(func(mean float64, count uint32) bool {
err = t.AddWeighted(mean, count)
return err == nil
})
return err
} | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"MergeDestructive",
"(",
"other",
"*",
"TDigest",
")",
"(",
"err",
"error",
")",
"{",
"if",
"other",
".",
"summary",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"other",
".",
"s... | // MergeDestructive joins a given digest into itself rendering
// the other digest invalid.
//
// This works as Merge above but its faster. Using this method
// requires caution as it makes 'other' useless - you must make
// sure you discard it without making further uses of it. | [
"MergeDestructive",
"joins",
"a",
"given",
"digest",
"into",
"itself",
"rendering",
"the",
"other",
"digest",
"invalid",
".",
"This",
"works",
"as",
"Merge",
"above",
"but",
"its",
"faster",
".",
"Using",
"this",
"method",
"requires",
"caution",
"as",
"it",
... | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L274-L285 |
142,680 | caio/go-tdigest | tdigest.go | CDF | func (t *TDigest) CDF(value float64) float64 {
if t.summary.Len() == 0 {
return math.NaN()
} else if t.summary.Len() == 1 {
if value < t.summary.Mean(0) {
return 0
}
return 1
}
// We have at least 2 centroids
left := (t.summary.Mean(1) - t.summary.Mean(0)) / 2
right := left
tot := 0.0
for i := 1; i... | go | func (t *TDigest) CDF(value float64) float64 {
if t.summary.Len() == 0 {
return math.NaN()
} else if t.summary.Len() == 1 {
if value < t.summary.Mean(0) {
return 0
}
return 1
}
// We have at least 2 centroids
left := (t.summary.Mean(1) - t.summary.Mean(0)) / 2
right := left
tot := 0.0
for i := 1; i... | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"CDF",
"(",
"value",
"float64",
")",
"float64",
"{",
"if",
"t",
".",
"summary",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"math",
".",
"NaN",
"(",
")",
"\n",
"}",
"else",
"if",
"t",
".",
"summary",
... | // CDF computes the fraction in which all samples are less than
// or equal to the given value. | [
"CDF",
"computes",
"the",
"fraction",
"in",
"which",
"all",
"samples",
"are",
"less",
"than",
"or",
"equal",
"to",
"the",
"given",
"value",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L289-L327 |
142,681 | caio/go-tdigest | tdigest.go | Clone | func (t *TDigest) Clone() *TDigest {
return &TDigest{
summary: t.summary.Clone(),
compression: t.compression,
count: t.count,
rng: t.rng,
}
} | go | func (t *TDigest) Clone() *TDigest {
return &TDigest{
summary: t.summary.Clone(),
compression: t.compression,
count: t.count,
rng: t.rng,
}
} | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"Clone",
"(",
")",
"*",
"TDigest",
"{",
"return",
"&",
"TDigest",
"{",
"summary",
":",
"t",
".",
"summary",
".",
"Clone",
"(",
")",
",",
"compression",
":",
"t",
".",
"compression",
",",
"count",
":",
"t",
"... | // Clone returns a deep copy of a TDigest. | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"a",
"TDigest",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L330-L337 |
142,682 | caio/go-tdigest | tdigest.go | ForEachCentroid | func (t *TDigest) ForEachCentroid(f func(mean float64, count uint32) bool) {
t.summary.ForEach(f)
} | go | func (t *TDigest) ForEachCentroid(f func(mean float64, count uint32) bool) {
t.summary.ForEach(f)
} | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"ForEachCentroid",
"(",
"f",
"func",
"(",
"mean",
"float64",
",",
"count",
"uint32",
")",
"bool",
")",
"{",
"t",
".",
"summary",
".",
"ForEach",
"(",
"f",
")",
"\n",
"}"
] | // ForEachCentroid calls the specified function for each centroid.
//
// Iteration stops when the supplied function returns false, or when all
// centroids have been iterated. | [
"ForEachCentroid",
"calls",
"the",
"specified",
"function",
"for",
"each",
"centroid",
".",
"Iteration",
"stops",
"when",
"the",
"supplied",
"function",
"returns",
"false",
"or",
"when",
"all",
"centroids",
"have",
"been",
"iterated",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/tdigest.go#L347-L349 |
142,683 | caio/go-tdigest | summary.go | findInsertionIndex | func (s *summary) findInsertionIndex(x float64) int {
// Binary search is only worthwhile if we have a lot of keys.
if len(s.means) < 250 {
for i, mean := range s.means {
if mean > x {
return i
}
}
return len(s.means)
}
return sort.Search(len(s.means), func(i int) bool {
return s.means[i] > x
})... | go | func (s *summary) findInsertionIndex(x float64) int {
// Binary search is only worthwhile if we have a lot of keys.
if len(s.means) < 250 {
for i, mean := range s.means {
if mean > x {
return i
}
}
return len(s.means)
}
return sort.Search(len(s.means), func(i int) bool {
return s.means[i] > x
})... | [
"func",
"(",
"s",
"*",
"summary",
")",
"findInsertionIndex",
"(",
"x",
"float64",
")",
"int",
"{",
"// Binary search is only worthwhile if we have a lot of keys.",
"if",
"len",
"(",
"s",
".",
"means",
")",
"<",
"250",
"{",
"for",
"i",
",",
"mean",
":=",
"ran... | // Always insert to the right | [
"Always",
"insert",
"to",
"the",
"right"
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/summary.go#L49-L63 |
142,684 | caio/go-tdigest | summary.go | shuffle | func (s *summary) shuffle(rng RNG) {
for i := len(s.means) - 1; i > 1; i-- {
s.Swap(i, rng.Intn(i+1))
}
} | go | func (s *summary) shuffle(rng RNG) {
for i := len(s.means) - 1; i > 1; i-- {
s.Swap(i, rng.Intn(i+1))
}
} | [
"func",
"(",
"s",
"*",
"summary",
")",
"shuffle",
"(",
"rng",
"RNG",
")",
"{",
"for",
"i",
":=",
"len",
"(",
"s",
".",
"means",
")",
"-",
"1",
";",
"i",
">",
"1",
";",
"i",
"--",
"{",
"s",
".",
"Swap",
"(",
"i",
",",
"rng",
".",
"Intn",
... | // Randomly shuffles summary contents, so they can be added to another summary
// with being pathological. Renders summary invalid. | [
"Randomly",
"shuffles",
"summary",
"contents",
"so",
"they",
"can",
"be",
"added",
"to",
"another",
"summary",
"with",
"being",
"pathological",
".",
"Renders",
"summary",
"invalid",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/summary.go#L166-L170 |
142,685 | caio/go-tdigest | summary.go | Swap | func (s *summary) Swap(i, j int) {
s.means[i], s.means[j] = s.means[j], s.means[i]
s.counts[i], s.counts[j] = s.counts[j], s.counts[i]
} | go | func (s *summary) Swap(i, j int) {
s.means[i], s.means[j] = s.means[j], s.means[i]
s.counts[i], s.counts[j] = s.counts[j], s.counts[i]
} | [
"func",
"(",
"s",
"*",
"summary",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"s",
".",
"means",
"[",
"i",
"]",
",",
"s",
".",
"means",
"[",
"j",
"]",
"=",
"s",
".",
"means",
"[",
"j",
"]",
",",
"s",
".",
"means",
"[",
"i",
"]",
... | // for sort.Interface | [
"for",
"sort",
".",
"Interface"
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/summary.go#L173-L176 |
142,686 | caio/go-tdigest | summary.go | sumUntilIndex | func sumUntilIndex(s []uint32, idx int) uint64 {
var cumSum uint64
var i int
for i = idx - 1; i >= 3; i -= 4 {
cumSum += uint64(s[i])
cumSum += uint64(s[i-1])
cumSum += uint64(s[i-2])
cumSum += uint64(s[i-3])
}
for ; i >= 0; i-- {
cumSum += uint64(s[i])
}
return cumSum
} | go | func sumUntilIndex(s []uint32, idx int) uint64 {
var cumSum uint64
var i int
for i = idx - 1; i >= 3; i -= 4 {
cumSum += uint64(s[i])
cumSum += uint64(s[i-1])
cumSum += uint64(s[i-2])
cumSum += uint64(s[i-3])
}
for ; i >= 0; i-- {
cumSum += uint64(s[i])
}
return cumSum
} | [
"func",
"sumUntilIndex",
"(",
"s",
"[",
"]",
"uint32",
",",
"idx",
"int",
")",
"uint64",
"{",
"var",
"cumSum",
"uint64",
"\n",
"var",
"i",
"int",
"\n",
"for",
"i",
"=",
"idx",
"-",
"1",
";",
"i",
">=",
"3",
";",
"i",
"-=",
"4",
"{",
"cumSum",
... | // A simple loop unroll saves a surprising amount of time. | [
"A",
"simple",
"loop",
"unroll",
"saves",
"a",
"surprising",
"amount",
"of",
"time",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/summary.go#L183-L196 |
142,687 | caio/go-tdigest | serialization.go | AsBytes | func (t TDigest) AsBytes() ([]byte, error) {
buffer := new(bytes.Buffer)
err := binary.Write(buffer, endianess, smallEncoding)
if err != nil {
return nil, err
}
err = binary.Write(buffer, endianess, t.compression)
if err != nil {
return nil, err
}
err = binary.Write(buffer, endianess, int32(t.summary.L... | go | func (t TDigest) AsBytes() ([]byte, error) {
buffer := new(bytes.Buffer)
err := binary.Write(buffer, endianess, smallEncoding)
if err != nil {
return nil, err
}
err = binary.Write(buffer, endianess, t.compression)
if err != nil {
return nil, err
}
err = binary.Write(buffer, endianess, int32(t.summary.L... | [
"func",
"(",
"t",
"TDigest",
")",
"AsBytes",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buffer",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"err",
":=",
"binary",
".",
"Write",
"(",
"buffer",
",",
"endianess",
",",
"sma... | // AsBytes serializes the digest into a byte array so it can be
// saved to disk or sent over the wire. | [
"AsBytes",
"serializes",
"the",
"digest",
"into",
"a",
"byte",
"array",
"so",
"it",
"can",
"be",
"saved",
"to",
"disk",
"or",
"sent",
"over",
"the",
"wire",
"."
] | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/serialization.go#L17-L59 |
142,688 | caio/go-tdigest | serialization.go | FromBytes | func (t *TDigest) FromBytes(buf []byte) error {
if len(buf) < 16 {
return errors.New("buffer too small for deserialization")
}
encoding := int32(endianess.Uint32(buf))
if encoding != smallEncoding {
return fmt.Errorf("unsupported encoding version: %d", encoding)
}
compression := math.Float64frombits(endiane... | go | func (t *TDigest) FromBytes(buf []byte) error {
if len(buf) < 16 {
return errors.New("buffer too small for deserialization")
}
encoding := int32(endianess.Uint32(buf))
if encoding != smallEncoding {
return fmt.Errorf("unsupported encoding version: %d", encoding)
}
compression := math.Float64frombits(endiane... | [
"func",
"(",
"t",
"*",
"TDigest",
")",
"FromBytes",
"(",
"buf",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"16",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"encoding",
":=",
"int32... | // FromBytes deserializes into the supplied TDigest struct, re-using
// and overwriting any existing buffers.
//
// This method reinitializes the digest from the provided buffer
// discarding any previously collected data. Notice that in case
// of errors this may leave the digest in a unusable state. | [
"FromBytes",
"deserializes",
"into",
"the",
"supplied",
"TDigest",
"struct",
"re",
"-",
"using",
"and",
"overwriting",
"any",
"existing",
"buffers",
".",
"This",
"method",
"reinitializes",
"the",
"digest",
"from",
"the",
"provided",
"buffer",
"discarding",
"any",
... | 1b379242c93d4d0653b5cf6269ee48c4effb1b97 | https://github.com/caio/go-tdigest/blob/1b379242c93d4d0653b5cf6269ee48c4effb1b97/serialization.go#L135-L190 |
142,689 | enceve/crypto | skein/skein1024/skein.go | New256 | func New256(key []byte) hash.Hash {
s := new(hashFunc)
s.initialize(32, &skein.Config{Key: key})
return s
} | go | func New256(key []byte) hash.Hash {
s := new(hashFunc)
s.initialize(32, &skein.Config{Key: key})
return s
} | [
"func",
"New256",
"(",
"key",
"[",
"]",
"byte",
")",
"hash",
".",
"Hash",
"{",
"s",
":=",
"new",
"(",
"hashFunc",
")",
"\n\n",
"s",
".",
"initialize",
"(",
"32",
",",
"&",
"skein",
".",
"Config",
"{",
"Key",
":",
"key",
"}",
")",
"\n\n",
"retur... | // New256 returns a hash.Hash computing the Skein1024 256 bit checksum.
// The key is optional and turns the hash into a MAC. | [
"New256",
"returns",
"a",
"hash",
".",
"Hash",
"computing",
"the",
"Skein1024",
"256",
"bit",
"checksum",
".",
"The",
"key",
"is",
"optional",
"and",
"turns",
"the",
"hash",
"into",
"a",
"MAC",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/skein/skein1024/skein.go#L98-L104 |
142,690 | enceve/crypto | skein/skein1024/skein.go | New | func New(hashsize int, conf *skein.Config) hash.Hash {
s := new(hashFunc)
s.initialize(hashsize, conf)
return s
} | go | func New(hashsize int, conf *skein.Config) hash.Hash {
s := new(hashFunc)
s.initialize(hashsize, conf)
return s
} | [
"func",
"New",
"(",
"hashsize",
"int",
",",
"conf",
"*",
"skein",
".",
"Config",
")",
"hash",
".",
"Hash",
"{",
"s",
":=",
"new",
"(",
"hashFunc",
")",
"\n",
"s",
".",
"initialize",
"(",
"hashsize",
",",
"conf",
")",
"\n",
"return",
"s",
"\n",
"}... | // New returns a hash.Hash computing the Skein1024 checksum with the given hash size.
// The conf is optional and configurates the hash.Hash | [
"New",
"returns",
"a",
"hash",
".",
"Hash",
"computing",
"the",
"Skein1024",
"checksum",
"with",
"the",
"given",
"hash",
"size",
".",
"The",
"conf",
"is",
"optional",
"and",
"configurates",
"the",
"hash",
".",
"Hash"
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/skein/skein1024/skein.go#L108-L112 |
142,691 | enceve/crypto | dh/dh.go | PublicKey | func (g *Group) PublicKey(private PrivateKey) (public PublicKey) {
public = new(big.Int).Exp(g.G, private, g.P)
return
} | go | func (g *Group) PublicKey(private PrivateKey) (public PublicKey) {
public = new(big.Int).Exp(g.G, private, g.P)
return
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"PublicKey",
"(",
"private",
"PrivateKey",
")",
"(",
"public",
"PublicKey",
")",
"{",
"public",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Exp",
"(",
"g",
".",
"G",
",",
"private",
",",
"g",
".",
"P",
")... | // PublicKey returns the public key corresponding to the given private one. | [
"PublicKey",
"returns",
"the",
"public",
"key",
"corresponding",
"to",
"the",
"given",
"private",
"one",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/dh/dh.go#L88-L91 |
142,692 | enceve/crypto | dh/dh.go | ComputeSecret | func (g *Group) ComputeSecret(private PrivateKey, peersPublic PublicKey) (secret *big.Int) {
secret = new(big.Int).Exp(peersPublic, private, g.P)
return
} | go | func (g *Group) ComputeSecret(private PrivateKey, peersPublic PublicKey) (secret *big.Int) {
secret = new(big.Int).Exp(peersPublic, private, g.P)
return
} | [
"func",
"(",
"g",
"*",
"Group",
")",
"ComputeSecret",
"(",
"private",
"PrivateKey",
",",
"peersPublic",
"PublicKey",
")",
"(",
"secret",
"*",
"big",
".",
"Int",
")",
"{",
"secret",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Exp",
"(",
"peersPubli... | // ComputeSecret returns the secret computed from
// the own private and the peer's public key. | [
"ComputeSecret",
"returns",
"the",
"secret",
"computed",
"from",
"the",
"own",
"private",
"and",
"the",
"peer",
"s",
"public",
"key",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/dh/dh.go#L105-L108 |
142,693 | enceve/crypto | chacha20/chacha20.go | NewCipher | func NewCipher(nonce *[NonceSize]byte, key *[32]byte) cipher.Stream {
return chacha.NewCipher(nonce, key, 20)
} | go | func NewCipher(nonce *[NonceSize]byte, key *[32]byte) cipher.Stream {
return chacha.NewCipher(nonce, key, 20)
} | [
"func",
"NewCipher",
"(",
"nonce",
"*",
"[",
"NonceSize",
"]",
"byte",
",",
"key",
"*",
"[",
"32",
"]",
"byte",
")",
"cipher",
".",
"Stream",
"{",
"return",
"chacha",
".",
"NewCipher",
"(",
"nonce",
",",
"key",
",",
"20",
")",
"\n",
"}"
] | // NewCipher returns a new cipher.Stream implementing the ChaCha20
// stream cipher. The nonce must be unique for one
// key for all time. | [
"NewCipher",
"returns",
"a",
"new",
"cipher",
".",
"Stream",
"implementing",
"the",
"ChaCha20",
"stream",
"cipher",
".",
"The",
"nonce",
"must",
"be",
"unique",
"for",
"one",
"key",
"for",
"all",
"time",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/chacha20/chacha20.go#L32-L34 |
142,694 | enceve/crypto | camellia/camellia_ref.go | f | func f(r0, r1, r2, r3 *uint32, k0, k1 uint32) {
k0 ^= *r0
k1 ^= *r1
t := sbox4_4404[byte(k0)]
t ^= sbox3_3033[byte(k0>>8)]
t ^= sbox2_0222[byte(k0>>16)]
t ^= sbox1_1110[byte(k0>>24)]
*r3 ^= (t >> 8) | (t << (32 - 8))
k0 = t
k0 ^= sbox1_1110[byte(k1)]
k0 ^= sbox4_4404[byte(k1>>8)]
k0 ^= sbox3_3033[byte(k1>>... | go | func f(r0, r1, r2, r3 *uint32, k0, k1 uint32) {
k0 ^= *r0
k1 ^= *r1
t := sbox4_4404[byte(k0)]
t ^= sbox3_3033[byte(k0>>8)]
t ^= sbox2_0222[byte(k0>>16)]
t ^= sbox1_1110[byte(k0>>24)]
*r3 ^= (t >> 8) | (t << (32 - 8))
k0 = t
k0 ^= sbox1_1110[byte(k1)]
k0 ^= sbox4_4404[byte(k1>>8)]
k0 ^= sbox3_3033[byte(k1>>... | [
"func",
"f",
"(",
"r0",
",",
"r1",
",",
"r2",
",",
"r3",
"*",
"uint32",
",",
"k0",
",",
"k1",
"uint32",
")",
"{",
"k0",
"^=",
"*",
"r0",
"\n",
"k1",
"^=",
"*",
"r1",
"\n\n",
"t",
":=",
"sbox4_4404",
"[",
"byte",
"(",
"k0",
")",
"]",
"\n",
... | // The camellia non-linear feistel function. | [
"The",
"camellia",
"non",
"-",
"linear",
"feistel",
"function",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/camellia/camellia_ref.go#L7-L25 |
142,695 | enceve/crypto | dh/ecdh/generic.go | GenericCurve | func GenericCurve(c elliptic.Curve) KeyExchange {
if c == nil {
panic("ecdh: curve is nil")
}
return genericCurve{curve: c}
} | go | func GenericCurve(c elliptic.Curve) KeyExchange {
if c == nil {
panic("ecdh: curve is nil")
}
return genericCurve{curve: c}
} | [
"func",
"GenericCurve",
"(",
"c",
"elliptic",
".",
"Curve",
")",
"KeyExchange",
"{",
"if",
"c",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"genericCurve",
"{",
"curve",
":",
"c",
"}",
"\n",
"}"
] | // GenericCurve creates a new ecdh.KeyExchange with
// generic elliptic.Curve implementations. | [
"GenericCurve",
"creates",
"a",
"new",
"ecdh",
".",
"KeyExchange",
"with",
"generic",
"elliptic",
".",
"Curve",
"implementations",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/dh/ecdh/generic.go#L31-L36 |
142,696 | enceve/crypto | siphash/siphash.go | Verify | func Verify(sum *[TagSize]byte, msg []byte, key *[16]byte) bool {
var out [TagSize]byte
Sum(&out, msg, key)
return subtle.ConstantTimeCompare(sum[:], out[:]) == 1
} | go | func Verify(sum *[TagSize]byte, msg []byte, key *[16]byte) bool {
var out [TagSize]byte
Sum(&out, msg, key)
return subtle.ConstantTimeCompare(sum[:], out[:]) == 1
} | [
"func",
"Verify",
"(",
"sum",
"*",
"[",
"TagSize",
"]",
"byte",
",",
"msg",
"[",
"]",
"byte",
",",
"key",
"*",
"[",
"16",
"]",
"byte",
")",
"bool",
"{",
"var",
"out",
"[",
"TagSize",
"]",
"byte",
"\n",
"Sum",
"(",
"&",
"out",
",",
"msg",
",",... | // Verify checks whether the given sum is equal to the
// computed checksum of msg. This function returns true
// if and only if the computed checksum is equal to the
// given sum. | [
"Verify",
"checks",
"whether",
"the",
"given",
"sum",
"is",
"equal",
"to",
"the",
"computed",
"checksum",
"of",
"msg",
".",
"This",
"function",
"returns",
"true",
"if",
"and",
"only",
"if",
"the",
"computed",
"checksum",
"is",
"equal",
"to",
"the",
"given"... | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/siphash/siphash.go#L31-L35 |
142,697 | enceve/crypto | cipher/eax.go | ctrCrypt | func (c *eaxCipher) ctrCrypt(dst, src []byte) {
length := len(src)
bs := c.blockCipher.BlockSize()
n := length & (^(length - bs))
for i := 0; i < n; i += bs {
j := i + bs
c.blockCipher.Encrypt(c.block, c.ctr)
crypto.XOR(dst[i:j], src[i:j], c.block)
// Increment counter
for k := len(c.ctr) - 1; k >= 0; k... | go | func (c *eaxCipher) ctrCrypt(dst, src []byte) {
length := len(src)
bs := c.blockCipher.BlockSize()
n := length & (^(length - bs))
for i := 0; i < n; i += bs {
j := i + bs
c.blockCipher.Encrypt(c.block, c.ctr)
crypto.XOR(dst[i:j], src[i:j], c.block)
// Increment counter
for k := len(c.ctr) - 1; k >= 0; k... | [
"func",
"(",
"c",
"*",
"eaxCipher",
")",
"ctrCrypt",
"(",
"dst",
",",
"src",
"[",
"]",
"byte",
")",
"{",
"length",
":=",
"len",
"(",
"src",
")",
"\n",
"bs",
":=",
"c",
".",
"blockCipher",
".",
"BlockSize",
"(",
")",
"\n",
"n",
":=",
"length",
"... | // ctrCrypt encrypts the bytes in src with the CTR mode and writes
// the ciphertext into dst | [
"ctrCrypt",
"encrypts",
"the",
"bytes",
"in",
"src",
"with",
"the",
"CTR",
"mode",
"and",
"writes",
"the",
"ciphertext",
"into",
"dst"
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/cipher/eax.go#L158-L181 |
142,698 | enceve/crypto | pad/pad.go | NewX923 | func NewX923(blocksize int) Padding {
if blocksize < 1 || blocksize > 255 {
panic("illegal blocksize - size must between 0 and 256")
}
pad := x923Padding(blocksize)
return pad
} | go | func NewX923(blocksize int) Padding {
if blocksize < 1 || blocksize > 255 {
panic("illegal blocksize - size must between 0 and 256")
}
pad := x923Padding(blocksize)
return pad
} | [
"func",
"NewX923",
"(",
"blocksize",
"int",
")",
"Padding",
"{",
"if",
"blocksize",
"<",
"1",
"||",
"blocksize",
">",
"255",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pad",
":=",
"x923Padding",
"(",
"blocksize",
")",
"\n",
"return",
"pad"... | // NewX923 returns a new pad.Padding implementing the ANSI X.923 scheme.
// Only block sizes between 1 and 255 are valid. | [
"NewX923",
"returns",
"a",
"new",
"pad",
".",
"Padding",
"implementing",
"the",
"ANSI",
"X",
".",
"923",
"scheme",
".",
"Only",
"block",
"sizes",
"between",
"1",
"and",
"255",
"are",
"valid",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/pad/pad.go#L45-L51 |
142,699 | enceve/crypto | pad/pad.go | NewPKCS7 | func NewPKCS7(blocksize int) Padding {
if blocksize < 1 || blocksize > 255 {
panic("illegal blocksize - size must between 0 and 256")
}
pad := pkcs7Padding(blocksize)
return pad
} | go | func NewPKCS7(blocksize int) Padding {
if blocksize < 1 || blocksize > 255 {
panic("illegal blocksize - size must between 0 and 256")
}
pad := pkcs7Padding(blocksize)
return pad
} | [
"func",
"NewPKCS7",
"(",
"blocksize",
"int",
")",
"Padding",
"{",
"if",
"blocksize",
"<",
"1",
"||",
"blocksize",
">",
"255",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pad",
":=",
"pkcs7Padding",
"(",
"blocksize",
")",
"\n",
"return",
"pa... | // NewPKCS7 returns a new pad.Padding implementing the PKCS 7 scheme.
// Only block sizes between 1 and 255 are valid. | [
"NewPKCS7",
"returns",
"a",
"new",
"pad",
".",
"Padding",
"implementing",
"the",
"PKCS",
"7",
"scheme",
".",
"Only",
"block",
"sizes",
"between",
"1",
"and",
"255",
"are",
"valid",
"."
] | 34d48bb938155e3b408f014835ee1f6e3b4c2672 | https://github.com/enceve/crypto/blob/34d48bb938155e3b408f014835ee1f6e3b4c2672/pad/pad.go#L55-L61 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.