id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,300 | sdboyer/gps | version_unifier.go | pairRevision | func (vu versionUnifier) pairRevision(id ProjectIdentifier, r Revision) []Version {
vl, err := vu.b.listVersions(id)
if err != nil {
return nil
}
vu.mtr.push("b-pair-rev")
p := []Version{r}
// doing it like this is a bit sloppy
for _, v2 := range vl {
if pv, ok := v2.(PairedVersion); ok {
if pv.Matches(r... | go | func (vu versionUnifier) pairRevision(id ProjectIdentifier, r Revision) []Version {
vl, err := vu.b.listVersions(id)
if err != nil {
return nil
}
vu.mtr.push("b-pair-rev")
p := []Version{r}
// doing it like this is a bit sloppy
for _, v2 := range vl {
if pv, ok := v2.(PairedVersion); ok {
if pv.Matches(r... | [
"func",
"(",
"vu",
"versionUnifier",
")",
"pairRevision",
"(",
"id",
"ProjectIdentifier",
",",
"r",
"Revision",
")",
"[",
"]",
"Version",
"{",
"vl",
",",
"err",
":=",
"vu",
".",
"b",
".",
"listVersions",
"(",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // pairRevision takes a Revision and attempts to pair it with all possible
// versionsby consulting the canonical version list of the provided
// ProjectIdentifier. | [
"pairRevision",
"takes",
"a",
"Revision",
"and",
"attempts",
"to",
"pair",
"it",
"with",
"all",
"possible",
"versionsby",
"consulting",
"the",
"canonical",
"version",
"list",
"of",
"the",
"provided",
"ProjectIdentifier",
"."
] | c056fb513887b1335e534c91daca4df510d29b66 | https://github.com/sdboyer/gps/blob/c056fb513887b1335e534c91daca4df510d29b66/version_unifier.go#L36-L55 |
149,301 | sdboyer/gps | version_unifier.go | matchesAny | func (vu versionUnifier) matchesAny(id ProjectIdentifier, c1, c2 Constraint) bool {
if c1.MatchesAny(c2) {
return true
}
vu.mtr.push("b-matches-any")
// This approach is slightly wasteful, but just SO much less verbose, and
// more easily understood.
var uc1, uc2 Constraint
if v1, ok := c1.(Version); ok {
u... | go | func (vu versionUnifier) matchesAny(id ProjectIdentifier, c1, c2 Constraint) bool {
if c1.MatchesAny(c2) {
return true
}
vu.mtr.push("b-matches-any")
// This approach is slightly wasteful, but just SO much less verbose, and
// more easily understood.
var uc1, uc2 Constraint
if v1, ok := c1.(Version); ok {
u... | [
"func",
"(",
"vu",
"versionUnifier",
")",
"matchesAny",
"(",
"id",
"ProjectIdentifier",
",",
"c1",
",",
"c2",
"Constraint",
")",
"bool",
"{",
"if",
"c1",
".",
"MatchesAny",
"(",
"c2",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"vu",
".",
"mtr",
"... | // matchesAny is the authoritative version of Constraint.MatchesAny. | [
"matchesAny",
"is",
"the",
"authoritative",
"version",
"of",
"Constraint",
".",
"MatchesAny",
"."
] | c056fb513887b1335e534c91daca4df510d29b66 | https://github.com/sdboyer/gps/blob/c056fb513887b1335e534c91daca4df510d29b66/version_unifier.go#L83-L106 |
149,302 | sdboyer/gps | version_unifier.go | intersect | func (vu versionUnifier) intersect(id ProjectIdentifier, c1, c2 Constraint) Constraint {
rc := c1.Intersect(c2)
if rc != none {
return rc
}
vu.mtr.push("b-intersect")
// This approach is slightly wasteful, but just SO much less verbose, and
// more easily understood.
var uc1, uc2 Constraint
if v1, ok := c1.(... | go | func (vu versionUnifier) intersect(id ProjectIdentifier, c1, c2 Constraint) Constraint {
rc := c1.Intersect(c2)
if rc != none {
return rc
}
vu.mtr.push("b-intersect")
// This approach is slightly wasteful, but just SO much less verbose, and
// more easily understood.
var uc1, uc2 Constraint
if v1, ok := c1.(... | [
"func",
"(",
"vu",
"versionUnifier",
")",
"intersect",
"(",
"id",
"ProjectIdentifier",
",",
"c1",
",",
"c2",
"Constraint",
")",
"Constraint",
"{",
"rc",
":=",
"c1",
".",
"Intersect",
"(",
"c2",
")",
"\n",
"if",
"rc",
"!=",
"none",
"{",
"return",
"rc",
... | // intersect is the authoritative version of Constraint.Intersect. | [
"intersect",
"is",
"the",
"authoritative",
"version",
"of",
"Constraint",
".",
"Intersect",
"."
] | c056fb513887b1335e534c91daca4df510d29b66 | https://github.com/sdboyer/gps/blob/c056fb513887b1335e534c91daca4df510d29b66/version_unifier.go#L109-L133 |
149,303 | sdboyer/gps | version_unifier.go | Matches | func (vtu versionTypeUnion) Matches(v Version) bool {
vtu2, otherIs := v.(versionTypeUnion)
for _, v1 := range vtu {
if otherIs {
for _, v2 := range vtu2 {
if v1.Matches(v2) {
return true
}
}
} else if v1.Matches(v) {
return true
}
}
return false
} | go | func (vtu versionTypeUnion) Matches(v Version) bool {
vtu2, otherIs := v.(versionTypeUnion)
for _, v1 := range vtu {
if otherIs {
for _, v2 := range vtu2 {
if v1.Matches(v2) {
return true
}
}
} else if v1.Matches(v) {
return true
}
}
return false
} | [
"func",
"(",
"vtu",
"versionTypeUnion",
")",
"Matches",
"(",
"v",
"Version",
")",
"bool",
"{",
"vtu2",
",",
"otherIs",
":=",
"v",
".",
"(",
"versionTypeUnion",
")",
"\n\n",
"for",
"_",
",",
"v1",
":=",
"range",
"vtu",
"{",
"if",
"otherIs",
"{",
"for"... | // Matches takes a version, and returns true if that version matches any version
// contained in the union.
//
// This DOES allow tags to match branches, albeit indirectly through a revision. | [
"Matches",
"takes",
"a",
"version",
"and",
"returns",
"true",
"if",
"that",
"version",
"matches",
"any",
"version",
"contained",
"in",
"the",
"union",
".",
"This",
"DOES",
"allow",
"tags",
"to",
"match",
"branches",
"albeit",
"indirectly",
"through",
"a",
"r... | c056fb513887b1335e534c91daca4df510d29b66 | https://github.com/sdboyer/gps/blob/c056fb513887b1335e534c91daca4df510d29b66/version_unifier.go#L198-L214 |
149,304 | heroku/authenticater | logplex_drain_tokens.go | AddToken | func (ldt *LogplexDrainToken) AddToken(token string) {
ldt.Lock()
ldt.tokens[token] = struct{}{}
ldt.Unlock()
} | go | func (ldt *LogplexDrainToken) AddToken(token string) {
ldt.Lock()
ldt.tokens[token] = struct{}{}
ldt.Unlock()
} | [
"func",
"(",
"ldt",
"*",
"LogplexDrainToken",
")",
"AddToken",
"(",
"token",
"string",
")",
"{",
"ldt",
".",
"Lock",
"(",
")",
"\n",
"ldt",
".",
"tokens",
"[",
"token",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"ldt",
".",
"Unlock",
"(",
")",... | // AddToken adds a token to the list of acceptable tokens. | [
"AddToken",
"adds",
"a",
"token",
"to",
"the",
"list",
"of",
"acceptable",
"tokens",
"."
] | 16ff6099109815e5523480d377232dc6021ba3cf | https://github.com/heroku/authenticater/blob/16ff6099109815e5523480d377232dc6021ba3cf/logplex_drain_tokens.go#L33-L37 |
149,305 | heroku/authenticater | logplex_drain_tokens.go | Authenticate | func (ldt *LogplexDrainToken) Authenticate(r *http.Request) (exists bool) {
if token := r.Header.Get("Logplex-Drain-Token"); token != "" {
ldt.RLock()
_, exists = ldt.tokens[token]
ldt.RUnlock()
}
return
} | go | func (ldt *LogplexDrainToken) Authenticate(r *http.Request) (exists bool) {
if token := r.Header.Get("Logplex-Drain-Token"); token != "" {
ldt.RLock()
_, exists = ldt.tokens[token]
ldt.RUnlock()
}
return
} | [
"func",
"(",
"ldt",
"*",
"LogplexDrainToken",
")",
"Authenticate",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"exists",
"bool",
")",
"{",
"if",
"token",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"token",
"!=",
"\"",
"... | // Authenticate the request if the Logplex-Drain-Token header contains a known
// token | [
"Authenticate",
"the",
"request",
"if",
"the",
"Logplex",
"-",
"Drain",
"-",
"Token",
"header",
"contains",
"a",
"known",
"token"
] | 16ff6099109815e5523480d377232dc6021ba3cf | https://github.com/heroku/authenticater/blob/16ff6099109815e5523480d377232dc6021ba3cf/logplex_drain_tokens.go#L41-L48 |
149,306 | heroku/authenticater | auth.go | WrapAuth | func WrapAuth(auth Authenticater, handle http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if auth.Authenticate(r) {
handle(w, r)
} else {
w.WriteHeader(http.StatusUnauthorized)
}
}
} | go | func WrapAuth(auth Authenticater, handle http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if auth.Authenticate(r) {
handle(w, r)
} else {
w.WriteHeader(http.StatusUnauthorized)
}
}
} | [
"func",
"WrapAuth",
"(",
"auth",
"Authenticater",
",",
"handle",
"http",
".",
"HandlerFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"auth",
... | // WrapAuth returns a http.Handlerfunc that runs the passed Handlerfunc if and
// only if the Authenticator can authenticate the request | [
"WrapAuth",
"returns",
"a",
"http",
".",
"Handlerfunc",
"that",
"runs",
"the",
"passed",
"Handlerfunc",
"if",
"and",
"only",
"if",
"the",
"Authenticator",
"can",
"authenticate",
"the",
"request"
] | 16ff6099109815e5523480d377232dc6021ba3cf | https://github.com/heroku/authenticater/blob/16ff6099109815e5523480d377232dc6021ba3cf/auth.go#L12-L20 |
149,307 | djherbis/fscache | lruhaunter.go | NewLRUHaunter | func NewLRUHaunter(maxItems int, maxSize int64, period time.Duration) LRUHaunter {
return &lruHaunter{
period: period,
maxItems: maxItems,
maxSize: maxSize,
}
} | go | func NewLRUHaunter(maxItems int, maxSize int64, period time.Duration) LRUHaunter {
return &lruHaunter{
period: period,
maxItems: maxItems,
maxSize: maxSize,
}
} | [
"func",
"NewLRUHaunter",
"(",
"maxItems",
"int",
",",
"maxSize",
"int64",
",",
"period",
"time",
".",
"Duration",
")",
"LRUHaunter",
"{",
"return",
"&",
"lruHaunter",
"{",
"period",
":",
"period",
",",
"maxItems",
":",
"maxItems",
",",
"maxSize",
":",
"max... | // NewLRUHaunter returns a simple haunter which runs every "period"
// and scrubs older files when the total file size is over maxSize or
// total item count is over maxItems.
// If maxItems or maxSize are 0, they won't be checked | [
"NewLRUHaunter",
"returns",
"a",
"simple",
"haunter",
"which",
"runs",
"every",
"period",
"and",
"scrubs",
"older",
"files",
"when",
"the",
"total",
"file",
"size",
"is",
"over",
"maxSize",
"or",
"total",
"item",
"count",
"is",
"over",
"maxItems",
".",
"If",... | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/lruhaunter.go#L29-L35 |
149,308 | djherbis/fscache | distrib.go | stdDistribution | func stdDistribution(key string, n uint64) uint64 {
h := sha1.New()
io.WriteString(h, key)
buf := bytes.NewBuffer(h.Sum(nil)[:8])
i, _ := binary.ReadUvarint(buf)
return i % n
} | go | func stdDistribution(key string, n uint64) uint64 {
h := sha1.New()
io.WriteString(h, key)
buf := bytes.NewBuffer(h.Sum(nil)[:8])
i, _ := binary.ReadUvarint(buf)
return i % n
} | [
"func",
"stdDistribution",
"(",
"key",
"string",
",",
"n",
"uint64",
")",
"uint64",
"{",
"h",
":=",
"sha1",
".",
"New",
"(",
")",
"\n",
"io",
".",
"WriteString",
"(",
"h",
",",
"key",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"h",
"... | // stdDistribution distributes the keyspace evenly. | [
"stdDistribution",
"distributes",
"the",
"keyspace",
"evenly",
"."
] | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/distrib.go#L21-L27 |
149,309 | djherbis/fscache | distrib.go | NewDistributor | func NewDistributor(caches ...Cache) Distributor {
if len(caches) == 0 {
return nil
}
return &distrib{
distribution: stdDistribution,
caches: caches,
size: uint64(len(caches)),
}
} | go | func NewDistributor(caches ...Cache) Distributor {
if len(caches) == 0 {
return nil
}
return &distrib{
distribution: stdDistribution,
caches: caches,
size: uint64(len(caches)),
}
} | [
"func",
"NewDistributor",
"(",
"caches",
"...",
"Cache",
")",
"Distributor",
"{",
"if",
"len",
"(",
"caches",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"distrib",
"{",
"distribution",
":",
"stdDistribution",
",",
"caches",
":"... | // NewDistributor returns a Distributor which evenly distributes the keyspace
// into the passed caches. | [
"NewDistributor",
"returns",
"a",
"Distributor",
"which",
"evenly",
"distributes",
"the",
"keyspace",
"into",
"the",
"passed",
"caches",
"."
] | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/distrib.go#L31-L40 |
149,310 | djherbis/fscache | server.go | ListenAndServe | func ListenAndServe(c Cache, addr string) error {
return (&server{c: c}).ListenAndServe(addr)
} | go | func ListenAndServe(c Cache, addr string) error {
return (&server{c: c}).ListenAndServe(addr)
} | [
"func",
"ListenAndServe",
"(",
"c",
"Cache",
",",
"addr",
"string",
")",
"error",
"{",
"return",
"(",
"&",
"server",
"{",
"c",
":",
"c",
"}",
")",
".",
"ListenAndServe",
"(",
"addr",
")",
"\n",
"}"
] | // ListenAndServe hosts a Cache for access via NewRemote | [
"ListenAndServe",
"hosts",
"a",
"Cache",
"for",
"access",
"via",
"NewRemote"
] | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/server.go#L12-L14 |
149,311 | djherbis/fscache | server.go | Close | func (s *safeCloser) Close() (err error) {
if s.r != nil {
err = s.r.Close()
} else if s.w != nil {
err = s.w.Close()
}
select {
case s.ch <- struct{}{}:
return err
default:
return s.c.Close()
}
} | go | func (s *safeCloser) Close() (err error) {
if s.r != nil {
err = s.r.Close()
} else if s.w != nil {
err = s.w.Close()
}
select {
case s.ch <- struct{}{}:
return err
default:
return s.c.Close()
}
} | [
"func",
"(",
"s",
"*",
"safeCloser",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
".",
"r",
"!=",
"nil",
"{",
"err",
"=",
"s",
".",
"r",
".",
"Close",
"(",
")",
"\n",
"}",
"else",
"if",
"s",
".",
"w",
"!=",
"nil",
"{"... | // Close only closes the underlying connection when ch is full. | [
"Close",
"only",
"closes",
"the",
"underlying",
"connection",
"when",
"ch",
"is",
"full",
"."
] | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/server.go#L162-L175 |
149,312 | djherbis/fscache | reaper.go | NewReaper | func NewReaper(expiry, period time.Duration) Reaper {
return &reaper{
expiry: expiry,
period: period,
}
} | go | func NewReaper(expiry, period time.Duration) Reaper {
return &reaper{
expiry: expiry,
period: period,
}
} | [
"func",
"NewReaper",
"(",
"expiry",
",",
"period",
"time",
".",
"Duration",
")",
"Reaper",
"{",
"return",
"&",
"reaper",
"{",
"expiry",
":",
"expiry",
",",
"period",
":",
"period",
",",
"}",
"\n",
"}"
] | // NewReaper returns a simple reaper which runs every "Period"
// and reaps files which are older than "expiry". | [
"NewReaper",
"returns",
"a",
"simple",
"reaper",
"which",
"runs",
"every",
"Period",
"and",
"reaps",
"files",
"which",
"are",
"older",
"than",
"expiry",
"."
] | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/reaper.go#L19-L24 |
149,313 | djherbis/fscache | fs.go | NewFs | func NewFs(dir string, mode os.FileMode) (FileSystem, error) {
fs := &stdFs{root: dir, init: func() error {
return os.MkdirAll(dir, mode)
}}
return fs, fs.init()
} | go | func NewFs(dir string, mode os.FileMode) (FileSystem, error) {
fs := &stdFs{root: dir, init: func() error {
return os.MkdirAll(dir, mode)
}}
return fs, fs.init()
} | [
"func",
"NewFs",
"(",
"dir",
"string",
",",
"mode",
"os",
".",
"FileMode",
")",
"(",
"FileSystem",
",",
"error",
")",
"{",
"fs",
":=",
"&",
"stdFs",
"{",
"root",
":",
"dir",
",",
"init",
":",
"func",
"(",
")",
"error",
"{",
"return",
"os",
".",
... | // NewFs returns a FileSystem rooted at directory dir.
// Dir is created with perms if it doesn't exist. | [
"NewFs",
"returns",
"a",
"FileSystem",
"rooted",
"at",
"directory",
"dir",
".",
"Dir",
"is",
"created",
"with",
"perms",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | 287ea9b8006928f4a9ad1b003f25837874696ce1 | https://github.com/djherbis/fscache/blob/287ea9b8006928f4a9ad1b003f25837874696ce1/fs.go#L47-L52 |
149,314 | sugyan/ttyrec2gif | player.go | TtyPlay | func (g *GifGenerator) TtyPlay(input string, term Terminal, capture func(int32) error) (err error) {
inFile, err := os.Open(input)
if err != nil {
return
}
defer inFile.Close()
reader := ttyread.NewTtyReader(inFile)
var prevTv *ttyread.TimeVal
for {
var data *ttyread.TtyData
data, err = reader.ReadData()
... | go | func (g *GifGenerator) TtyPlay(input string, term Terminal, capture func(int32) error) (err error) {
inFile, err := os.Open(input)
if err != nil {
return
}
defer inFile.Close()
reader := ttyread.NewTtyReader(inFile)
var prevTv *ttyread.TimeVal
for {
var data *ttyread.TtyData
data, err = reader.ReadData()
... | [
"func",
"(",
"g",
"*",
"GifGenerator",
")",
"TtyPlay",
"(",
"input",
"string",
",",
"term",
"Terminal",
",",
"capture",
"func",
"(",
"int32",
")",
"error",
")",
"(",
"err",
"error",
")",
"{",
"inFile",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"inp... | // TtyPlay reads ttyrecord file and play | [
"TtyPlay",
"reads",
"ttyrecord",
"file",
"and",
"play"
] | d25ebb322ff03e2ac1988bed2e41280708e17aac | https://github.com/sugyan/ttyrec2gif/blob/d25ebb322ff03e2ac1988bed2e41280708e17aac/player.go#L15-L51 |
149,315 | sugyan/ttyrec2gif | generator.go | Generate | func (g *GifGenerator) Generate(input string, output string) (err error) {
// virtual terminal
var state = terminal.State{}
vt, err := terminal.Create(&state, ioutil.NopCloser(bytes.NewBuffer([]byte{})))
if err != nil {
return
}
defer vt.Close()
vt.Resize(g.Col, g.Row)
// play and capture
var (
images []*... | go | func (g *GifGenerator) Generate(input string, output string) (err error) {
// virtual terminal
var state = terminal.State{}
vt, err := terminal.Create(&state, ioutil.NopCloser(bytes.NewBuffer([]byte{})))
if err != nil {
return
}
defer vt.Close()
vt.Resize(g.Col, g.Row)
// play and capture
var (
images []*... | [
"func",
"(",
"g",
"*",
"GifGenerator",
")",
"Generate",
"(",
"input",
"string",
",",
"output",
"string",
")",
"(",
"err",
"error",
")",
"{",
"// virtual terminal",
"var",
"state",
"=",
"terminal",
".",
"State",
"{",
"}",
"\n",
"vt",
",",
"err",
":=",
... | // Generate writes to outFile an animated GIF | [
"Generate",
"writes",
"to",
"outFile",
"an",
"animated",
"GIF"
] | d25ebb322ff03e2ac1988bed2e41280708e17aac | https://github.com/sugyan/ttyrec2gif/blob/d25ebb322ff03e2ac1988bed2e41280708e17aac/generator.go#L31-L81 |
149,316 | jedisct1/xsecretbox | sharedkey.go | SharedKey | func SharedKey(secretKey [32]byte, publicKey [32]byte) ([32]byte, error) {
var sharedKey [32]byte
curve25519.ScalarMult(&sharedKey, &secretKey, &publicKey)
c := byte(0)
for i := 0; i < 32; i++ {
c |= sharedKey[i]
}
if c == 0 {
return sharedKey, errors.New("weak public key")
}
var nonce [16]byte
chacha.HCha... | go | func SharedKey(secretKey [32]byte, publicKey [32]byte) ([32]byte, error) {
var sharedKey [32]byte
curve25519.ScalarMult(&sharedKey, &secretKey, &publicKey)
c := byte(0)
for i := 0; i < 32; i++ {
c |= sharedKey[i]
}
if c == 0 {
return sharedKey, errors.New("weak public key")
}
var nonce [16]byte
chacha.HCha... | [
"func",
"SharedKey",
"(",
"secretKey",
"[",
"32",
"]",
"byte",
",",
"publicKey",
"[",
"32",
"]",
"byte",
")",
"(",
"[",
"32",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"sharedKey",
"[",
"32",
"]",
"byte",
"\n",
"curve25519",
".",
"ScalarMult",
"(... | // SharedKey computes a shared secret compatible with the one used by `crypto_box_xchacha20poly1305`` | [
"SharedKey",
"computes",
"a",
"shared",
"secret",
"compatible",
"with",
"the",
"one",
"used",
"by",
"crypto_box_xchacha20poly1305"
] | 855e18301bf05f96b551af3986061926758be0ca | https://github.com/jedisct1/xsecretbox/blob/855e18301bf05f96b551af3986061926758be0ca/sharedkey.go#L11-L24 |
149,317 | QuentinPerez/go-encodeUrl | examples/main.go | changeNameAndTag | func changeNameAndTag() {
encurl.AddEncodeFunc(nameEqualBadCode)
values, errs := encurl.Translate(&ID{"qperez", "Quentin Perez"}, overloadFieldNameAndTag)
if errs != nil {
logrus.Fatal(errs)
}
fmt.Printf("https://example.com/?%v\n", values.Encode())
} | go | func changeNameAndTag() {
encurl.AddEncodeFunc(nameEqualBadCode)
values, errs := encurl.Translate(&ID{"qperez", "Quentin Perez"}, overloadFieldNameAndTag)
if errs != nil {
logrus.Fatal(errs)
}
fmt.Printf("https://example.com/?%v\n", values.Encode())
} | [
"func",
"changeNameAndTag",
"(",
")",
"{",
"encurl",
".",
"AddEncodeFunc",
"(",
"nameEqualBadCode",
")",
"\n",
"values",
",",
"errs",
":=",
"encurl",
".",
"Translate",
"(",
"&",
"ID",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"overloadFieldNameAndTag",
... | // changTag overloads the tag field | [
"changTag",
"overloads",
"the",
"tag",
"field"
] | 645a9dbeee154c68e218053e604de21f1e3d91d0 | https://github.com/QuentinPerez/go-encodeUrl/blob/645a9dbeee154c68e218053e604de21f1e3d91d0/examples/main.go#L29-L36 |
149,318 | blockloop/tea | url.go | URLInt | func URLInt(r *http.Request, key, validation string) (int, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.Atoi(p)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Context(), &i, vali... | go | func URLInt(r *http.Request, key, validation string) (int, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.Atoi(p)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Context(), &i, vali... | [
"func",
"URLInt",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"key",
",",
"validation",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"p",
":=",
"strings",
".",
"TrimSpace",
"(",
"chi",
".",
"URLParam",
"(",
"r",
",",
"key",
")",
")",
"\n",
... | // URLInt gets a URL parameter from the request and parses it as an int. If
// the value of the URL parameter is empty then ErrNoURLParam is returned.
// If parsing passes, then the validation key will be used to validate the
// value of the int using Validate | [
"URLInt",
"gets",
"a",
"URL",
"parameter",
"from",
"the",
"request",
"and",
"parses",
"it",
"as",
"an",
"int",
".",
"If",
"the",
"value",
"of",
"the",
"URL",
"parameter",
"is",
"empty",
"then",
"ErrNoURLParam",
"is",
"returned",
".",
"If",
"parsing",
"pa... | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/url.go#L19-L34 |
149,319 | blockloop/tea | url.go | URLInt64 | func URLInt64(r *http.Request, key, validation string) (int64, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.ParseInt(p, 0, 64)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Cont... | go | func URLInt64(r *http.Request, key, validation string) (int64, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.ParseInt(p, 0, 64)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Cont... | [
"func",
"URLInt64",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"key",
",",
"validation",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"p",
":=",
"strings",
".",
"TrimSpace",
"(",
"chi",
".",
"URLParam",
"(",
"r",
",",
"key",
")",
")",
"\... | // URLInt64 gets a URL parameter from the request and parses it as an int64. If
// the value of the URL parameter is empty then ErrNoURLParam is returned.
// If parsing passes, then the validation key will be used to validate the
// value of the int64 using Validate | [
"URLInt64",
"gets",
"a",
"URL",
"parameter",
"from",
"the",
"request",
"and",
"parses",
"it",
"as",
"an",
"int64",
".",
"If",
"the",
"value",
"of",
"the",
"URL",
"parameter",
"is",
"empty",
"then",
"ErrNoURLParam",
"is",
"returned",
".",
"If",
"parsing",
... | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/url.go#L40-L55 |
149,320 | blockloop/tea | url.go | URLFloat | func URLFloat(r *http.Request, key, validation string) (float64, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.ParseFloat(p, 64)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Con... | go | func URLFloat(r *http.Request, key, validation string) (float64, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.ParseFloat(p, 64)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Con... | [
"func",
"URLFloat",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"key",
",",
"validation",
"string",
")",
"(",
"float64",
",",
"error",
")",
"{",
"p",
":=",
"strings",
".",
"TrimSpace",
"(",
"chi",
".",
"URLParam",
"(",
"r",
",",
"key",
")",
")",
... | // URLFloat gets a URL parameter from the request and parses it as an float. If
// the value of the URL parameter is empty then ErrNoURLParam is returned.
// If parsing passes, then the validation key will be used to validate the
// value of the float using Validate | [
"URLFloat",
"gets",
"a",
"URL",
"parameter",
"from",
"the",
"request",
"and",
"parses",
"it",
"as",
"an",
"float",
".",
"If",
"the",
"value",
"of",
"the",
"URL",
"parameter",
"is",
"empty",
"then",
"ErrNoURLParam",
"is",
"returned",
".",
"If",
"parsing",
... | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/url.go#L61-L76 |
149,321 | blockloop/tea | url.go | URLUint | func URLUint(r *http.Request, key, validation string) (uint64, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.ParseUint(p, 0, 64)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Con... | go | func URLUint(r *http.Request, key, validation string) (uint64, error) {
p := strings.TrimSpace(chi.URLParam(r, key))
if len(p) == 0 {
return 0, ErrNoURLParam
}
i, err := strconv.ParseUint(p, 0, 64)
if err != nil {
return 0, err
}
if len(validation) == 0 {
return i, nil
}
return i, Validate.VarCtx(r.Con... | [
"func",
"URLUint",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"key",
",",
"validation",
"string",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"p",
":=",
"strings",
".",
"TrimSpace",
"(",
"chi",
".",
"URLParam",
"(",
"r",
",",
"key",
")",
")",
"\... | // URLUint gets a URL parameter from the request and parses it as an uint64. If
// the value of the URL parameter is empty then ErrNoURLParam is returned.
// If parsing passes, then the validation key will be used to validate the
// value of the uint64 using Validate | [
"URLUint",
"gets",
"a",
"URL",
"parameter",
"from",
"the",
"request",
"and",
"parses",
"it",
"as",
"an",
"uint64",
".",
"If",
"the",
"value",
"of",
"the",
"URL",
"parameter",
"is",
"empty",
"then",
"ErrNoURLParam",
"is",
"returned",
".",
"If",
"parsing",
... | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/url.go#L82-L97 |
149,322 | blockloop/tea | errors.go | NotFound | func NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
_, msg := StatusError(404)
Responder(w, r, msg)
} | go | func NotFound(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
_, msg := StatusError(404)
Responder(w, r, msg)
} | [
"func",
"NotFound",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"404",
")",
"\n",
"_",
",",
"msg",
":=",
"StatusError",
"(",
"404",
")",
"\n",
"Responder",
"(",
"w",
",",
... | // NotFound is a handler for 404 requests | [
"NotFound",
"is",
"a",
"handler",
"for",
"404",
"requests"
] | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/errors.go#L69-L73 |
149,323 | jedisct1/xsecretbox | xsecretbox.go | Seal | func Seal(out, nonce, message, key []byte) []byte {
if len(nonce) != NonceSize {
panic("unsupported nonce size")
}
if len(key) != KeySize {
panic("unsupported key size")
}
var firstBlock [64]byte
cipher, _ := chacha.NewCipher(nonce, key, 20)
cipher.XORKeyStream(firstBlock[:], firstBlock[:])
var polyKey [32... | go | func Seal(out, nonce, message, key []byte) []byte {
if len(nonce) != NonceSize {
panic("unsupported nonce size")
}
if len(key) != KeySize {
panic("unsupported key size")
}
var firstBlock [64]byte
cipher, _ := chacha.NewCipher(nonce, key, 20)
cipher.XORKeyStream(firstBlock[:], firstBlock[:])
var polyKey [32... | [
"func",
"Seal",
"(",
"out",
",",
"nonce",
",",
"message",
",",
"key",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"if",
"len",
"(",
"nonce",
")",
"!=",
"NonceSize",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"key... | // Seal does what the name suggests | [
"Seal",
"does",
"what",
"the",
"name",
"suggests"
] | 855e18301bf05f96b551af3986061926758be0ca | https://github.com/jedisct1/xsecretbox/blob/855e18301bf05f96b551af3986061926758be0ca/xsecretbox.go#L21-L60 |
149,324 | jedisct1/xsecretbox | xsecretbox.go | Open | func Open(out, nonce, box, key []byte) ([]byte, error) {
if len(nonce) != NonceSize {
panic("unsupported nonce size")
}
if len(key) != KeySize {
panic("unsupported key size")
}
if len(box) < TagSize {
return nil, errors.New("ciphertext is too short")
}
var firstBlock [64]byte
cipher, _ := chacha.NewCiphe... | go | func Open(out, nonce, box, key []byte) ([]byte, error) {
if len(nonce) != NonceSize {
panic("unsupported nonce size")
}
if len(key) != KeySize {
panic("unsupported key size")
}
if len(box) < TagSize {
return nil, errors.New("ciphertext is too short")
}
var firstBlock [64]byte
cipher, _ := chacha.NewCiphe... | [
"func",
"Open",
"(",
"out",
",",
"nonce",
",",
"box",
",",
"key",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"nonce",
")",
"!=",
"NonceSize",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
... | // Open does what the name suggests | [
"Open",
"does",
"what",
"the",
"name",
"suggests"
] | 855e18301bf05f96b551af3986061926758be0ca | https://github.com/jedisct1/xsecretbox/blob/855e18301bf05f96b551af3986061926758be0ca/xsecretbox.go#L63-L104 |
149,325 | nanobox-io/nanobox-logtap | collector/http.go | GenerateHttpCollector | func GenerateHttpCollector(kind string, l *logtap.Logtap) http.HandlerFunc {
headerName := "X-" + kind + "-Id"
return func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return
}
logLevel := lumber.LvlInt(r.Header.Get("X-Log-Level"))
header := r.Header.Get(h... | go | func GenerateHttpCollector(kind string, l *logtap.Logtap) http.HandlerFunc {
headerName := "X-" + kind + "-Id"
return func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return
}
logLevel := lumber.LvlInt(r.Header.Get("X-Log-Level"))
header := r.Header.Get(h... | [
"func",
"GenerateHttpCollector",
"(",
"kind",
"string",
",",
"l",
"*",
"logtap",
".",
"Logtap",
")",
"http",
".",
"HandlerFunc",
"{",
"headerName",
":=",
"\"",
"\"",
"+",
"kind",
"+",
"\"",
"\"",
"\n",
"return",
"func",
"(",
"w",
"http",
".",
"Response... | // create and return a http handler that can be dropped into an api. | [
"create",
"and",
"return",
"a",
"http",
"handler",
"that",
"can",
"be",
"dropped",
"into",
"an",
"api",
"."
] | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/collector/http.go#L19-L33 |
149,326 | nanobox-io/nanobox-logtap | collector/syslog.go | SyslogUDPStart | func SyslogUDPStart(kind, address string, l *logtap.Logtap) (io.Closer, error) {
parsedAddress, err := net.ResolveUDPAddr("udp", address)
if err != nil {
return nil, err
}
socket, err := net.ListenUDP("udp", parsedAddress)
if err != nil {
return nil, err
}
go func() {
var buf []byte = make([]byte, 1024)
... | go | func SyslogUDPStart(kind, address string, l *logtap.Logtap) (io.Closer, error) {
parsedAddress, err := net.ResolveUDPAddr("udp", address)
if err != nil {
return nil, err
}
socket, err := net.ListenUDP("udp", parsedAddress)
if err != nil {
return nil, err
}
go func() {
var buf []byte = make([]byte, 1024)
... | [
"func",
"SyslogUDPStart",
"(",
"kind",
",",
"address",
"string",
",",
"l",
"*",
"logtap",
".",
"Logtap",
")",
"(",
"io",
".",
"Closer",
",",
"error",
")",
"{",
"parsedAddress",
",",
"err",
":=",
"net",
".",
"ResolveUDPAddr",
"(",
"\"",
"\"",
",",
"ad... | // Start begins listening to the syslog port transfers all
// syslog messages on the wChan | [
"Start",
"begins",
"listening",
"to",
"the",
"syslog",
"port",
"transfers",
"all",
"syslog",
"messages",
"on",
"the",
"wChan"
] | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/collector/syslog.go#L41-L72 |
149,327 | nanobox-io/nanobox-logtap | collector/syslog.go | parseMessage | func parseMessage(b []byte) (msg logtap.Message) {
parsers := make([]syslogparser.LogParser, 3)
parsers[0] = rfc3164.NewParser(b)
parsers[1] = rfc5424.NewParser(b)
parsers[2] = &fakeSyslog{b}
for _, parser := range parsers {
err := parser.Parse()
if err == nil {
parsedData := parser.Dump()
msg.Time = pa... | go | func parseMessage(b []byte) (msg logtap.Message) {
parsers := make([]syslogparser.LogParser, 3)
parsers[0] = rfc3164.NewParser(b)
parsers[1] = rfc5424.NewParser(b)
parsers[2] = &fakeSyslog{b}
for _, parser := range parsers {
err := parser.Parse()
if err == nil {
parsedData := parser.Dump()
msg.Time = pa... | [
"func",
"parseMessage",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"msg",
"logtap",
".",
"Message",
")",
"{",
"parsers",
":=",
"make",
"(",
"[",
"]",
"syslogparser",
".",
"LogParser",
",",
"3",
")",
"\n",
"parsers",
"[",
"0",
"]",
"=",
"rfc3164",
".",
... | // parseMessage parses the syslog message and returns a msg
// if the msg is not parsable or a standard formatted syslog message
// it will drop the whole message into the content and make up a timestamp
// and a severity | [
"parseMessage",
"parses",
"the",
"syslog",
"message",
"and",
"returns",
"a",
"msg",
"if",
"the",
"msg",
"is",
"not",
"parsable",
"or",
"a",
"standard",
"formatted",
"syslog",
"message",
"it",
"will",
"drop",
"the",
"whole",
"message",
"into",
"the",
"content... | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/collector/syslog.go#L116-L139 |
149,328 | blockloop/tea | tea.go | Handler | func Handler(h StatusHandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, response := h(w, r)
w.WriteHeader(status)
if response == nil {
return
}
Responder(w, r, response)
}
} | go | func Handler(h StatusHandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, response := h(w, r)
w.WriteHeader(status)
if response == nil {
return
}
Responder(w, r, response)
}
} | [
"func",
"Handler",
"(",
"h",
"StatusHandlerFunc",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"status",
",",
"response",
":=",
"h",
"(",
"w",
",",
"... | // Handler wraps a StatusHandlerFunc and returns a standard lib http.HandlerFunc | [
"Handler",
"wraps",
"a",
"StatusHandlerFunc",
"and",
"returns",
"a",
"standard",
"lib",
"http",
".",
"HandlerFunc"
] | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/tea.go#L19-L29 |
149,329 | nanobox-io/nanobox-logtap | logtap.go | New | func New(log Logger) *Logtap {
if log == nil {
log = lumber.NewConsoleLogger(lumber.ERROR)
}
return &Logtap{
log: log,
drains: make(map[string]drainChannels),
}
} | go | func New(log Logger) *Logtap {
if log == nil {
log = lumber.NewConsoleLogger(lumber.ERROR)
}
return &Logtap{
log: log,
drains: make(map[string]drainChannels),
}
} | [
"func",
"New",
"(",
"log",
"Logger",
")",
"*",
"Logtap",
"{",
"if",
"log",
"==",
"nil",
"{",
"log",
"=",
"lumber",
".",
"NewConsoleLogger",
"(",
"lumber",
".",
"ERROR",
")",
"\n",
"}",
"\n",
"return",
"&",
"Logtap",
"{",
"log",
":",
"log",
",",
"... | // Establishes a new logtap object
// and makes sure it has a logger | [
"Establishes",
"a",
"new",
"logtap",
"object",
"and",
"makes",
"sure",
"it",
"has",
"a",
"logger"
] | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/logtap.go#L53-L61 |
149,330 | nanobox-io/nanobox-logtap | logtap.go | AddDrain | func (l *Logtap) AddDrain(tag string, drain Drain) {
channels := drainChannels{
done: make(chan bool),
send: make(chan Message),
}
go func() {
for {
select {
case <-channels.done:
return
case msg := <-channels.send:
drain(l.log, msg)
}
}
}()
l.drains[tag] = channels
} | go | func (l *Logtap) AddDrain(tag string, drain Drain) {
channels := drainChannels{
done: make(chan bool),
send: make(chan Message),
}
go func() {
for {
select {
case <-channels.done:
return
case msg := <-channels.send:
drain(l.log, msg)
}
}
}()
l.drains[tag] = channels
} | [
"func",
"(",
"l",
"*",
"Logtap",
")",
"AddDrain",
"(",
"tag",
"string",
",",
"drain",
"Drain",
")",
"{",
"channels",
":=",
"drainChannels",
"{",
"done",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"send",
":",
"make",
"(",
"chan",
"Message",
")",
"... | // AddDrain addes a drain to the listeners and sets its logger | [
"AddDrain",
"addes",
"a",
"drain",
"to",
"the",
"listeners",
"and",
"sets",
"its",
"logger"
] | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/logtap.go#L71-L89 |
149,331 | nanobox-io/nanobox-logtap | logtap.go | RemoveDrain | func (l *Logtap) RemoveDrain(tag string) {
drain, ok := l.drains[tag]
if ok {
close(drain.done)
delete(l.drains, tag)
}
} | go | func (l *Logtap) RemoveDrain(tag string) {
drain, ok := l.drains[tag]
if ok {
close(drain.done)
delete(l.drains, tag)
}
} | [
"func",
"(",
"l",
"*",
"Logtap",
")",
"RemoveDrain",
"(",
"tag",
"string",
")",
"{",
"drain",
",",
"ok",
":=",
"l",
".",
"drains",
"[",
"tag",
"]",
"\n",
"if",
"ok",
"{",
"close",
"(",
"drain",
".",
"done",
")",
"\n",
"delete",
"(",
"l",
".",
... | // RemoveDrain drops a drain | [
"RemoveDrain",
"drops",
"a",
"drain"
] | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/logtap.go#L92-L98 |
149,332 | nanobox-io/nanobox-logtap | logtap.go | WriteMessage | func (l *Logtap) WriteMessage(msg Message) {
group := sync.WaitGroup{}
for _, drain := range l.drains {
group.Add(1)
go func(myDrain drainChannels) {
select {
case <-myDrain.done:
case myDrain.send <- msg:
}
group.Done()
}(drain)
}
group.Wait()
} | go | func (l *Logtap) WriteMessage(msg Message) {
group := sync.WaitGroup{}
for _, drain := range l.drains {
group.Add(1)
go func(myDrain drainChannels) {
select {
case <-myDrain.done:
case myDrain.send <- msg:
}
group.Done()
}(drain)
}
group.Wait()
} | [
"func",
"(",
"l",
"*",
"Logtap",
")",
"WriteMessage",
"(",
"msg",
"Message",
")",
"{",
"group",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"_",
",",
"drain",
":=",
"range",
"l",
".",
"drains",
"{",
"group",
".",
"Add",
"(",
"1",
")",
... | // WriteMessage broadcasts to all drains in seperate go routines
// Returns once all drains have received the message, but may not have processed
// the message yet | [
"WriteMessage",
"broadcasts",
"to",
"all",
"drains",
"in",
"seperate",
"go",
"routines",
"Returns",
"once",
"all",
"drains",
"have",
"received",
"the",
"message",
"but",
"may",
"not",
"have",
"processed",
"the",
"message",
"yet"
] | 5584500c6e11a10c9a586fb09ed935102addb0bc | https://github.com/nanobox-io/nanobox-logtap/blob/5584500c6e11a10c9a586fb09ed935102addb0bc/logtap.go#L113-L126 |
149,333 | blockloop/tea | request.go | Body | func Body(r *http.Request, v interface{}) error {
if err := json.NewDecoder(r.Body).Decode(v); err != nil {
return err
}
return Validate.StructCtx(r.Context(), v)
} | go | func Body(r *http.Request, v interface{}) error {
if err := json.NewDecoder(r.Body).Decode(v); err != nil {
return err
}
return Validate.StructCtx(r.Context(), v)
} | [
"func",
"Body",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")",
".",
"Decode",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"... | // Body parses a JSON request body and validates it's contents | [
"Body",
"parses",
"a",
"JSON",
"request",
"body",
"and",
"validates",
"it",
"s",
"contents"
] | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/request.go#L13-L18 |
149,334 | blockloop/tea | request.go | Logger | func Logger(r *http.Request) log.Interface {
ctx := r.Context()
if ll, ok := ctx.Value(loggerKey).(log.Interface); ok {
return ll
}
return NewLogger(r)
} | go | func Logger(r *http.Request) log.Interface {
ctx := r.Context()
if ll, ok := ctx.Value(loggerKey).(log.Interface); ok {
return ll
}
return NewLogger(r)
} | [
"func",
"Logger",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"log",
".",
"Interface",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"if",
"ll",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"loggerKey",
")",
".",
"(",
"log",
".",
"Interf... | // Logger pulls a logger from request context or creates a new one
// with NewLogger if one does not exist | [
"Logger",
"pulls",
"a",
"logger",
"from",
"request",
"context",
"or",
"creates",
"a",
"new",
"one",
"with",
"NewLogger",
"if",
"one",
"does",
"not",
"exist"
] | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/request.go#L39-L45 |
149,335 | blockloop/tea | request.go | LoggerCtx | func LoggerCtx(r *http.Request) (log.Interface, context.Context) {
l := Logger(r)
return l, context.WithValue(r.Context(), loggerKey, l)
} | go | func LoggerCtx(r *http.Request) (log.Interface, context.Context) {
l := Logger(r)
return l, context.WithValue(r.Context(), loggerKey, l)
} | [
"func",
"LoggerCtx",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"log",
".",
"Interface",
",",
"context",
".",
"Context",
")",
"{",
"l",
":=",
"Logger",
"(",
"r",
")",
"\n",
"return",
"l",
",",
"context",
".",
"WithValue",
"(",
"r",
".",
"Co... | // LoggerCtx uses Logger to get a log.Interface and appends it to
// the request context, returning the new context with the logger value
// to be retrieved within Handlers | [
"LoggerCtx",
"uses",
"Logger",
"to",
"get",
"a",
"log",
".",
"Interface",
"and",
"appends",
"it",
"to",
"the",
"request",
"context",
"returning",
"the",
"new",
"context",
"with",
"the",
"logger",
"value",
"to",
"be",
"retrieved",
"within",
"Handlers"
] | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/request.go#L50-L53 |
149,336 | blockloop/tea | request.go | LoggerMiddleware | func LoggerMiddleware(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
_, ctx := LoggerCtx(r)
next.ServeHTTP(w, r.WithContext(ctx))
}
return http.HandlerFunc(fn)
} | go | func LoggerMiddleware(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
_, ctx := LoggerCtx(r)
next.ServeHTTP(w, r.WithContext(ctx))
}
return http.HandlerFunc(fn)
} | [
"func",
"LoggerMiddleware",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"fn",
":=",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"_",
",",
"ctx",
":=",
"LoggerCtx",
"(",
... | // LoggerMiddleware appends a logger with request information using
// LoggerCtx to every request | [
"LoggerMiddleware",
"appends",
"a",
"logger",
"with",
"request",
"information",
"using",
"LoggerCtx",
"to",
"every",
"request"
] | 1753fa2d55332fa0a9df3655ef0872a478881d15 | https://github.com/blockloop/tea/blob/1753fa2d55332fa0a9df3655ef0872a478881d15/request.go#L57-L64 |
149,337 | motemen/go-colorine | colorine.go | NewLogger | func NewLogger(prefixes Prefixes, defaultStyle TextStyle) *Logger {
prefixes[""] = defaultStyle
return &Logger{Prefixes: prefixes, output: os.Stdout}
} | go | func NewLogger(prefixes Prefixes, defaultStyle TextStyle) *Logger {
prefixes[""] = defaultStyle
return &Logger{Prefixes: prefixes, output: os.Stdout}
} | [
"func",
"NewLogger",
"(",
"prefixes",
"Prefixes",
",",
"defaultStyle",
"TextStyle",
")",
"*",
"Logger",
"{",
"prefixes",
"[",
"\"",
"\"",
"]",
"=",
"defaultStyle",
"\n",
"return",
"&",
"Logger",
"{",
"Prefixes",
":",
"prefixes",
",",
"output",
":",
"os",
... | // NewLogger creates a new Logger. prefixes is a prefix-string-to-text-style
// mapping. The log prefix is colored using this table. If no entry is found in
// prefixes, defaultStyle is used.
//
// By default, no prefix is registered to any text style. | [
"NewLogger",
"creates",
"a",
"new",
"Logger",
".",
"prefixes",
"is",
"a",
"prefix",
"-",
"string",
"-",
"to",
"-",
"text",
"-",
"style",
"mapping",
".",
"The",
"log",
"prefix",
"is",
"colored",
"using",
"this",
"table",
".",
"If",
"no",
"entry",
"is",
... | 45d19169413a019e4e2be69629dde5c7d92f8706 | https://github.com/motemen/go-colorine/blob/45d19169413a019e4e2be69629dde5c7d92f8706/colorine.go#L103-L106 |
149,338 | motemen/go-colorine | colorine.go | Log | func (logger *Logger) Log(prefix, message string) {
textStyle, ok := logger.Prefixes[prefix]
if !ok {
textStyle, ok = logger.Prefixes[""]
if !ok {
textStyle = Default
}
}
out := logger.getOutput()
logger.mu.Lock()
defer logger.mu.Unlock()
ct.ChangeColor(
textStyle.Foreground.Color,
textStyle.Fore... | go | func (logger *Logger) Log(prefix, message string) {
textStyle, ok := logger.Prefixes[prefix]
if !ok {
textStyle, ok = logger.Prefixes[""]
if !ok {
textStyle = Default
}
}
out := logger.getOutput()
logger.mu.Lock()
defer logger.mu.Unlock()
ct.ChangeColor(
textStyle.Foreground.Color,
textStyle.Fore... | [
"func",
"(",
"logger",
"*",
"Logger",
")",
"Log",
"(",
"prefix",
",",
"message",
"string",
")",
"{",
"textStyle",
",",
"ok",
":=",
"logger",
".",
"Prefixes",
"[",
"prefix",
"]",
"\n",
"if",
"!",
"ok",
"{",
"textStyle",
",",
"ok",
"=",
"logger",
"."... | // Log prints messages to console. prefix is colored using the logger.prefixes
// table. | [
"Log",
"prints",
"messages",
"to",
"console",
".",
"prefix",
"is",
"colored",
"using",
"the",
"logger",
".",
"prefixes",
"table",
"."
] | 45d19169413a019e4e2be69629dde5c7d92f8706 | https://github.com/motemen/go-colorine/blob/45d19169413a019e4e2be69629dde5c7d92f8706/colorine.go#L110-L136 |
149,339 | poy/eachers | becalled.go | Match | func (c *Called) Match(actual interface{}) (success bool, err error) {
val := reflect.ValueOf(actual)
if val.Kind() != reflect.Struct && val.Kind() != reflect.Chan {
return false, errors.New("BeCalled requires a channel or struct full of channel fields")
}
if len(c.calls) == 0 {
c.calls = append(c.calls, []inte... | go | func (c *Called) Match(actual interface{}) (success bool, err error) {
val := reflect.ValueOf(actual)
if val.Kind() != reflect.Struct && val.Kind() != reflect.Chan {
return false, errors.New("BeCalled requires a channel or struct full of channel fields")
}
if len(c.calls) == 0 {
c.calls = append(c.calls, []inte... | [
"func",
"(",
"c",
"*",
"Called",
")",
"Match",
"(",
"actual",
"interface",
"{",
"}",
")",
"(",
"success",
"bool",
",",
"err",
"error",
")",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"actual",
")",
"\n",
"if",
"val",
".",
"Kind",
"(",
")",... | // Match asserts that actual was called. If there are any argument
// slices in c, it will assert that actual was called with those
// arguments. | [
"Match",
"asserts",
"that",
"actual",
"was",
"called",
".",
"If",
"there",
"are",
"any",
"argument",
"slices",
"in",
"c",
"it",
"will",
"assert",
"that",
"actual",
"was",
"called",
"with",
"those",
"arguments",
"."
] | 23942921fe772047c14eac173c9d08aa3a6189bf | https://github.com/poy/eachers/blob/23942921fe772047c14eac173c9d08aa3a6189bf/becalled.go#L45-L93 |
149,340 | poy/eachers | becalled.go | FailureMessage | func (c *Called) FailureMessage(actual interface{}) (message string) {
message = fmt.Sprintf("Expected %#v to be called", actual)
if len(c.matchFailures) == 0 {
return message
}
return message + " with args:\n" + strings.Join(c.matchFailures, "\n")
} | go | func (c *Called) FailureMessage(actual interface{}) (message string) {
message = fmt.Sprintf("Expected %#v to be called", actual)
if len(c.matchFailures) == 0 {
return message
}
return message + " with args:\n" + strings.Join(c.matchFailures, "\n")
} | [
"func",
"(",
"c",
"*",
"Called",
")",
"FailureMessage",
"(",
"actual",
"interface",
"{",
"}",
")",
"(",
"message",
"string",
")",
"{",
"message",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"actual",
")",
"\n",
"if",
"len",
"(",
"c",
".",
"... | // FailureMessage returns the message when c failed to match a call. | [
"FailureMessage",
"returns",
"the",
"message",
"when",
"c",
"failed",
"to",
"match",
"a",
"call",
"."
] | 23942921fe772047c14eac173c9d08aa3a6189bf | https://github.com/poy/eachers/blob/23942921fe772047c14eac173c9d08aa3a6189bf/becalled.go#L108-L114 |
149,341 | poy/eachers | becalled.go | NegatedFailureMessage | func (c *Called) NegatedFailureMessage(actual interface{}) (message string) {
msg := fmt.Sprintf("Expected %#v not to be called", actual)
if len(c.matched[0]) == 0 {
return msg
}
return fmt.Sprintf("%s with args (%s)", msg, joinInter(c.matched[0], ", "))
} | go | func (c *Called) NegatedFailureMessage(actual interface{}) (message string) {
msg := fmt.Sprintf("Expected %#v not to be called", actual)
if len(c.matched[0]) == 0 {
return msg
}
return fmt.Sprintf("%s with args (%s)", msg, joinInter(c.matched[0], ", "))
} | [
"func",
"(",
"c",
"*",
"Called",
")",
"NegatedFailureMessage",
"(",
"actual",
"interface",
"{",
"}",
")",
"(",
"message",
"string",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"actual",
")",
"\n",
"if",
"len",
"(",
"c",
".",... | // NegatedFailureMessage returns the message when c matched a call and
// shouldn't have. | [
"NegatedFailureMessage",
"returns",
"the",
"message",
"when",
"c",
"matched",
"a",
"call",
"and",
"shouldn",
"t",
"have",
"."
] | 23942921fe772047c14eac173c9d08aa3a6189bf | https://github.com/poy/eachers/blob/23942921fe772047c14eac173c9d08aa3a6189bf/becalled.go#L118-L124 |
149,342 | kaeuferportal/stack2struct | stack2struct.go | Current | func Current(stack stackTrace) {
rawStack := make([]byte, 1<<16)
rawStack = rawStack[:runtime.Stack(rawStack, false)]
Parse(rawStack, stack)
} | go | func Current(stack stackTrace) {
rawStack := make([]byte, 1<<16)
rawStack = rawStack[:runtime.Stack(rawStack, false)]
Parse(rawStack, stack)
} | [
"func",
"Current",
"(",
"stack",
"stackTrace",
")",
"{",
"rawStack",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
"<<",
"16",
")",
"\n",
"rawStack",
"=",
"rawStack",
"[",
":",
"runtime",
".",
"Stack",
"(",
"rawStack",
",",
"false",
")",
"]",
"\n"... | // Current loads the current stacktrace into a given stack | [
"Current",
"loads",
"the",
"current",
"stacktrace",
"into",
"a",
"given",
"stack"
] | 6838fbadc9188e5d5778b0c708da95d90653bda0 | https://github.com/kaeuferportal/stack2struct/blob/6838fbadc9188e5d5778b0c708da95d90653bda0/stack2struct.go#L33-L37 |
149,343 | kaeuferportal/stack2struct | stack2struct.go | extractPackageName | func extractPackageName(line string) (packageName, methodName string) {
packagePath, packageNameAndFunction := splitAtLastSlash(line)
parts := strings.Split(packageNameAndFunction, ".")
packageName = parts[0]
if len(packagePath) > 0 {
packageName = fmt.Sprintf("%s/%s", packagePath, packageName)
}
methodName = s... | go | func extractPackageName(line string) (packageName, methodName string) {
packagePath, packageNameAndFunction := splitAtLastSlash(line)
parts := strings.Split(packageNameAndFunction, ".")
packageName = parts[0]
if len(packagePath) > 0 {
packageName = fmt.Sprintf("%s/%s", packagePath, packageName)
}
methodName = s... | [
"func",
"extractPackageName",
"(",
"line",
"string",
")",
"(",
"packageName",
",",
"methodName",
"string",
")",
"{",
"packagePath",
",",
"packageNameAndFunction",
":=",
"splitAtLastSlash",
"(",
"line",
")",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"p... | // extractPageName receives a trace line and extracts packageName and
// methodName. | [
"extractPageName",
"receives",
"a",
"trace",
"line",
"and",
"extracts",
"packageName",
"and",
"methodName",
"."
] | 6838fbadc9188e5d5778b0c708da95d90653bda0 | https://github.com/kaeuferportal/stack2struct/blob/6838fbadc9188e5d5778b0c708da95d90653bda0/stack2struct.go#L62-L71 |
149,344 | kaeuferportal/stack2struct | stack2struct.go | extractLineNumberAndFile | func extractLineNumberAndFile(line string) (lineNumber int, fileName string) {
_, fileAndLine := splitAtLastSlash(line)
fileAndLine = removeSpaceAndSuffix(fileAndLine)
parts := strings.Split(fileAndLine, ":")
numberAsString := parts[1]
number, _ := strconv.ParseUint(numberAsString, 10, 32)
lineNumber = int(numbe... | go | func extractLineNumberAndFile(line string) (lineNumber int, fileName string) {
_, fileAndLine := splitAtLastSlash(line)
fileAndLine = removeSpaceAndSuffix(fileAndLine)
parts := strings.Split(fileAndLine, ":")
numberAsString := parts[1]
number, _ := strconv.ParseUint(numberAsString, 10, 32)
lineNumber = int(numbe... | [
"func",
"extractLineNumberAndFile",
"(",
"line",
"string",
")",
"(",
"lineNumber",
"int",
",",
"fileName",
"string",
")",
"{",
"_",
",",
"fileAndLine",
":=",
"splitAtLastSlash",
"(",
"line",
")",
"\n",
"fileAndLine",
"=",
"removeSpaceAndSuffix",
"(",
"fileAndLin... | // extractLineNumberAndFile receives a trace line and extracts lineNumber and
// fileName. | [
"extractLineNumberAndFile",
"receives",
"a",
"trace",
"line",
"and",
"extracts",
"lineNumber",
"and",
"fileName",
"."
] | 6838fbadc9188e5d5778b0c708da95d90653bda0 | https://github.com/kaeuferportal/stack2struct/blob/6838fbadc9188e5d5778b0c708da95d90653bda0/stack2struct.go#L75-L86 |
149,345 | kaeuferportal/stack2struct | stack2struct.go | splitAtLastSlash | func splitAtLastSlash(line string) (left, right string) {
parts := strings.Split(line, "/")
right = parts[len(parts)-1]
left = strings.Join(parts[:len(parts)-1], "/")
return
} | go | func splitAtLastSlash(line string) (left, right string) {
parts := strings.Split(line, "/")
right = parts[len(parts)-1]
left = strings.Join(parts[:len(parts)-1], "/")
return
} | [
"func",
"splitAtLastSlash",
"(",
"line",
"string",
")",
"(",
"left",
",",
"right",
"string",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"right",
"=",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
... | // splitAtLastSlash splits a string at the last found slash and returns the
// respective strings left and right of the slash. | [
"splitAtLastSlash",
"splits",
"a",
"string",
"at",
"the",
"last",
"found",
"slash",
"and",
"returns",
"the",
"respective",
"strings",
"left",
"and",
"right",
"of",
"the",
"slash",
"."
] | 6838fbadc9188e5d5778b0c708da95d90653bda0 | https://github.com/kaeuferportal/stack2struct/blob/6838fbadc9188e5d5778b0c708da95d90653bda0/stack2struct.go#L90-L95 |
149,346 | kaeuferportal/stack2struct | stack2struct.go | removeSpaceAndSuffix | func removeSpaceAndSuffix(line string) string {
parts := strings.Split(line, " ")
return strings.Join(parts[:len(parts)-1], " ")
} | go | func removeSpaceAndSuffix(line string) string {
parts := strings.Split(line, " ")
return strings.Join(parts[:len(parts)-1], " ")
} | [
"func",
"removeSpaceAndSuffix",
"(",
"line",
"string",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"return",
"strings",
".",
"Join",
"(",
"parts",
"[",
":",
"len",
"(",
"parts",
")",
"-",
"1",
... | // removeSpaceAndSuffix splits the given string at ' ' and cuts off the part
// found after the last space. | [
"removeSpaceAndSuffix",
"splits",
"the",
"given",
"string",
"at",
"and",
"cuts",
"off",
"the",
"part",
"found",
"after",
"the",
"last",
"space",
"."
] | 6838fbadc9188e5d5778b0c708da95d90653bda0 | https://github.com/kaeuferportal/stack2struct/blob/6838fbadc9188e5d5778b0c708da95d90653bda0/stack2struct.go#L99-L102 |
149,347 | giantswarm/microerror | microerror.go | Maskf | func Maskf(err error, f string, v ...interface{}) error {
return handler.Maskf(err, f, v...)
} | go | func Maskf(err error, f string, v ...interface{}) error {
return handler.Maskf(err, f, v...)
} | [
"func",
"Maskf",
"(",
"err",
"error",
",",
"f",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"handler",
".",
"Maskf",
"(",
"err",
",",
"f",
",",
"v",
"...",
")",
"\n",
"}"
] | // Maskf is like Mask. In addition to that it takes a format string and
// variadic arguments like fmt.Sprintf. The format string and variadic
// arguments are used to annotate the given errgo error. | [
"Maskf",
"is",
"like",
"Mask",
".",
"In",
"addition",
"to",
"that",
"it",
"takes",
"a",
"format",
"string",
"and",
"variadic",
"arguments",
"like",
"fmt",
".",
"Sprintf",
".",
"The",
"format",
"string",
"and",
"variadic",
"arguments",
"are",
"used",
"to",
... | dc32fd459f94c7f9f938366135f6a19b3f9c63a9 | https://github.com/giantswarm/microerror/blob/dc32fd459f94c7f9f938366135f6a19b3f9c63a9/microerror.go#L41-L43 |
149,348 | evalphobia/eurekache | eurekache.go | AddCacheSource | func (e *Eurekache) AddCacheSource(cache Cache) {
if cache == nil {
return
}
e.caches = append(e.caches, cache)
} | go | func (e *Eurekache) AddCacheSource(cache Cache) {
if cache == nil {
return
}
e.caches = append(e.caches, cache)
} | [
"func",
"(",
"e",
"*",
"Eurekache",
")",
"AddCacheSource",
"(",
"cache",
"Cache",
")",
"{",
"if",
"cache",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"e",
".",
"caches",
"=",
"append",
"(",
"e",
".",
"caches",
",",
"cache",
")",
"\n",
"}"
] | // AddCacheSource adds cache source | [
"AddCacheSource",
"adds",
"cache",
"source"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/eurekache.go#L39-L45 |
149,349 | evalphobia/eurekache | eurekache.go | Get | func (e *Eurekache) Get(key string, data interface{}) (ok bool) {
ch := make(chan bool, 1)
// get cache
go func() {
for _, c := range e.caches {
ok = c.Get(key, data)
if ok {
ch <- true
return
}
}
ch <- false
}()
// get cache or timeout
select {
case <-ch:
return
case <-time.After(e.re... | go | func (e *Eurekache) Get(key string, data interface{}) (ok bool) {
ch := make(chan bool, 1)
// get cache
go func() {
for _, c := range e.caches {
ok = c.Get(key, data)
if ok {
ch <- true
return
}
}
ch <- false
}()
// get cache or timeout
select {
case <-ch:
return
case <-time.After(e.re... | [
"func",
"(",
"e",
"*",
"Eurekache",
")",
"Get",
"(",
"key",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"(",
"ok",
"bool",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"// get cache",
"go",
"func",
"(",
")",
"{... | // Get searches cache by given key and returns flag of cache is existed or not.
// when cache hit, data is assigned. | [
"Get",
"searches",
"cache",
"by",
"given",
"key",
"and",
"returns",
"flag",
"of",
"cache",
"is",
"existed",
"or",
"not",
".",
"when",
"cache",
"hit",
"data",
"is",
"assigned",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/eurekache.go#L65-L86 |
149,350 | evalphobia/eurekache | eurekache.go | GetInterface | func (e *Eurekache) GetInterface(key string) (v interface{}, ok bool) {
ch := make(chan bool, 1)
// get cache
go func() {
for _, c := range e.caches {
v, ok = c.GetInterface(key)
if ok {
ch <- true
return
}
}
ch <- false
}()
// get cache or timeout
select {
case <-ch:
return
case <-tim... | go | func (e *Eurekache) GetInterface(key string) (v interface{}, ok bool) {
ch := make(chan bool, 1)
// get cache
go func() {
for _, c := range e.caches {
v, ok = c.GetInterface(key)
if ok {
ch <- true
return
}
}
ch <- false
}()
// get cache or timeout
select {
case <-ch:
return
case <-tim... | [
"func",
"(",
"e",
"*",
"Eurekache",
")",
"GetInterface",
"(",
"key",
"string",
")",
"(",
"v",
"interface",
"{",
"}",
",",
"ok",
"bool",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"// get cache",
"go",
"func",
"(",
")"... | // GetInterface searches cache by given key and returns interface value. | [
"GetInterface",
"searches",
"cache",
"by",
"given",
"key",
"and",
"returns",
"interface",
"value",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/eurekache.go#L89-L110 |
149,351 | evalphobia/eurekache | eurekache.go | GetGobBytes | func (e *Eurekache) GetGobBytes(key string) (b []byte, ok bool) {
ch := make(chan bool, 1)
// get cache
go func() {
for _, c := range e.caches {
b, ok = c.GetGobBytes(key)
if ok {
ch <- true
return
}
}
ch <- false
}()
// get cache or timeout
select {
case <-ch:
return
case <-time.After... | go | func (e *Eurekache) GetGobBytes(key string) (b []byte, ok bool) {
ch := make(chan bool, 1)
// get cache
go func() {
for _, c := range e.caches {
b, ok = c.GetGobBytes(key)
if ok {
ch <- true
return
}
}
ch <- false
}()
// get cache or timeout
select {
case <-ch:
return
case <-time.After... | [
"func",
"(",
"e",
"*",
"Eurekache",
")",
"GetGobBytes",
"(",
"key",
"string",
")",
"(",
"b",
"[",
"]",
"byte",
",",
"ok",
"bool",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"// get cache",
"go",
"func",
"(",
")",
"{... | // GetGobBytes searches cache by given key and returns gob-encoded value. | [
"GetGobBytes",
"searches",
"cache",
"by",
"given",
"key",
"and",
"returns",
"gob",
"-",
"encoded",
"value",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/eurekache.go#L113-L134 |
149,352 | evalphobia/eurekache | eurekache.go | Set | func (e *Eurekache) Set(key string, data interface{}) {
ch := make(chan bool, 1)
// set cache
go func() {
for _, c := range e.caches {
c.Set(key, data)
}
ch <- true
}()
// set cache or timeout
select {
case <-ch:
return
case <-time.After(e.writeTimeout):
return
}
} | go | func (e *Eurekache) Set(key string, data interface{}) {
ch := make(chan bool, 1)
// set cache
go func() {
for _, c := range e.caches {
c.Set(key, data)
}
ch <- true
}()
// set cache or timeout
select {
case <-ch:
return
case <-time.After(e.writeTimeout):
return
}
} | [
"func",
"(",
"e",
"*",
"Eurekache",
")",
"Set",
"(",
"key",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"bool",
",",
"1",
")",
"\n",
"// set cache",
"go",
"func",
"(",
")",
"{",
"for",
"_",
",",
"c",... | // Set sets data into all of cache sources. | [
"Set",
"sets",
"data",
"into",
"all",
"of",
"cache",
"sources",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/eurekache.go#L137-L154 |
149,353 | evalphobia/eurekache | eurekache.go | CopyValue | func CopyValue(dst, src interface{}) bool {
vvDst := reflect.ValueOf(dst)
switch {
case vvDst.Kind() != reflect.Ptr:
// cannot assign value for non-pointer
return false
case vvDst.IsNil():
// cannot assign value for nil
return false
}
vvDst = vvDst.Elem()
if !vvDst.CanSet() {
return false
}
vvSrc :... | go | func CopyValue(dst, src interface{}) bool {
vvDst := reflect.ValueOf(dst)
switch {
case vvDst.Kind() != reflect.Ptr:
// cannot assign value for non-pointer
return false
case vvDst.IsNil():
// cannot assign value for nil
return false
}
vvDst = vvDst.Elem()
if !vvDst.CanSet() {
return false
}
vvSrc :... | [
"func",
"CopyValue",
"(",
"dst",
",",
"src",
"interface",
"{",
"}",
")",
"bool",
"{",
"vvDst",
":=",
"reflect",
".",
"ValueOf",
"(",
"dst",
")",
"\n",
"switch",
"{",
"case",
"vvDst",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
":",
"// cann... | // CopyValue copies src value into dst. | [
"CopyValue",
"copies",
"src",
"value",
"into",
"dst",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/eurekache.go#L177-L208 |
149,354 | evalphobia/eurekache | memorycache/memory.go | NewCacheTTL | func NewCacheTTL(max int) *CacheTTL {
if max == 0 {
return nil
}
return &CacheTTL{
items: make(map[string]*eurekache.Item),
maxSize: max,
deleteQueue: make([]string, 0, max),
}
} | go | func NewCacheTTL(max int) *CacheTTL {
if max == 0 {
return nil
}
return &CacheTTL{
items: make(map[string]*eurekache.Item),
maxSize: max,
deleteQueue: make([]string, 0, max),
}
} | [
"func",
"NewCacheTTL",
"(",
"max",
"int",
")",
"*",
"CacheTTL",
"{",
"if",
"max",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"CacheTTL",
"{",
"items",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"eurekache",
".",
"Item... | // NewCacheTTL returns initialized CacheTTL
// max value limits maximum saved item size. | [
"NewCacheTTL",
"returns",
"initialized",
"CacheTTL",
"max",
"value",
"limits",
"maximum",
"saved",
"item",
"size",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/memorycache/memory.go#L24-L34 |
149,355 | evalphobia/eurekache | memorycache/memory.go | Get | func (c *CacheTTL) Get(key string, data interface{}) bool {
c.itemsMu.RLock()
defer c.itemsMu.RUnlock()
item, ok := c.items[key]
switch {
case !ok:
return false
case !c.isValidItem(item):
return false
default:
return eurekache.CopyValue(data, item.Value)
}
} | go | func (c *CacheTTL) Get(key string, data interface{}) bool {
c.itemsMu.RLock()
defer c.itemsMu.RUnlock()
item, ok := c.items[key]
switch {
case !ok:
return false
case !c.isValidItem(item):
return false
default:
return eurekache.CopyValue(data, item.Value)
}
} | [
"func",
"(",
"c",
"*",
"CacheTTL",
")",
"Get",
"(",
"key",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"bool",
"{",
"c",
".",
"itemsMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"itemsMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"item",
... | // Get searches cache on memory by given key and returns flag of cache is existed or not.
// when cache hit, data is assigned. | [
"Get",
"searches",
"cache",
"on",
"memory",
"by",
"given",
"key",
"and",
"returns",
"flag",
"of",
"cache",
"is",
"existed",
"or",
"not",
".",
"when",
"cache",
"hit",
"data",
"is",
"assigned",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/memorycache/memory.go#L43-L56 |
149,356 | evalphobia/eurekache | memorycache/memory.go | GetInterface | func (c *CacheTTL) GetInterface(key string) (interface{}, bool) {
c.itemsMu.RLock()
defer c.itemsMu.RUnlock()
if item, ok := c.items[key]; ok {
if c.isValidItem(item) {
return item.Value, true
}
}
return nil, false
} | go | func (c *CacheTTL) GetInterface(key string) (interface{}, bool) {
c.itemsMu.RLock()
defer c.itemsMu.RUnlock()
if item, ok := c.items[key]; ok {
if c.isValidItem(item) {
return item.Value, true
}
}
return nil, false
} | [
"func",
"(",
"c",
"*",
"CacheTTL",
")",
"GetInterface",
"(",
"key",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"c",
".",
"itemsMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"itemsMu",
".",
"RUnlock",
"(",
")",
"\n\n... | // GetInterface searches cache on memory by given key and returns interface value. | [
"GetInterface",
"searches",
"cache",
"on",
"memory",
"by",
"given",
"key",
"and",
"returns",
"interface",
"value",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/memorycache/memory.go#L59-L70 |
149,357 | evalphobia/eurekache | memorycache/memory.go | GetGobBytes | func (c *CacheTTL) GetGobBytes(key string) ([]byte, bool) {
c.itemsMu.RLock()
defer c.itemsMu.RUnlock()
if item, ok := c.items[key]; ok {
if c.isValidItem(item) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(item.Value)
if err == nil {
return buf.Bytes(), true
}
}
}
r... | go | func (c *CacheTTL) GetGobBytes(key string) ([]byte, bool) {
c.itemsMu.RLock()
defer c.itemsMu.RUnlock()
if item, ok := c.items[key]; ok {
if c.isValidItem(item) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(item.Value)
if err == nil {
return buf.Bytes(), true
}
}
}
r... | [
"func",
"(",
"c",
"*",
"CacheTTL",
")",
"GetGobBytes",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"c",
".",
"itemsMu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"itemsMu",
".",
"RUnlock",
"(",
")",
"\n\n",
"... | // GetGobBytes searches cache on memory by given key and returns gob-encoded value. | [
"GetGobBytes",
"searches",
"cache",
"on",
"memory",
"by",
"given",
"key",
"and",
"returns",
"gob",
"-",
"encoded",
"value",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/memorycache/memory.go#L73-L89 |
149,358 | evalphobia/eurekache | memorycache/memory.go | isValidItem | func (c *CacheTTL) isValidItem(item *eurekache.Item) bool {
if item.Value == nil {
return false
}
return item.ExpiredAt > time.Now().UnixNano()
} | go | func (c *CacheTTL) isValidItem(item *eurekache.Item) bool {
if item.Value == nil {
return false
}
return item.ExpiredAt > time.Now().UnixNano()
} | [
"func",
"(",
"c",
"*",
"CacheTTL",
")",
"isValidItem",
"(",
"item",
"*",
"eurekache",
".",
"Item",
")",
"bool",
"{",
"if",
"item",
".",
"Value",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"item",
".",
"ExpiredAt",
">",
"time",
... | // isValidItem checks if the item is expired or not | [
"isValidItem",
"checks",
"if",
"the",
"item",
"is",
"expired",
"or",
"not"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/memorycache/memory.go#L141-L146 |
149,359 | evalphobia/eurekache | item.go | Init | func (i *Item) Init() {
i.CreatedAt = time.Now().UnixNano()
i.ExpiredAt = math.MaxInt64
i.Value = nil
} | go | func (i *Item) Init() {
i.CreatedAt = time.Now().UnixNano()
i.ExpiredAt = math.MaxInt64
i.Value = nil
} | [
"func",
"(",
"i",
"*",
"Item",
")",
"Init",
"(",
")",
"{",
"i",
".",
"CreatedAt",
"=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"\n",
"i",
".",
"ExpiredAt",
"=",
"math",
".",
"MaxInt64",
"\n",
"i",
".",
"Value",
"=",
"nil",
"\... | // Init initializes Item | [
"Init",
"initializes",
"Item"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/item.go#L28-L32 |
149,360 | evalphobia/eurekache | item.go | SetExpire | func (i *Item) SetExpire(ttl int64) {
if ttl == 0 {
return
}
i.ExpiredAt = i.CreatedAt + ttl*int64(time.Millisecond)
} | go | func (i *Item) SetExpire(ttl int64) {
if ttl == 0 {
return
}
i.ExpiredAt = i.CreatedAt + ttl*int64(time.Millisecond)
} | [
"func",
"(",
"i",
"*",
"Item",
")",
"SetExpire",
"(",
"ttl",
"int64",
")",
"{",
"if",
"ttl",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n",
"i",
".",
"ExpiredAt",
"=",
"i",
".",
"CreatedAt",
"+",
"ttl",
"*",
"int64",
"(",
"time",
".",
"Millisecond",
... | // SetExpire updates ExpiredAt from given ttl millisec | [
"SetExpire",
"updates",
"ExpiredAt",
"from",
"given",
"ttl",
"millisec"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/item.go#L35-L40 |
149,361 | evalphobia/eurekache | rediscache/redis.go | Select | func (c *RedisCache) Select(num int) {
c.dbno = strconv.Itoa(num)
} | go | func (c *RedisCache) Select(num int) {
c.dbno = strconv.Itoa(num)
} | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"Select",
"(",
"num",
"int",
")",
"{",
"c",
".",
"dbno",
"=",
"strconv",
".",
"Itoa",
"(",
"num",
")",
"\n",
"}"
] | // Select sets db number for redis-server | [
"Select",
"sets",
"db",
"number",
"for",
"redis",
"-",
"server"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L45-L47 |
149,362 | evalphobia/eurekache | rediscache/redis.go | Get | func (c *RedisCache) Get(key string, data interface{}) bool {
b, ok := c.GetGobBytes(key)
if !ok {
return false
}
dec := gob.NewDecoder(bytes.NewBuffer(b))
dec.Decode(data)
return true
} | go | func (c *RedisCache) Get(key string, data interface{}) bool {
b, ok := c.GetGobBytes(key)
if !ok {
return false
}
dec := gob.NewDecoder(bytes.NewBuffer(b))
dec.Decode(data)
return true
} | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"Get",
"(",
"key",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"bool",
"{",
"b",
",",
"ok",
":=",
"c",
".",
"GetGobBytes",
"(",
"key",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}... | // Get searches cache by given key from redis and returns flag of cache is existed or not.
// when cache hit, data is assigned. | [
"Get",
"searches",
"cache",
"by",
"given",
"key",
"from",
"redis",
"and",
"returns",
"flag",
"of",
"cache",
"is",
"existed",
"or",
"not",
".",
"when",
"cache",
"hit",
"data",
"is",
"assigned",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L51-L60 |
149,363 | evalphobia/eurekache | rediscache/redis.go | GetInterface | func (c *RedisCache) GetInterface(key string) (interface{}, bool) {
item, ok := c.getGobItem(key)
if !ok {
return nil, false
}
return item.Value, true
} | go | func (c *RedisCache) GetInterface(key string) (interface{}, bool) {
item, ok := c.getGobItem(key)
if !ok {
return nil, false
}
return item.Value, true
} | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"GetInterface",
"(",
"key",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"item",
",",
"ok",
":=",
"c",
".",
"getGobItem",
"(",
"key",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",... | // GetInterface searches cache by given key from redis and returns interface value. | [
"GetInterface",
"searches",
"cache",
"by",
"given",
"key",
"from",
"redis",
"and",
"returns",
"interface",
"value",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L63-L70 |
149,364 | evalphobia/eurekache | rediscache/redis.go | GetGobBytes | func (c *RedisCache) GetGobBytes(key string) ([]byte, bool) {
item, ok := c.getGobItem(key)
switch {
case !ok:
return nil, false
case item.Value == nil:
return nil, false
}
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(item.Value)
if err != nil {
return nil, false
}
return buf.By... | go | func (c *RedisCache) GetGobBytes(key string) ([]byte, bool) {
item, ok := c.getGobItem(key)
switch {
case !ok:
return nil, false
case item.Value == nil:
return nil, false
}
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(item.Value)
if err != nil {
return nil, false
}
return buf.By... | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"GetGobBytes",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"item",
",",
"ok",
":=",
"c",
".",
"getGobItem",
"(",
"key",
")",
"\n",
"switch",
"{",
"case",
"!",
"ok",
":",
"re... | // GetGobBytes searches cache by given key from redis and returns gob-encoded value. | [
"GetGobBytes",
"searches",
"cache",
"by",
"given",
"key",
"from",
"redis",
"and",
"returns",
"gob",
"-",
"encoded",
"value",
"."
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L73-L90 |
149,365 | evalphobia/eurekache | rediscache/redis.go | getGobItem | func (c *RedisCache) getGobItem(key string) (*eurekache.Item, bool) {
conn, err := c.conn()
if err != nil {
return nil, false
}
defer conn.Close()
data, err := conn.Do("GET", c.prefix+key)
if err != nil {
return nil, false
}
b, err := redis.Bytes(data, err)
if err != nil {
return nil, false
}
var it... | go | func (c *RedisCache) getGobItem(key string) (*eurekache.Item, bool) {
conn, err := c.conn()
if err != nil {
return nil, false
}
defer conn.Close()
data, err := conn.Do("GET", c.prefix+key)
if err != nil {
return nil, false
}
b, err := redis.Bytes(data, err)
if err != nil {
return nil, false
}
var it... | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"getGobItem",
"(",
"key",
"string",
")",
"(",
"*",
"eurekache",
".",
"Item",
",",
"bool",
")",
"{",
"conn",
",",
"err",
":=",
"c",
".",
"conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // getGobItem searches cache by given key from redis and returns Item data | [
"getGobItem",
"searches",
"cache",
"by",
"given",
"key",
"from",
"redis",
"and",
"returns",
"Item",
"data"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L93-L118 |
149,366 | evalphobia/eurekache | rediscache/redis.go | Set | func (c *RedisCache) Set(key string, data interface{}) error {
return c.SetExpire(key, data, c.defaultTTL)
} | go | func (c *RedisCache) Set(key string, data interface{}) error {
return c.SetExpire(key, data, c.defaultTTL)
} | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"Set",
"(",
"key",
"string",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"c",
".",
"SetExpire",
"(",
"key",
",",
"data",
",",
"c",
".",
"defaultTTL",
")",
"\n",
"}"
] | // Set sets data into redis. data is wrapped by gob-encoded Item | [
"Set",
"sets",
"data",
"into",
"redis",
".",
"data",
"is",
"wrapped",
"by",
"gob",
"-",
"encoded",
"Item"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L121-L123 |
149,367 | evalphobia/eurekache | rediscache/redis.go | SetExpire | func (c *RedisCache) SetExpire(key string, data interface{}, ttl int64) error {
conn, err := c.conn()
if err != nil {
return err
}
defer conn.Close()
if data == nil {
_, err = conn.Do("DEL", c.prefix+key)
return err
}
item := eurekache.NewItem()
item.SetExpire(ttl)
item.Value = data
var buf bytes.Buf... | go | func (c *RedisCache) SetExpire(key string, data interface{}, ttl int64) error {
conn, err := c.conn()
if err != nil {
return err
}
defer conn.Close()
if data == nil {
_, err = conn.Do("DEL", c.prefix+key)
return err
}
item := eurekache.NewItem()
item.SetExpire(ttl)
item.Value = data
var buf bytes.Buf... | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"SetExpire",
"(",
"key",
"string",
",",
"data",
"interface",
"{",
"}",
",",
"ttl",
"int64",
")",
"error",
"{",
"conn",
",",
"err",
":=",
"c",
".",
"conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // SetExpire sets data into redis with TTL. data is wrapped by gob-encoded Item | [
"SetExpire",
"sets",
"data",
"into",
"redis",
"with",
"TTL",
".",
"data",
"is",
"wrapped",
"by",
"gob",
"-",
"encoded",
"Item"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L126-L161 |
149,368 | evalphobia/eurekache | rediscache/redis.go | conn | func (c *RedisCache) conn() (redis.Conn, error) {
if c.pool == nil {
return nil, errNilPool
}
conn := c.pool.Get()
err := conn.Err()
if err != nil {
return nil, err
}
_, err = conn.Do("SELECT", c.dbno)
if err != nil {
return nil, err
}
return conn, nil
} | go | func (c *RedisCache) conn() (redis.Conn, error) {
if c.pool == nil {
return nil, errNilPool
}
conn := c.pool.Get()
err := conn.Err()
if err != nil {
return nil, err
}
_, err = conn.Do("SELECT", c.dbno)
if err != nil {
return nil, err
}
return conn, nil
} | [
"func",
"(",
"c",
"*",
"RedisCache",
")",
"conn",
"(",
")",
"(",
"redis",
".",
"Conn",
",",
"error",
")",
"{",
"if",
"c",
".",
"pool",
"==",
"nil",
"{",
"return",
"nil",
",",
"errNilPool",
"\n",
"}",
"\n\n",
"conn",
":=",
"c",
".",
"pool",
".",... | // conn returns redis.Conn created from redis.Pool | [
"conn",
"returns",
"redis",
".",
"Conn",
"created",
"from",
"redis",
".",
"Pool"
] | 43939e8daa657bfdaa2b69b63168473dbf8f45bc | https://github.com/evalphobia/eurekache/blob/43939e8daa657bfdaa2b69b63168473dbf8f45bc/rediscache/redis.go#L164-L181 |
149,369 | Wessie/appdirs | appdirs.go | UserData | func (app *App) UserData() string {
return UserDataDir(app.Name, app.Author, app.Version, app.Roaming)
} | go | func (app *App) UserData() string {
return UserDataDir(app.Name, app.Author, app.Version, app.Roaming)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"UserData",
"(",
")",
"string",
"{",
"return",
"UserDataDir",
"(",
"app",
".",
"Name",
",",
"app",
".",
"Author",
",",
"app",
".",
"Version",
",",
"app",
".",
"Roaming",
")",
"\n",
"}"
] | // UserData returns the full path to the user-specific data directory | [
"UserData",
"returns",
"the",
"full",
"path",
"to",
"the",
"user",
"-",
"specific",
"data",
"directory"
] | 6573e894f8e294cbae0c4e45c25ff9f2e2918a4e | https://github.com/Wessie/appdirs/blob/6573e894f8e294cbae0c4e45c25ff9f2e2918a4e/appdirs.go#L42-L44 |
149,370 | Wessie/appdirs | appdirs.go | SiteData | func (app *App) SiteData() string {
return SiteDataDir(app.Name, app.Author, app.Version)
} | go | func (app *App) SiteData() string {
return SiteDataDir(app.Name, app.Author, app.Version)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"SiteData",
"(",
")",
"string",
"{",
"return",
"SiteDataDir",
"(",
"app",
".",
"Name",
",",
"app",
".",
"Author",
",",
"app",
".",
"Version",
")",
"\n",
"}"
] | // SiteData returns the full path to the user-shared data directory | [
"SiteData",
"returns",
"the",
"full",
"path",
"to",
"the",
"user",
"-",
"shared",
"data",
"directory"
] | 6573e894f8e294cbae0c4e45c25ff9f2e2918a4e | https://github.com/Wessie/appdirs/blob/6573e894f8e294cbae0c4e45c25ff9f2e2918a4e/appdirs.go#L47-L49 |
149,371 | Wessie/appdirs | appdirs.go | SiteConfig | func (app *App) SiteConfig() string {
return SiteConfigDir(app.Name, app.Author, app.Version)
} | go | func (app *App) SiteConfig() string {
return SiteConfigDir(app.Name, app.Author, app.Version)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"SiteConfig",
"(",
")",
"string",
"{",
"return",
"SiteConfigDir",
"(",
"app",
".",
"Name",
",",
"app",
".",
"Author",
",",
"app",
".",
"Version",
")",
"\n",
"}"
] | // SiteConfig returns the full path to the user-shared configuration directory | [
"SiteConfig",
"returns",
"the",
"full",
"path",
"to",
"the",
"user",
"-",
"shared",
"configuration",
"directory"
] | 6573e894f8e294cbae0c4e45c25ff9f2e2918a4e | https://github.com/Wessie/appdirs/blob/6573e894f8e294cbae0c4e45c25ff9f2e2918a4e/appdirs.go#L52-L54 |
149,372 | Wessie/appdirs | appdirs.go | UserConfig | func (app *App) UserConfig() string {
return UserConfigDir(app.Name, app.Author, app.Version, app.Roaming)
} | go | func (app *App) UserConfig() string {
return UserConfigDir(app.Name, app.Author, app.Version, app.Roaming)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"UserConfig",
"(",
")",
"string",
"{",
"return",
"UserConfigDir",
"(",
"app",
".",
"Name",
",",
"app",
".",
"Author",
",",
"app",
".",
"Version",
",",
"app",
".",
"Roaming",
")",
"\n",
"}"
] | // UserConfig returns the full path to the user-specific configuration directory | [
"UserConfig",
"returns",
"the",
"full",
"path",
"to",
"the",
"user",
"-",
"specific",
"configuration",
"directory"
] | 6573e894f8e294cbae0c4e45c25ff9f2e2918a4e | https://github.com/Wessie/appdirs/blob/6573e894f8e294cbae0c4e45c25ff9f2e2918a4e/appdirs.go#L57-L59 |
149,373 | Wessie/appdirs | appdirs.go | UserCache | func (app *App) UserCache() string {
return UserCacheDir(app.Name, app.Author, app.Version, app.Opinion)
} | go | func (app *App) UserCache() string {
return UserCacheDir(app.Name, app.Author, app.Version, app.Opinion)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"UserCache",
"(",
")",
"string",
"{",
"return",
"UserCacheDir",
"(",
"app",
".",
"Name",
",",
"app",
".",
"Author",
",",
"app",
".",
"Version",
",",
"app",
".",
"Opinion",
")",
"\n",
"}"
] | // UserCache returns the full path to the user-specific cache directory | [
"UserCache",
"returns",
"the",
"full",
"path",
"to",
"the",
"user",
"-",
"specific",
"cache",
"directory"
] | 6573e894f8e294cbae0c4e45c25ff9f2e2918a4e | https://github.com/Wessie/appdirs/blob/6573e894f8e294cbae0c4e45c25ff9f2e2918a4e/appdirs.go#L62-L64 |
149,374 | Wessie/appdirs | appdirs.go | UserLog | func (app *App) UserLog() string {
return UserLogDir(app.Name, app.Author, app.Version, app.Opinion)
} | go | func (app *App) UserLog() string {
return UserLogDir(app.Name, app.Author, app.Version, app.Opinion)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"UserLog",
"(",
")",
"string",
"{",
"return",
"UserLogDir",
"(",
"app",
".",
"Name",
",",
"app",
".",
"Author",
",",
"app",
".",
"Version",
",",
"app",
".",
"Opinion",
")",
"\n",
"}"
] | // UserLog returns the full path to the user-specific log directory | [
"UserLog",
"returns",
"the",
"full",
"path",
"to",
"the",
"user",
"-",
"specific",
"log",
"directory"
] | 6573e894f8e294cbae0c4e45c25ff9f2e2918a4e | https://github.com/Wessie/appdirs/blob/6573e894f8e294cbae0c4e45c25ff9f2e2918a4e/appdirs.go#L67-L69 |
149,375 | lestrrat-go/bufferpool | bufferpool.go | Get | func (bp *BufferPool) Get() *bytes.Buffer {
return bp.pool.Get().(*bytes.Buffer)
} | go | func (bp *BufferPool) Get() *bytes.Buffer {
return bp.pool.Get().(*bytes.Buffer)
} | [
"func",
"(",
"bp",
"*",
"BufferPool",
")",
"Get",
"(",
")",
"*",
"bytes",
".",
"Buffer",
"{",
"return",
"bp",
".",
"pool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"bytes",
".",
"Buffer",
")",
"\n",
"}"
] | // Get returns a bytes.Buffer from the specified pool | [
"Get",
"returns",
"a",
"bytes",
".",
"Buffer",
"from",
"the",
"specified",
"pool"
] | e7784e1b3e37191cf8ffaf14170f2703cd96c2cd | https://github.com/lestrrat-go/bufferpool/blob/e7784e1b3e37191cf8ffaf14170f2703cd96c2cd/bufferpool.go#L40-L42 |
149,376 | lestrrat-go/bufferpool | bufferpool.go | Release | func (bp *BufferPool) Release(buf *bytes.Buffer) {
buf.Reset()
bp.pool.Put(buf)
} | go | func (bp *BufferPool) Release(buf *bytes.Buffer) {
buf.Reset()
bp.pool.Put(buf)
} | [
"func",
"(",
"bp",
"*",
"BufferPool",
")",
"Release",
"(",
"buf",
"*",
"bytes",
".",
"Buffer",
")",
"{",
"buf",
".",
"Reset",
"(",
")",
"\n",
"bp",
".",
"pool",
".",
"Put",
"(",
"buf",
")",
"\n",
"}"
] | // Release puts the given bytes.Buffer back in the specified pool after
// resetting it | [
"Release",
"puts",
"the",
"given",
"bytes",
".",
"Buffer",
"back",
"in",
"the",
"specified",
"pool",
"after",
"resetting",
"it"
] | e7784e1b3e37191cf8ffaf14170f2703cd96c2cd | https://github.com/lestrrat-go/bufferpool/blob/e7784e1b3e37191cf8ffaf14170f2703cd96c2cd/bufferpool.go#L46-L49 |
149,377 | timewasted/linode | parameters.go | Get | func (p Parameters) Get(key string) string {
if p == nil {
return ""
}
value, ok := p[key]
if !ok {
return ""
}
return value
} | go | func (p Parameters) Get(key string) string {
if p == nil {
return ""
}
value, ok := p[key]
if !ok {
return ""
}
return value
} | [
"func",
"(",
"p",
"Parameters",
")",
"Get",
"(",
"key",
"string",
")",
"string",
"{",
"if",
"p",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"value",
",",
"ok",
":=",
"p",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\... | // Get gets the parameter associated with the given key. If no parameter is
// associated with the key, Get returns the empty string. | [
"Get",
"gets",
"the",
"parameter",
"associated",
"with",
"the",
"given",
"key",
".",
"If",
"no",
"parameter",
"is",
"associated",
"with",
"the",
"key",
"Get",
"returns",
"the",
"empty",
"string",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/parameters.go#L16-L25 |
149,378 | timewasted/linode | dns/dns.go | GetDomains | func (d *DNS) GetDomains(domainId interface{}) ([]*Domain, error) {
params := linode.Parameters{}
if domainId != nil {
id, ok := domainId.(int)
if ok {
params.Set("DomainID", strconv.Itoa(id))
}
}
var list []*Domain
_, err := d.linode.Request("domain.list", params, &list)
if err != nil {
return nil, e... | go | func (d *DNS) GetDomains(domainId interface{}) ([]*Domain, error) {
params := linode.Parameters{}
if domainId != nil {
id, ok := domainId.(int)
if ok {
params.Set("DomainID", strconv.Itoa(id))
}
}
var list []*Domain
_, err := d.linode.Request("domain.list", params, &list)
if err != nil {
return nil, e... | [
"func",
"(",
"d",
"*",
"DNS",
")",
"GetDomains",
"(",
"domainId",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"*",
"Domain",
",",
"error",
")",
"{",
"params",
":=",
"linode",
".",
"Parameters",
"{",
"}",
"\n",
"if",
"domainId",
"!=",
"nil",
"{",
"... | // GetDomains executes the "domain.list" API call. When domainID is nil, this
// will return a list of domains. Otherwise, it will return only the domain
// specified by domainID. | [
"GetDomains",
"executes",
"the",
"domain",
".",
"list",
"API",
"call",
".",
"When",
"domainID",
"is",
"nil",
"this",
"will",
"return",
"a",
"list",
"of",
"domains",
".",
"Otherwise",
"it",
"will",
"return",
"only",
"the",
"domain",
"specified",
"by",
"doma... | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/dns.go#L39-L54 |
149,379 | timewasted/linode | dns/dns.go | GetDomainResources | func (d *DNS) GetDomainResources(domainID int) ([]*Resource, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
}
var list []*Resource
_, err := d.linode.Request("domain.resource.list", params, &list)
if err != nil {
return nil, err
}
return list, nil
} | go | func (d *DNS) GetDomainResources(domainID int) ([]*Resource, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
}
var list []*Resource
_, err := d.linode.Request("domain.resource.list", params, &list)
if err != nil {
return nil, err
}
return list, nil
} | [
"func",
"(",
"d",
"*",
"DNS",
")",
"GetDomainResources",
"(",
"domainID",
"int",
")",
"(",
"[",
"]",
"*",
"Resource",
",",
"error",
")",
"{",
"params",
":=",
"linode",
".",
"Parameters",
"{",
"\"",
"\"",
":",
"strconv",
".",
"Itoa",
"(",
"domainID",
... | // GetDomainResources executes the "domain.resource.list" API call. This will
// return a list of domain resources associated with the specified domainID. | [
"GetDomainResources",
"executes",
"the",
"domain",
".",
"resource",
".",
"list",
"API",
"call",
".",
"This",
"will",
"return",
"a",
"list",
"of",
"domain",
"resources",
"associated",
"with",
"the",
"specified",
"domainID",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/dns.go#L58-L69 |
149,380 | timewasted/linode | errors.go | NewApiError | func NewApiError(code int, msg string) *Error {
return &Error{
apiError: &apiError{
code: code,
msg: msg,
},
Err: nil,
}
} | go | func NewApiError(code int, msg string) *Error {
return &Error{
apiError: &apiError{
code: code,
msg: msg,
},
Err: nil,
}
} | [
"func",
"NewApiError",
"(",
"code",
"int",
",",
"msg",
"string",
")",
"*",
"Error",
"{",
"return",
"&",
"Error",
"{",
"apiError",
":",
"&",
"apiError",
"{",
"code",
":",
"code",
",",
"msg",
":",
"msg",
",",
"}",
",",
"Err",
":",
"nil",
",",
"}",
... | // NewApiError returns an instance of Error which represents an API error. | [
"NewApiError",
"returns",
"an",
"instance",
"of",
"Error",
"which",
"represents",
"an",
"API",
"error",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/errors.go#L49-L57 |
149,381 | timewasted/linode | dns/domain.go | DeleteDomain | func (d *DNS) DeleteDomain(domainID int) (*DomainResponse, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
}
var response *DomainResponse
_, err := d.linode.Request("domain.delete", params, &response)
if err != nil {
return nil, err
}
return response, nil
} | go | func (d *DNS) DeleteDomain(domainID int) (*DomainResponse, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
}
var response *DomainResponse
_, err := d.linode.Request("domain.delete", params, &response)
if err != nil {
return nil, err
}
return response, nil
} | [
"func",
"(",
"d",
"*",
"DNS",
")",
"DeleteDomain",
"(",
"domainID",
"int",
")",
"(",
"*",
"DomainResponse",
",",
"error",
")",
"{",
"params",
":=",
"linode",
".",
"Parameters",
"{",
"\"",
"\"",
":",
"strconv",
".",
"Itoa",
"(",
"domainID",
")",
",",
... | // DeleteDomain executes the "domain.delete" API call. This will delete the
// domain specified by domainID. | [
"DeleteDomain",
"executes",
"the",
"domain",
".",
"delete",
"API",
"call",
".",
"This",
"will",
"delete",
"the",
"domain",
"specified",
"by",
"domainID",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/domain.go#L37-L47 |
149,382 | timewasted/linode | dns/domain.go | GetDomain | func (d *DNS) GetDomain(domain string) (*Domain, error) {
list, err := d.GetDomains(nil)
if err != nil {
return nil, err
}
for _, d := range list {
if strings.EqualFold(d.Domain, domain) {
return d, nil
}
}
return nil, linode.NewError(errors.New("dns: requested domain not found"))
} | go | func (d *DNS) GetDomain(domain string) (*Domain, error) {
list, err := d.GetDomains(nil)
if err != nil {
return nil, err
}
for _, d := range list {
if strings.EqualFold(d.Domain, domain) {
return d, nil
}
}
return nil, linode.NewError(errors.New("dns: requested domain not found"))
} | [
"func",
"(",
"d",
"*",
"DNS",
")",
"GetDomain",
"(",
"domain",
"string",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"list",
",",
"err",
":=",
"d",
".",
"GetDomains",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"... | // GetDomain returns the specified domain. This search is not case-sensitive. | [
"GetDomain",
"returns",
"the",
"specified",
"domain",
".",
"This",
"search",
"is",
"not",
"case",
"-",
"sensitive",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/domain.go#L50-L63 |
149,383 | timewasted/linode | linode.go | New | func New(apiKey string) *Linode {
return &Linode{
apiEndpoint: ApiEndpoint,
apiKey: apiKey,
actions: []Action{},
}
} | go | func New(apiKey string) *Linode {
return &Linode{
apiEndpoint: ApiEndpoint,
apiKey: apiKey,
actions: []Action{},
}
} | [
"func",
"New",
"(",
"apiKey",
"string",
")",
"*",
"Linode",
"{",
"return",
"&",
"Linode",
"{",
"apiEndpoint",
":",
"ApiEndpoint",
",",
"apiKey",
":",
"apiKey",
",",
"actions",
":",
"[",
"]",
"Action",
"{",
"}",
",",
"}",
"\n",
"}"
] | // New returns a pointer to a new Linode object. | [
"New",
"returns",
"a",
"pointer",
"to",
"a",
"new",
"Linode",
"object",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/linode.go#L58-L64 |
149,384 | timewasted/linode | linode.go | Request | func (l *Linode) Request(action string, params Parameters, result interface{}) (*Response, error) {
// Initialize the request.
req, err := http.NewRequest("GET", l.apiEndpoint, nil)
if err != nil {
return nil, NewError(err)
}
params.Set(apiAction, action)
params.Set(apiKey, l.apiKey)
req.URL.RawQuery = params.... | go | func (l *Linode) Request(action string, params Parameters, result interface{}) (*Response, error) {
// Initialize the request.
req, err := http.NewRequest("GET", l.apiEndpoint, nil)
if err != nil {
return nil, NewError(err)
}
params.Set(apiAction, action)
params.Set(apiKey, l.apiKey)
req.URL.RawQuery = params.... | [
"func",
"(",
"l",
"*",
"Linode",
")",
"Request",
"(",
"action",
"string",
",",
"params",
"Parameters",
",",
"result",
"interface",
"{",
"}",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"// Initialize the request.",
"req",
",",
"err",
":=",
"http",... | // Request performs a single API operation and returns the full response. | [
"Request",
"performs",
"a",
"single",
"API",
"operation",
"and",
"returns",
"the",
"full",
"response",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/linode.go#L73-L114 |
149,385 | timewasted/linode | linode.go | Batch | func (l *Linode) Batch(action string, params Parameters, result interface{}) {
params.Set(apiAction, action)
l.actions = append(l.actions, Action{
parameters: params,
result: result,
})
} | go | func (l *Linode) Batch(action string, params Parameters, result interface{}) {
params.Set(apiAction, action)
l.actions = append(l.actions, Action{
parameters: params,
result: result,
})
} | [
"func",
"(",
"l",
"*",
"Linode",
")",
"Batch",
"(",
"action",
"string",
",",
"params",
"Parameters",
",",
"result",
"interface",
"{",
"}",
")",
"{",
"params",
".",
"Set",
"(",
"apiAction",
",",
"action",
")",
"\n",
"l",
".",
"actions",
"=",
"append",... | // Batch adds a new action to the batch request to be performed. | [
"Batch",
"adds",
"a",
"new",
"action",
"to",
"the",
"batch",
"request",
"to",
"be",
"performed",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/linode.go#L117-L123 |
149,386 | timewasted/linode | linode.go | Process | func (l *Linode) Process() ([]*Response, error) {
// Quickly handle the case where we have zero or one actions to perform.
count := len(l.actions)
if count == 0 {
return nil, NewError(errors.New("linode: request must contain at least one action"))
}
defer l.Reset()
if count == 1 {
resp, err := l.Request(l.act... | go | func (l *Linode) Process() ([]*Response, error) {
// Quickly handle the case where we have zero or one actions to perform.
count := len(l.actions)
if count == 0 {
return nil, NewError(errors.New("linode: request must contain at least one action"))
}
defer l.Reset()
if count == 1 {
resp, err := l.Request(l.act... | [
"func",
"(",
"l",
"*",
"Linode",
")",
"Process",
"(",
")",
"(",
"[",
"]",
"*",
"Response",
",",
"error",
")",
"{",
"// Quickly handle the case where we have zero or one actions to perform.",
"count",
":=",
"len",
"(",
"l",
".",
"actions",
")",
"\n",
"if",
"c... | // Process performs all batch actions that have been added. | [
"Process",
"performs",
"all",
"batch",
"actions",
"that",
"have",
"been",
"added",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/linode.go#L126-L192 |
149,387 | timewasted/linode | dns/resource.go | CreateDomainResourceA | func (d *DNS) CreateDomainResourceA(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "A",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
} | go | func (d *DNS) CreateDomainResourceA(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "A",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
} | [
"func",
"(",
"d",
"*",
"DNS",
")",
"CreateDomainResourceA",
"(",
"domainID",
"int",
",",
"name",
",",
"target",
"string",
",",
"ttlSeconds",
"int",
")",
"(",
"*",
"ResourceResponse",
",",
"error",
")",
"{",
"return",
"d",
".",
"createDomainResource",
"(",
... | // CreateDomainResourceA executes the "domain.resource.create" API call. This
// will create a new "A" resource using the specified parameters. | [
"CreateDomainResourceA",
"executes",
"the",
"domain",
".",
"resource",
".",
"create",
"API",
"call",
".",
"This",
"will",
"create",
"a",
"new",
"A",
"resource",
"using",
"the",
"specified",
"parameters",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/resource.go#L34-L42 |
149,388 | timewasted/linode | dns/resource.go | CreateDomainResource | func (d *DNS) CreateDomainResource(r *Resource) (*ResourceResponse, error) {
// Ensure that the resource has a name.
if len(r.Name) == 0 {
return nil, linode.NewError(errors.New("dns: creating a resource requires Name be specified"))
}
// Initialize parameters that are shared across resource types.
params := li... | go | func (d *DNS) CreateDomainResource(r *Resource) (*ResourceResponse, error) {
// Ensure that the resource has a name.
if len(r.Name) == 0 {
return nil, linode.NewError(errors.New("dns: creating a resource requires Name be specified"))
}
// Initialize parameters that are shared across resource types.
params := li... | [
"func",
"(",
"d",
"*",
"DNS",
")",
"CreateDomainResource",
"(",
"r",
"*",
"Resource",
")",
"(",
"*",
"ResourceResponse",
",",
"error",
")",
"{",
"// Ensure that the resource has a name.",
"if",
"len",
"(",
"r",
".",
"Name",
")",
"==",
"0",
"{",
"return",
... | // CreateDomainResource executes the "domain.resource.create" API call. This
// will create a new resource using the values specified in the resource. | [
"CreateDomainResource",
"executes",
"the",
"domain",
".",
"resource",
".",
"create",
"API",
"call",
".",
"This",
"will",
"create",
"a",
"new",
"resource",
"using",
"the",
"values",
"specified",
"in",
"the",
"resource",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/resource.go#L123-L183 |
149,389 | timewasted/linode | dns/resource.go | createDomainResource | func (d *DNS) createDomainResource(params linode.Parameters) (*ResourceResponse, error) {
var response *ResourceResponse
_, err := d.linode.Request("domain.resource.create", params, &response)
if err != nil {
return nil, err
}
return response, nil
} | go | func (d *DNS) createDomainResource(params linode.Parameters) (*ResourceResponse, error) {
var response *ResourceResponse
_, err := d.linode.Request("domain.resource.create", params, &response)
if err != nil {
return nil, err
}
return response, nil
} | [
"func",
"(",
"d",
"*",
"DNS",
")",
"createDomainResource",
"(",
"params",
"linode",
".",
"Parameters",
")",
"(",
"*",
"ResourceResponse",
",",
"error",
")",
"{",
"var",
"response",
"*",
"ResourceResponse",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"linode",... | // createDomainResource executes the "domain.resource.create" API call. This
// will create a resource using the specified parameters. | [
"createDomainResource",
"executes",
"the",
"domain",
".",
"resource",
".",
"create",
"API",
"call",
".",
"This",
"will",
"create",
"a",
"resource",
"using",
"the",
"specified",
"parameters",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/resource.go#L187-L194 |
149,390 | timewasted/linode | dns/resource.go | DeleteDomainResource | func (d *DNS) DeleteDomainResource(domainID, resourceID int) (*ResourceResponse, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
"ResourceID": strconv.Itoa(resourceID),
}
var response *ResourceResponse
_, err := d.linode.Request("domain.resource.delete", params, &response)
if err !=... | go | func (d *DNS) DeleteDomainResource(domainID, resourceID int) (*ResourceResponse, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
"ResourceID": strconv.Itoa(resourceID),
}
var response *ResourceResponse
_, err := d.linode.Request("domain.resource.delete", params, &response)
if err !=... | [
"func",
"(",
"d",
"*",
"DNS",
")",
"DeleteDomainResource",
"(",
"domainID",
",",
"resourceID",
"int",
")",
"(",
"*",
"ResourceResponse",
",",
"error",
")",
"{",
"params",
":=",
"linode",
".",
"Parameters",
"{",
"\"",
"\"",
":",
"strconv",
".",
"Itoa",
... | // DeleteDomainResource executes the "domain.resource.delete" API call. This
// will delete the resource specified by resourceID under the domain specified
// by domainID. | [
"DeleteDomainResource",
"executes",
"the",
"domain",
".",
"resource",
".",
"delete",
"API",
"call",
".",
"This",
"will",
"delete",
"the",
"resource",
"specified",
"by",
"resourceID",
"under",
"the",
"domain",
"specified",
"by",
"domainID",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/resource.go#L199-L210 |
149,391 | timewasted/linode | dns/resource.go | GetResourcesByType | func (d *DNS) GetResourcesByType(domainID int, res_type string) ([]*Resource, error) {
resources, err := d.GetDomainResources(domainID)
if err != nil {
return nil, err
}
list := []*Resource{}
for _, r := range resources {
if strings.EqualFold(r.Type, res_type) {
list = append(list, r)
}
}
return list,... | go | func (d *DNS) GetResourcesByType(domainID int, res_type string) ([]*Resource, error) {
resources, err := d.GetDomainResources(domainID)
if err != nil {
return nil, err
}
list := []*Resource{}
for _, r := range resources {
if strings.EqualFold(r.Type, res_type) {
list = append(list, r)
}
}
return list,... | [
"func",
"(",
"d",
"*",
"DNS",
")",
"GetResourcesByType",
"(",
"domainID",
"int",
",",
"res_type",
"string",
")",
"(",
"[",
"]",
"*",
"Resource",
",",
"error",
")",
"{",
"resources",
",",
"err",
":=",
"d",
".",
"GetDomainResources",
"(",
"domainID",
")"... | // GetResourceByType returns a list of domain resources that match the specified
// type. This search is not case-sensitive. | [
"GetResourceByType",
"returns",
"a",
"list",
"of",
"domain",
"resources",
"that",
"match",
"the",
"specified",
"type",
".",
"This",
"search",
"is",
"not",
"case",
"-",
"sensitive",
"."
] | 37e84520dcf74488f67654f9c775b9752c232dc1 | https://github.com/timewasted/linode/blob/37e84520dcf74488f67654f9c775b9752c232dc1/dns/resource.go#L214-L228 |
149,392 | mbland/hmacauth | hmacauth.go | DigestNameToCryptoHash | func DigestNameToCryptoHash(name string) (result crypto.Hash, err error) {
var supported bool
if result, supported = supportedAlgorithms[name]; !supported {
err = errors.New("hmacauth: hash algorithm not supported: " +
name)
}
return
} | go | func DigestNameToCryptoHash(name string) (result crypto.Hash, err error) {
var supported bool
if result, supported = supportedAlgorithms[name]; !supported {
err = errors.New("hmacauth: hash algorithm not supported: " +
name)
}
return
} | [
"func",
"DigestNameToCryptoHash",
"(",
"name",
"string",
")",
"(",
"result",
"crypto",
".",
"Hash",
",",
"err",
"error",
")",
"{",
"var",
"supported",
"bool",
"\n",
"if",
"result",
",",
"supported",
"=",
"supportedAlgorithms",
"[",
"name",
"]",
";",
"!",
... | // DigestNameToCryptoHash returns the crypto.Hash value corresponding to the
// algorithm name, or an error if the algorithm is not supported. | [
"DigestNameToCryptoHash",
"returns",
"the",
"crypto",
".",
"Hash",
"value",
"corresponding",
"to",
"the",
"algorithm",
"name",
"or",
"an",
"error",
"if",
"the",
"algorithm",
"is",
"not",
"supported",
"."
] | 44256dfd4bfa7594cfa73587a464ca890e85971a | https://github.com/mbland/hmacauth/blob/44256dfd4bfa7594cfa73587a464ca890e85971a/hmacauth.go#L68-L75 |
149,393 | mbland/hmacauth | hmacauth.go | CryptoHashToDigestName | func CryptoHashToDigestName(id crypto.Hash) (result string, err error) {
var supported bool
if result, supported = algorithmName[id]; !supported {
err = errors.New("hmacauth: unsupported crypto.Hash #" +
strconv.Itoa(int(id)))
}
return
} | go | func CryptoHashToDigestName(id crypto.Hash) (result string, err error) {
var supported bool
if result, supported = algorithmName[id]; !supported {
err = errors.New("hmacauth: unsupported crypto.Hash #" +
strconv.Itoa(int(id)))
}
return
} | [
"func",
"CryptoHashToDigestName",
"(",
"id",
"crypto",
".",
"Hash",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"var",
"supported",
"bool",
"\n",
"if",
"result",
",",
"supported",
"=",
"algorithmName",
"[",
"id",
"]",
";",
"!",
"supporte... | // CryptoHashToDigestName returns the algorithm name corresponding to the
// crypto.Hash ID, or an error if the algorithm is not supported. | [
"CryptoHashToDigestName",
"returns",
"the",
"algorithm",
"name",
"corresponding",
"to",
"the",
"crypto",
".",
"Hash",
"ID",
"or",
"an",
"error",
"if",
"the",
"algorithm",
"is",
"not",
"supported",
"."
] | 44256dfd4bfa7594cfa73587a464ca890e85971a | https://github.com/mbland/hmacauth/blob/44256dfd4bfa7594cfa73587a464ca890e85971a/hmacauth.go#L79-L86 |
149,394 | mbland/hmacauth | hmacauth.go | NewHmacAuth | func NewHmacAuth(hash crypto.Hash, key []byte, header string,
headers []string) HmacAuth {
if hash.Available() == false {
var name string
var supported bool
if name, supported = algorithmName[hash]; !supported {
name = "#" + strconv.Itoa(int(hash))
}
panic("hmacauth: hash algorithm " + name + " is unavai... | go | func NewHmacAuth(hash crypto.Hash, key []byte, header string,
headers []string) HmacAuth {
if hash.Available() == false {
var name string
var supported bool
if name, supported = algorithmName[hash]; !supported {
name = "#" + strconv.Itoa(int(hash))
}
panic("hmacauth: hash algorithm " + name + " is unavai... | [
"func",
"NewHmacAuth",
"(",
"hash",
"crypto",
".",
"Hash",
",",
"key",
"[",
"]",
"byte",
",",
"header",
"string",
",",
"headers",
"[",
"]",
"string",
")",
"HmacAuth",
"{",
"if",
"hash",
".",
"Available",
"(",
")",
"==",
"false",
"{",
"var",
"name",
... | // NewHmacAuth returns an HmacAuth object that can be used to sign or
// authenticate HTTP requests based on the supplied parameters. | [
"NewHmacAuth",
"returns",
"an",
"HmacAuth",
"object",
"that",
"can",
"be",
"used",
"to",
"sign",
"or",
"authenticate",
"HTTP",
"requests",
"based",
"on",
"the",
"supplied",
"parameters",
"."
] | 44256dfd4bfa7594cfa73587a464ca890e85971a | https://github.com/mbland/hmacauth/blob/44256dfd4bfa7594cfa73587a464ca890e85971a/hmacauth.go#L97-L112 |
149,395 | pivotal-golang/conceal | conceal.go | NewCloak | func NewCloak(key []byte) (Cloak, error) {
cipherBlock, err := aes.NewCipher(resizeKey(key))
if err != nil {
return Cloak{}, err
}
return Cloak{
cipherBlock: cipherBlock,
}, nil
} | go | func NewCloak(key []byte) (Cloak, error) {
cipherBlock, err := aes.NewCipher(resizeKey(key))
if err != nil {
return Cloak{}, err
}
return Cloak{
cipherBlock: cipherBlock,
}, nil
} | [
"func",
"NewCloak",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"Cloak",
",",
"error",
")",
"{",
"cipherBlock",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"resizeKey",
"(",
"key",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Cloak",
... | // NewCloak takes a key that is resized to 16 bytes and used as a key in AES encryption.
// It returns a Cloak. If the key cannot be used to create a cipherBlock, an error is returned. | [
"NewCloak",
"takes",
"a",
"key",
"that",
"is",
"resized",
"to",
"16",
"bytes",
"and",
"used",
"as",
"a",
"key",
"in",
"AES",
"encryption",
".",
"It",
"returns",
"a",
"Cloak",
".",
"If",
"the",
"key",
"cannot",
"be",
"used",
"to",
"create",
"a",
"ciph... | 4e1bd02ae7068f9bf69a076f4037eab5dab75c77 | https://github.com/pivotal-golang/conceal/blob/4e1bd02ae7068f9bf69a076f4037eab5dab75c77/conceal.go#L33-L42 |
149,396 | pivotal-golang/conceal | conceal.go | Veil | func (cloak Cloak) Veil(data []byte) ([]byte, error) {
encodedData := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
base64.StdEncoding.Encode(encodedData, data)
cipherText := make([]byte, aes.BlockSize+len(encodedData))
initializationVector := cipherText[:aes.BlockSize]
_, err := rand.Read(initialization... | go | func (cloak Cloak) Veil(data []byte) ([]byte, error) {
encodedData := make([]byte, base64.StdEncoding.EncodedLen(len(data)))
base64.StdEncoding.Encode(encodedData, data)
cipherText := make([]byte, aes.BlockSize+len(encodedData))
initializationVector := cipherText[:aes.BlockSize]
_, err := rand.Read(initialization... | [
"func",
"(",
"cloak",
"Cloak",
")",
"Veil",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"encodedData",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"base64",
".",
"StdEncoding",
".",
"EncodedLen",
"(",
"len",
"... | // Veil base64 encodes a slice of bytes and uses aes encryption. It returns an encrypted slice of bytes,
// and an error. | [
"Veil",
"base64",
"encodes",
"a",
"slice",
"of",
"bytes",
"and",
"uses",
"aes",
"encryption",
".",
"It",
"returns",
"an",
"encrypted",
"slice",
"of",
"bytes",
"and",
"an",
"error",
"."
] | 4e1bd02ae7068f9bf69a076f4037eab5dab75c77 | https://github.com/pivotal-golang/conceal/blob/4e1bd02ae7068f9bf69a076f4037eab5dab75c77/conceal.go#L51-L68 |
149,397 | pivotal-golang/conceal | conceal.go | Unveil | func (cloak Cloak) Unveil(data []byte) ([]byte, error) {
decodedData := make([]byte, base64.URLEncoding.DecodedLen(len(data)))
n, err := base64.URLEncoding.Decode(decodedData, data)
if err != nil {
return []byte{}, err
}
decodedData = decodedData[:n]
if len(decodedData) < aes.BlockSize {
return []byte{}, Cip... | go | func (cloak Cloak) Unveil(data []byte) ([]byte, error) {
decodedData := make([]byte, base64.URLEncoding.DecodedLen(len(data)))
n, err := base64.URLEncoding.Decode(decodedData, data)
if err != nil {
return []byte{}, err
}
decodedData = decodedData[:n]
if len(decodedData) < aes.BlockSize {
return []byte{}, Cip... | [
"func",
"(",
"cloak",
"Cloak",
")",
"Unveil",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"decodedData",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"base64",
".",
"URLEncoding",
".",
"DecodedLen",
"(",
"len",
... | // Unveil base64 decodes a slice of bytes and uses aes encryption to decrypt. It returns a decrypted slice of bytes,
// and an error. A CipherLengthError is returned if the data is less than 16 bytes. | [
"Unveil",
"base64",
"decodes",
"a",
"slice",
"of",
"bytes",
"and",
"uses",
"aes",
"encryption",
"to",
"decrypt",
".",
"It",
"returns",
"a",
"decrypted",
"slice",
"of",
"bytes",
"and",
"an",
"error",
".",
"A",
"CipherLengthError",
"is",
"returned",
"if",
"t... | 4e1bd02ae7068f9bf69a076f4037eab5dab75c77 | https://github.com/pivotal-golang/conceal/blob/4e1bd02ae7068f9bf69a076f4037eab5dab75c77/conceal.go#L72-L97 |
149,398 | cortesi/termlog | context.go | NewContext | func NewContext(ctx context.Context, logger Logger) context.Context {
return context.WithValue(ctx, "termlog", logger)
} | go | func NewContext(ctx context.Context, logger Logger) context.Context {
return context.WithValue(ctx, "termlog", logger)
} | [
"func",
"NewContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"logger",
"Logger",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"\"",
"\"",
",",
"logger",
")",
"\n",
"}"
] | // NewContext creates a new context with an included Logger | [
"NewContext",
"creates",
"a",
"new",
"context",
"with",
"an",
"included",
"Logger"
] | 87cefd5ac843f65364f70a1fd2477bb6437690e8 | https://github.com/cortesi/termlog/blob/87cefd5ac843f65364f70a1fd2477bb6437690e8/context.go#L6-L8 |
149,399 | cortesi/termlog | context.go | FromContext | func FromContext(ctx context.Context) Logger {
logger, ok := ctx.Value("termlog").(Logger)
if !ok {
l := NewLog()
l.Quiet()
return l
}
return logger
} | go | func FromContext(ctx context.Context) Logger {
logger, ok := ctx.Value("termlog").(Logger)
if !ok {
l := NewLog()
l.Quiet()
return l
}
return logger
} | [
"func",
"FromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"Logger",
"{",
"logger",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"\"",
"\"",
")",
".",
"(",
"Logger",
")",
"\n",
"if",
"!",
"ok",
"{",
"l",
":=",
"NewLog",
"(",
")",
"\n",
"l... | // FromContext retrieves a Logger from a context. If no logger is present, we
// return a new silenced logger that will produce no output. | [
"FromContext",
"retrieves",
"a",
"Logger",
"from",
"a",
"context",
".",
"If",
"no",
"logger",
"is",
"present",
"we",
"return",
"a",
"new",
"silenced",
"logger",
"that",
"will",
"produce",
"no",
"output",
"."
] | 87cefd5ac843f65364f70a1fd2477bb6437690e8 | https://github.com/cortesi/termlog/blob/87cefd5ac843f65364f70a1fd2477bb6437690e8/context.go#L12-L20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.