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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
146,500 |
BurntSushi/toml
|
lex.go
|
lexDatetime
|
func lexDatetime(lx *lexer) stateFn {
r := lx.next()
if isDigit(r) {
return lexDatetime
}
switch r {
case '-', 'T', ':', '.', 'Z', '+':
return lexDatetime
}
lx.backup()
lx.emit(itemDatetime)
return lx.pop()
}
|
go
|
func lexDatetime(lx *lexer) stateFn {
r := lx.next()
if isDigit(r) {
return lexDatetime
}
switch r {
case '-', 'T', ':', '.', 'Z', '+':
return lexDatetime
}
lx.backup()
lx.emit(itemDatetime)
return lx.pop()
}
|
[
"func",
"lexDatetime",
"(",
"lx",
"*",
"lexer",
")",
"stateFn",
"{",
"r",
":=",
"lx",
".",
"next",
"(",
")",
"\n",
"if",
"isDigit",
"(",
"r",
")",
"{",
"return",
"lexDatetime",
"\n",
"}",
"\n",
"switch",
"r",
"{",
"case",
"'-'",
",",
"'T'",
",",
"':'",
",",
"'.'",
",",
"'Z'",
",",
"'+'",
":",
"return",
"lexDatetime",
"\n",
"}",
"\n\n",
"lx",
".",
"backup",
"(",
")",
"\n",
"lx",
".",
"emit",
"(",
"itemDatetime",
")",
"\n",
"return",
"lx",
".",
"pop",
"(",
")",
"\n",
"}"
] |
// lexDatetime consumes a Datetime, to a first approximation.
// The parser validates that it matches one of the accepted formats.
|
[
"lexDatetime",
"consumes",
"a",
"Datetime",
"to",
"a",
"first",
"approximation",
".",
"The",
"parser",
"validates",
"that",
"it",
"matches",
"one",
"of",
"the",
"accepted",
"formats",
"."
] |
3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005
|
https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/lex.go#L772-L785
|
146,501 |
BurntSushi/toml
|
encode.go
|
NewEncoder
|
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{
w: bufio.NewWriter(w),
Indent: " ",
}
}
|
go
|
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{
w: bufio.NewWriter(w),
Indent: " ",
}
}
|
[
"func",
"NewEncoder",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"Encoder",
"{",
"return",
"&",
"Encoder",
"{",
"w",
":",
"bufio",
".",
"NewWriter",
"(",
"w",
")",
",",
"Indent",
":",
"\"",
"\"",
",",
"}",
"\n",
"}"
] |
// NewEncoder returns a TOML encoder that encodes Go values to the io.Writer
// given. By default, a single indentation level is 2 spaces.
|
[
"NewEncoder",
"returns",
"a",
"TOML",
"encoder",
"that",
"encodes",
"Go",
"values",
"to",
"the",
"io",
".",
"Writer",
"given",
".",
"By",
"default",
"a",
"single",
"indentation",
"level",
"is",
"2",
"spaces",
"."
] |
3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005
|
https://github.com/BurntSushi/toml/blob/3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005/encode.go#L56-L61
|
146,502 |
bluele/gcache
|
lru.go
|
evict
|
func (c *LRUCache) evict(count int) {
for i := 0; i < count; i++ {
ent := c.evictList.Back()
if ent == nil {
return
} else {
c.removeElement(ent)
}
}
}
|
go
|
func (c *LRUCache) evict(count int) {
for i := 0; i < count; i++ {
ent := c.evictList.Back()
if ent == nil {
return
} else {
c.removeElement(ent)
}
}
}
|
[
"func",
"(",
"c",
"*",
"LRUCache",
")",
"evict",
"(",
"count",
"int",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
"{",
"ent",
":=",
"c",
".",
"evictList",
".",
"Back",
"(",
")",
"\n",
"if",
"ent",
"==",
"nil",
"{",
"return",
"\n",
"}",
"else",
"{",
"c",
".",
"removeElement",
"(",
"ent",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// evict removes the oldest item from the cache.
|
[
"evict",
"removes",
"the",
"oldest",
"item",
"from",
"the",
"cache",
"."
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/lru.go#L174-L183
|
146,503 |
bluele/gcache
|
arc.go
|
Has
|
func (c *ARC) Has(key interface{}) bool {
c.mu.RLock()
defer c.mu.RUnlock()
now := time.Now()
return c.has(key, &now)
}
|
go
|
func (c *ARC) Has(key interface{}) bool {
c.mu.RLock()
defer c.mu.RUnlock()
now := time.Now()
return c.has(key, &now)
}
|
[
"func",
"(",
"c",
"*",
"ARC",
")",
"Has",
"(",
"key",
"interface",
"{",
"}",
")",
"bool",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"return",
"c",
".",
"has",
"(",
"key",
",",
"&",
"now",
")",
"\n",
"}"
] |
// Has checks if key exists in cache
|
[
"Has",
"checks",
"if",
"key",
"exists",
"in",
"cache"
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/arc.go#L267-L272
|
146,504 |
bluele/gcache
|
arc.go
|
Keys
|
func (c *ARC) Keys() []interface{} {
keys := []interface{}{}
for _, k := range c.keys() {
_, err := c.GetIFPresent(k)
if err == nil {
keys = append(keys, k)
}
}
return keys
}
|
go
|
func (c *ARC) Keys() []interface{} {
keys := []interface{}{}
for _, k := range c.keys() {
_, err := c.GetIFPresent(k)
if err == nil {
keys = append(keys, k)
}
}
return keys
}
|
[
"func",
"(",
"c",
"*",
"ARC",
")",
"Keys",
"(",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"keys",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"c",
".",
"keys",
"(",
")",
"{",
"_",
",",
"err",
":=",
"c",
".",
"GetIFPresent",
"(",
"k",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"keys",
"\n",
"}"
] |
// Keys returns a slice of the keys in the cache.
|
[
"Keys",
"returns",
"a",
"slice",
"of",
"the",
"keys",
"in",
"the",
"cache",
"."
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/arc.go#L329-L338
|
146,505 |
bluele/gcache
|
arc.go
|
GetALL
|
func (c *ARC) GetALL() map[interface{}]interface{} {
m := make(map[interface{}]interface{})
for _, k := range c.keys() {
v, err := c.GetIFPresent(k)
if err == nil {
m[k] = v
}
}
return m
}
|
go
|
func (c *ARC) GetALL() map[interface{}]interface{} {
m := make(map[interface{}]interface{})
for _, k := range c.keys() {
v, err := c.GetIFPresent(k)
if err == nil {
m[k] = v
}
}
return m
}
|
[
"func",
"(",
"c",
"*",
"ARC",
")",
"GetALL",
"(",
")",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"interface",
"{",
"}",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"c",
".",
"keys",
"(",
")",
"{",
"v",
",",
"err",
":=",
"c",
".",
"GetIFPresent",
"(",
"k",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"m",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] |
// GetALL returns all key-value pairs in the cache.
|
[
"GetALL",
"returns",
"all",
"key",
"-",
"value",
"pairs",
"in",
"the",
"cache",
"."
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/arc.go#L341-L350
|
146,506 |
bluele/gcache
|
lfu.go
|
Set
|
func (c *LFUCache) Set(key, value interface{}) error {
c.mu.Lock()
defer c.mu.Unlock()
_, err := c.set(key, value)
return err
}
|
go
|
func (c *LFUCache) Set(key, value interface{}) error {
c.mu.Lock()
defer c.mu.Unlock()
_, err := c.set(key, value)
return err
}
|
[
"func",
"(",
"c",
"*",
"LFUCache",
")",
"Set",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"err",
":=",
"c",
".",
"set",
"(",
"key",
",",
"value",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Set a new key-value pair
|
[
"Set",
"a",
"new",
"key",
"-",
"value",
"pair"
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/lfu.go#L34-L39
|
146,507 |
bluele/gcache
|
lfu.go
|
SetWithExpire
|
func (c *LFUCache) SetWithExpire(key, value interface{}, expiration time.Duration) error {
c.mu.Lock()
defer c.mu.Unlock()
item, err := c.set(key, value)
if err != nil {
return err
}
t := c.clock.Now().Add(expiration)
item.(*lfuItem).expiration = &t
return nil
}
|
go
|
func (c *LFUCache) SetWithExpire(key, value interface{}, expiration time.Duration) error {
c.mu.Lock()
defer c.mu.Unlock()
item, err := c.set(key, value)
if err != nil {
return err
}
t := c.clock.Now().Add(expiration)
item.(*lfuItem).expiration = &t
return nil
}
|
[
"func",
"(",
"c",
"*",
"LFUCache",
")",
"SetWithExpire",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
",",
"expiration",
"time",
".",
"Duration",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"item",
",",
"err",
":=",
"c",
".",
"set",
"(",
"key",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"t",
":=",
"c",
".",
"clock",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"expiration",
")",
"\n",
"item",
".",
"(",
"*",
"lfuItem",
")",
".",
"expiration",
"=",
"&",
"t",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Set a new key-value pair with an expiration time
|
[
"Set",
"a",
"new",
"key",
"-",
"value",
"pair",
"with",
"an",
"expiration",
"time"
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/lfu.go#L42-L53
|
146,508 |
bluele/gcache
|
lfu.go
|
Get
|
func (c *LFUCache) Get(key interface{}) (interface{}, error) {
v, err := c.get(key, false)
if err == KeyNotFoundError {
return c.getWithLoader(key, true)
}
return v, err
}
|
go
|
func (c *LFUCache) Get(key interface{}) (interface{}, error) {
v, err := c.get(key, false)
if err == KeyNotFoundError {
return c.getWithLoader(key, true)
}
return v, err
}
|
[
"func",
"(",
"c",
"*",
"LFUCache",
")",
"Get",
"(",
"key",
"interface",
"{",
"}",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"v",
",",
"err",
":=",
"c",
".",
"get",
"(",
"key",
",",
"false",
")",
"\n",
"if",
"err",
"==",
"KeyNotFoundError",
"{",
"return",
"c",
".",
"getWithLoader",
"(",
"key",
",",
"true",
")",
"\n",
"}",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] |
// Get a value from cache pool using key if it exists.
// If it dose not exists key and has LoaderFunc,
// generate a value using `LoaderFunc` method returns value.
|
[
"Get",
"a",
"value",
"from",
"cache",
"pool",
"using",
"key",
"if",
"it",
"exists",
".",
"If",
"it",
"dose",
"not",
"exists",
"key",
"and",
"has",
"LoaderFunc",
"generate",
"a",
"value",
"using",
"LoaderFunc",
"method",
"returns",
"value",
"."
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/lfu.go#L102-L108
|
146,509 |
bluele/gcache
|
lfu.go
|
evict
|
func (c *LFUCache) evict(count int) {
entry := c.freqList.Front()
for i := 0; i < count; {
if entry == nil {
return
} else {
for item, _ := range entry.Value.(*freqEntry).items {
if i >= count {
return
}
c.removeItem(item)
i++
}
entry = entry.Next()
}
}
}
|
go
|
func (c *LFUCache) evict(count int) {
entry := c.freqList.Front()
for i := 0; i < count; {
if entry == nil {
return
} else {
for item, _ := range entry.Value.(*freqEntry).items {
if i >= count {
return
}
c.removeItem(item)
i++
}
entry = entry.Next()
}
}
}
|
[
"func",
"(",
"c",
"*",
"LFUCache",
")",
"evict",
"(",
"count",
"int",
")",
"{",
"entry",
":=",
"c",
".",
"freqList",
".",
"Front",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"count",
";",
"{",
"if",
"entry",
"==",
"nil",
"{",
"return",
"\n",
"}",
"else",
"{",
"for",
"item",
",",
"_",
":=",
"range",
"entry",
".",
"Value",
".",
"(",
"*",
"freqEntry",
")",
".",
"items",
"{",
"if",
"i",
">=",
"count",
"{",
"return",
"\n",
"}",
"\n",
"c",
".",
"removeItem",
"(",
"item",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"entry",
"=",
"entry",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// evict removes the least frequence item from the cache.
|
[
"evict",
"removes",
"the",
"least",
"frequence",
"item",
"from",
"the",
"cache",
"."
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/lfu.go#L198-L214
|
146,510 |
bluele/gcache
|
stats.go
|
HitRate
|
func (st *stats) HitRate() float64 {
hc, mc := st.HitCount(), st.MissCount()
total := hc + mc
if total == 0 {
return 0.0
}
return float64(hc) / float64(total)
}
|
go
|
func (st *stats) HitRate() float64 {
hc, mc := st.HitCount(), st.MissCount()
total := hc + mc
if total == 0 {
return 0.0
}
return float64(hc) / float64(total)
}
|
[
"func",
"(",
"st",
"*",
"stats",
")",
"HitRate",
"(",
")",
"float64",
"{",
"hc",
",",
"mc",
":=",
"st",
".",
"HitCount",
"(",
")",
",",
"st",
".",
"MissCount",
"(",
")",
"\n",
"total",
":=",
"hc",
"+",
"mc",
"\n",
"if",
"total",
"==",
"0",
"{",
"return",
"0.0",
"\n",
"}",
"\n",
"return",
"float64",
"(",
"hc",
")",
"/",
"float64",
"(",
"total",
")",
"\n",
"}"
] |
// HitRate returns rate for cache hitting
|
[
"HitRate",
"returns",
"rate",
"for",
"cache",
"hitting"
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/stats.go#L46-L53
|
146,511 |
bluele/gcache
|
cache.go
|
load
|
func (c *baseCache) load(key interface{}, cb func(interface{}, *time.Duration, error) (interface{}, error), isWait bool) (interface{}, bool, error) {
v, called, err := c.loadGroup.Do(key, func() (v interface{}, e error) {
defer func() {
if r := recover(); r != nil {
e = fmt.Errorf("Loader panics: %v", r)
}
}()
return cb(c.loaderExpireFunc(key))
}, isWait)
if err != nil {
return nil, called, err
}
return v, called, nil
}
|
go
|
func (c *baseCache) load(key interface{}, cb func(interface{}, *time.Duration, error) (interface{}, error), isWait bool) (interface{}, bool, error) {
v, called, err := c.loadGroup.Do(key, func() (v interface{}, e error) {
defer func() {
if r := recover(); r != nil {
e = fmt.Errorf("Loader panics: %v", r)
}
}()
return cb(c.loaderExpireFunc(key))
}, isWait)
if err != nil {
return nil, called, err
}
return v, called, nil
}
|
[
"func",
"(",
"c",
"*",
"baseCache",
")",
"load",
"(",
"key",
"interface",
"{",
"}",
",",
"cb",
"func",
"(",
"interface",
"{",
"}",
",",
"*",
"time",
".",
"Duration",
",",
"error",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
",",
"isWait",
"bool",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
",",
"error",
")",
"{",
"v",
",",
"called",
",",
"err",
":=",
"c",
".",
"loadGroup",
".",
"Do",
"(",
"key",
",",
"func",
"(",
")",
"(",
"v",
"interface",
"{",
"}",
",",
"e",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"r",
":=",
"recover",
"(",
")",
";",
"r",
"!=",
"nil",
"{",
"e",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"cb",
"(",
"c",
".",
"loaderExpireFunc",
"(",
"key",
")",
")",
"\n",
"}",
",",
"isWait",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"called",
",",
"err",
"\n",
"}",
"\n",
"return",
"v",
",",
"called",
",",
"nil",
"\n",
"}"
] |
// load a new value using by specified key.
|
[
"load",
"a",
"new",
"value",
"using",
"by",
"specified",
"key",
"."
] |
79ae3b2d8680cbc7ad3dba9db66b8a648575221c
|
https://github.com/bluele/gcache/blob/79ae3b2d8680cbc7ad3dba9db66b8a648575221c/cache.go#L192-L205
|
146,512 |
bitly/oauth2_proxy
|
options.go
|
secretBytes
|
func secretBytes(secret string) []byte {
b, err := base64.URLEncoding.DecodeString(addPadding(secret))
if err == nil {
return []byte(addPadding(string(b)))
}
return []byte(secret)
}
|
go
|
func secretBytes(secret string) []byte {
b, err := base64.URLEncoding.DecodeString(addPadding(secret))
if err == nil {
return []byte(addPadding(string(b)))
}
return []byte(secret)
}
|
[
"func",
"secretBytes",
"(",
"secret",
"string",
")",
"[",
"]",
"byte",
"{",
"b",
",",
"err",
":=",
"base64",
".",
"URLEncoding",
".",
"DecodeString",
"(",
"addPadding",
"(",
"secret",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"[",
"]",
"byte",
"(",
"addPadding",
"(",
"string",
"(",
"b",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
"secret",
")",
"\n",
"}"
] |
// secretBytes attempts to base64 decode the secret, if that fails it treats the secret as binary
|
[
"secretBytes",
"attempts",
"to",
"base64",
"decode",
"the",
"secret",
"if",
"that",
"fails",
"it",
"treats",
"the",
"secret",
"as",
"binary"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/options.go#L329-L335
|
146,513 |
bitly/oauth2_proxy
|
providers/internal_util.go
|
stripParam
|
func stripParam(param, endpoint string) string {
u, err := url.Parse(endpoint)
if err != nil {
log.Printf("error attempting to strip %s: %s", param, err)
return endpoint
}
if u.RawQuery != "" {
values, err := url.ParseQuery(u.RawQuery)
if err != nil {
log.Printf("error attempting to strip %s: %s", param, err)
return u.String()
}
if val := values.Get(param); val != "" {
values.Set(param, val[:(len(val)/2)]+"...")
u.RawQuery = values.Encode()
return u.String()
}
}
return endpoint
}
|
go
|
func stripParam(param, endpoint string) string {
u, err := url.Parse(endpoint)
if err != nil {
log.Printf("error attempting to strip %s: %s", param, err)
return endpoint
}
if u.RawQuery != "" {
values, err := url.ParseQuery(u.RawQuery)
if err != nil {
log.Printf("error attempting to strip %s: %s", param, err)
return u.String()
}
if val := values.Get(param); val != "" {
values.Set(param, val[:(len(val)/2)]+"...")
u.RawQuery = values.Encode()
return u.String()
}
}
return endpoint
}
|
[
"func",
"stripParam",
"(",
"param",
",",
"endpoint",
"string",
")",
"string",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"endpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"param",
",",
"err",
")",
"\n",
"return",
"endpoint",
"\n",
"}",
"\n\n",
"if",
"u",
".",
"RawQuery",
"!=",
"\"",
"\"",
"{",
"values",
",",
"err",
":=",
"url",
".",
"ParseQuery",
"(",
"u",
".",
"RawQuery",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"param",
",",
"err",
")",
"\n",
"return",
"u",
".",
"String",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"val",
":=",
"values",
".",
"Get",
"(",
"param",
")",
";",
"val",
"!=",
"\"",
"\"",
"{",
"values",
".",
"Set",
"(",
"param",
",",
"val",
"[",
":",
"(",
"len",
"(",
"val",
")",
"/",
"2",
")",
"]",
"+",
"\"",
"\"",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"values",
".",
"Encode",
"(",
")",
"\n",
"return",
"u",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"endpoint",
"\n",
"}"
] |
// stripParam generalizes the obfuscation of a particular
// query parameter - typically 'access_token' or 'client_secret'
// The parameter's second half is replaced by '...' and returned
// as part of the encoded query parameters.
// If the target parameter isn't found, the endpoint is returned
// unmodified.
|
[
"stripParam",
"generalizes",
"the",
"obfuscation",
"of",
"a",
"particular",
"query",
"parameter",
"-",
"typically",
"access_token",
"or",
"client_secret",
"The",
"parameter",
"s",
"second",
"half",
"is",
"replaced",
"by",
"...",
"and",
"returned",
"as",
"part",
"of",
"the",
"encoded",
"query",
"parameters",
".",
"If",
"the",
"target",
"parameter",
"isn",
"t",
"found",
"the",
"endpoint",
"is",
"returned",
"unmodified",
"."
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/providers/internal_util.go#L24-L46
|
146,514 |
bitly/oauth2_proxy
|
providers/internal_util.go
|
validateToken
|
func validateToken(p Provider, access_token string, header http.Header) bool {
if access_token == "" || p.Data().ValidateURL == nil {
return false
}
endpoint := p.Data().ValidateURL.String()
if len(header) == 0 {
params := url.Values{"access_token": {access_token}}
endpoint = endpoint + "?" + params.Encode()
}
resp, err := api.RequestUnparsedResponse(endpoint, header)
if err != nil {
log.Printf("GET %s", stripToken(endpoint))
log.Printf("token validation request failed: %s", err)
return false
}
body, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
log.Printf("%d GET %s %s", resp.StatusCode, stripToken(endpoint), body)
if resp.StatusCode == 200 {
return true
}
log.Printf("token validation request failed: status %d - %s", resp.StatusCode, body)
return false
}
|
go
|
func validateToken(p Provider, access_token string, header http.Header) bool {
if access_token == "" || p.Data().ValidateURL == nil {
return false
}
endpoint := p.Data().ValidateURL.String()
if len(header) == 0 {
params := url.Values{"access_token": {access_token}}
endpoint = endpoint + "?" + params.Encode()
}
resp, err := api.RequestUnparsedResponse(endpoint, header)
if err != nil {
log.Printf("GET %s", stripToken(endpoint))
log.Printf("token validation request failed: %s", err)
return false
}
body, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
log.Printf("%d GET %s %s", resp.StatusCode, stripToken(endpoint), body)
if resp.StatusCode == 200 {
return true
}
log.Printf("token validation request failed: status %d - %s", resp.StatusCode, body)
return false
}
|
[
"func",
"validateToken",
"(",
"p",
"Provider",
",",
"access_token",
"string",
",",
"header",
"http",
".",
"Header",
")",
"bool",
"{",
"if",
"access_token",
"==",
"\"",
"\"",
"||",
"p",
".",
"Data",
"(",
")",
".",
"ValidateURL",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"endpoint",
":=",
"p",
".",
"Data",
"(",
")",
".",
"ValidateURL",
".",
"String",
"(",
")",
"\n",
"if",
"len",
"(",
"header",
")",
"==",
"0",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"access_token",
"}",
"}",
"\n",
"endpoint",
"=",
"endpoint",
"+",
"\"",
"\"",
"+",
"params",
".",
"Encode",
"(",
")",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"api",
".",
"RequestUnparsedResponse",
"(",
"endpoint",
",",
"header",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"stripToken",
"(",
"endpoint",
")",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"body",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
",",
"stripToken",
"(",
"endpoint",
")",
",",
"body",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"==",
"200",
"{",
"return",
"true",
"\n",
"}",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"resp",
".",
"StatusCode",
",",
"body",
")",
"\n",
"return",
"false",
"\n",
"}"
] |
// validateToken returns true if token is valid
|
[
"validateToken",
"returns",
"true",
"if",
"token",
"is",
"valid"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/providers/internal_util.go#L49-L74
|
146,515 |
bitly/oauth2_proxy
|
logging_handler.go
|
writeLogLine
|
func (h loggingHandler) writeLogLine(username, upstream string, req *http.Request, url url.URL, ts time.Time, status int, size int) {
if username == "" {
username = "-"
}
if upstream == "" {
upstream = "-"
}
if url.User != nil && username == "-" {
if name := url.User.Username(); name != "" {
username = name
}
}
client := req.Header.Get("X-Real-IP")
if client == "" {
client = req.RemoteAddr
}
if c, _, err := net.SplitHostPort(client); err == nil {
client = c
}
duration := float64(time.Now().Sub(ts)) / float64(time.Second)
h.logTemplate.Execute(h.writer, logMessageData{
Client: client,
Host: req.Host,
Protocol: req.Proto,
RequestDuration: fmt.Sprintf("%0.3f", duration),
RequestMethod: req.Method,
RequestURI: fmt.Sprintf("%q", url.RequestURI()),
ResponseSize: fmt.Sprintf("%d", size),
StatusCode: fmt.Sprintf("%d", status),
Timestamp: ts.Format("02/Jan/2006:15:04:05 -0700"),
Upstream: upstream,
UserAgent: fmt.Sprintf("%q", req.UserAgent()),
Username: username,
})
h.writer.Write([]byte("\n"))
}
|
go
|
func (h loggingHandler) writeLogLine(username, upstream string, req *http.Request, url url.URL, ts time.Time, status int, size int) {
if username == "" {
username = "-"
}
if upstream == "" {
upstream = "-"
}
if url.User != nil && username == "-" {
if name := url.User.Username(); name != "" {
username = name
}
}
client := req.Header.Get("X-Real-IP")
if client == "" {
client = req.RemoteAddr
}
if c, _, err := net.SplitHostPort(client); err == nil {
client = c
}
duration := float64(time.Now().Sub(ts)) / float64(time.Second)
h.logTemplate.Execute(h.writer, logMessageData{
Client: client,
Host: req.Host,
Protocol: req.Proto,
RequestDuration: fmt.Sprintf("%0.3f", duration),
RequestMethod: req.Method,
RequestURI: fmt.Sprintf("%q", url.RequestURI()),
ResponseSize: fmt.Sprintf("%d", size),
StatusCode: fmt.Sprintf("%d", status),
Timestamp: ts.Format("02/Jan/2006:15:04:05 -0700"),
Upstream: upstream,
UserAgent: fmt.Sprintf("%q", req.UserAgent()),
Username: username,
})
h.writer.Write([]byte("\n"))
}
|
[
"func",
"(",
"h",
"loggingHandler",
")",
"writeLogLine",
"(",
"username",
",",
"upstream",
"string",
",",
"req",
"*",
"http",
".",
"Request",
",",
"url",
"url",
".",
"URL",
",",
"ts",
"time",
".",
"Time",
",",
"status",
"int",
",",
"size",
"int",
")",
"{",
"if",
"username",
"==",
"\"",
"\"",
"{",
"username",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"upstream",
"==",
"\"",
"\"",
"{",
"upstream",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"url",
".",
"User",
"!=",
"nil",
"&&",
"username",
"==",
"\"",
"\"",
"{",
"if",
"name",
":=",
"url",
".",
"User",
".",
"Username",
"(",
")",
";",
"name",
"!=",
"\"",
"\"",
"{",
"username",
"=",
"name",
"\n",
"}",
"\n",
"}",
"\n\n",
"client",
":=",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"client",
"==",
"\"",
"\"",
"{",
"client",
"=",
"req",
".",
"RemoteAddr",
"\n",
"}",
"\n\n",
"if",
"c",
",",
"_",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"client",
")",
";",
"err",
"==",
"nil",
"{",
"client",
"=",
"c",
"\n",
"}",
"\n\n",
"duration",
":=",
"float64",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"ts",
")",
")",
"/",
"float64",
"(",
"time",
".",
"Second",
")",
"\n\n",
"h",
".",
"logTemplate",
".",
"Execute",
"(",
"h",
".",
"writer",
",",
"logMessageData",
"{",
"Client",
":",
"client",
",",
"Host",
":",
"req",
".",
"Host",
",",
"Protocol",
":",
"req",
".",
"Proto",
",",
"RequestDuration",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"duration",
")",
",",
"RequestMethod",
":",
"req",
".",
"Method",
",",
"RequestURI",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"url",
".",
"RequestURI",
"(",
")",
")",
",",
"ResponseSize",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"size",
")",
",",
"StatusCode",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"status",
")",
",",
"Timestamp",
":",
"ts",
".",
"Format",
"(",
"\"",
"\"",
")",
",",
"Upstream",
":",
"upstream",
",",
"UserAgent",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"req",
".",
"UserAgent",
"(",
")",
")",
",",
"Username",
":",
"username",
",",
"}",
")",
"\n\n",
"h",
".",
"writer",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"}"
] |
// Log entry for req similar to Apache Common Log Format.
// ts is the timestamp with which the entry should be logged.
// status, size are used to provide the response HTTP status and size.
|
[
"Log",
"entry",
"for",
"req",
"similar",
"to",
"Apache",
"Common",
"Log",
"Format",
".",
"ts",
"is",
"the",
"timestamp",
"with",
"which",
"the",
"entry",
"should",
"be",
"logged",
".",
"status",
"size",
"are",
"used",
"to",
"provide",
"the",
"response",
"HTTP",
"status",
"and",
"size",
"."
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/logging_handler.go#L120-L160
|
146,516 |
bitly/oauth2_proxy
|
cookie/cookies.go
|
SignedValue
|
func SignedValue(seed string, key string, value string, now time.Time) string {
encodedValue := base64.URLEncoding.EncodeToString([]byte(value))
timeStr := fmt.Sprintf("%d", now.Unix())
sig := cookieSignature(seed, key, encodedValue, timeStr)
cookieVal := fmt.Sprintf("%s|%s|%s", encodedValue, timeStr, sig)
return cookieVal
}
|
go
|
func SignedValue(seed string, key string, value string, now time.Time) string {
encodedValue := base64.URLEncoding.EncodeToString([]byte(value))
timeStr := fmt.Sprintf("%d", now.Unix())
sig := cookieSignature(seed, key, encodedValue, timeStr)
cookieVal := fmt.Sprintf("%s|%s|%s", encodedValue, timeStr, sig)
return cookieVal
}
|
[
"func",
"SignedValue",
"(",
"seed",
"string",
",",
"key",
"string",
",",
"value",
"string",
",",
"now",
"time",
".",
"Time",
")",
"string",
"{",
"encodedValue",
":=",
"base64",
".",
"URLEncoding",
".",
"EncodeToString",
"(",
"[",
"]",
"byte",
"(",
"value",
")",
")",
"\n",
"timeStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"now",
".",
"Unix",
"(",
")",
")",
"\n",
"sig",
":=",
"cookieSignature",
"(",
"seed",
",",
"key",
",",
"encodedValue",
",",
"timeStr",
")",
"\n",
"cookieVal",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"encodedValue",
",",
"timeStr",
",",
"sig",
")",
"\n",
"return",
"cookieVal",
"\n",
"}"
] |
// SignedValue returns a cookie that is signed and can later be checked with Validate
|
[
"SignedValue",
"returns",
"a",
"cookie",
"that",
"is",
"signed",
"and",
"can",
"later",
"be",
"checked",
"with",
"Validate"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/cookie/cookies.go#L53-L59
|
146,517 |
bitly/oauth2_proxy
|
cookie/cookies.go
|
NewCipher
|
func NewCipher(secret []byte) (*Cipher, error) {
c, err := aes.NewCipher(secret)
if err != nil {
return nil, err
}
return &Cipher{Block: c}, err
}
|
go
|
func NewCipher(secret []byte) (*Cipher, error) {
c, err := aes.NewCipher(secret)
if err != nil {
return nil, err
}
return &Cipher{Block: c}, err
}
|
[
"func",
"NewCipher",
"(",
"secret",
"[",
"]",
"byte",
")",
"(",
"*",
"Cipher",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"secret",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Cipher",
"{",
"Block",
":",
"c",
"}",
",",
"err",
"\n",
"}"
] |
// NewCipher returns a new aes Cipher for encrypting cookie values
|
[
"NewCipher",
"returns",
"a",
"new",
"aes",
"Cipher",
"for",
"encrypting",
"cookie",
"values"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/cookie/cookies.go#L88-L94
|
146,518 |
bitly/oauth2_proxy
|
cookie/cookies.go
|
Encrypt
|
func (c *Cipher) Encrypt(value string) (string, error) {
ciphertext := make([]byte, aes.BlockSize+len(value))
iv := ciphertext[:aes.BlockSize]
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
return "", fmt.Errorf("failed to create initialization vector %s", err)
}
stream := cipher.NewCFBEncrypter(c.Block, iv)
stream.XORKeyStream(ciphertext[aes.BlockSize:], []byte(value))
return base64.StdEncoding.EncodeToString(ciphertext), nil
}
|
go
|
func (c *Cipher) Encrypt(value string) (string, error) {
ciphertext := make([]byte, aes.BlockSize+len(value))
iv := ciphertext[:aes.BlockSize]
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
return "", fmt.Errorf("failed to create initialization vector %s", err)
}
stream := cipher.NewCFBEncrypter(c.Block, iv)
stream.XORKeyStream(ciphertext[aes.BlockSize:], []byte(value))
return base64.StdEncoding.EncodeToString(ciphertext), nil
}
|
[
"func",
"(",
"c",
"*",
"Cipher",
")",
"Encrypt",
"(",
"value",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ciphertext",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"aes",
".",
"BlockSize",
"+",
"len",
"(",
"value",
")",
")",
"\n",
"iv",
":=",
"ciphertext",
"[",
":",
"aes",
".",
"BlockSize",
"]",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"rand",
".",
"Reader",
",",
"iv",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"stream",
":=",
"cipher",
".",
"NewCFBEncrypter",
"(",
"c",
".",
"Block",
",",
"iv",
")",
"\n",
"stream",
".",
"XORKeyStream",
"(",
"ciphertext",
"[",
"aes",
".",
"BlockSize",
":",
"]",
",",
"[",
"]",
"byte",
"(",
"value",
")",
")",
"\n",
"return",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"ciphertext",
")",
",",
"nil",
"\n",
"}"
] |
// Encrypt a value for use in a cookie
|
[
"Encrypt",
"a",
"value",
"for",
"use",
"in",
"a",
"cookie"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/cookie/cookies.go#L97-L107
|
146,519 |
bitly/oauth2_proxy
|
cookie/cookies.go
|
Decrypt
|
func (c *Cipher) Decrypt(s string) (string, error) {
encrypted, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return "", fmt.Errorf("failed to decrypt cookie value %s", err)
}
if len(encrypted) < aes.BlockSize {
return "", fmt.Errorf("encrypted cookie value should be "+
"at least %d bytes, but is only %d bytes",
aes.BlockSize, len(encrypted))
}
iv := encrypted[:aes.BlockSize]
encrypted = encrypted[aes.BlockSize:]
stream := cipher.NewCFBDecrypter(c.Block, iv)
stream.XORKeyStream(encrypted, encrypted)
return string(encrypted), nil
}
|
go
|
func (c *Cipher) Decrypt(s string) (string, error) {
encrypted, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return "", fmt.Errorf("failed to decrypt cookie value %s", err)
}
if len(encrypted) < aes.BlockSize {
return "", fmt.Errorf("encrypted cookie value should be "+
"at least %d bytes, but is only %d bytes",
aes.BlockSize, len(encrypted))
}
iv := encrypted[:aes.BlockSize]
encrypted = encrypted[aes.BlockSize:]
stream := cipher.NewCFBDecrypter(c.Block, iv)
stream.XORKeyStream(encrypted, encrypted)
return string(encrypted), nil
}
|
[
"func",
"(",
"c",
"*",
"Cipher",
")",
"Decrypt",
"(",
"s",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"encrypted",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"encrypted",
")",
"<",
"aes",
".",
"BlockSize",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"aes",
".",
"BlockSize",
",",
"len",
"(",
"encrypted",
")",
")",
"\n",
"}",
"\n\n",
"iv",
":=",
"encrypted",
"[",
":",
"aes",
".",
"BlockSize",
"]",
"\n",
"encrypted",
"=",
"encrypted",
"[",
"aes",
".",
"BlockSize",
":",
"]",
"\n",
"stream",
":=",
"cipher",
".",
"NewCFBDecrypter",
"(",
"c",
".",
"Block",
",",
"iv",
")",
"\n",
"stream",
".",
"XORKeyStream",
"(",
"encrypted",
",",
"encrypted",
")",
"\n\n",
"return",
"string",
"(",
"encrypted",
")",
",",
"nil",
"\n",
"}"
] |
// Decrypt a value from a cookie to it's original string
|
[
"Decrypt",
"a",
"value",
"from",
"a",
"cookie",
"to",
"it",
"s",
"original",
"string"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/cookie/cookies.go#L110-L128
|
146,520 |
bitly/oauth2_proxy
|
providers/provider_default.go
|
GetLoginURL
|
func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
var a url.URL
a = *p.LoginURL
params, _ := url.ParseQuery(a.RawQuery)
params.Set("redirect_uri", redirectURI)
params.Set("approval_prompt", p.ApprovalPrompt)
params.Add("scope", p.Scope)
params.Set("client_id", p.ClientID)
params.Set("response_type", "code")
params.Add("state", state)
a.RawQuery = params.Encode()
return a.String()
}
|
go
|
func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
var a url.URL
a = *p.LoginURL
params, _ := url.ParseQuery(a.RawQuery)
params.Set("redirect_uri", redirectURI)
params.Set("approval_prompt", p.ApprovalPrompt)
params.Add("scope", p.Scope)
params.Set("client_id", p.ClientID)
params.Set("response_type", "code")
params.Add("state", state)
a.RawQuery = params.Encode()
return a.String()
}
|
[
"func",
"(",
"p",
"*",
"ProviderData",
")",
"GetLoginURL",
"(",
"redirectURI",
",",
"state",
"string",
")",
"string",
"{",
"var",
"a",
"url",
".",
"URL",
"\n",
"a",
"=",
"*",
"p",
".",
"LoginURL",
"\n",
"params",
",",
"_",
":=",
"url",
".",
"ParseQuery",
"(",
"a",
".",
"RawQuery",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"redirectURI",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"p",
".",
"ApprovalPrompt",
")",
"\n",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
"p",
".",
"Scope",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"p",
".",
"ClientID",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"params",
".",
"Add",
"(",
"\"",
"\"",
",",
"state",
")",
"\n",
"a",
".",
"RawQuery",
"=",
"params",
".",
"Encode",
"(",
")",
"\n",
"return",
"a",
".",
"String",
"(",
")",
"\n",
"}"
] |
// GetLoginURL with typical oauth parameters
|
[
"GetLoginURL",
"with",
"typical",
"oauth",
"parameters"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/providers/provider_default.go#L81-L93
|
146,521 |
bitly/oauth2_proxy
|
providers/provider_default.go
|
CookieForSession
|
func (p *ProviderData) CookieForSession(s *SessionState, c *cookie.Cipher) (string, error) {
return s.EncodeSessionState(c)
}
|
go
|
func (p *ProviderData) CookieForSession(s *SessionState, c *cookie.Cipher) (string, error) {
return s.EncodeSessionState(c)
}
|
[
"func",
"(",
"p",
"*",
"ProviderData",
")",
"CookieForSession",
"(",
"s",
"*",
"SessionState",
",",
"c",
"*",
"cookie",
".",
"Cipher",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"s",
".",
"EncodeSessionState",
"(",
"c",
")",
"\n",
"}"
] |
// CookieForSession serializes a session state for storage in a cookie
|
[
"CookieForSession",
"serializes",
"a",
"session",
"state",
"for",
"storage",
"in",
"a",
"cookie"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/providers/provider_default.go#L96-L98
|
146,522 |
bitly/oauth2_proxy
|
providers/provider_default.go
|
SessionFromCookie
|
func (p *ProviderData) SessionFromCookie(v string, c *cookie.Cipher) (s *SessionState, err error) {
return DecodeSessionState(v, c)
}
|
go
|
func (p *ProviderData) SessionFromCookie(v string, c *cookie.Cipher) (s *SessionState, err error) {
return DecodeSessionState(v, c)
}
|
[
"func",
"(",
"p",
"*",
"ProviderData",
")",
"SessionFromCookie",
"(",
"v",
"string",
",",
"c",
"*",
"cookie",
".",
"Cipher",
")",
"(",
"s",
"*",
"SessionState",
",",
"err",
"error",
")",
"{",
"return",
"DecodeSessionState",
"(",
"v",
",",
"c",
")",
"\n",
"}"
] |
// SessionFromCookie deserializes a session from a cookie value
|
[
"SessionFromCookie",
"deserializes",
"a",
"session",
"from",
"a",
"cookie",
"value"
] |
fa2771998a98a5bfdfa3c3503757668ac4f1c8ec
|
https://github.com/bitly/oauth2_proxy/blob/fa2771998a98a5bfdfa3c3503757668ac4f1c8ec/providers/provider_default.go#L101-L103
|
146,523 |
mattn/go-sqlite3
|
_example/custom_func/main.go
|
xor
|
func xor(xs ...int64) int64 {
var ret int64
for _, x := range xs {
ret ^= x
}
return ret
}
|
go
|
func xor(xs ...int64) int64 {
var ret int64
for _, x := range xs {
ret ^= x
}
return ret
}
|
[
"func",
"xor",
"(",
"xs",
"...",
"int64",
")",
"int64",
"{",
"var",
"ret",
"int64",
"\n",
"for",
"_",
",",
"x",
":=",
"range",
"xs",
"{",
"ret",
"^=",
"x",
"\n",
"}",
"\n",
"return",
"ret",
"\n",
"}"
] |
// Computes the bitwise exclusive-or of all its arguments
|
[
"Computes",
"the",
"bitwise",
"exclusive",
"-",
"or",
"of",
"all",
"its",
"arguments"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/_example/custom_func/main.go#L19-L25
|
146,524 |
mattn/go-sqlite3
|
sqlite3_trace.go
|
popTraceMapping
|
func popTraceMapping(connHandle uintptr) (TraceConfig, bool) {
traceMapLock.Lock()
defer traceMapLock.Unlock()
entryCopy, found := traceMap[connHandle]
if found {
delete(traceMap, connHandle)
fmt.Printf("Pop handle 0x%x: deleted trace config %v.\n", connHandle, entryCopy.config)
}
return entryCopy.config, found
}
|
go
|
func popTraceMapping(connHandle uintptr) (TraceConfig, bool) {
traceMapLock.Lock()
defer traceMapLock.Unlock()
entryCopy, found := traceMap[connHandle]
if found {
delete(traceMap, connHandle)
fmt.Printf("Pop handle 0x%x: deleted trace config %v.\n", connHandle, entryCopy.config)
}
return entryCopy.config, found
}
|
[
"func",
"popTraceMapping",
"(",
"connHandle",
"uintptr",
")",
"(",
"TraceConfig",
",",
"bool",
")",
"{",
"traceMapLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"traceMapLock",
".",
"Unlock",
"(",
")",
"\n\n",
"entryCopy",
",",
"found",
":=",
"traceMap",
"[",
"connHandle",
"]",
"\n",
"if",
"found",
"{",
"delete",
"(",
"traceMap",
",",
"connHandle",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"connHandle",
",",
"entryCopy",
".",
"config",
")",
"\n",
"}",
"\n",
"return",
"entryCopy",
".",
"config",
",",
"found",
"\n",
"}"
] |
// 'pop' = get and delete from map before returning the value to the caller
|
[
"pop",
"=",
"get",
"and",
"delete",
"from",
"map",
"before",
"returning",
"the",
"value",
"to",
"the",
"caller"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_trace.go#L229-L239
|
146,525 |
mattn/go-sqlite3
|
backup.go
|
Backup
|
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
destptr := C.CString(dest)
defer C.free(unsafe.Pointer(destptr))
srcptr := C.CString(src)
defer C.free(unsafe.Pointer(srcptr))
if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
bb := &SQLiteBackup{b: b}
runtime.SetFinalizer(bb, (*SQLiteBackup).Finish)
return bb, nil
}
return nil, c.lastError()
}
|
go
|
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
destptr := C.CString(dest)
defer C.free(unsafe.Pointer(destptr))
srcptr := C.CString(src)
defer C.free(unsafe.Pointer(srcptr))
if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
bb := &SQLiteBackup{b: b}
runtime.SetFinalizer(bb, (*SQLiteBackup).Finish)
return bb, nil
}
return nil, c.lastError()
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"Backup",
"(",
"dest",
"string",
",",
"conn",
"*",
"SQLiteConn",
",",
"src",
"string",
")",
"(",
"*",
"SQLiteBackup",
",",
"error",
")",
"{",
"destptr",
":=",
"C",
".",
"CString",
"(",
"dest",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"destptr",
")",
")",
"\n",
"srcptr",
":=",
"C",
".",
"CString",
"(",
"src",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"srcptr",
")",
")",
"\n\n",
"if",
"b",
":=",
"C",
".",
"sqlite3_backup_init",
"(",
"c",
".",
"db",
",",
"destptr",
",",
"conn",
".",
"db",
",",
"srcptr",
")",
";",
"b",
"!=",
"nil",
"{",
"bb",
":=",
"&",
"SQLiteBackup",
"{",
"b",
":",
"b",
"}",
"\n",
"runtime",
".",
"SetFinalizer",
"(",
"bb",
",",
"(",
"*",
"SQLiteBackup",
")",
".",
"Finish",
")",
"\n",
"return",
"bb",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"c",
".",
"lastError",
"(",
")",
"\n",
"}"
] |
// Backup make backup from src to dest.
|
[
"Backup",
"make",
"backup",
"from",
"src",
"to",
"dest",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/backup.go#L28-L40
|
146,526 |
mattn/go-sqlite3
|
backup.go
|
Close
|
func (b *SQLiteBackup) Close() error {
ret := C.sqlite3_backup_finish(b.b)
// sqlite3_backup_finish() never fails, it just returns the
// error code from previous operations, so clean up before
// checking and returning an error
b.b = nil
runtime.SetFinalizer(b, nil)
if ret != 0 {
return Error{Code: ErrNo(ret)}
}
return nil
}
|
go
|
func (b *SQLiteBackup) Close() error {
ret := C.sqlite3_backup_finish(b.b)
// sqlite3_backup_finish() never fails, it just returns the
// error code from previous operations, so clean up before
// checking and returning an error
b.b = nil
runtime.SetFinalizer(b, nil)
if ret != 0 {
return Error{Code: ErrNo(ret)}
}
return nil
}
|
[
"func",
"(",
"b",
"*",
"SQLiteBackup",
")",
"Close",
"(",
")",
"error",
"{",
"ret",
":=",
"C",
".",
"sqlite3_backup_finish",
"(",
"b",
".",
"b",
")",
"\n\n",
"// sqlite3_backup_finish() never fails, it just returns the",
"// error code from previous operations, so clean up before",
"// checking and returning an error",
"b",
".",
"b",
"=",
"nil",
"\n",
"runtime",
".",
"SetFinalizer",
"(",
"b",
",",
"nil",
")",
"\n\n",
"if",
"ret",
"!=",
"0",
"{",
"return",
"Error",
"{",
"Code",
":",
"ErrNo",
"(",
"ret",
")",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close close backup.
|
[
"Close",
"close",
"backup",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/backup.go#L72-L85
|
146,527 |
mattn/go-sqlite3
|
sqlite3_context.go
|
ResultBool
|
func (c *SQLiteContext) ResultBool(b bool) {
if b {
c.ResultInt(1)
} else {
c.ResultInt(0)
}
}
|
go
|
func (c *SQLiteContext) ResultBool(b bool) {
if b {
c.ResultInt(1)
} else {
c.ResultInt(0)
}
}
|
[
"func",
"(",
"c",
"*",
"SQLiteContext",
")",
"ResultBool",
"(",
"b",
"bool",
")",
"{",
"if",
"b",
"{",
"c",
".",
"ResultInt",
"(",
"1",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"ResultInt",
"(",
"0",
")",
"\n",
"}",
"\n",
"}"
] |
// ResultBool sets the result of an SQL function.
|
[
"ResultBool",
"sets",
"the",
"result",
"of",
"an",
"SQL",
"function",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_context.go#L41-L47
|
146,528 |
mattn/go-sqlite3
|
error.go
|
Extend
|
func (err ErrNo) Extend(by int) ErrNoExtended {
return ErrNoExtended(int(err) | (by << 8))
}
|
go
|
func (err ErrNo) Extend(by int) ErrNoExtended {
return ErrNoExtended(int(err) | (by << 8))
}
|
[
"func",
"(",
"err",
"ErrNo",
")",
"Extend",
"(",
"by",
"int",
")",
"ErrNoExtended",
"{",
"return",
"ErrNoExtended",
"(",
"int",
"(",
"err",
")",
"|",
"(",
"by",
"<<",
"8",
")",
")",
"\n",
"}"
] |
// Extend return extended errno.
|
[
"Extend",
"return",
"extended",
"errno",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/error.go#L65-L67
|
146,529 |
mattn/go-sqlite3
|
error.go
|
Error
|
func (err ErrNoExtended) Error() string {
return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
}
|
go
|
func (err ErrNoExtended) Error() string {
return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
}
|
[
"func",
"(",
"err",
"ErrNoExtended",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"Error",
"{",
"Code",
":",
"ErrNo",
"(",
"C",
".",
"int",
"(",
"err",
")",
"&",
"ErrNoMask",
")",
",",
"ExtendedCode",
":",
"err",
"}",
".",
"Error",
"(",
")",
"\n",
"}"
] |
// Error return error message that is extended code.
|
[
"Error",
"return",
"error",
"message",
"that",
"is",
"extended",
"code",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/error.go#L70-L72
|
146,530 |
mattn/go-sqlite3
|
sqlite3_opt_vtable.go
|
mPrintf
|
func mPrintf(format, arg string) *C.char {
cf := C.CString(format)
defer C.free(unsafe.Pointer(cf))
ca := C.CString(arg)
defer C.free(unsafe.Pointer(ca))
return C._sqlite3_mprintf(cf, ca)
}
|
go
|
func mPrintf(format, arg string) *C.char {
cf := C.CString(format)
defer C.free(unsafe.Pointer(cf))
ca := C.CString(arg)
defer C.free(unsafe.Pointer(ca))
return C._sqlite3_mprintf(cf, ca)
}
|
[
"func",
"mPrintf",
"(",
"format",
",",
"arg",
"string",
")",
"*",
"C",
".",
"char",
"{",
"cf",
":=",
"C",
".",
"CString",
"(",
"format",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cf",
")",
")",
"\n",
"ca",
":=",
"C",
".",
"CString",
"(",
"arg",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"ca",
")",
")",
"\n",
"return",
"C",
".",
"_sqlite3_mprintf",
"(",
"cf",
",",
"ca",
")",
"\n",
"}"
] |
// mPrintf is a utility wrapper around sqlite3_mprintf
|
[
"mPrintf",
"is",
"a",
"utility",
"wrapper",
"around",
"sqlite3_mprintf"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_opt_vtable.go#L340-L346
|
146,531 |
mattn/go-sqlite3
|
sqlite3.go
|
Version
|
func Version() (libVersion string, libVersionNumber int, sourceID string) {
libVersion = C.GoString(C.sqlite3_libversion())
libVersionNumber = int(C.sqlite3_libversion_number())
sourceID = C.GoString(C.sqlite3_sourceid())
return libVersion, libVersionNumber, sourceID
}
|
go
|
func Version() (libVersion string, libVersionNumber int, sourceID string) {
libVersion = C.GoString(C.sqlite3_libversion())
libVersionNumber = int(C.sqlite3_libversion_number())
sourceID = C.GoString(C.sqlite3_sourceid())
return libVersion, libVersionNumber, sourceID
}
|
[
"func",
"Version",
"(",
")",
"(",
"libVersion",
"string",
",",
"libVersionNumber",
"int",
",",
"sourceID",
"string",
")",
"{",
"libVersion",
"=",
"C",
".",
"GoString",
"(",
"C",
".",
"sqlite3_libversion",
"(",
")",
")",
"\n",
"libVersionNumber",
"=",
"int",
"(",
"C",
".",
"sqlite3_libversion_number",
"(",
")",
")",
"\n",
"sourceID",
"=",
"C",
".",
"GoString",
"(",
"C",
".",
"sqlite3_sourceid",
"(",
")",
")",
"\n",
"return",
"libVersion",
",",
"libVersionNumber",
",",
"sourceID",
"\n",
"}"
] |
// Version returns SQLite library version information.
|
[
"Version",
"returns",
"SQLite",
"library",
"version",
"information",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L234-L239
|
146,532 |
mattn/go-sqlite3
|
sqlite3.go
|
Commit
|
func (tx *SQLiteTx) Commit() error {
_, err := tx.c.exec(context.Background(), "COMMIT", nil)
if err != nil && err.(Error).Code == C.SQLITE_BUSY {
// sqlite3 will leave the transaction open in this scenario.
// However, database/sql considers the transaction complete once we
// return from Commit() - we must clean up to honour its semantics.
tx.c.exec(context.Background(), "ROLLBACK", nil)
}
return err
}
|
go
|
func (tx *SQLiteTx) Commit() error {
_, err := tx.c.exec(context.Background(), "COMMIT", nil)
if err != nil && err.(Error).Code == C.SQLITE_BUSY {
// sqlite3 will leave the transaction open in this scenario.
// However, database/sql considers the transaction complete once we
// return from Commit() - we must clean up to honour its semantics.
tx.c.exec(context.Background(), "ROLLBACK", nil)
}
return err
}
|
[
"func",
"(",
"tx",
"*",
"SQLiteTx",
")",
"Commit",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"c",
".",
"exec",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
".",
"(",
"Error",
")",
".",
"Code",
"==",
"C",
".",
"SQLITE_BUSY",
"{",
"// sqlite3 will leave the transaction open in this scenario.",
"// However, database/sql considers the transaction complete once we",
"// return from Commit() - we must clean up to honour its semantics.",
"tx",
".",
"c",
".",
"exec",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Commit transaction.
|
[
"Commit",
"transaction",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L436-L445
|
146,533 |
mattn/go-sqlite3
|
sqlite3.go
|
Rollback
|
func (tx *SQLiteTx) Rollback() error {
_, err := tx.c.exec(context.Background(), "ROLLBACK", nil)
return err
}
|
go
|
func (tx *SQLiteTx) Rollback() error {
_, err := tx.c.exec(context.Background(), "ROLLBACK", nil)
return err
}
|
[
"func",
"(",
"tx",
"*",
"SQLiteTx",
")",
"Rollback",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"c",
".",
"exec",
"(",
"context",
".",
"Background",
"(",
")",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Rollback transaction.
|
[
"Rollback",
"transaction",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L448-L451
|
146,534 |
mattn/go-sqlite3
|
sqlite3.go
|
AutoCommit
|
func (c *SQLiteConn) AutoCommit() bool {
c.mu.Lock()
defer c.mu.Unlock()
return int(C.sqlite3_get_autocommit(c.db)) != 0
}
|
go
|
func (c *SQLiteConn) AutoCommit() bool {
c.mu.Lock()
defer c.mu.Unlock()
return int(C.sqlite3_get_autocommit(c.db)) != 0
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"AutoCommit",
"(",
")",
"bool",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"sqlite3_get_autocommit",
"(",
"c",
".",
"db",
")",
")",
"!=",
"0",
"\n",
"}"
] |
// AutoCommit return which currently auto commit or not.
|
[
"AutoCommit",
"return",
"which",
"currently",
"auto",
"commit",
"or",
"not",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L742-L746
|
146,535 |
mattn/go-sqlite3
|
sqlite3.go
|
Query
|
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
list := make([]namedValue, len(args))
for i, v := range args {
list[i] = namedValue{
Ordinal: i + 1,
Value: v,
}
}
return c.query(context.Background(), query, list)
}
|
go
|
func (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
list := make([]namedValue, len(args))
for i, v := range args {
list[i] = namedValue{
Ordinal: i + 1,
Value: v,
}
}
return c.query(context.Background(), query, list)
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"Query",
"(",
"query",
"string",
",",
"args",
"[",
"]",
"driver",
".",
"Value",
")",
"(",
"driver",
".",
"Rows",
",",
"error",
")",
"{",
"list",
":=",
"make",
"(",
"[",
"]",
"namedValue",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"args",
"{",
"list",
"[",
"i",
"]",
"=",
"namedValue",
"{",
"Ordinal",
":",
"i",
"+",
"1",
",",
"Value",
":",
"v",
",",
"}",
"\n",
"}",
"\n",
"return",
"c",
".",
"query",
"(",
"context",
".",
"Background",
"(",
")",
",",
"query",
",",
"list",
")",
"\n",
"}"
] |
// Query implements Queryer.
|
[
"Query",
"implements",
"Queryer",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L817-L826
|
146,536 |
mattn/go-sqlite3
|
sqlite3.go
|
Begin
|
func (c *SQLiteConn) Begin() (driver.Tx, error) {
return c.begin(context.Background())
}
|
go
|
func (c *SQLiteConn) Begin() (driver.Tx, error) {
return c.begin(context.Background())
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"Begin",
"(",
")",
"(",
"driver",
".",
"Tx",
",",
"error",
")",
"{",
"return",
"c",
".",
"begin",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"}"
] |
// Begin transaction.
|
[
"Begin",
"transaction",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L861-L863
|
146,537 |
mattn/go-sqlite3
|
sqlite3.go
|
Close
|
func (c *SQLiteConn) Close() error {
rv := C.sqlite3_close_v2(c.db)
if rv != C.SQLITE_OK {
return c.lastError()
}
deleteHandles(c)
c.mu.Lock()
c.db = nil
c.mu.Unlock()
runtime.SetFinalizer(c, nil)
return nil
}
|
go
|
func (c *SQLiteConn) Close() error {
rv := C.sqlite3_close_v2(c.db)
if rv != C.SQLITE_OK {
return c.lastError()
}
deleteHandles(c)
c.mu.Lock()
c.db = nil
c.mu.Unlock()
runtime.SetFinalizer(c, nil)
return nil
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"Close",
"(",
")",
"error",
"{",
"rv",
":=",
"C",
".",
"sqlite3_close_v2",
"(",
"c",
".",
"db",
")",
"\n",
"if",
"rv",
"!=",
"C",
".",
"SQLITE_OK",
"{",
"return",
"c",
".",
"lastError",
"(",
")",
"\n",
"}",
"\n",
"deleteHandles",
"(",
"c",
")",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"db",
"=",
"nil",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"runtime",
".",
"SetFinalizer",
"(",
"c",
",",
"nil",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close the connection.
|
[
"Close",
"the",
"connection",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1650-L1661
|
146,538 |
mattn/go-sqlite3
|
sqlite3.go
|
Prepare
|
func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
return c.prepare(context.Background(), query)
}
|
go
|
func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
return c.prepare(context.Background(), query)
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"Prepare",
"(",
"query",
"string",
")",
"(",
"driver",
".",
"Stmt",
",",
"error",
")",
"{",
"return",
"c",
".",
"prepare",
"(",
"context",
".",
"Background",
"(",
")",
",",
"query",
")",
"\n",
"}"
] |
// Prepare the query string. Return a new statement.
|
[
"Prepare",
"the",
"query",
"string",
".",
"Return",
"a",
"new",
"statement",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1673-L1675
|
146,539 |
mattn/go-sqlite3
|
sqlite3.go
|
Close
|
func (s *SQLiteStmt) Close() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.closed {
return nil
}
s.closed = true
if !s.c.dbConnOpen() {
return errors.New("sqlite statement with already closed database connection")
}
rv := C.sqlite3_finalize(s.s)
s.s = nil
if rv != C.SQLITE_OK {
return s.c.lastError()
}
runtime.SetFinalizer(s, nil)
return nil
}
|
go
|
func (s *SQLiteStmt) Close() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.closed {
return nil
}
s.closed = true
if !s.c.dbConnOpen() {
return errors.New("sqlite statement with already closed database connection")
}
rv := C.sqlite3_finalize(s.s)
s.s = nil
if rv != C.SQLITE_OK {
return s.c.lastError()
}
runtime.SetFinalizer(s, nil)
return nil
}
|
[
"func",
"(",
"s",
"*",
"SQLiteStmt",
")",
"Close",
"(",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"s",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"closed",
"=",
"true",
"\n",
"if",
"!",
"s",
".",
"c",
".",
"dbConnOpen",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"rv",
":=",
"C",
".",
"sqlite3_finalize",
"(",
"s",
".",
"s",
")",
"\n",
"s",
".",
"s",
"=",
"nil",
"\n",
"if",
"rv",
"!=",
"C",
".",
"SQLITE_OK",
"{",
"return",
"s",
".",
"c",
".",
"lastError",
"(",
")",
"\n",
"}",
"\n",
"runtime",
".",
"SetFinalizer",
"(",
"s",
",",
"nil",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close the statement.
|
[
"Close",
"the",
"statement",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1737-L1754
|
146,540 |
mattn/go-sqlite3
|
sqlite3.go
|
Query
|
func (s *SQLiteStmt) Query(args []driver.Value) (driver.Rows, error) {
list := make([]namedValue, len(args))
for i, v := range args {
list[i] = namedValue{
Ordinal: i + 1,
Value: v,
}
}
return s.query(context.Background(), list)
}
|
go
|
func (s *SQLiteStmt) Query(args []driver.Value) (driver.Rows, error) {
list := make([]namedValue, len(args))
for i, v := range args {
list[i] = namedValue{
Ordinal: i + 1,
Value: v,
}
}
return s.query(context.Background(), list)
}
|
[
"func",
"(",
"s",
"*",
"SQLiteStmt",
")",
"Query",
"(",
"args",
"[",
"]",
"driver",
".",
"Value",
")",
"(",
"driver",
".",
"Rows",
",",
"error",
")",
"{",
"list",
":=",
"make",
"(",
"[",
"]",
"namedValue",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"args",
"{",
"list",
"[",
"i",
"]",
"=",
"namedValue",
"{",
"Ordinal",
":",
"i",
"+",
"1",
",",
"Value",
":",
"v",
",",
"}",
"\n",
"}",
"\n",
"return",
"s",
".",
"query",
"(",
"context",
".",
"Background",
"(",
")",
",",
"list",
")",
"\n",
"}"
] |
// Query the statement with arguments. Return records.
|
[
"Query",
"the",
"statement",
"with",
"arguments",
".",
"Return",
"records",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1826-L1835
|
146,541 |
mattn/go-sqlite3
|
sqlite3.go
|
Exec
|
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
list := make([]namedValue, len(args))
for i, v := range args {
list[i] = namedValue{
Ordinal: i + 1,
Value: v,
}
}
return s.exec(context.Background(), list)
}
|
go
|
func (s *SQLiteStmt) Exec(args []driver.Value) (driver.Result, error) {
list := make([]namedValue, len(args))
for i, v := range args {
list[i] = namedValue{
Ordinal: i + 1,
Value: v,
}
}
return s.exec(context.Background(), list)
}
|
[
"func",
"(",
"s",
"*",
"SQLiteStmt",
")",
"Exec",
"(",
"args",
"[",
"]",
"driver",
".",
"Value",
")",
"(",
"driver",
".",
"Result",
",",
"error",
")",
"{",
"list",
":=",
"make",
"(",
"[",
"]",
"namedValue",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"args",
"{",
"list",
"[",
"i",
"]",
"=",
"namedValue",
"{",
"Ordinal",
":",
"i",
"+",
"1",
",",
"Value",
":",
"v",
",",
"}",
"\n",
"}",
"\n",
"return",
"s",
".",
"exec",
"(",
"context",
".",
"Background",
"(",
")",
",",
"list",
")",
"\n",
"}"
] |
// Exec execute the statement with arguments. Return result object.
|
[
"Exec",
"execute",
"the",
"statement",
"with",
"arguments",
".",
"Return",
"result",
"object",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1881-L1890
|
146,542 |
mattn/go-sqlite3
|
sqlite3.go
|
Close
|
func (rc *SQLiteRows) Close() error {
rc.s.mu.Lock()
if rc.s.closed || rc.closed {
rc.s.mu.Unlock()
return nil
}
rc.closed = true
if rc.done != nil {
close(rc.done)
}
if rc.cls {
rc.s.mu.Unlock()
return rc.s.Close()
}
rv := C.sqlite3_reset(rc.s.s)
if rv != C.SQLITE_OK {
rc.s.mu.Unlock()
return rc.s.c.lastError()
}
rc.s.mu.Unlock()
return nil
}
|
go
|
func (rc *SQLiteRows) Close() error {
rc.s.mu.Lock()
if rc.s.closed || rc.closed {
rc.s.mu.Unlock()
return nil
}
rc.closed = true
if rc.done != nil {
close(rc.done)
}
if rc.cls {
rc.s.mu.Unlock()
return rc.s.Close()
}
rv := C.sqlite3_reset(rc.s.s)
if rv != C.SQLITE_OK {
rc.s.mu.Unlock()
return rc.s.c.lastError()
}
rc.s.mu.Unlock()
return nil
}
|
[
"func",
"(",
"rc",
"*",
"SQLiteRows",
")",
"Close",
"(",
")",
"error",
"{",
"rc",
".",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"rc",
".",
"s",
".",
"closed",
"||",
"rc",
".",
"closed",
"{",
"rc",
".",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"rc",
".",
"closed",
"=",
"true",
"\n",
"if",
"rc",
".",
"done",
"!=",
"nil",
"{",
"close",
"(",
"rc",
".",
"done",
")",
"\n",
"}",
"\n",
"if",
"rc",
".",
"cls",
"{",
"rc",
".",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"rc",
".",
"s",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"rv",
":=",
"C",
".",
"sqlite3_reset",
"(",
"rc",
".",
"s",
".",
"s",
")",
"\n",
"if",
"rv",
"!=",
"C",
".",
"SQLITE_OK",
"{",
"rc",
".",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"rc",
".",
"s",
".",
"c",
".",
"lastError",
"(",
")",
"\n",
"}",
"\n",
"rc",
".",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close the rows.
|
[
"Close",
"the",
"rows",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1928-L1949
|
146,543 |
mattn/go-sqlite3
|
sqlite3.go
|
Columns
|
func (rc *SQLiteRows) Columns() []string {
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
if rc.s.s != nil && rc.nc != len(rc.cols) {
rc.cols = make([]string, rc.nc)
for i := 0; i < rc.nc; i++ {
rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i)))
}
}
return rc.cols
}
|
go
|
func (rc *SQLiteRows) Columns() []string {
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
if rc.s.s != nil && rc.nc != len(rc.cols) {
rc.cols = make([]string, rc.nc)
for i := 0; i < rc.nc; i++ {
rc.cols[i] = C.GoString(C.sqlite3_column_name(rc.s.s, C.int(i)))
}
}
return rc.cols
}
|
[
"func",
"(",
"rc",
"*",
"SQLiteRows",
")",
"Columns",
"(",
")",
"[",
"]",
"string",
"{",
"rc",
".",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rc",
".",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"rc",
".",
"s",
".",
"s",
"!=",
"nil",
"&&",
"rc",
".",
"nc",
"!=",
"len",
"(",
"rc",
".",
"cols",
")",
"{",
"rc",
".",
"cols",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"rc",
".",
"nc",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"rc",
".",
"nc",
";",
"i",
"++",
"{",
"rc",
".",
"cols",
"[",
"i",
"]",
"=",
"C",
".",
"GoString",
"(",
"C",
".",
"sqlite3_column_name",
"(",
"rc",
".",
"s",
".",
"s",
",",
"C",
".",
"int",
"(",
"i",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rc",
".",
"cols",
"\n",
"}"
] |
// Columns return column names.
|
[
"Columns",
"return",
"column",
"names",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1952-L1962
|
146,544 |
mattn/go-sqlite3
|
sqlite3.go
|
DeclTypes
|
func (rc *SQLiteRows) DeclTypes() []string {
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
return rc.declTypes()
}
|
go
|
func (rc *SQLiteRows) DeclTypes() []string {
rc.s.mu.Lock()
defer rc.s.mu.Unlock()
return rc.declTypes()
}
|
[
"func",
"(",
"rc",
"*",
"SQLiteRows",
")",
"DeclTypes",
"(",
")",
"[",
"]",
"string",
"{",
"rc",
".",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"rc",
".",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"rc",
".",
"declTypes",
"(",
")",
"\n",
"}"
] |
// DeclTypes return column types.
|
[
"DeclTypes",
"return",
"column",
"types",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3.go#L1975-L1979
|
146,545 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSSHA1
|
func CryptEncoderSSHA1(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha1.Sum(p)
return h[:]
}
}
|
go
|
func CryptEncoderSSHA1(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha1.Sum(p)
return h[:]
}
}
|
[
"func",
"CryptEncoderSSHA1",
"(",
"salt",
"string",
")",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"return",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"s",
":=",
"[",
"]",
"byte",
"(",
"salt",
")",
"\n",
"p",
":=",
"append",
"(",
"pass",
",",
"s",
"...",
")",
"\n",
"h",
":=",
"sha1",
".",
"Sum",
"(",
"p",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}",
"\n",
"}"
] |
// CryptEncoderSSHA1 encodes a password with SHA1 with the
// configured salt.
|
[
"CryptEncoderSSHA1",
"encodes",
"a",
"password",
"with",
"SHA1",
"with",
"the",
"configured",
"salt",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L60-L67
|
146,546 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSHA256
|
func CryptEncoderSHA256(pass []byte, hash interface{}) []byte {
h := sha256.Sum256(pass)
return h[:]
}
|
go
|
func CryptEncoderSHA256(pass []byte, hash interface{}) []byte {
h := sha256.Sum256(pass)
return h[:]
}
|
[
"func",
"CryptEncoderSHA256",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"h",
":=",
"sha256",
".",
"Sum256",
"(",
"pass",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}"
] |
// CryptEncoderSHA256 encodes a password with SHA256
|
[
"CryptEncoderSHA256",
"encodes",
"a",
"password",
"with",
"SHA256"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L70-L73
|
146,547 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSSHA256
|
func CryptEncoderSSHA256(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha256.Sum256(p)
return h[:]
}
}
|
go
|
func CryptEncoderSSHA256(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha256.Sum256(p)
return h[:]
}
}
|
[
"func",
"CryptEncoderSSHA256",
"(",
"salt",
"string",
")",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"return",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"s",
":=",
"[",
"]",
"byte",
"(",
"salt",
")",
"\n",
"p",
":=",
"append",
"(",
"pass",
",",
"s",
"...",
")",
"\n",
"h",
":=",
"sha256",
".",
"Sum256",
"(",
"p",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}",
"\n",
"}"
] |
// CryptEncoderSSHA256 encodes a password with SHA256
// with the configured salt
|
[
"CryptEncoderSSHA256",
"encodes",
"a",
"password",
"with",
"SHA256",
"with",
"the",
"configured",
"salt"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L77-L84
|
146,548 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSHA384
|
func CryptEncoderSHA384(pass []byte, hash interface{}) []byte {
h := sha512.Sum384(pass)
return h[:]
}
|
go
|
func CryptEncoderSHA384(pass []byte, hash interface{}) []byte {
h := sha512.Sum384(pass)
return h[:]
}
|
[
"func",
"CryptEncoderSHA384",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"h",
":=",
"sha512",
".",
"Sum384",
"(",
"pass",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}"
] |
// CryptEncoderSHA384 encodes a password with SHA384
|
[
"CryptEncoderSHA384",
"encodes",
"a",
"password",
"with",
"SHA384"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L87-L90
|
146,549 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSSHA384
|
func CryptEncoderSSHA384(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha512.Sum384(p)
return h[:]
}
}
|
go
|
func CryptEncoderSSHA384(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha512.Sum384(p)
return h[:]
}
}
|
[
"func",
"CryptEncoderSSHA384",
"(",
"salt",
"string",
")",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"return",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"s",
":=",
"[",
"]",
"byte",
"(",
"salt",
")",
"\n",
"p",
":=",
"append",
"(",
"pass",
",",
"s",
"...",
")",
"\n",
"h",
":=",
"sha512",
".",
"Sum384",
"(",
"p",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}",
"\n",
"}"
] |
// CryptEncoderSSHA384 encodes a password with SHA384
// with the configured salt
|
[
"CryptEncoderSSHA384",
"encodes",
"a",
"password",
"with",
"SHA384",
"with",
"the",
"configured",
"salt"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L94-L101
|
146,550 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSHA512
|
func CryptEncoderSHA512(pass []byte, hash interface{}) []byte {
h := sha512.Sum512(pass)
return h[:]
}
|
go
|
func CryptEncoderSHA512(pass []byte, hash interface{}) []byte {
h := sha512.Sum512(pass)
return h[:]
}
|
[
"func",
"CryptEncoderSHA512",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"h",
":=",
"sha512",
".",
"Sum512",
"(",
"pass",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}"
] |
// CryptEncoderSHA512 encodes a password with SHA512
|
[
"CryptEncoderSHA512",
"encodes",
"a",
"password",
"with",
"SHA512"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L104-L107
|
146,551 |
mattn/go-sqlite3
|
sqlite3_func_crypt.go
|
CryptEncoderSSHA512
|
func CryptEncoderSSHA512(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha512.Sum512(p)
return h[:]
}
}
|
go
|
func CryptEncoderSSHA512(salt string) func(pass []byte, hash interface{}) []byte {
return func(pass []byte, hash interface{}) []byte {
s := []byte(salt)
p := append(pass, s...)
h := sha512.Sum512(p)
return h[:]
}
}
|
[
"func",
"CryptEncoderSSHA512",
"(",
"salt",
"string",
")",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"return",
"func",
"(",
"pass",
"[",
"]",
"byte",
",",
"hash",
"interface",
"{",
"}",
")",
"[",
"]",
"byte",
"{",
"s",
":=",
"[",
"]",
"byte",
"(",
"salt",
")",
"\n",
"p",
":=",
"append",
"(",
"pass",
",",
"s",
"...",
")",
"\n",
"h",
":=",
"sha512",
".",
"Sum512",
"(",
"p",
")",
"\n",
"return",
"h",
"[",
":",
"]",
"\n",
"}",
"\n",
"}"
] |
// CryptEncoderSSHA512 encodes a password with SHA512
// with the configured salt
|
[
"CryptEncoderSSHA512",
"encodes",
"a",
"password",
"with",
"SHA512",
"with",
"the",
"configured",
"salt"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_func_crypt.go#L111-L118
|
146,552 |
mattn/go-sqlite3
|
sqlite3_go18.go
|
Ping
|
func (c *SQLiteConn) Ping(ctx context.Context) error {
if c.db == nil {
return errors.New("Connection was closed")
}
return nil
}
|
go
|
func (c *SQLiteConn) Ping(ctx context.Context) error {
if c.db == nil {
return errors.New("Connection was closed")
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"Ping",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"c",
".",
"db",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Ping implement Pinger.
|
[
"Ping",
"implement",
"Pinger",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_go18.go#L19-L24
|
146,553 |
mattn/go-sqlite3
|
sqlite3_go18.go
|
PrepareContext
|
func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
return c.prepare(ctx, query)
}
|
go
|
func (c *SQLiteConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
return c.prepare(ctx, query)
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"PrepareContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"query",
"string",
")",
"(",
"driver",
".",
"Stmt",
",",
"error",
")",
"{",
"return",
"c",
".",
"prepare",
"(",
"ctx",
",",
"query",
")",
"\n",
"}"
] |
// PrepareContext implement ConnPrepareContext.
|
[
"PrepareContext",
"implement",
"ConnPrepareContext",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_go18.go#L45-L47
|
146,554 |
mattn/go-sqlite3
|
sqlite3_go18.go
|
BeginTx
|
func (c *SQLiteConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
return c.begin(ctx)
}
|
go
|
func (c *SQLiteConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
return c.begin(ctx)
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"BeginTx",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"driver",
".",
"TxOptions",
")",
"(",
"driver",
".",
"Tx",
",",
"error",
")",
"{",
"return",
"c",
".",
"begin",
"(",
"ctx",
")",
"\n",
"}"
] |
// BeginTx implement ConnBeginTx.
|
[
"BeginTx",
"implement",
"ConnBeginTx",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_go18.go#L50-L52
|
146,555 |
mattn/go-sqlite3
|
sqlite3_load_extension.go
|
LoadExtension
|
func (c *SQLiteConn) LoadExtension(lib string, entry string) error {
rv := C.sqlite3_enable_load_extension(c.db, 1)
if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
}
clib := C.CString(lib)
defer C.free(unsafe.Pointer(clib))
centry := C.CString(entry)
defer C.free(unsafe.Pointer(centry))
rv = C.sqlite3_load_extension(c.db, clib, centry, nil)
if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
}
rv = C.sqlite3_enable_load_extension(c.db, 0)
if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
}
return nil
}
|
go
|
func (c *SQLiteConn) LoadExtension(lib string, entry string) error {
rv := C.sqlite3_enable_load_extension(c.db, 1)
if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
}
clib := C.CString(lib)
defer C.free(unsafe.Pointer(clib))
centry := C.CString(entry)
defer C.free(unsafe.Pointer(centry))
rv = C.sqlite3_load_extension(c.db, clib, centry, nil)
if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
}
rv = C.sqlite3_enable_load_extension(c.db, 0)
if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(c.db)))
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"LoadExtension",
"(",
"lib",
"string",
",",
"entry",
"string",
")",
"error",
"{",
"rv",
":=",
"C",
".",
"sqlite3_enable_load_extension",
"(",
"c",
".",
"db",
",",
"1",
")",
"\n",
"if",
"rv",
"!=",
"C",
".",
"SQLITE_OK",
"{",
"return",
"errors",
".",
"New",
"(",
"C",
".",
"GoString",
"(",
"C",
".",
"sqlite3_errmsg",
"(",
"c",
".",
"db",
")",
")",
")",
"\n",
"}",
"\n\n",
"clib",
":=",
"C",
".",
"CString",
"(",
"lib",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"clib",
")",
")",
"\n",
"centry",
":=",
"C",
".",
"CString",
"(",
"entry",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"centry",
")",
")",
"\n\n",
"rv",
"=",
"C",
".",
"sqlite3_load_extension",
"(",
"c",
".",
"db",
",",
"clib",
",",
"centry",
",",
"nil",
")",
"\n",
"if",
"rv",
"!=",
"C",
".",
"SQLITE_OK",
"{",
"return",
"errors",
".",
"New",
"(",
"C",
".",
"GoString",
"(",
"C",
".",
"sqlite3_errmsg",
"(",
"c",
".",
"db",
")",
")",
")",
"\n",
"}",
"\n\n",
"rv",
"=",
"C",
".",
"sqlite3_enable_load_extension",
"(",
"c",
".",
"db",
",",
"0",
")",
"\n",
"if",
"rv",
"!=",
"C",
".",
"SQLITE_OK",
"{",
"return",
"errors",
".",
"New",
"(",
"C",
".",
"GoString",
"(",
"C",
".",
"sqlite3_errmsg",
"(",
"c",
".",
"db",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// LoadExtension load the sqlite3 extension.
|
[
"LoadExtension",
"load",
"the",
"sqlite3",
"extension",
"."
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_load_extension.go#L48-L70
|
146,556 |
mattn/go-sqlite3
|
sqlite3_opt_userauth.go
|
AuthEnabled
|
func (c *SQLiteConn) AuthEnabled() (exists bool) {
rv := c.authEnabled()
if rv == 1 {
exists = true
}
return
}
|
go
|
func (c *SQLiteConn) AuthEnabled() (exists bool) {
rv := c.authEnabled()
if rv == 1 {
exists = true
}
return
}
|
[
"func",
"(",
"c",
"*",
"SQLiteConn",
")",
"AuthEnabled",
"(",
")",
"(",
"exists",
"bool",
")",
"{",
"rv",
":=",
"c",
".",
"authEnabled",
"(",
")",
"\n",
"if",
"rv",
"==",
"1",
"{",
"exists",
"=",
"true",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// AuthEnabled checks if the database is protected by user authentication
|
[
"AuthEnabled",
"checks",
"if",
"the",
"database",
"is",
"protected",
"by",
"user",
"authentication"
] |
5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3
|
https://github.com/mattn/go-sqlite3/blob/5994cc52dfa89a4ee21ac891b06fbc1ea02c52d3/sqlite3_opt_userauth.go#L268-L275
|
146,557 |
gliderlabs/registrator
|
consul/consul.go
|
Ping
|
func (r *ConsulAdapter) Ping() error {
status := r.client.Status()
leader, err := status.Leader()
if err != nil {
return err
}
log.Println("consul: current leader ", leader)
return nil
}
|
go
|
func (r *ConsulAdapter) Ping() error {
status := r.client.Status()
leader, err := status.Leader()
if err != nil {
return err
}
log.Println("consul: current leader ", leader)
return nil
}
|
[
"func",
"(",
"r",
"*",
"ConsulAdapter",
")",
"Ping",
"(",
")",
"error",
"{",
"status",
":=",
"r",
".",
"client",
".",
"Status",
"(",
")",
"\n",
"leader",
",",
"err",
":=",
"status",
".",
"Leader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"leader",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Ping will try to connect to consul by attempting to retrieve the current leader.
|
[
"Ping",
"will",
"try",
"to",
"connect",
"to",
"consul",
"by",
"attempting",
"to",
"retrieve",
"the",
"current",
"leader",
"."
] |
da90d170da9dd7e1a8d9a13429d44686dc3d118f
|
https://github.com/gliderlabs/registrator/blob/da90d170da9dd7e1a8d9a13429d44686dc3d118f/consul/consul.go#L69-L78
|
146,558 |
orcaman/concurrent-map
|
concurrent_map.go
|
New
|
func New() ConcurrentMap {
m := make(ConcurrentMap, SHARD_COUNT)
for i := 0; i < SHARD_COUNT; i++ {
m[i] = &ConcurrentMapShared{items: make(map[string]interface{})}
}
return m
}
|
go
|
func New() ConcurrentMap {
m := make(ConcurrentMap, SHARD_COUNT)
for i := 0; i < SHARD_COUNT; i++ {
m[i] = &ConcurrentMapShared{items: make(map[string]interface{})}
}
return m
}
|
[
"func",
"New",
"(",
")",
"ConcurrentMap",
"{",
"m",
":=",
"make",
"(",
"ConcurrentMap",
",",
"SHARD_COUNT",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"SHARD_COUNT",
";",
"i",
"++",
"{",
"m",
"[",
"i",
"]",
"=",
"&",
"ConcurrentMapShared",
"{",
"items",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"}",
"\n",
"}",
"\n",
"return",
"m",
"\n",
"}"
] |
// Creates a new concurrent map.
|
[
"Creates",
"a",
"new",
"concurrent",
"map",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L21-L27
|
146,559 |
orcaman/concurrent-map
|
concurrent_map.go
|
GetShard
|
func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared {
return m[uint(fnv32(key))%uint(SHARD_COUNT)]
}
|
go
|
func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared {
return m[uint(fnv32(key))%uint(SHARD_COUNT)]
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"GetShard",
"(",
"key",
"string",
")",
"*",
"ConcurrentMapShared",
"{",
"return",
"m",
"[",
"uint",
"(",
"fnv32",
"(",
"key",
")",
")",
"%",
"uint",
"(",
"SHARD_COUNT",
")",
"]",
"\n",
"}"
] |
// GetShard returns shard under given key
|
[
"GetShard",
"returns",
"shard",
"under",
"given",
"key"
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L30-L32
|
146,560 |
orcaman/concurrent-map
|
concurrent_map.go
|
Set
|
func (m ConcurrentMap) Set(key string, value interface{}) {
// Get map shard.
shard := m.GetShard(key)
shard.Lock()
shard.items[key] = value
shard.Unlock()
}
|
go
|
func (m ConcurrentMap) Set(key string, value interface{}) {
// Get map shard.
shard := m.GetShard(key)
shard.Lock()
shard.items[key] = value
shard.Unlock()
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Set",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"{",
"// Get map shard.",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"Lock",
"(",
")",
"\n",
"shard",
".",
"items",
"[",
"key",
"]",
"=",
"value",
"\n",
"shard",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Sets the given value under the specified key.
|
[
"Sets",
"the",
"given",
"value",
"under",
"the",
"specified",
"key",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L44-L50
|
146,561 |
orcaman/concurrent-map
|
concurrent_map.go
|
Upsert
|
func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{}) {
shard := m.GetShard(key)
shard.Lock()
v, ok := shard.items[key]
res = cb(ok, v, value)
shard.items[key] = res
shard.Unlock()
return res
}
|
go
|
func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{}) {
shard := m.GetShard(key)
shard.Lock()
v, ok := shard.items[key]
res = cb(ok, v, value)
shard.items[key] = res
shard.Unlock()
return res
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Upsert",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"cb",
"UpsertCb",
")",
"(",
"res",
"interface",
"{",
"}",
")",
"{",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"Lock",
"(",
")",
"\n",
"v",
",",
"ok",
":=",
"shard",
".",
"items",
"[",
"key",
"]",
"\n",
"res",
"=",
"cb",
"(",
"ok",
",",
"v",
",",
"value",
")",
"\n",
"shard",
".",
"items",
"[",
"key",
"]",
"=",
"res",
"\n",
"shard",
".",
"Unlock",
"(",
")",
"\n",
"return",
"res",
"\n",
"}"
] |
// Insert or Update - updates existing element or inserts a new one using UpsertCb
|
[
"Insert",
"or",
"Update",
"-",
"updates",
"existing",
"element",
"or",
"inserts",
"a",
"new",
"one",
"using",
"UpsertCb"
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L59-L67
|
146,562 |
orcaman/concurrent-map
|
concurrent_map.go
|
SetIfAbsent
|
func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool {
// Get map shard.
shard := m.GetShard(key)
shard.Lock()
_, ok := shard.items[key]
if !ok {
shard.items[key] = value
}
shard.Unlock()
return !ok
}
|
go
|
func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool {
// Get map shard.
shard := m.GetShard(key)
shard.Lock()
_, ok := shard.items[key]
if !ok {
shard.items[key] = value
}
shard.Unlock()
return !ok
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"SetIfAbsent",
"(",
"key",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"// Get map shard.",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"Lock",
"(",
")",
"\n",
"_",
",",
"ok",
":=",
"shard",
".",
"items",
"[",
"key",
"]",
"\n",
"if",
"!",
"ok",
"{",
"shard",
".",
"items",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"shard",
".",
"Unlock",
"(",
")",
"\n",
"return",
"!",
"ok",
"\n",
"}"
] |
// Sets the given value under the specified key if no value was associated with it.
|
[
"Sets",
"the",
"given",
"value",
"under",
"the",
"specified",
"key",
"if",
"no",
"value",
"was",
"associated",
"with",
"it",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L70-L80
|
146,563 |
orcaman/concurrent-map
|
concurrent_map.go
|
Get
|
func (m ConcurrentMap) Get(key string) (interface{}, bool) {
// Get shard
shard := m.GetShard(key)
shard.RLock()
// Get item from shard.
val, ok := shard.items[key]
shard.RUnlock()
return val, ok
}
|
go
|
func (m ConcurrentMap) Get(key string) (interface{}, bool) {
// Get shard
shard := m.GetShard(key)
shard.RLock()
// Get item from shard.
val, ok := shard.items[key]
shard.RUnlock()
return val, ok
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Get",
"(",
"key",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"bool",
")",
"{",
"// Get shard",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"RLock",
"(",
")",
"\n",
"// Get item from shard.",
"val",
",",
"ok",
":=",
"shard",
".",
"items",
"[",
"key",
"]",
"\n",
"shard",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"val",
",",
"ok",
"\n",
"}"
] |
// Get retrieves an element from map under given key.
|
[
"Get",
"retrieves",
"an",
"element",
"from",
"map",
"under",
"given",
"key",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L83-L91
|
146,564 |
orcaman/concurrent-map
|
concurrent_map.go
|
Count
|
func (m ConcurrentMap) Count() int {
count := 0
for i := 0; i < SHARD_COUNT; i++ {
shard := m[i]
shard.RLock()
count += len(shard.items)
shard.RUnlock()
}
return count
}
|
go
|
func (m ConcurrentMap) Count() int {
count := 0
for i := 0; i < SHARD_COUNT; i++ {
shard := m[i]
shard.RLock()
count += len(shard.items)
shard.RUnlock()
}
return count
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Count",
"(",
")",
"int",
"{",
"count",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"SHARD_COUNT",
";",
"i",
"++",
"{",
"shard",
":=",
"m",
"[",
"i",
"]",
"\n",
"shard",
".",
"RLock",
"(",
")",
"\n",
"count",
"+=",
"len",
"(",
"shard",
".",
"items",
")",
"\n",
"shard",
".",
"RUnlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"count",
"\n",
"}"
] |
// Count returns the number of elements within the map.
|
[
"Count",
"returns",
"the",
"number",
"of",
"elements",
"within",
"the",
"map",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L94-L103
|
146,565 |
orcaman/concurrent-map
|
concurrent_map.go
|
Has
|
func (m ConcurrentMap) Has(key string) bool {
// Get shard
shard := m.GetShard(key)
shard.RLock()
// See if element is within shard.
_, ok := shard.items[key]
shard.RUnlock()
return ok
}
|
go
|
func (m ConcurrentMap) Has(key string) bool {
// Get shard
shard := m.GetShard(key)
shard.RLock()
// See if element is within shard.
_, ok := shard.items[key]
shard.RUnlock()
return ok
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Has",
"(",
"key",
"string",
")",
"bool",
"{",
"// Get shard",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"RLock",
"(",
")",
"\n",
"// See if element is within shard.",
"_",
",",
"ok",
":=",
"shard",
".",
"items",
"[",
"key",
"]",
"\n",
"shard",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"ok",
"\n",
"}"
] |
// Looks up an item under specified key
|
[
"Looks",
"up",
"an",
"item",
"under",
"specified",
"key"
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L106-L114
|
146,566 |
orcaman/concurrent-map
|
concurrent_map.go
|
Remove
|
func (m ConcurrentMap) Remove(key string) {
// Try to get shard.
shard := m.GetShard(key)
shard.Lock()
delete(shard.items, key)
shard.Unlock()
}
|
go
|
func (m ConcurrentMap) Remove(key string) {
// Try to get shard.
shard := m.GetShard(key)
shard.Lock()
delete(shard.items, key)
shard.Unlock()
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Remove",
"(",
"key",
"string",
")",
"{",
"// Try to get shard.",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"shard",
".",
"items",
",",
"key",
")",
"\n",
"shard",
".",
"Unlock",
"(",
")",
"\n",
"}"
] |
// Remove removes an element from the map.
|
[
"Remove",
"removes",
"an",
"element",
"from",
"the",
"map",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L117-L123
|
146,567 |
orcaman/concurrent-map
|
concurrent_map.go
|
Pop
|
func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool) {
// Try to get shard.
shard := m.GetShard(key)
shard.Lock()
v, exists = shard.items[key]
delete(shard.items, key)
shard.Unlock()
return v, exists
}
|
go
|
func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool) {
// Try to get shard.
shard := m.GetShard(key)
shard.Lock()
v, exists = shard.items[key]
delete(shard.items, key)
shard.Unlock()
return v, exists
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"Pop",
"(",
"key",
"string",
")",
"(",
"v",
"interface",
"{",
"}",
",",
"exists",
"bool",
")",
"{",
"// Try to get shard.",
"shard",
":=",
"m",
".",
"GetShard",
"(",
"key",
")",
"\n",
"shard",
".",
"Lock",
"(",
")",
"\n",
"v",
",",
"exists",
"=",
"shard",
".",
"items",
"[",
"key",
"]",
"\n",
"delete",
"(",
"shard",
".",
"items",
",",
"key",
")",
"\n",
"shard",
".",
"Unlock",
"(",
")",
"\n",
"return",
"v",
",",
"exists",
"\n",
"}"
] |
// Pop removes an element from the map and returns it
|
[
"Pop",
"removes",
"an",
"element",
"from",
"the",
"map",
"and",
"returns",
"it"
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L146-L154
|
146,568 |
orcaman/concurrent-map
|
concurrent_map.go
|
IterBuffered
|
func (m ConcurrentMap) IterBuffered() <-chan Tuple {
chans := snapshot(m)
total := 0
for _, c := range chans {
total += cap(c)
}
ch := make(chan Tuple, total)
go fanIn(chans, ch)
return ch
}
|
go
|
func (m ConcurrentMap) IterBuffered() <-chan Tuple {
chans := snapshot(m)
total := 0
for _, c := range chans {
total += cap(c)
}
ch := make(chan Tuple, total)
go fanIn(chans, ch)
return ch
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"IterBuffered",
"(",
")",
"<-",
"chan",
"Tuple",
"{",
"chans",
":=",
"snapshot",
"(",
"m",
")",
"\n",
"total",
":=",
"0",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"chans",
"{",
"total",
"+=",
"cap",
"(",
"c",
")",
"\n",
"}",
"\n",
"ch",
":=",
"make",
"(",
"chan",
"Tuple",
",",
"total",
")",
"\n",
"go",
"fanIn",
"(",
"chans",
",",
"ch",
")",
"\n",
"return",
"ch",
"\n",
"}"
] |
// IterBuffered returns a buffered iterator which could be used in a for range loop.
|
[
"IterBuffered",
"returns",
"a",
"buffered",
"iterator",
"which",
"could",
"be",
"used",
"in",
"a",
"for",
"range",
"loop",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L178-L187
|
146,569 |
orcaman/concurrent-map
|
concurrent_map.go
|
snapshot
|
func snapshot(m ConcurrentMap) (chans []chan Tuple) {
chans = make([]chan Tuple, SHARD_COUNT)
wg := sync.WaitGroup{}
wg.Add(SHARD_COUNT)
// Foreach shard.
for index, shard := range m {
go func(index int, shard *ConcurrentMapShared) {
// Foreach key, value pair.
shard.RLock()
chans[index] = make(chan Tuple, len(shard.items))
wg.Done()
for key, val := range shard.items {
chans[index] <- Tuple{key, val}
}
shard.RUnlock()
close(chans[index])
}(index, shard)
}
wg.Wait()
return chans
}
|
go
|
func snapshot(m ConcurrentMap) (chans []chan Tuple) {
chans = make([]chan Tuple, SHARD_COUNT)
wg := sync.WaitGroup{}
wg.Add(SHARD_COUNT)
// Foreach shard.
for index, shard := range m {
go func(index int, shard *ConcurrentMapShared) {
// Foreach key, value pair.
shard.RLock()
chans[index] = make(chan Tuple, len(shard.items))
wg.Done()
for key, val := range shard.items {
chans[index] <- Tuple{key, val}
}
shard.RUnlock()
close(chans[index])
}(index, shard)
}
wg.Wait()
return chans
}
|
[
"func",
"snapshot",
"(",
"m",
"ConcurrentMap",
")",
"(",
"chans",
"[",
"]",
"chan",
"Tuple",
")",
"{",
"chans",
"=",
"make",
"(",
"[",
"]",
"chan",
"Tuple",
",",
"SHARD_COUNT",
")",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"wg",
".",
"Add",
"(",
"SHARD_COUNT",
")",
"\n",
"// Foreach shard.",
"for",
"index",
",",
"shard",
":=",
"range",
"m",
"{",
"go",
"func",
"(",
"index",
"int",
",",
"shard",
"*",
"ConcurrentMapShared",
")",
"{",
"// Foreach key, value pair.",
"shard",
".",
"RLock",
"(",
")",
"\n",
"chans",
"[",
"index",
"]",
"=",
"make",
"(",
"chan",
"Tuple",
",",
"len",
"(",
"shard",
".",
"items",
")",
")",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"for",
"key",
",",
"val",
":=",
"range",
"shard",
".",
"items",
"{",
"chans",
"[",
"index",
"]",
"<-",
"Tuple",
"{",
"key",
",",
"val",
"}",
"\n",
"}",
"\n",
"shard",
".",
"RUnlock",
"(",
")",
"\n",
"close",
"(",
"chans",
"[",
"index",
"]",
")",
"\n",
"}",
"(",
"index",
",",
"shard",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"chans",
"\n",
"}"
] |
// Returns a array of channels that contains elements in each shard,
// which likely takes a snapshot of `m`.
// It returns once the size of each buffered channel is determined,
// before all the channels are populated using goroutines.
|
[
"Returns",
"a",
"array",
"of",
"channels",
"that",
"contains",
"elements",
"in",
"each",
"shard",
"which",
"likely",
"takes",
"a",
"snapshot",
"of",
"m",
".",
"It",
"returns",
"once",
"the",
"size",
"of",
"each",
"buffered",
"channel",
"is",
"determined",
"before",
"all",
"the",
"channels",
"are",
"populated",
"using",
"goroutines",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L193-L213
|
146,570 |
orcaman/concurrent-map
|
concurrent_map.go
|
fanIn
|
func fanIn(chans []chan Tuple, out chan Tuple) {
wg := sync.WaitGroup{}
wg.Add(len(chans))
for _, ch := range chans {
go func(ch chan Tuple) {
for t := range ch {
out <- t
}
wg.Done()
}(ch)
}
wg.Wait()
close(out)
}
|
go
|
func fanIn(chans []chan Tuple, out chan Tuple) {
wg := sync.WaitGroup{}
wg.Add(len(chans))
for _, ch := range chans {
go func(ch chan Tuple) {
for t := range ch {
out <- t
}
wg.Done()
}(ch)
}
wg.Wait()
close(out)
}
|
[
"func",
"fanIn",
"(",
"chans",
"[",
"]",
"chan",
"Tuple",
",",
"out",
"chan",
"Tuple",
")",
"{",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"wg",
".",
"Add",
"(",
"len",
"(",
"chans",
")",
")",
"\n",
"for",
"_",
",",
"ch",
":=",
"range",
"chans",
"{",
"go",
"func",
"(",
"ch",
"chan",
"Tuple",
")",
"{",
"for",
"t",
":=",
"range",
"ch",
"{",
"out",
"<-",
"t",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
"ch",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"out",
")",
"\n",
"}"
] |
// fanIn reads elements from channels `chans` into channel `out`
|
[
"fanIn",
"reads",
"elements",
"from",
"channels",
"chans",
"into",
"channel",
"out"
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L216-L229
|
146,571 |
orcaman/concurrent-map
|
concurrent_map.go
|
IterCb
|
func (m ConcurrentMap) IterCb(fn IterCb) {
for idx := range m {
shard := (m)[idx]
shard.RLock()
for key, value := range shard.items {
fn(key, value)
}
shard.RUnlock()
}
}
|
go
|
func (m ConcurrentMap) IterCb(fn IterCb) {
for idx := range m {
shard := (m)[idx]
shard.RLock()
for key, value := range shard.items {
fn(key, value)
}
shard.RUnlock()
}
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"IterCb",
"(",
"fn",
"IterCb",
")",
"{",
"for",
"idx",
":=",
"range",
"m",
"{",
"shard",
":=",
"(",
"m",
")",
"[",
"idx",
"]",
"\n",
"shard",
".",
"RLock",
"(",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"shard",
".",
"items",
"{",
"fn",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"shard",
".",
"RUnlock",
"(",
")",
"\n",
"}",
"\n",
"}"
] |
// Callback based iterator, cheapest way to read
// all elements in a map.
|
[
"Callback",
"based",
"iterator",
"cheapest",
"way",
"to",
"read",
"all",
"elements",
"in",
"a",
"map",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L251-L260
|
146,572 |
orcaman/concurrent-map
|
concurrent_map.go
|
MarshalJSON
|
func (m ConcurrentMap) MarshalJSON() ([]byte, error) {
// Create a temporary map, which will hold all item spread across shards.
tmp := make(map[string]interface{})
// Insert items to temporary map.
for item := range m.IterBuffered() {
tmp[item.Key] = item.Val
}
return json.Marshal(tmp)
}
|
go
|
func (m ConcurrentMap) MarshalJSON() ([]byte, error) {
// Create a temporary map, which will hold all item spread across shards.
tmp := make(map[string]interface{})
// Insert items to temporary map.
for item := range m.IterBuffered() {
tmp[item.Key] = item.Val
}
return json.Marshal(tmp)
}
|
[
"func",
"(",
"m",
"ConcurrentMap",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Create a temporary map, which will hold all item spread across shards.",
"tmp",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",
"// Insert items to temporary map.",
"for",
"item",
":=",
"range",
"m",
".",
"IterBuffered",
"(",
")",
"{",
"tmp",
"[",
"item",
".",
"Key",
"]",
"=",
"item",
".",
"Val",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"tmp",
")",
"\n",
"}"
] |
//Reviles ConcurrentMap "private" variables to json marshal.
|
[
"Reviles",
"ConcurrentMap",
"private",
"variables",
"to",
"json",
"marshal",
"."
] |
2693aad1ed7517c2bb5b3a42cb8fde88b941d89d
|
https://github.com/orcaman/concurrent-map/blob/2693aad1ed7517c2bb5b3a42cb8fde88b941d89d/concurrent_map.go#L294-L303
|
146,573 |
golang/example
|
gotypes/weave.go
|
include
|
func include(file, tag string) (string, error) {
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()
startre, err := regexp.Compile("!\\+" + tag + "$")
if err != nil {
return "", err
}
endre, err := regexp.Compile("!\\-" + tag + "$")
if err != nil {
return "", err
}
var text bytes.Buffer
in := bufio.NewScanner(f)
var on bool
for in.Scan() {
line := in.Text()
switch {
case startre.MatchString(line):
on = true
case endre.MatchString(line):
on = false
case on:
text.WriteByte('\t')
text.WriteString(line)
text.WriteByte('\n')
}
}
if text.Len() == 0 {
return "", fmt.Errorf("no lines of %s matched tag %q", file, tag)
}
return text.String(), nil
}
|
go
|
func include(file, tag string) (string, error) {
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()
startre, err := regexp.Compile("!\\+" + tag + "$")
if err != nil {
return "", err
}
endre, err := regexp.Compile("!\\-" + tag + "$")
if err != nil {
return "", err
}
var text bytes.Buffer
in := bufio.NewScanner(f)
var on bool
for in.Scan() {
line := in.Text()
switch {
case startre.MatchString(line):
on = true
case endre.MatchString(line):
on = false
case on:
text.WriteByte('\t')
text.WriteString(line)
text.WriteByte('\n')
}
}
if text.Len() == 0 {
return "", fmt.Errorf("no lines of %s matched tag %q", file, tag)
}
return text.String(), nil
}
|
[
"func",
"include",
"(",
"file",
",",
"tag",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"startre",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"\"",
"\\\\",
"\"",
"+",
"tag",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"endre",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"\"",
"\\\\",
"\"",
"+",
"tag",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"text",
"bytes",
".",
"Buffer",
"\n",
"in",
":=",
"bufio",
".",
"NewScanner",
"(",
"f",
")",
"\n",
"var",
"on",
"bool",
"\n",
"for",
"in",
".",
"Scan",
"(",
")",
"{",
"line",
":=",
"in",
".",
"Text",
"(",
")",
"\n",
"switch",
"{",
"case",
"startre",
".",
"MatchString",
"(",
"line",
")",
":",
"on",
"=",
"true",
"\n",
"case",
"endre",
".",
"MatchString",
"(",
"line",
")",
":",
"on",
"=",
"false",
"\n",
"case",
"on",
":",
"text",
".",
"WriteByte",
"(",
"'\\t'",
")",
"\n",
"text",
".",
"WriteString",
"(",
"line",
")",
"\n",
"text",
".",
"WriteByte",
"(",
"'\\n'",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"text",
".",
"Len",
"(",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"file",
",",
"tag",
")",
"\n",
"}",
"\n",
"return",
"text",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// include processes an included file, and returns the included text.
// Only lines between those matching !+tag and !-tag will be returned.
// This is true even if tag=="".
|
[
"include",
"processes",
"an",
"included",
"file",
"and",
"returns",
"the",
"included",
"text",
".",
"Only",
"lines",
"between",
"those",
"matching",
"!",
"+",
"tag",
"and",
"!",
"-",
"tag",
"will",
"be",
"returned",
".",
"This",
"is",
"true",
"even",
"if",
"tag",
"==",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/weave.go#L105-L141
|
146,574 |
golang/example
|
gotypes/weave.go
|
cleanListing
|
func cleanListing(text string) string {
lines := strings.Split(text, "\n")
// remove minimum number of leading tabs from all non-blank lines
tabs := 999
for i, line := range lines {
if strings.TrimSpace(line) == "" {
lines[i] = ""
} else {
if n := leadingTabs(line); n < tabs {
tabs = n
}
}
}
for i, line := range lines {
if line != "" {
line := line[tabs:]
lines[i] = line // remove leading tabs
}
}
// remove leading blank lines
for len(lines) > 0 && lines[0] == "" {
lines = lines[1:]
}
// remove trailing blank lines
for len(lines) > 0 && lines[len(lines)-1] == "" {
lines = lines[:len(lines)-1]
}
return strings.Join(lines, "\n")
}
|
go
|
func cleanListing(text string) string {
lines := strings.Split(text, "\n")
// remove minimum number of leading tabs from all non-blank lines
tabs := 999
for i, line := range lines {
if strings.TrimSpace(line) == "" {
lines[i] = ""
} else {
if n := leadingTabs(line); n < tabs {
tabs = n
}
}
}
for i, line := range lines {
if line != "" {
line := line[tabs:]
lines[i] = line // remove leading tabs
}
}
// remove leading blank lines
for len(lines) > 0 && lines[0] == "" {
lines = lines[1:]
}
// remove trailing blank lines
for len(lines) > 0 && lines[len(lines)-1] == "" {
lines = lines[:len(lines)-1]
}
return strings.Join(lines, "\n")
}
|
[
"func",
"cleanListing",
"(",
"text",
"string",
")",
"string",
"{",
"lines",
":=",
"strings",
".",
"Split",
"(",
"text",
",",
"\"",
"\\n",
"\"",
")",
"\n\n",
"// remove minimum number of leading tabs from all non-blank lines",
"tabs",
":=",
"999",
"\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"strings",
".",
"TrimSpace",
"(",
"line",
")",
"==",
"\"",
"\"",
"{",
"lines",
"[",
"i",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"if",
"n",
":=",
"leadingTabs",
"(",
"line",
")",
";",
"n",
"<",
"tabs",
"{",
"tabs",
"=",
"n",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"if",
"line",
"!=",
"\"",
"\"",
"{",
"line",
":=",
"line",
"[",
"tabs",
":",
"]",
"\n",
"lines",
"[",
"i",
"]",
"=",
"line",
"// remove leading tabs",
"\n",
"}",
"\n",
"}",
"\n\n",
"// remove leading blank lines",
"for",
"len",
"(",
"lines",
")",
">",
"0",
"&&",
"lines",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"lines",
"=",
"lines",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"// remove trailing blank lines",
"for",
"len",
"(",
"lines",
")",
">",
"0",
"&&",
"lines",
"[",
"len",
"(",
"lines",
")",
"-",
"1",
"]",
"==",
"\"",
"\"",
"{",
"lines",
"=",
"lines",
"[",
":",
"len",
"(",
"lines",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"lines",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}"
] |
// cleanListing removes entirely blank leading and trailing lines from
// text, and removes n leading tabs.
|
[
"cleanListing",
"removes",
"entirely",
"blank",
"leading",
"and",
"trailing",
"lines",
"from",
"text",
"and",
"removes",
"n",
"leading",
"tabs",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/weave.go#L151-L181
|
146,575 |
golang/example
|
gotypes/typeandvalue/main.go
|
nodeString
|
func nodeString(n ast.Node) string {
var buf bytes.Buffer
format.Node(&buf, fset, n)
return buf.String()
}
|
go
|
func nodeString(n ast.Node) string {
var buf bytes.Buffer
format.Node(&buf, fset, n)
return buf.String()
}
|
[
"func",
"nodeString",
"(",
"n",
"ast",
".",
"Node",
")",
"string",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"format",
".",
"Node",
"(",
"&",
"buf",
",",
"fset",
",",
"n",
")",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
"\n",
"}"
] |
// nodeString formats a syntax tree in the style of gofmt.
|
[
"nodeString",
"formats",
"a",
"syntax",
"tree",
"in",
"the",
"style",
"of",
"gofmt",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/typeandvalue/main.go#L61-L65
|
146,576 |
golang/example
|
gotypes/typeandvalue/main.go
|
mode
|
func mode(tv types.TypeAndValue) string {
s := ""
if tv.IsVoid() {
s += ",void"
}
if tv.IsType() {
s += ",type"
}
if tv.IsBuiltin() {
s += ",builtin"
}
if tv.IsValue() {
s += ",value"
}
if tv.IsNil() {
s += ",nil"
}
if tv.Addressable() {
s += ",addressable"
}
if tv.Assignable() {
s += ",assignable"
}
if tv.HasOk() {
s += ",ok"
}
return s[1:]
}
|
go
|
func mode(tv types.TypeAndValue) string {
s := ""
if tv.IsVoid() {
s += ",void"
}
if tv.IsType() {
s += ",type"
}
if tv.IsBuiltin() {
s += ",builtin"
}
if tv.IsValue() {
s += ",value"
}
if tv.IsNil() {
s += ",nil"
}
if tv.Addressable() {
s += ",addressable"
}
if tv.Assignable() {
s += ",assignable"
}
if tv.HasOk() {
s += ",ok"
}
return s[1:]
}
|
[
"func",
"mode",
"(",
"tv",
"types",
".",
"TypeAndValue",
")",
"string",
"{",
"s",
":=",
"\"",
"\"",
"\n",
"if",
"tv",
".",
"IsVoid",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"IsType",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"IsBuiltin",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"IsValue",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"IsNil",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"Addressable",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"Assignable",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"tv",
".",
"HasOk",
"(",
")",
"{",
"s",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"s",
"[",
"1",
":",
"]",
"\n",
"}"
] |
// mode returns a string describing the mode of an expression.
|
[
"mode",
"returns",
"a",
"string",
"describing",
"the",
"mode",
"of",
"an",
"expression",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/typeandvalue/main.go#L68-L95
|
146,577 |
golang/example
|
outyet/main.go
|
NewServer
|
func NewServer(version, url string, period time.Duration) *Server {
s := &Server{version: version, url: url, period: period}
go s.poll()
return s
}
|
go
|
func NewServer(version, url string, period time.Duration) *Server {
s := &Server{version: version, url: url, period: period}
go s.poll()
return s
}
|
[
"func",
"NewServer",
"(",
"version",
",",
"url",
"string",
",",
"period",
"time",
".",
"Duration",
")",
"*",
"Server",
"{",
"s",
":=",
"&",
"Server",
"{",
"version",
":",
"version",
",",
"url",
":",
"url",
",",
"period",
":",
"period",
"}",
"\n",
"go",
"s",
".",
"poll",
"(",
")",
"\n",
"return",
"s",
"\n",
"}"
] |
// NewServer returns an initialized outyet server.
|
[
"NewServer",
"returns",
"an",
"initialized",
"outyet",
"server",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L70-L74
|
146,578 |
golang/example
|
outyet/main.go
|
poll
|
func (s *Server) poll() {
for !isTagged(s.url) {
pollSleep(s.period)
}
s.mu.Lock()
s.yes = true
s.mu.Unlock()
pollDone()
}
|
go
|
func (s *Server) poll() {
for !isTagged(s.url) {
pollSleep(s.period)
}
s.mu.Lock()
s.yes = true
s.mu.Unlock()
pollDone()
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"poll",
"(",
")",
"{",
"for",
"!",
"isTagged",
"(",
"s",
".",
"url",
")",
"{",
"pollSleep",
"(",
"s",
".",
"period",
")",
"\n",
"}",
"\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"yes",
"=",
"true",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"pollDone",
"(",
")",
"\n",
"}"
] |
// poll polls the change URL for the specified period until the tag exists.
// Then it sets the Server's yes field true and exits.
|
[
"poll",
"polls",
"the",
"change",
"URL",
"for",
"the",
"specified",
"period",
"until",
"the",
"tag",
"exists",
".",
"Then",
"it",
"sets",
"the",
"Server",
"s",
"yes",
"field",
"true",
"and",
"exits",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L78-L86
|
146,579 |
golang/example
|
outyet/main.go
|
isTagged
|
func isTagged(url string) bool {
pollCount.Add(1)
r, err := http.Head(url)
if err != nil {
log.Print(err)
pollError.Set(err.Error())
pollErrorCount.Add(1)
return false
}
return r.StatusCode == http.StatusOK
}
|
go
|
func isTagged(url string) bool {
pollCount.Add(1)
r, err := http.Head(url)
if err != nil {
log.Print(err)
pollError.Set(err.Error())
pollErrorCount.Add(1)
return false
}
return r.StatusCode == http.StatusOK
}
|
[
"func",
"isTagged",
"(",
"url",
"string",
")",
"bool",
"{",
"pollCount",
".",
"Add",
"(",
"1",
")",
"\n",
"r",
",",
"err",
":=",
"http",
".",
"Head",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"err",
")",
"\n",
"pollError",
".",
"Set",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"pollErrorCount",
".",
"Add",
"(",
"1",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"return",
"r",
".",
"StatusCode",
"==",
"http",
".",
"StatusOK",
"\n",
"}"
] |
// isTagged makes an HTTP HEAD request to the given URL and reports whether it
// returned a 200 OK response.
|
[
"isTagged",
"makes",
"an",
"HTTP",
"HEAD",
"request",
"to",
"the",
"given",
"URL",
"and",
"reports",
"whether",
"it",
"returned",
"a",
"200",
"OK",
"response",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L96-L106
|
146,580 |
golang/example
|
outyet/main.go
|
ServeHTTP
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hitCount.Add(1)
s.mu.RLock()
data := struct {
URL string
Version string
Yes bool
}{
s.url,
s.version,
s.yes,
}
s.mu.RUnlock()
err := tmpl.Execute(w, data)
if err != nil {
log.Print(err)
}
}
|
go
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hitCount.Add(1)
s.mu.RLock()
data := struct {
URL string
Version string
Yes bool
}{
s.url,
s.version,
s.yes,
}
s.mu.RUnlock()
err := tmpl.Execute(w, data)
if err != nil {
log.Print(err)
}
}
|
[
"func",
"(",
"s",
"*",
"Server",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"hitCount",
".",
"Add",
"(",
"1",
")",
"\n",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"data",
":=",
"struct",
"{",
"URL",
"string",
"\n",
"Version",
"string",
"\n",
"Yes",
"bool",
"\n",
"}",
"{",
"s",
".",
"url",
",",
"s",
".",
"version",
",",
"s",
".",
"yes",
",",
"}",
"\n",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"err",
":=",
"tmpl",
".",
"Execute",
"(",
"w",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// ServeHTTP implements the HTTP user interface.
|
[
"ServeHTTP",
"implements",
"the",
"HTTP",
"user",
"interface",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/outyet/main.go#L109-L126
|
146,581 |
golang/example
|
gotypes/lookup/lookup.go
|
main
|
func main() {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "hello.go", hello, parser.ParseComments)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check("cmd/hello", fset, []*ast.File{f}, nil)
if err != nil {
log.Fatal(err) // type error
}
// Each comment contains a name.
// Look up that name in the innermost scope enclosing the comment.
for _, comment := range f.Comments {
pos := comment.Pos()
name := strings.TrimSpace(comment.Text())
fmt.Printf("At %s,\t%q = ", fset.Position(pos), name)
inner := pkg.Scope().Innermost(pos)
if _, obj := inner.LookupParent(name, pos); obj != nil {
fmt.Println(obj)
} else {
fmt.Println("not found")
}
}
}
|
go
|
func main() {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "hello.go", hello, parser.ParseComments)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check("cmd/hello", fset, []*ast.File{f}, nil)
if err != nil {
log.Fatal(err) // type error
}
// Each comment contains a name.
// Look up that name in the innermost scope enclosing the comment.
for _, comment := range f.Comments {
pos := comment.Pos()
name := strings.TrimSpace(comment.Text())
fmt.Printf("At %s,\t%q = ", fset.Position(pos), name)
inner := pkg.Scope().Innermost(pos)
if _, obj := inner.LookupParent(name, pos); obj != nil {
fmt.Println(obj)
} else {
fmt.Println("not found")
}
}
}
|
[
"func",
"main",
"(",
")",
"{",
"fset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"f",
",",
"err",
":=",
"parser",
".",
"ParseFile",
"(",
"fset",
",",
"\"",
"\"",
",",
"hello",
",",
"parser",
".",
"ParseComments",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"// parse error",
"\n",
"}",
"\n\n",
"conf",
":=",
"types",
".",
"Config",
"{",
"Importer",
":",
"importer",
".",
"Default",
"(",
")",
"}",
"\n",
"pkg",
",",
"err",
":=",
"conf",
".",
"Check",
"(",
"\"",
"\"",
",",
"fset",
",",
"[",
"]",
"*",
"ast",
".",
"File",
"{",
"f",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"// type error",
"\n",
"}",
"\n\n",
"// Each comment contains a name.",
"// Look up that name in the innermost scope enclosing the comment.",
"for",
"_",
",",
"comment",
":=",
"range",
"f",
".",
"Comments",
"{",
"pos",
":=",
"comment",
".",
"Pos",
"(",
")",
"\n",
"name",
":=",
"strings",
".",
"TrimSpace",
"(",
"comment",
".",
"Text",
"(",
")",
")",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"fset",
".",
"Position",
"(",
"pos",
")",
",",
"name",
")",
"\n",
"inner",
":=",
"pkg",
".",
"Scope",
"(",
")",
".",
"Innermost",
"(",
"pos",
")",
"\n",
"if",
"_",
",",
"obj",
":=",
"inner",
".",
"LookupParent",
"(",
"name",
",",
"pos",
")",
";",
"obj",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"obj",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
//!-input
//!+main
|
[
"!",
"-",
"input",
"!",
"+",
"main"
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/lookup/lookup.go#L36-L62
|
146,582 |
golang/example
|
gotypes/implements/main.go
|
main
|
func main() {
// Parse one file.
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "input.go", input, 0)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check("hello", fset, []*ast.File{f}, nil)
if err != nil {
log.Fatal(err) // type error
}
//!+implements
// Find all named types at package level.
var allNamed []*types.Named
for _, name := range pkg.Scope().Names() {
if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok {
allNamed = append(allNamed, obj.Type().(*types.Named))
}
}
// Test assignability of all distinct pairs of
// named types (T, U) where U is an interface.
for _, T := range allNamed {
for _, U := range allNamed {
if T == U || !types.IsInterface(U) {
continue
}
if types.AssignableTo(T, U) {
fmt.Printf("%s satisfies %s\n", T, U)
} else if !types.IsInterface(T) &&
types.AssignableTo(types.NewPointer(T), U) {
fmt.Printf("%s satisfies %s\n", types.NewPointer(T), U)
}
}
}
//!-implements
}
|
go
|
func main() {
// Parse one file.
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "input.go", input, 0)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check("hello", fset, []*ast.File{f}, nil)
if err != nil {
log.Fatal(err) // type error
}
//!+implements
// Find all named types at package level.
var allNamed []*types.Named
for _, name := range pkg.Scope().Names() {
if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok {
allNamed = append(allNamed, obj.Type().(*types.Named))
}
}
// Test assignability of all distinct pairs of
// named types (T, U) where U is an interface.
for _, T := range allNamed {
for _, U := range allNamed {
if T == U || !types.IsInterface(U) {
continue
}
if types.AssignableTo(T, U) {
fmt.Printf("%s satisfies %s\n", T, U)
} else if !types.IsInterface(T) &&
types.AssignableTo(types.NewPointer(T), U) {
fmt.Printf("%s satisfies %s\n", types.NewPointer(T), U)
}
}
}
//!-implements
}
|
[
"func",
"main",
"(",
")",
"{",
"// Parse one file.",
"fset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"f",
",",
"err",
":=",
"parser",
".",
"ParseFile",
"(",
"fset",
",",
"\"",
"\"",
",",
"input",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"// parse error",
"\n",
"}",
"\n",
"conf",
":=",
"types",
".",
"Config",
"{",
"Importer",
":",
"importer",
".",
"Default",
"(",
")",
"}",
"\n",
"pkg",
",",
"err",
":=",
"conf",
".",
"Check",
"(",
"\"",
"\"",
",",
"fset",
",",
"[",
"]",
"*",
"ast",
".",
"File",
"{",
"f",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"// type error",
"\n",
"}",
"\n\n",
"//!+implements",
"// Find all named types at package level.",
"var",
"allNamed",
"[",
"]",
"*",
"types",
".",
"Named",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"pkg",
".",
"Scope",
"(",
")",
".",
"Names",
"(",
")",
"{",
"if",
"obj",
",",
"ok",
":=",
"pkg",
".",
"Scope",
"(",
")",
".",
"Lookup",
"(",
"name",
")",
".",
"(",
"*",
"types",
".",
"TypeName",
")",
";",
"ok",
"{",
"allNamed",
"=",
"append",
"(",
"allNamed",
",",
"obj",
".",
"Type",
"(",
")",
".",
"(",
"*",
"types",
".",
"Named",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Test assignability of all distinct pairs of",
"// named types (T, U) where U is an interface.",
"for",
"_",
",",
"T",
":=",
"range",
"allNamed",
"{",
"for",
"_",
",",
"U",
":=",
"range",
"allNamed",
"{",
"if",
"T",
"==",
"U",
"||",
"!",
"types",
".",
"IsInterface",
"(",
"U",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"types",
".",
"AssignableTo",
"(",
"T",
",",
"U",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"T",
",",
"U",
")",
"\n",
"}",
"else",
"if",
"!",
"types",
".",
"IsInterface",
"(",
"T",
")",
"&&",
"types",
".",
"AssignableTo",
"(",
"types",
".",
"NewPointer",
"(",
"T",
")",
",",
"U",
")",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"types",
".",
"NewPointer",
"(",
"T",
")",
",",
"U",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"//!-implements",
"}"
] |
//!-input
|
[
"!",
"-",
"input"
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/gotypes/implements/main.go#L29-L67
|
146,583 |
golang/example
|
template/main.go
|
indexHandler
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
data := &Index{
Title: "Image gallery",
Body: "Welcome to the image gallery.",
}
for name, img := range images {
data.Links = append(data.Links, Link{
URL: "/image/" + name,
Title: img.Title,
})
}
if err := indexTemplate.Execute(w, data); err != nil {
log.Println(err)
}
}
|
go
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
data := &Index{
Title: "Image gallery",
Body: "Welcome to the image gallery.",
}
for name, img := range images {
data.Links = append(data.Links, Link{
URL: "/image/" + name,
Title: img.Title,
})
}
if err := indexTemplate.Execute(w, data); err != nil {
log.Println(err)
}
}
|
[
"func",
"indexHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"data",
":=",
"&",
"Index",
"{",
"Title",
":",
"\"",
"\"",
",",
"Body",
":",
"\"",
"\"",
",",
"}",
"\n",
"for",
"name",
",",
"img",
":=",
"range",
"images",
"{",
"data",
".",
"Links",
"=",
"append",
"(",
"data",
".",
"Links",
",",
"Link",
"{",
"URL",
":",
"\"",
"\"",
"+",
"name",
",",
"Title",
":",
"img",
".",
"Title",
",",
"}",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"indexTemplate",
".",
"Execute",
"(",
"w",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// indexHandler is an HTTP handler that serves the index page.
|
[
"indexHandler",
"is",
"an",
"HTTP",
"handler",
"that",
"serves",
"the",
"index",
"page",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/template/main.go#L55-L69
|
146,584 |
golang/example
|
template/main.go
|
imageHandler
|
func imageHandler(w http.ResponseWriter, r *http.Request) {
data, ok := images[strings.TrimPrefix(r.URL.Path, "/image/")]
if !ok {
http.NotFound(w, r)
return
}
if err := imageTemplate.Execute(w, data); err != nil {
log.Println(err)
}
}
|
go
|
func imageHandler(w http.ResponseWriter, r *http.Request) {
data, ok := images[strings.TrimPrefix(r.URL.Path, "/image/")]
if !ok {
http.NotFound(w, r)
return
}
if err := imageTemplate.Execute(w, data); err != nil {
log.Println(err)
}
}
|
[
"func",
"imageHandler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"data",
",",
"ok",
":=",
"images",
"[",
"strings",
".",
"TrimPrefix",
"(",
"r",
".",
"URL",
".",
"Path",
",",
"\"",
"\"",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"http",
".",
"NotFound",
"(",
"w",
",",
"r",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
":=",
"imageTemplate",
".",
"Execute",
"(",
"w",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Println",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// imageHandler is an HTTP handler that serves the image pages.
|
[
"imageHandler",
"is",
"an",
"HTTP",
"handler",
"that",
"serves",
"the",
"image",
"pages",
"."
] |
46695d81d1fae905a270fb7db8a4d11a334562fe
|
https://github.com/golang/example/blob/46695d81d1fae905a270fb7db8a4d11a334562fe/template/main.go#L82-L91
|
146,585 |
kardianos/govendor
|
context/label.go
|
FindLabel
|
func FindLabel(version string, labels []Label) Label {
list := make([]*labelAnalysis, 0, 6)
exact := strings.HasPrefix(version, "=")
version = strings.TrimPrefix(version, "=")
for _, label := range labels {
if exact {
if label.Text == version {
return label
}
continue
}
if !strings.HasPrefix(label.Text, version) {
continue
}
remain := strings.TrimPrefix(label.Text, version)
if len(remain) > 0 {
next := remain[0]
// The stated version must either be the full label,
// followed by a "." or "-".
if next != '.' && next != '-' {
continue
}
}
list = append(list, &labelAnalysis{
Label: label,
Groups: make([]labelGroup, 0, 3),
})
}
if len(list) == 0 {
return Label{Source: LabelNone}
}
buf := &bytes.Buffer{}
for _, item := range list {
item.fillSections(buf)
buf.Reset()
}
sort.Sort(labelAnalysisList(list))
return list[0].Label
}
|
go
|
func FindLabel(version string, labels []Label) Label {
list := make([]*labelAnalysis, 0, 6)
exact := strings.HasPrefix(version, "=")
version = strings.TrimPrefix(version, "=")
for _, label := range labels {
if exact {
if label.Text == version {
return label
}
continue
}
if !strings.HasPrefix(label.Text, version) {
continue
}
remain := strings.TrimPrefix(label.Text, version)
if len(remain) > 0 {
next := remain[0]
// The stated version must either be the full label,
// followed by a "." or "-".
if next != '.' && next != '-' {
continue
}
}
list = append(list, &labelAnalysis{
Label: label,
Groups: make([]labelGroup, 0, 3),
})
}
if len(list) == 0 {
return Label{Source: LabelNone}
}
buf := &bytes.Buffer{}
for _, item := range list {
item.fillSections(buf)
buf.Reset()
}
sort.Sort(labelAnalysisList(list))
return list[0].Label
}
|
[
"func",
"FindLabel",
"(",
"version",
"string",
",",
"labels",
"[",
"]",
"Label",
")",
"Label",
"{",
"list",
":=",
"make",
"(",
"[",
"]",
"*",
"labelAnalysis",
",",
"0",
",",
"6",
")",
"\n\n",
"exact",
":=",
"strings",
".",
"HasPrefix",
"(",
"version",
",",
"\"",
"\"",
")",
"\n",
"version",
"=",
"strings",
".",
"TrimPrefix",
"(",
"version",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"label",
":=",
"range",
"labels",
"{",
"if",
"exact",
"{",
"if",
"label",
".",
"Text",
"==",
"version",
"{",
"return",
"label",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"label",
".",
"Text",
",",
"version",
")",
"{",
"continue",
"\n",
"}",
"\n",
"remain",
":=",
"strings",
".",
"TrimPrefix",
"(",
"label",
".",
"Text",
",",
"version",
")",
"\n",
"if",
"len",
"(",
"remain",
")",
">",
"0",
"{",
"next",
":=",
"remain",
"[",
"0",
"]",
"\n",
"// The stated version must either be the full label,",
"// followed by a \".\" or \"-\".",
"if",
"next",
"!=",
"'.'",
"&&",
"next",
"!=",
"'-'",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"list",
"=",
"append",
"(",
"list",
",",
"&",
"labelAnalysis",
"{",
"Label",
":",
"label",
",",
"Groups",
":",
"make",
"(",
"[",
"]",
"labelGroup",
",",
"0",
",",
"3",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"list",
")",
"==",
"0",
"{",
"return",
"Label",
"{",
"Source",
":",
"LabelNone",
"}",
"\n",
"}",
"\n\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"list",
"{",
"item",
".",
"fillSections",
"(",
"buf",
")",
"\n",
"buf",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"labelAnalysisList",
"(",
"list",
")",
")",
"\n",
"return",
"list",
"[",
"0",
"]",
".",
"Label",
"\n",
"}"
] |
// FindLabel matches a single label from a list of labels, given a version.
// If the returning label.Source is LabelNone, then no labels match.
//
// Labels are first broken into sections separated by "-". Shortest wins.
// If they have the same number of above sections, then they are compared
// further. Number sequences are treated as numbers. Numbers do not need a
// separator. The "." is a break point as well.
|
[
"FindLabel",
"matches",
"a",
"single",
"label",
"from",
"a",
"list",
"of",
"labels",
"given",
"a",
"version",
".",
"If",
"the",
"returning",
"label",
".",
"Source",
"is",
"LabelNone",
"then",
"no",
"labels",
"match",
".",
"Labels",
"are",
"first",
"broken",
"into",
"sections",
"separated",
"by",
"-",
".",
"Shortest",
"wins",
".",
"If",
"they",
"have",
"the",
"same",
"number",
"of",
"above",
"sections",
"then",
"they",
"are",
"compared",
"further",
".",
"Number",
"sequences",
"are",
"treated",
"as",
"numbers",
".",
"Numbers",
"do",
"not",
"need",
"a",
"separator",
".",
"The",
".",
"is",
"a",
"break",
"point",
"as",
"well",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/label.go#L199-L240
|
146,586 |
kardianos/govendor
|
context/version.go
|
isVersion
|
func isVersion(s string) bool {
hasPunct := false
onlyNumber := true
onlyHexLetter := true
for _, r := range s {
isNumber := unicode.IsNumber(r)
isLetter := unicode.IsLetter(r)
hasPunct = hasPunct || unicode.IsPunct(r)
onlyNumber = onlyNumber && isNumber
if isLetter {
low := unicode.ToLower(r)
onlyHexLetter = onlyHexLetter && low <= 'f'
}
}
if hasPunct {
return true
}
if !onlyHexLetter {
return true
}
num, err := strconv.ParseInt(s, 10, 64)
if err == nil {
if num > 100 {
return false // numeric revision.
}
}
if len(s) > 5 && onlyHexLetter {
return false // hex revision
}
return true
}
|
go
|
func isVersion(s string) bool {
hasPunct := false
onlyNumber := true
onlyHexLetter := true
for _, r := range s {
isNumber := unicode.IsNumber(r)
isLetter := unicode.IsLetter(r)
hasPunct = hasPunct || unicode.IsPunct(r)
onlyNumber = onlyNumber && isNumber
if isLetter {
low := unicode.ToLower(r)
onlyHexLetter = onlyHexLetter && low <= 'f'
}
}
if hasPunct {
return true
}
if !onlyHexLetter {
return true
}
num, err := strconv.ParseInt(s, 10, 64)
if err == nil {
if num > 100 {
return false // numeric revision.
}
}
if len(s) > 5 && onlyHexLetter {
return false // hex revision
}
return true
}
|
[
"func",
"isVersion",
"(",
"s",
"string",
")",
"bool",
"{",
"hasPunct",
":=",
"false",
"\n",
"onlyNumber",
":=",
"true",
"\n",
"onlyHexLetter",
":=",
"true",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"isNumber",
":=",
"unicode",
".",
"IsNumber",
"(",
"r",
")",
"\n",
"isLetter",
":=",
"unicode",
".",
"IsLetter",
"(",
"r",
")",
"\n\n",
"hasPunct",
"=",
"hasPunct",
"||",
"unicode",
".",
"IsPunct",
"(",
"r",
")",
"\n",
"onlyNumber",
"=",
"onlyNumber",
"&&",
"isNumber",
"\n\n",
"if",
"isLetter",
"{",
"low",
":=",
"unicode",
".",
"ToLower",
"(",
"r",
")",
"\n",
"onlyHexLetter",
"=",
"onlyHexLetter",
"&&",
"low",
"<=",
"'f'",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"hasPunct",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"!",
"onlyHexLetter",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"num",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"s",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"num",
">",
"100",
"{",
"return",
"false",
"// numeric revision.",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"s",
")",
">",
"5",
"&&",
"onlyHexLetter",
"{",
"return",
"false",
"// hex revision",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// IsVersion returns true if the string is a version.
|
[
"IsVersion",
"returns",
"true",
"if",
"the",
"string",
"is",
"a",
"version",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/version.go#L13-L47
|
146,587 |
kardianos/govendor
|
context/path.go
|
isStdLib
|
func (ctx *Context) isStdLib(importPath string) (yes bool, err error) {
if importPath == "builtin" || importPath == "unsafe" || importPath == "C" {
yes = true
return
}
dir := filepath.Join(ctx.Goroot, importPath)
fi, _ := os.Stat(dir)
if fi == nil {
return
}
if !fi.IsDir() {
return
}
yes, err = hasGoFileInFolder(dir)
return
}
|
go
|
func (ctx *Context) isStdLib(importPath string) (yes bool, err error) {
if importPath == "builtin" || importPath == "unsafe" || importPath == "C" {
yes = true
return
}
dir := filepath.Join(ctx.Goroot, importPath)
fi, _ := os.Stat(dir)
if fi == nil {
return
}
if !fi.IsDir() {
return
}
yes, err = hasGoFileInFolder(dir)
return
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"isStdLib",
"(",
"importPath",
"string",
")",
"(",
"yes",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"importPath",
"==",
"\"",
"\"",
"||",
"importPath",
"==",
"\"",
"\"",
"||",
"importPath",
"==",
"\"",
"\"",
"{",
"yes",
"=",
"true",
"\n",
"return",
"\n",
"}",
"\n\n",
"dir",
":=",
"filepath",
".",
"Join",
"(",
"ctx",
".",
"Goroot",
",",
"importPath",
")",
"\n",
"fi",
",",
"_",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
"\n",
"if",
"fi",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"\n",
"}",
"\n\n",
"yes",
",",
"err",
"=",
"hasGoFileInFolder",
"(",
"dir",
")",
"\n",
"return",
"\n",
"}"
] |
// Import path is in GOROOT or is a special package.
|
[
"Import",
"path",
"is",
"in",
"GOROOT",
"or",
"is",
"a",
"special",
"package",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L16-L33
|
146,588 |
kardianos/govendor
|
context/path.go
|
findImportDir
|
func (ctx *Context) findImportDir(relative, importPath string) (dir, gopath string, err error) {
if importPath == "builtin" || importPath == "unsafe" || importPath == "C" {
return filepath.Join(ctx.Goroot, importPath), ctx.Goroot, nil
}
if len(relative) != 0 {
rel := relative
for {
look := filepath.Join(rel, ctx.VendorDiscoverFolder, importPath)
nextRel := filepath.Join(rel, "..")
if rel == nextRel {
break
}
rel = nextRel
fi, err := os.Stat(look)
if os.IsNotExist(err) {
continue
}
if err != nil {
continue
}
if !fi.IsDir() {
continue
}
for _, gopath = range ctx.GopathList {
if pathos.FileHasPrefix(look, gopath) {
hasGo, err := hasGoFileInFolder(look)
if err != nil {
return "", "", err
}
if hasGo {
return look, gopath, nil
}
}
}
}
}
for _, gopath = range ctx.GopathList {
dir := filepath.Join(gopath, importPath)
fi, err := os.Stat(dir)
if os.IsNotExist(err) {
continue
}
if fi == nil {
continue
}
if !fi.IsDir() {
continue
}
return dir, gopath, nil
}
return "", "", ErrNotInGOPATH{importPath}
}
|
go
|
func (ctx *Context) findImportDir(relative, importPath string) (dir, gopath string, err error) {
if importPath == "builtin" || importPath == "unsafe" || importPath == "C" {
return filepath.Join(ctx.Goroot, importPath), ctx.Goroot, nil
}
if len(relative) != 0 {
rel := relative
for {
look := filepath.Join(rel, ctx.VendorDiscoverFolder, importPath)
nextRel := filepath.Join(rel, "..")
if rel == nextRel {
break
}
rel = nextRel
fi, err := os.Stat(look)
if os.IsNotExist(err) {
continue
}
if err != nil {
continue
}
if !fi.IsDir() {
continue
}
for _, gopath = range ctx.GopathList {
if pathos.FileHasPrefix(look, gopath) {
hasGo, err := hasGoFileInFolder(look)
if err != nil {
return "", "", err
}
if hasGo {
return look, gopath, nil
}
}
}
}
}
for _, gopath = range ctx.GopathList {
dir := filepath.Join(gopath, importPath)
fi, err := os.Stat(dir)
if os.IsNotExist(err) {
continue
}
if fi == nil {
continue
}
if !fi.IsDir() {
continue
}
return dir, gopath, nil
}
return "", "", ErrNotInGOPATH{importPath}
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"findImportDir",
"(",
"relative",
",",
"importPath",
"string",
")",
"(",
"dir",
",",
"gopath",
"string",
",",
"err",
"error",
")",
"{",
"if",
"importPath",
"==",
"\"",
"\"",
"||",
"importPath",
"==",
"\"",
"\"",
"||",
"importPath",
"==",
"\"",
"\"",
"{",
"return",
"filepath",
".",
"Join",
"(",
"ctx",
".",
"Goroot",
",",
"importPath",
")",
",",
"ctx",
".",
"Goroot",
",",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"relative",
")",
"!=",
"0",
"{",
"rel",
":=",
"relative",
"\n",
"for",
"{",
"look",
":=",
"filepath",
".",
"Join",
"(",
"rel",
",",
"ctx",
".",
"VendorDiscoverFolder",
",",
"importPath",
")",
"\n",
"nextRel",
":=",
"filepath",
".",
"Join",
"(",
"rel",
",",
"\"",
"\"",
")",
"\n",
"if",
"rel",
"==",
"nextRel",
"{",
"break",
"\n",
"}",
"\n",
"rel",
"=",
"nextRel",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"look",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"gopath",
"=",
"range",
"ctx",
".",
"GopathList",
"{",
"if",
"pathos",
".",
"FileHasPrefix",
"(",
"look",
",",
"gopath",
")",
"{",
"hasGo",
",",
"err",
":=",
"hasGoFileInFolder",
"(",
"look",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"hasGo",
"{",
"return",
"look",
",",
"gopath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"}",
"\n",
"for",
"_",
",",
"gopath",
"=",
"range",
"ctx",
".",
"GopathList",
"{",
"dir",
":=",
"filepath",
".",
"Join",
"(",
"gopath",
",",
"importPath",
")",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"fi",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"return",
"dir",
",",
"gopath",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrNotInGOPATH",
"{",
"importPath",
"}",
"\n",
"}"
] |
// findImportDir finds the absolute directory. If rel is empty vendor folders
// are not looked in.
|
[
"findImportDir",
"finds",
"the",
"absolute",
"directory",
".",
"If",
"rel",
"is",
"empty",
"vendor",
"folders",
"are",
"not",
"looked",
"in",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L37-L90
|
146,589 |
kardianos/govendor
|
context/path.go
|
findImportPath
|
func (ctx *Context) findImportPath(dir string) (importPath, gopath string, err error) {
dirResolved, err := filepath.EvalSymlinks(dir)
if err != nil {
return "", "", err
}
dirs := make([]string, 1)
dirs = append(dirs, dir)
if dir != dirResolved {
dirs = append(dirs, dirResolved)
}
for _, gopath := range ctx.GopathList {
for _, dir := range dirs {
if pathos.FileHasPrefix(dir, gopath) || pathos.FileStringEquals(dir, gopath) {
importPath = pathos.FileTrimPrefix(dir, gopath)
importPath = pathos.SlashToImportPath(importPath)
return importPath, gopath, nil
}
}
}
return "", "", ErrNotInGOPATH{dir}
}
|
go
|
func (ctx *Context) findImportPath(dir string) (importPath, gopath string, err error) {
dirResolved, err := filepath.EvalSymlinks(dir)
if err != nil {
return "", "", err
}
dirs := make([]string, 1)
dirs = append(dirs, dir)
if dir != dirResolved {
dirs = append(dirs, dirResolved)
}
for _, gopath := range ctx.GopathList {
for _, dir := range dirs {
if pathos.FileHasPrefix(dir, gopath) || pathos.FileStringEquals(dir, gopath) {
importPath = pathos.FileTrimPrefix(dir, gopath)
importPath = pathos.SlashToImportPath(importPath)
return importPath, gopath, nil
}
}
}
return "", "", ErrNotInGOPATH{dir}
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"findImportPath",
"(",
"dir",
"string",
")",
"(",
"importPath",
",",
"gopath",
"string",
",",
"err",
"error",
")",
"{",
"dirResolved",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"dirs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"1",
")",
"\n",
"dirs",
"=",
"append",
"(",
"dirs",
",",
"dir",
")",
"\n",
"if",
"dir",
"!=",
"dirResolved",
"{",
"dirs",
"=",
"append",
"(",
"dirs",
",",
"dirResolved",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"gopath",
":=",
"range",
"ctx",
".",
"GopathList",
"{",
"for",
"_",
",",
"dir",
":=",
"range",
"dirs",
"{",
"if",
"pathos",
".",
"FileHasPrefix",
"(",
"dir",
",",
"gopath",
")",
"||",
"pathos",
".",
"FileStringEquals",
"(",
"dir",
",",
"gopath",
")",
"{",
"importPath",
"=",
"pathos",
".",
"FileTrimPrefix",
"(",
"dir",
",",
"gopath",
")",
"\n",
"importPath",
"=",
"pathos",
".",
"SlashToImportPath",
"(",
"importPath",
")",
"\n",
"return",
"importPath",
",",
"gopath",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"ErrNotInGOPATH",
"{",
"dir",
"}",
"\n",
"}"
] |
// findImportPath takes a absolute directory and returns the import path and go path.
|
[
"findImportPath",
"takes",
"a",
"absolute",
"directory",
"and",
"returns",
"the",
"import",
"path",
"and",
"go",
"path",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L93-L114
|
146,590 |
kardianos/govendor
|
context/path.go
|
RemovePackage
|
func RemovePackage(path, root string, tree bool) error {
// Ensure the path is empty of files.
dir, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
// Remove package files.
fl, err := dir.Readdir(-1)
dir.Close()
if err != nil {
return err
}
for _, fi := range fl {
fullPath := filepath.Join(path, fi.Name())
if fi.IsDir() {
if tree {
// If tree == true then remove sub-directories too.
err = os.RemoveAll(fullPath)
if err != nil {
return err
}
}
continue
}
err = os.Remove(fullPath)
if err != nil {
return err
}
}
// Remove empty parent folders.
// Ignore errors here.
for i := 0; i <= looplimit; i++ {
if pathos.FileStringEquals(path, root) {
return nil
}
dir, err := os.Open(path)
if err != nil {
// fmt.Fprintf(os.Stderr, "Failedd to open directory %q: %v\n", path, err)
return nil
}
fl, err := dir.Readdir(1)
dir.Close()
if err != nil && err != io.EOF {
// fmt.Fprintf(os.Stderr, "Failedd to list directory %q: %v\n", path, err)
return nil
}
if len(fl) > 0 {
allAreLicense := true
for _, fi := range fl {
if !isLicenseFile(fi.Name()) {
allAreLicense = false
break
}
}
if !allAreLicense {
return nil
}
}
err = os.RemoveAll(path)
if err != nil {
// fmt.Fprintf(os.Stderr, "Failedd to remove empty directory %q: %v\n", path, err)
return nil
}
nextPath := filepath.Clean(filepath.Join(path, ".."))
// Check for root.
if nextPath == path {
return nil
}
path = nextPath
}
panic("removePackage() remove parent folders")
}
|
go
|
func RemovePackage(path, root string, tree bool) error {
// Ensure the path is empty of files.
dir, err := os.Open(path)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
// Remove package files.
fl, err := dir.Readdir(-1)
dir.Close()
if err != nil {
return err
}
for _, fi := range fl {
fullPath := filepath.Join(path, fi.Name())
if fi.IsDir() {
if tree {
// If tree == true then remove sub-directories too.
err = os.RemoveAll(fullPath)
if err != nil {
return err
}
}
continue
}
err = os.Remove(fullPath)
if err != nil {
return err
}
}
// Remove empty parent folders.
// Ignore errors here.
for i := 0; i <= looplimit; i++ {
if pathos.FileStringEquals(path, root) {
return nil
}
dir, err := os.Open(path)
if err != nil {
// fmt.Fprintf(os.Stderr, "Failedd to open directory %q: %v\n", path, err)
return nil
}
fl, err := dir.Readdir(1)
dir.Close()
if err != nil && err != io.EOF {
// fmt.Fprintf(os.Stderr, "Failedd to list directory %q: %v\n", path, err)
return nil
}
if len(fl) > 0 {
allAreLicense := true
for _, fi := range fl {
if !isLicenseFile(fi.Name()) {
allAreLicense = false
break
}
}
if !allAreLicense {
return nil
}
}
err = os.RemoveAll(path)
if err != nil {
// fmt.Fprintf(os.Stderr, "Failedd to remove empty directory %q: %v\n", path, err)
return nil
}
nextPath := filepath.Clean(filepath.Join(path, ".."))
// Check for root.
if nextPath == path {
return nil
}
path = nextPath
}
panic("removePackage() remove parent folders")
}
|
[
"func",
"RemovePackage",
"(",
"path",
",",
"root",
"string",
",",
"tree",
"bool",
")",
"error",
"{",
"// Ensure the path is empty of files.",
"dir",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Remove package files.",
"fl",
",",
"err",
":=",
"dir",
".",
"Readdir",
"(",
"-",
"1",
")",
"\n",
"dir",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fl",
"{",
"fullPath",
":=",
"filepath",
".",
"Join",
"(",
"path",
",",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"if",
"tree",
"{",
"// If tree == true then remove sub-directories too.",
"err",
"=",
"os",
".",
"RemoveAll",
"(",
"fullPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"err",
"=",
"os",
".",
"Remove",
"(",
"fullPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Remove empty parent folders.",
"// Ignore errors here.",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"looplimit",
";",
"i",
"++",
"{",
"if",
"pathos",
".",
"FileStringEquals",
"(",
"path",
",",
"root",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"dir",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// fmt.Fprintf(os.Stderr, \"Failedd to open directory %q: %v\\n\", path, err)",
"return",
"nil",
"\n",
"}",
"\n\n",
"fl",
",",
"err",
":=",
"dir",
".",
"Readdir",
"(",
"1",
")",
"\n",
"dir",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"// fmt.Fprintf(os.Stderr, \"Failedd to list directory %q: %v\\n\", path, err)",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"fl",
")",
">",
"0",
"{",
"allAreLicense",
":=",
"true",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fl",
"{",
"if",
"!",
"isLicenseFile",
"(",
"fi",
".",
"Name",
"(",
")",
")",
"{",
"allAreLicense",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"allAreLicense",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"err",
"=",
"os",
".",
"RemoveAll",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// fmt.Fprintf(os.Stderr, \"Failedd to remove empty directory %q: %v\\n\", path, err)",
"return",
"nil",
"\n",
"}",
"\n",
"nextPath",
":=",
"filepath",
".",
"Clean",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"// Check for root.",
"if",
"nextPath",
"==",
"path",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"path",
"=",
"nextPath",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// RemovePackage removes the specified folder files. If folder is empty when
// done (no nested folders, remove the folder and any empty parent folders.
|
[
"RemovePackage",
"removes",
"the",
"specified",
"folder",
"files",
".",
"If",
"folder",
"is",
"empty",
"when",
"done",
"(",
"no",
"nested",
"folders",
"remove",
"the",
"folder",
"and",
"any",
"empty",
"parent",
"folders",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/path.go#L158-L235
|
146,591 |
kardianos/govendor
|
internal/gt/vcs.go
|
Setup
|
func (h *HttpHandler) Setup() VcsHandle {
vcs := h.newer(h)
vcs.create()
h.g.onClean(vcs.remove)
h.handles[vcs.pkg()] = vcs
return vcs
}
|
go
|
func (h *HttpHandler) Setup() VcsHandle {
vcs := h.newer(h)
vcs.create()
h.g.onClean(vcs.remove)
h.handles[vcs.pkg()] = vcs
return vcs
}
|
[
"func",
"(",
"h",
"*",
"HttpHandler",
")",
"Setup",
"(",
")",
"VcsHandle",
"{",
"vcs",
":=",
"h",
".",
"newer",
"(",
"h",
")",
"\n",
"vcs",
".",
"create",
"(",
")",
"\n",
"h",
".",
"g",
".",
"onClean",
"(",
"vcs",
".",
"remove",
")",
"\n\n",
"h",
".",
"handles",
"[",
"vcs",
".",
"pkg",
"(",
")",
"]",
"=",
"vcs",
"\n",
"return",
"vcs",
"\n",
"}"
] |
// Setup returns type with Remove function that can be defer'ed.
|
[
"Setup",
"returns",
"type",
"with",
"Remove",
"function",
"that",
"can",
"be",
"defer",
"ed",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/internal/gt/vcs.go#L65-L72
|
146,592 |
kardianos/govendor
|
context/resolve.go
|
loadPackage
|
func (ctx *Context) loadPackage() error {
ctx.loaded = true
ctx.dirty = false
ctx.statusCache = nil
ctx.Package = make(map[string]*Package, len(ctx.Package))
// We following the root symlink only in case the root of the repo is symlinked into the GOPATH
// This could happen during on some CI that didn't checkout into the GOPATH
rootdir, err := filepath.EvalSymlinks(ctx.RootDir)
if err != nil {
return err
}
err = filepath.Walk(rootdir, func(path string, info os.FileInfo, err error) error {
if info == nil {
return err
}
if !info.IsDir() {
// We replace the directory path (followed by the symlink), to the real go repo package name/path
// ex : replace "<somewhere>/govendor.source.repo" to "github.com/kardianos/govendor"
path = strings.Replace(path, rootdir, ctx.RootDir, 1)
_, err = ctx.addFileImports(path, ctx.RootGopath)
return err
}
name := info.Name()
// Still go into "_workspace" to aid godep migration.
if name == "_workspace" {
return nil
}
switch name[0] {
case '.', '_':
return filepath.SkipDir
}
switch name {
case "testdata", "node_modules":
return filepath.SkipDir
}
return nil
})
if err != nil {
return err
}
// Finally, set any unset status.
return ctx.determinePackageStatus()
}
|
go
|
func (ctx *Context) loadPackage() error {
ctx.loaded = true
ctx.dirty = false
ctx.statusCache = nil
ctx.Package = make(map[string]*Package, len(ctx.Package))
// We following the root symlink only in case the root of the repo is symlinked into the GOPATH
// This could happen during on some CI that didn't checkout into the GOPATH
rootdir, err := filepath.EvalSymlinks(ctx.RootDir)
if err != nil {
return err
}
err = filepath.Walk(rootdir, func(path string, info os.FileInfo, err error) error {
if info == nil {
return err
}
if !info.IsDir() {
// We replace the directory path (followed by the symlink), to the real go repo package name/path
// ex : replace "<somewhere>/govendor.source.repo" to "github.com/kardianos/govendor"
path = strings.Replace(path, rootdir, ctx.RootDir, 1)
_, err = ctx.addFileImports(path, ctx.RootGopath)
return err
}
name := info.Name()
// Still go into "_workspace" to aid godep migration.
if name == "_workspace" {
return nil
}
switch name[0] {
case '.', '_':
return filepath.SkipDir
}
switch name {
case "testdata", "node_modules":
return filepath.SkipDir
}
return nil
})
if err != nil {
return err
}
// Finally, set any unset status.
return ctx.determinePackageStatus()
}
|
[
"func",
"(",
"ctx",
"*",
"Context",
")",
"loadPackage",
"(",
")",
"error",
"{",
"ctx",
".",
"loaded",
"=",
"true",
"\n",
"ctx",
".",
"dirty",
"=",
"false",
"\n",
"ctx",
".",
"statusCache",
"=",
"nil",
"\n",
"ctx",
".",
"Package",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Package",
",",
"len",
"(",
"ctx",
".",
"Package",
")",
")",
"\n",
"// We following the root symlink only in case the root of the repo is symlinked into the GOPATH",
"// This could happen during on some CI that didn't checkout into the GOPATH",
"rootdir",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"ctx",
".",
"RootDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"filepath",
".",
"Walk",
"(",
"rootdir",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"info",
"==",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"info",
".",
"IsDir",
"(",
")",
"{",
"// We replace the directory path (followed by the symlink), to the real go repo package name/path",
"// ex : replace \"<somewhere>/govendor.source.repo\" to \"github.com/kardianos/govendor\"",
"path",
"=",
"strings",
".",
"Replace",
"(",
"path",
",",
"rootdir",
",",
"ctx",
".",
"RootDir",
",",
"1",
")",
"\n",
"_",
",",
"err",
"=",
"ctx",
".",
"addFileImports",
"(",
"path",
",",
"ctx",
".",
"RootGopath",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"name",
":=",
"info",
".",
"Name",
"(",
")",
"\n",
"// Still go into \"_workspace\" to aid godep migration.",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"name",
"[",
"0",
"]",
"{",
"case",
"'.'",
",",
"'_'",
":",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}",
"\n",
"switch",
"name",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Finally, set any unset status.",
"return",
"ctx",
".",
"determinePackageStatus",
"(",
")",
"\n",
"}"
] |
// loadPackage sets up the context with package information and
// is called before any initial operation is performed.
|
[
"loadPackage",
"sets",
"up",
"the",
"context",
"with",
"package",
"information",
"and",
"is",
"called",
"before",
"any",
"initial",
"operation",
"is",
"performed",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/resolve.go#L36-L78
|
146,593 |
kardianos/govendor
|
vcs/vcs.go
|
RegisterVCS
|
func RegisterVCS(vcs Vcs) {
registerSync.Lock()
defer registerSync.Unlock()
vcsRegistry = append(vcsRegistry, vcs)
}
|
go
|
func RegisterVCS(vcs Vcs) {
registerSync.Lock()
defer registerSync.Unlock()
vcsRegistry = append(vcsRegistry, vcs)
}
|
[
"func",
"RegisterVCS",
"(",
"vcs",
"Vcs",
")",
"{",
"registerSync",
".",
"Lock",
"(",
")",
"\n",
"defer",
"registerSync",
".",
"Unlock",
"(",
")",
"\n\n",
"vcsRegistry",
"=",
"append",
"(",
"vcsRegistry",
",",
"vcs",
")",
"\n",
"}"
] |
// RegisterVCS adds a new VCS to use.
|
[
"RegisterVCS",
"adds",
"a",
"new",
"VCS",
"to",
"use",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/vcs/vcs.go#L38-L43
|
146,594 |
kardianos/govendor
|
vcs/vcs.go
|
FindVcs
|
func FindVcs(root, packageDir string) (info *VcsInfo, err error) {
if !filepath.IsAbs(root) {
return nil, nil
}
if !filepath.IsAbs(packageDir) {
return nil, nil
}
path := packageDir
for i := 0; i <= looplimit; i++ {
for _, vcs := range vcsRegistry {
info, err = vcs.Find(path)
if err != nil {
return nil, err
}
if info != nil {
return info, nil
}
}
nextPath := filepath.Clean(filepath.Join(path, ".."))
// Check for root.
if nextPath == path {
return nil, nil
}
if !pathos.FileHasPrefix(nextPath, root) {
return nil, nil
}
path = nextPath
}
panic("loop limit")
}
|
go
|
func FindVcs(root, packageDir string) (info *VcsInfo, err error) {
if !filepath.IsAbs(root) {
return nil, nil
}
if !filepath.IsAbs(packageDir) {
return nil, nil
}
path := packageDir
for i := 0; i <= looplimit; i++ {
for _, vcs := range vcsRegistry {
info, err = vcs.Find(path)
if err != nil {
return nil, err
}
if info != nil {
return info, nil
}
}
nextPath := filepath.Clean(filepath.Join(path, ".."))
// Check for root.
if nextPath == path {
return nil, nil
}
if !pathos.FileHasPrefix(nextPath, root) {
return nil, nil
}
path = nextPath
}
panic("loop limit")
}
|
[
"func",
"FindVcs",
"(",
"root",
",",
"packageDir",
"string",
")",
"(",
"info",
"*",
"VcsInfo",
",",
"err",
"error",
")",
"{",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"root",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"filepath",
".",
"IsAbs",
"(",
"packageDir",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"path",
":=",
"packageDir",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"looplimit",
";",
"i",
"++",
"{",
"for",
"_",
",",
"vcs",
":=",
"range",
"vcsRegistry",
"{",
"info",
",",
"err",
"=",
"vcs",
".",
"Find",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"info",
"!=",
"nil",
"{",
"return",
"info",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"nextPath",
":=",
"filepath",
".",
"Clean",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"// Check for root.",
"if",
"nextPath",
"==",
"path",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"pathos",
".",
"FileHasPrefix",
"(",
"nextPath",
",",
"root",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"path",
"=",
"nextPath",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// FindVcs determines the version control information given a package dir and
// lowest root dir.
|
[
"FindVcs",
"determines",
"the",
"version",
"control",
"information",
"given",
"a",
"package",
"dir",
"and",
"lowest",
"root",
"dir",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/vcs/vcs.go#L49-L79
|
146,595 |
kardianos/govendor
|
migrate/migrate.go
|
MigrateWD
|
func MigrateWD(from From) error {
wd, err := os.Getwd()
if err != nil {
return err
}
return Migrate(from, wd)
}
|
go
|
func MigrateWD(from From) error {
wd, err := os.Getwd()
if err != nil {
return err
}
return Migrate(from, wd)
}
|
[
"func",
"MigrateWD",
"(",
"from",
"From",
")",
"error",
"{",
"wd",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"Migrate",
"(",
"from",
",",
"wd",
")",
"\n",
"}"
] |
// Migrate from the given system using the current working directory.
|
[
"Migrate",
"from",
"the",
"given",
"system",
"using",
"the",
"current",
"working",
"directory",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/migrate/migrate.go#L30-L36
|
146,596 |
kardianos/govendor
|
migrate/migrate.go
|
SystemList
|
func SystemList() []string {
list := make([]string, 0, len(registered))
for key := range registered {
list = append(list, string(key))
}
sort.Strings(list)
return list
}
|
go
|
func SystemList() []string {
list := make([]string, 0, len(registered))
for key := range registered {
list = append(list, string(key))
}
sort.Strings(list)
return list
}
|
[
"func",
"SystemList",
"(",
")",
"[",
"]",
"string",
"{",
"list",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"registered",
")",
")",
"\n",
"for",
"key",
":=",
"range",
"registered",
"{",
"list",
"=",
"append",
"(",
"list",
",",
"string",
"(",
"key",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"list",
")",
"\n",
"return",
"list",
"\n",
"}"
] |
// SystemList list available migration systems.
|
[
"SystemList",
"list",
"available",
"migration",
"systems",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/migrate/migrate.go#L39-L46
|
146,597 |
kardianos/govendor
|
migrate/migrate.go
|
Migrate
|
func Migrate(from From, root string) error {
sys, found := registered[from]
if !found {
return ErrNoSuchSystem{
NotExist: string(from),
Has: SystemList(),
}
}
sys, err := sys.Check(root)
if err != nil {
return err
}
if sys == nil {
return errors.New("Root not found.")
}
return sys.Migrate(root)
}
|
go
|
func Migrate(from From, root string) error {
sys, found := registered[from]
if !found {
return ErrNoSuchSystem{
NotExist: string(from),
Has: SystemList(),
}
}
sys, err := sys.Check(root)
if err != nil {
return err
}
if sys == nil {
return errors.New("Root not found.")
}
return sys.Migrate(root)
}
|
[
"func",
"Migrate",
"(",
"from",
"From",
",",
"root",
"string",
")",
"error",
"{",
"sys",
",",
"found",
":=",
"registered",
"[",
"from",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"ErrNoSuchSystem",
"{",
"NotExist",
":",
"string",
"(",
"from",
")",
",",
"Has",
":",
"SystemList",
"(",
")",
",",
"}",
"\n",
"}",
"\n",
"sys",
",",
"err",
":=",
"sys",
".",
"Check",
"(",
"root",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"sys",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sys",
".",
"Migrate",
"(",
"root",
")",
"\n",
"}"
] |
// Migrate from the given system using the given root.
|
[
"Migrate",
"from",
"the",
"given",
"system",
"using",
"the",
"given",
"root",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/migrate/migrate.go#L49-L65
|
146,598 |
kardianos/govendor
|
run/run.go
|
Run
|
func Run(w io.Writer, appArgs []string, ask prompt.Prompt) (help.HelpMessage, error) {
r := &runner{}
return r.run(w, appArgs, ask)
}
|
go
|
func Run(w io.Writer, appArgs []string, ask prompt.Prompt) (help.HelpMessage, error) {
r := &runner{}
return r.run(w, appArgs, ask)
}
|
[
"func",
"Run",
"(",
"w",
"io",
".",
"Writer",
",",
"appArgs",
"[",
"]",
"string",
",",
"ask",
"prompt",
".",
"Prompt",
")",
"(",
"help",
".",
"HelpMessage",
",",
"error",
")",
"{",
"r",
":=",
"&",
"runner",
"{",
"}",
"\n",
"return",
"r",
".",
"run",
"(",
"w",
",",
"appArgs",
",",
"ask",
")",
"\n",
"}"
] |
// Run is isoloated from main and os.Args to help with testing.
// Shouldn't directly print to console, just write through w.
|
[
"Run",
"is",
"isoloated",
"from",
"main",
"and",
"os",
".",
"Args",
"to",
"help",
"with",
"testing",
".",
"Shouldn",
"t",
"directly",
"print",
"to",
"console",
"just",
"write",
"through",
"w",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/run/run.go#L42-L45
|
146,599 |
kardianos/govendor
|
context/license.go
|
licenseWalk
|
func licenseWalk(root, startIn string, found func(folder, name string) error) error {
folder := startIn
for i := 0; i <= looplimit; i++ {
dir, err := os.Open(folder)
if err != nil {
return err
}
fl, err := dir.Readdir(-1)
dir.Close()
if err != nil {
return err
}
for _, fi := range fl {
name := fi.Name()
if name[0] == '.' {
continue
}
if fi.IsDir() {
continue
}
if !isLicenseFile(name) {
continue
}
err = found(folder, name)
if err != nil {
return err
}
}
if len(folder) <= len(root) {
return nil
}
nextFolder := filepath.Clean(filepath.Join(folder, ".."))
if nextFolder == folder {
return nil
}
folder = nextFolder
}
panic("licenseFind loop limit")
}
|
go
|
func licenseWalk(root, startIn string, found func(folder, name string) error) error {
folder := startIn
for i := 0; i <= looplimit; i++ {
dir, err := os.Open(folder)
if err != nil {
return err
}
fl, err := dir.Readdir(-1)
dir.Close()
if err != nil {
return err
}
for _, fi := range fl {
name := fi.Name()
if name[0] == '.' {
continue
}
if fi.IsDir() {
continue
}
if !isLicenseFile(name) {
continue
}
err = found(folder, name)
if err != nil {
return err
}
}
if len(folder) <= len(root) {
return nil
}
nextFolder := filepath.Clean(filepath.Join(folder, ".."))
if nextFolder == folder {
return nil
}
folder = nextFolder
}
panic("licenseFind loop limit")
}
|
[
"func",
"licenseWalk",
"(",
"root",
",",
"startIn",
"string",
",",
"found",
"func",
"(",
"folder",
",",
"name",
"string",
")",
"error",
")",
"error",
"{",
"folder",
":=",
"startIn",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<=",
"looplimit",
";",
"i",
"++",
"{",
"dir",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"folder",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fl",
",",
"err",
":=",
"dir",
".",
"Readdir",
"(",
"-",
"1",
")",
"\n",
"dir",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fl",
"{",
"name",
":=",
"fi",
".",
"Name",
"(",
")",
"\n",
"if",
"name",
"[",
"0",
"]",
"==",
"'.'",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"isLicenseFile",
"(",
"name",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"err",
"=",
"found",
"(",
"folder",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"folder",
")",
"<=",
"len",
"(",
"root",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"nextFolder",
":=",
"filepath",
".",
"Clean",
"(",
"filepath",
".",
"Join",
"(",
"folder",
",",
"\"",
"\"",
")",
")",
"\n\n",
"if",
"nextFolder",
"==",
"folder",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"folder",
"=",
"nextFolder",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// licenseWalk starts in a folder and searches up the folder tree
// for license like files. Found files are reported to the found function.
|
[
"licenseWalk",
"starts",
"in",
"a",
"folder",
"and",
"searches",
"up",
"the",
"folder",
"tree",
"for",
"license",
"like",
"files",
".",
"Found",
"files",
"are",
"reported",
"to",
"the",
"found",
"function",
"."
] |
d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62
|
https://github.com/kardianos/govendor/blob/d0fd0db8a43d4b87c2ce416f60ae78407f3f3c62/context/license.go#L110-L153
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.