id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
151,700
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/scanner.go
Init
func (s *Scanner) Init(file *token.File, src []byte, err ErrorHandler, mode Mode) { // Explicitly initialize all fields since a scanner may be reused. if file.Size() != len(src) { panic(fmt.Sprintf("file size (%d) does not match src len (%d)", file.Size(), len(src))) } s.file = file s.dir, _ = filepath.Split(file.Name()) s.src = src s.err = err s.mode = mode s.ch = ' ' s.offset = 0 s.rdOffset = 0 s.lineOffset = 0 s.ErrorCount = 0 s.nextVal = false s.next() }
go
func (s *Scanner) Init(file *token.File, src []byte, err ErrorHandler, mode Mode) { // Explicitly initialize all fields since a scanner may be reused. if file.Size() != len(src) { panic(fmt.Sprintf("file size (%d) does not match src len (%d)", file.Size(), len(src))) } s.file = file s.dir, _ = filepath.Split(file.Name()) s.src = src s.err = err s.mode = mode s.ch = ' ' s.offset = 0 s.rdOffset = 0 s.lineOffset = 0 s.ErrorCount = 0 s.nextVal = false s.next() }
[ "func", "(", "s", "*", "Scanner", ")", "Init", "(", "file", "*", "token", ".", "File", ",", "src", "[", "]", "byte", ",", "err", "ErrorHandler", ",", "mode", "Mode", ")", "{", "// Explicitly initialize all fields since a scanner may be reused.", "if", "file", ...
// Init prepares the scanner s to tokenize the text src by setting the // scanner at the beginning of src. The scanner uses the file set file // for position information and it adds line information for each line. // It is ok to re-use the same file when re-scanning the same file as // line information which is already present is ignored. Init causes a // panic if the file size does not match the src size. // // Calls to Scan will invoke the error handler err if they encounter a // syntax error and err is not nil. Also, for each error encountered, // the Scanner field ErrorCount is incremented by one. The mode parameter // determines how comments are handled. // // Note that Init may call err if there is an error in the first character // of the file. //
[ "Init", "prepares", "the", "scanner", "s", "to", "tokenize", "the", "text", "src", "by", "setting", "the", "scanner", "at", "the", "beginning", "of", "src", ".", "The", "scanner", "uses", "the", "file", "set", "file", "for", "position", "information", "and...
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/scanner.go#L112-L131
151,701
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/types/int.go
ParseInt
func ParseInt(intptr interface{}, val string, mode IntMode) error { val = strings.TrimSpace(val) verb := byte(0) switch mode { case Dec: verb = 'd' case Dec + Hex: if prefix0x(val) { verb = 'v' } else { verb = 'd' } case Dec + Oct: if prefix0(val) && !prefix0x(val) { verb = 'v' } else { verb = 'd' } case Dec + Hex + Oct: verb = 'v' case Hex: if prefix0x(val) { verb = 'v' } else { verb = 'x' } case Oct: verb = 'o' case Hex + Oct: if prefix0(val) { verb = 'v' } else { return errIntAmbig } } if verb == 0 { panic("unsupported mode") } return ScanFully(intptr, val, verb) }
go
func ParseInt(intptr interface{}, val string, mode IntMode) error { val = strings.TrimSpace(val) verb := byte(0) switch mode { case Dec: verb = 'd' case Dec + Hex: if prefix0x(val) { verb = 'v' } else { verb = 'd' } case Dec + Oct: if prefix0(val) && !prefix0x(val) { verb = 'v' } else { verb = 'd' } case Dec + Hex + Oct: verb = 'v' case Hex: if prefix0x(val) { verb = 'v' } else { verb = 'x' } case Oct: verb = 'o' case Hex + Oct: if prefix0(val) { verb = 'v' } else { return errIntAmbig } } if verb == 0 { panic("unsupported mode") } return ScanFully(intptr, val, verb) }
[ "func", "ParseInt", "(", "intptr", "interface", "{", "}", ",", "val", "string", ",", "mode", "IntMode", ")", "error", "{", "val", "=", "strings", ".", "TrimSpace", "(", "val", ")", "\n", "verb", ":=", "byte", "(", "0", ")", "\n", "switch", "mode", ...
// ParseInt parses val using mode into intptr, which must be a pointer to an // integer kind type. Non-decimal value require prefix `0` or `0x` in the cases // when mode permits ambiguity of base; otherwise the prefix can be omitted.
[ "ParseInt", "parses", "val", "using", "mode", "into", "intptr", "which", "must", "be", "a", "pointer", "to", "an", "integer", "kind", "type", ".", "Non", "-", "decimal", "value", "require", "prefix", "0", "or", "0x", "in", "the", "cases", "when", "mode",...
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/types/int.go#L47-L86
151,702
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/types/enum.go
AddVals
func (ep *EnumParser) AddVals(vals map[string]interface{}) { if ep.vals == nil { ep.vals = make(map[string]interface{}) } for k, v := range vals { if ep.Type == "" { ep.Type = reflect.TypeOf(v).Name() } if !ep.CaseMatch { k = strings.ToLower(k) } ep.vals[k] = v } }
go
func (ep *EnumParser) AddVals(vals map[string]interface{}) { if ep.vals == nil { ep.vals = make(map[string]interface{}) } for k, v := range vals { if ep.Type == "" { ep.Type = reflect.TypeOf(v).Name() } if !ep.CaseMatch { k = strings.ToLower(k) } ep.vals[k] = v } }
[ "func", "(", "ep", "*", "EnumParser", ")", "AddVals", "(", "vals", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "if", "ep", ".", "vals", "==", "nil", "{", "ep", ".", "vals", "=", "make", "(", "map", "[", "string", "]", "interface",...
// AddVals adds strings and values to an EnumParser.
[ "AddVals", "adds", "strings", "and", "values", "to", "an", "EnumParser", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/types/enum.go#L19-L32
151,703
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/types/enum.go
Parse
func (ep EnumParser) Parse(s string) (interface{}, error) { if !ep.CaseMatch { s = strings.ToLower(s) } v, ok := ep.vals[s] if !ok { return false, fmt.Errorf("failed to parse %s %#q", ep.Type, s) } return v, nil }
go
func (ep EnumParser) Parse(s string) (interface{}, error) { if !ep.CaseMatch { s = strings.ToLower(s) } v, ok := ep.vals[s] if !ok { return false, fmt.Errorf("failed to parse %s %#q", ep.Type, s) } return v, nil }
[ "func", "(", "ep", "EnumParser", ")", "Parse", "(", "s", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "!", "ep", ".", "CaseMatch", "{", "s", "=", "strings", ".", "ToLower", "(", "s", ")", "\n", "}", "\n", "v", ",", ...
// Parse parses the string and returns the value or an error.
[ "Parse", "parses", "the", "string", "and", "returns", "the", "value", "or", "an", "error", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/types/enum.go#L35-L44
151,704
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go
Add
func (p *ErrorList) Add(pos token.Position, msg string) { *p = append(*p, &Error{pos, msg}) }
go
func (p *ErrorList) Add(pos token.Position, msg string) { *p = append(*p, &Error{pos, msg}) }
[ "func", "(", "p", "*", "ErrorList", ")", "Add", "(", "pos", "token", ".", "Position", ",", "msg", "string", ")", "{", "*", "p", "=", "append", "(", "*", "p", ",", "&", "Error", "{", "pos", ",", "msg", "}", ")", "\n", "}" ]
// Add adds an Error with given position and error message to an ErrorList.
[ "Add", "adds", "an", "Error", "with", "given", "position", "and", "error", "message", "to", "an", "ErrorList", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go#L43-L45
151,705
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go
RemoveMultiples
func (p *ErrorList) RemoveMultiples() { sort.Sort(p) var last token.Position // initial last.Line is != any legal error line i := 0 for _, e := range *p { if e.Pos.Filename != last.Filename || e.Pos.Line != last.Line { last = e.Pos (*p)[i] = e i++ } } (*p) = (*p)[0:i] }
go
func (p *ErrorList) RemoveMultiples() { sort.Sort(p) var last token.Position // initial last.Line is != any legal error line i := 0 for _, e := range *p { if e.Pos.Filename != last.Filename || e.Pos.Line != last.Line { last = e.Pos (*p)[i] = e i++ } } (*p) = (*p)[0:i] }
[ "func", "(", "p", "*", "ErrorList", ")", "RemoveMultiples", "(", ")", "{", "sort", ".", "Sort", "(", "p", ")", "\n", "var", "last", "token", ".", "Position", "// initial last.Line is != any legal error line", "\n", "i", ":=", "0", "\n", "for", "_", ",", ...
// RemoveMultiples sorts an ErrorList and removes all but the first error per line.
[ "RemoveMultiples", "sorts", "an", "ErrorList", "and", "removes", "all", "but", "the", "first", "error", "per", "line", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go#L75-L87
151,706
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go
Error
func (p ErrorList) Error() string { switch len(p) { case 0: return "no errors" case 1: return p[0].Error() } return fmt.Sprintf("%s (and %d more errors)", p[0], len(p)-1) }
go
func (p ErrorList) Error() string { switch len(p) { case 0: return "no errors" case 1: return p[0].Error() } return fmt.Sprintf("%s (and %d more errors)", p[0], len(p)-1) }
[ "func", "(", "p", "ErrorList", ")", "Error", "(", ")", "string", "{", "switch", "len", "(", "p", ")", "{", "case", "0", ":", "return", "\"", "\"", "\n", "case", "1", ":", "return", "p", "[", "0", "]", ".", "Error", "(", ")", "\n", "}", "\n", ...
// An ErrorList implements the error interface.
[ "An", "ErrorList", "implements", "the", "error", "interface", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go#L90-L98
151,707
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go
PrintError
func PrintError(w io.Writer, err error) { if list, ok := err.(ErrorList); ok { for _, e := range list { fmt.Fprintf(w, "%s\n", e) } } else if err != nil { fmt.Fprintf(w, "%s\n", err) } }
go
func PrintError(w io.Writer, err error) { if list, ok := err.(ErrorList); ok { for _, e := range list { fmt.Fprintf(w, "%s\n", e) } } else if err != nil { fmt.Fprintf(w, "%s\n", err) } }
[ "func", "PrintError", "(", "w", "io", ".", "Writer", ",", "err", "error", ")", "{", "if", "list", ",", "ok", ":=", "err", ".", "(", "ErrorList", ")", ";", "ok", "{", "for", "_", ",", "e", ":=", "range", "list", "{", "fmt", ".", "Fprintf", "(", ...
// PrintError is a utility function that prints a list of errors to w, // one error per line, if the err parameter is an ErrorList. Otherwise // it prints the err string. //
[ "PrintError", "is", "a", "utility", "function", "that", "prints", "a", "list", "of", "errors", "to", "w", "one", "error", "per", "line", "if", "the", "err", "parameter", "is", "an", "ErrorList", ".", "Otherwise", "it", "prints", "the", "err", "string", "...
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/scanner/errors.go#L113-L121
151,708
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/read.go
ReadInto
func ReadInto(config interface{}, reader io.Reader) error { src, err := ioutil.ReadAll(reader) if err != nil { return err } fset := token.NewFileSet() file := fset.AddFile("", fset.Base(), len(src)) return readInto(config, fset, file, src) }
go
func ReadInto(config interface{}, reader io.Reader) error { src, err := ioutil.ReadAll(reader) if err != nil { return err } fset := token.NewFileSet() file := fset.AddFile("", fset.Base(), len(src)) return readInto(config, fset, file, src) }
[ "func", "ReadInto", "(", "config", "interface", "{", "}", ",", "reader", "io", ".", "Reader", ")", "error", "{", "src", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}",...
// ReadInto reads gcfg formatted data from reader and sets the values into the // corresponding fields in config.
[ "ReadInto", "reads", "gcfg", "formatted", "data", "from", "reader", "and", "sets", "the", "values", "into", "the", "corresponding", "fields", "in", "config", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/read.go#L149-L157
151,709
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/read.go
ReadStringInto
func ReadStringInto(config interface{}, str string) error { r := strings.NewReader(str) return ReadInto(config, r) }
go
func ReadStringInto(config interface{}, str string) error { r := strings.NewReader(str) return ReadInto(config, r) }
[ "func", "ReadStringInto", "(", "config", "interface", "{", "}", ",", "str", "string", ")", "error", "{", "r", ":=", "strings", ".", "NewReader", "(", "str", ")", "\n", "return", "ReadInto", "(", "config", ",", "r", ")", "\n", "}" ]
// ReadStringInto reads gcfg formatted data from str and sets the values into // the corresponding fields in config.
[ "ReadStringInto", "reads", "gcfg", "formatted", "data", "from", "str", "and", "sets", "the", "values", "into", "the", "corresponding", "fields", "in", "config", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/read.go#L161-L164
151,710
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/read.go
ReadFileInto
func ReadFileInto(config interface{}, filename string) error { f, err := os.Open(filename) if err != nil { return err } defer f.Close() src, err := ioutil.ReadAll(f) if err != nil { return err } fset := token.NewFileSet() file := fset.AddFile(filename, fset.Base(), len(src)) return readInto(config, fset, file, src) }
go
func ReadFileInto(config interface{}, filename string) error { f, err := os.Open(filename) if err != nil { return err } defer f.Close() src, err := ioutil.ReadAll(f) if err != nil { return err } fset := token.NewFileSet() file := fset.AddFile(filename, fset.Base(), len(src)) return readInto(config, fset, file, src) }
[ "func", "ReadFileInto", "(", "config", "interface", "{", "}", ",", "filename", "string", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defe...
// ReadFileInto reads gcfg formatted data from the file filename and sets the // values into the corresponding fields in config.
[ "ReadFileInto", "reads", "gcfg", "formatted", "data", "from", "the", "file", "filename", "and", "sets", "the", "values", "into", "the", "corresponding", "fields", "in", "config", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/read.go#L168-L181
151,711
etsy/mixer
match/match.go
isPaired
func isPaired(p Person) bool { for k, v := range pairs { if k == p || v == p { return true } } return false }
go
func isPaired(p Person) bool { for k, v := range pairs { if k == p || v == p { return true } } return false }
[ "func", "isPaired", "(", "p", "Person", ")", "bool", "{", "for", "k", ",", "v", ":=", "range", "pairs", "{", "if", "k", "==", "p", "||", "v", "==", "p", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isPaired checks the map of pairs to see if they are already paired
[ "isPaired", "checks", "the", "map", "of", "pairs", "to", "see", "if", "they", "are", "already", "paired" ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/match/match.go#L244-L251
151,712
etsy/mixer
match/match.go
pickRandom
func pickRandom(cur_person Person) (*Person, error) { list := rand.Perm(len(avail_pool)) for i := range list { var random Person = avail_pool[i] if isValid(cur_person, random, true) { avail_pool = append(avail_pool[:i], avail_pool[i+1:]...) return &random, nil } } return nil, fmt.Errorf("couldn't find an available participant") }
go
func pickRandom(cur_person Person) (*Person, error) { list := rand.Perm(len(avail_pool)) for i := range list { var random Person = avail_pool[i] if isValid(cur_person, random, true) { avail_pool = append(avail_pool[:i], avail_pool[i+1:]...) return &random, nil } } return nil, fmt.Errorf("couldn't find an available participant") }
[ "func", "pickRandom", "(", "cur_person", "Person", ")", "(", "*", "Person", ",", "error", ")", "{", "list", ":=", "rand", ".", "Perm", "(", "len", "(", "avail_pool", ")", ")", "\n", "for", "i", ":=", "range", "list", "{", "var", "random", "Person", ...
// pickRandom will pick a random person but make sure they adhere to criteria
[ "pickRandom", "will", "pick", "a", "random", "person", "but", "make", "sure", "they", "adhere", "to", "criteria" ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/match/match.go#L254-L265
151,713
etsy/mixer
match/match.go
isValid
func isValid(cur_person Person, other_person Person, check_pairing bool) bool { if other_person.Id == cur_person.Id { dbg.Printf(" same person %v\n", other_person) return false } if pairedTooRecently(cur_person, other_person) { dbg.Printf(" too recent %v\n", other_person) return false } return true }
go
func isValid(cur_person Person, other_person Person, check_pairing bool) bool { if other_person.Id == cur_person.Id { dbg.Printf(" same person %v\n", other_person) return false } if pairedTooRecently(cur_person, other_person) { dbg.Printf(" too recent %v\n", other_person) return false } return true }
[ "func", "isValid", "(", "cur_person", "Person", ",", "other_person", "Person", ",", "check_pairing", "bool", ")", "bool", "{", "if", "other_person", ".", "Id", "==", "cur_person", ".", "Id", "{", "dbg", ".", "Printf", "(", "\"", "\\n", "\"", ",", "other_...
// isValid means they can't get themself // or have been paired with this person in the recent past
[ "isValid", "means", "they", "can", "t", "get", "themself", "or", "have", "been", "paired", "with", "this", "person", "in", "the", "recent", "past" ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/match/match.go#L269-L281
151,714
etsy/mixer
match/match.go
pairedTooRecently
func pairedTooRecently(cur_person Person, other_person Person) bool { pair := GetLastPairing(cur_person.Id, other_person.Id) if pair.Id == 0 { return false } else { if (current_week - pair.Week) <= (num_participants - 1) { dbg.Printf(" vv paired recently in the past on week %d\n", pair.Week) return true } } return false }
go
func pairedTooRecently(cur_person Person, other_person Person) bool { pair := GetLastPairing(cur_person.Id, other_person.Id) if pair.Id == 0 { return false } else { if (current_week - pair.Week) <= (num_participants - 1) { dbg.Printf(" vv paired recently in the past on week %d\n", pair.Week) return true } } return false }
[ "func", "pairedTooRecently", "(", "cur_person", "Person", ",", "other_person", "Person", ")", "bool", "{", "pair", ":=", "GetLastPairing", "(", "cur_person", ".", "Id", ",", "other_person", ".", "Id", ")", "\n", "if", "pair", ".", "Id", "==", "0", "{", "...
// pairedTooRecently is false if they have never been paired together, // or true if difference in weeks since last meet is greater than the // total number of people in the pool
[ "pairedTooRecently", "is", "false", "if", "they", "have", "never", "been", "paired", "together", "or", "true", "if", "difference", "in", "weeks", "since", "last", "meet", "is", "greater", "than", "the", "total", "number", "of", "people", "in", "the", "pool" ...
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/match/match.go#L286-L298
151,715
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/types/bool.go
ParseBool
func ParseBool(s string) (bool, error) { v, err := boolParser.Parse(s) if err != nil { return false, err } return v.(bool), nil }
go
func ParseBool(s string) (bool, error) { v, err := boolParser.Parse(s) if err != nil { return false, err } return v.(bool), nil }
[ "func", "ParseBool", "(", "s", "string", ")", "(", "bool", ",", "error", ")", "{", "v", ",", "err", ":=", "boolParser", ".", "Parse", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", ...
// ParseBool parses bool values according to the definitions in BoolValues. // Parsing is case-insensitive.
[ "ParseBool", "parses", "bool", "values", "according", "to", "the", "definitions", "in", "BoolValues", ".", "Parsing", "is", "case", "-", "insensitive", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/types/bool.go#L17-L23
151,716
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/token/serialize.go
Read
func (s *FileSet) Read(decode func(interface{}) error) error { var ss serializedFileSet if err := decode(&ss); err != nil { return err } s.mutex.Lock() s.base = ss.Base files := make([]*File, len(ss.Files)) for i := 0; i < len(ss.Files); i++ { f := &ss.Files[i] files[i] = &File{s, f.Name, f.Base, f.Size, f.Lines, f.Infos} } s.files = files s.last = nil s.mutex.Unlock() return nil }
go
func (s *FileSet) Read(decode func(interface{}) error) error { var ss serializedFileSet if err := decode(&ss); err != nil { return err } s.mutex.Lock() s.base = ss.Base files := make([]*File, len(ss.Files)) for i := 0; i < len(ss.Files); i++ { f := &ss.Files[i] files[i] = &File{s, f.Name, f.Base, f.Size, f.Lines, f.Infos} } s.files = files s.last = nil s.mutex.Unlock() return nil }
[ "func", "(", "s", "*", "FileSet", ")", "Read", "(", "decode", "func", "(", "interface", "{", "}", ")", "error", ")", "error", "{", "var", "ss", "serializedFileSet", "\n", "if", "err", ":=", "decode", "(", "&", "ss", ")", ";", "err", "!=", "nil", ...
// Read calls decode to deserialize a file set into s; s must not be nil.
[ "Read", "calls", "decode", "to", "deserialize", "a", "file", "set", "into", "s", ";", "s", "must", "not", "be", "nil", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/token/serialize.go#L22-L40
151,717
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/token/serialize.go
Write
func (s *FileSet) Write(encode func(interface{}) error) error { var ss serializedFileSet s.mutex.Lock() ss.Base = s.base files := make([]serializedFile, len(s.files)) for i, f := range s.files { files[i] = serializedFile{f.name, f.base, f.size, f.lines, f.infos} } ss.Files = files s.mutex.Unlock() return encode(ss) }
go
func (s *FileSet) Write(encode func(interface{}) error) error { var ss serializedFileSet s.mutex.Lock() ss.Base = s.base files := make([]serializedFile, len(s.files)) for i, f := range s.files { files[i] = serializedFile{f.name, f.base, f.size, f.lines, f.infos} } ss.Files = files s.mutex.Unlock() return encode(ss) }
[ "func", "(", "s", "*", "FileSet", ")", "Write", "(", "encode", "func", "(", "interface", "{", "}", ")", "error", ")", "error", "{", "var", "ss", "serializedFileSet", "\n\n", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "ss", ".", "Base", "=", ...
// Write calls encode to serialize the file set s.
[ "Write", "calls", "encode", "to", "serialize", "the", "file", "set", "s", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/token/serialize.go#L43-L56
151,718
etsy/mixer
Godeps/_workspace/src/gopkg.in/gcfg.v1/types/scan.go
ScanFully
func ScanFully(ptr interface{}, val string, verb byte) error { t := reflect.ValueOf(ptr).Elem().Type() // attempt to read extra bytes to make sure the value is consumed var b []byte n, err := fmt.Sscanf(val, "%"+string(verb)+"%s", ptr, &b) switch { case n < 1 || n == 1 && err != io.EOF: return fmt.Errorf("failed to parse %q as %v: %v", val, t, err) case n > 1: return fmt.Errorf("failed to parse %q as %v: extra characters %q", val, t, string(b)) } // n == 1 && err == io.EOF return nil }
go
func ScanFully(ptr interface{}, val string, verb byte) error { t := reflect.ValueOf(ptr).Elem().Type() // attempt to read extra bytes to make sure the value is consumed var b []byte n, err := fmt.Sscanf(val, "%"+string(verb)+"%s", ptr, &b) switch { case n < 1 || n == 1 && err != io.EOF: return fmt.Errorf("failed to parse %q as %v: %v", val, t, err) case n > 1: return fmt.Errorf("failed to parse %q as %v: extra characters %q", val, t, string(b)) } // n == 1 && err == io.EOF return nil }
[ "func", "ScanFully", "(", "ptr", "interface", "{", "}", ",", "val", "string", ",", "verb", "byte", ")", "error", "{", "t", ":=", "reflect", ".", "ValueOf", "(", "ptr", ")", ".", "Elem", "(", ")", ".", "Type", "(", ")", "\n", "// attempt to read extra...
// ScanFully uses fmt.Sscanf with verb to fully scan val into ptr.
[ "ScanFully", "uses", "fmt", ".", "Sscanf", "with", "verb", "to", "fully", "scan", "val", "into", "ptr", "." ]
439e3e5fc3756b5f25399a2947c30f1df3de3f47
https://github.com/etsy/mixer/blob/439e3e5fc3756b5f25399a2947c30f1df3de3f47/Godeps/_workspace/src/gopkg.in/gcfg.v1/types/scan.go#L10-L23
151,719
codemodus/swagui
suidata2/suidata2.go
New
func New() *SUIData2 { aliases := map[string]string{ "swagger-ui.js": "swagger-ui.min.js", } as := assets.New(Asset, aliases) return &SUIData2{ as: as, index: "index.html", def: "http://petstore.swagger.io/v2/swagger.json", } }
go
func New() *SUIData2 { aliases := map[string]string{ "swagger-ui.js": "swagger-ui.min.js", } as := assets.New(Asset, aliases) return &SUIData2{ as: as, index: "index.html", def: "http://petstore.swagger.io/v2/swagger.json", } }
[ "func", "New", "(", ")", "*", "SUIData2", "{", "aliases", ":=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "}", "\n\n", "as", ":=", "assets", ".", "New", "(", "Asset", ",", "aliases", ")", "\n\n", "return", "&", ...
// New sets up a new SUIData2.
[ "New", "sets", "up", "a", "new", "SUIData2", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/suidata2/suidata2.go#L18-L30
151,720
codemodus/swagui
internal/assets/assets.go
New
func New(fn AssetFunc, aliases map[string]string) *Assets { return &Assets{ assetFn: fn, aliases: aliases, cache: make(map[string][]byte), } }
go
func New(fn AssetFunc, aliases map[string]string) *Assets { return &Assets{ assetFn: fn, aliases: aliases, cache: make(map[string][]byte), } }
[ "func", "New", "(", "fn", "AssetFunc", ",", "aliases", "map", "[", "string", "]", "string", ")", "*", "Assets", "{", "return", "&", "Assets", "{", "assetFn", ":", "fn", ",", "aliases", ":", "aliases", ",", "cache", ":", "make", "(", "map", "[", "st...
// New sets up Assets.
[ "New", "sets", "up", "Assets", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/internal/assets/assets.go#L20-L26
151,721
codemodus/swagui
internal/assets/assets.go
Asset
func (as *Assets) Asset(name string) ([]byte, error) { return as.assetFn(valueOrKey(as.aliases, name)) }
go
func (as *Assets) Asset(name string) ([]byte, error) { return as.assetFn(valueOrKey(as.aliases, name)) }
[ "func", "(", "as", "*", "Assets", ")", "Asset", "(", "name", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "as", ".", "assetFn", "(", "valueOrKey", "(", "as", ".", "aliases", ",", "name", ")", ")", "\n", "}" ]
// Asset accesses assets using available aliases.
[ "Asset", "accesses", "assets", "using", "available", "aliases", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/internal/assets/assets.go#L29-L31
151,722
codemodus/swagui
swagui.go
New
func New(notFound http.Handler, p Provider) (*Swagui, error) { efmt := "new swagui: %s" if notFound == nil { notFound = http.NotFoundHandler() } if p == nil { return nil, fmt.Errorf(efmt, "provider must be set") } s := Swagui{ nf: notFound, p: p, } return &s, nil }
go
func New(notFound http.Handler, p Provider) (*Swagui, error) { efmt := "new swagui: %s" if notFound == nil { notFound = http.NotFoundHandler() } if p == nil { return nil, fmt.Errorf(efmt, "provider must be set") } s := Swagui{ nf: notFound, p: p, } return &s, nil }
[ "func", "New", "(", "notFound", "http", ".", "Handler", ",", "p", "Provider", ")", "(", "*", "Swagui", ",", "error", ")", "{", "efmt", ":=", "\"", "\"", "\n\n", "if", "notFound", "==", "nil", "{", "notFound", "=", "http", ".", "NotFoundHandler", "(",...
// New returns a Swagui, or an error if no provider is set.
[ "New", "returns", "a", "Swagui", "or", "an", "error", "if", "no", "provider", "is", "set", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/swagui.go#L23-L39
151,723
codemodus/swagui
swagui.go
Handler
func (s *Swagui) Handler(defaultDefinition string) http.Handler { return s.p.Handler(s.nf, defaultDefinition) }
go
func (s *Swagui) Handler(defaultDefinition string) http.Handler { return s.p.Handler(s.nf, defaultDefinition) }
[ "func", "(", "s", "*", "Swagui", ")", "Handler", "(", "defaultDefinition", "string", ")", "http", ".", "Handler", "{", "return", "s", ".", "p", ".", "Handler", "(", "s", ".", "nf", ",", "defaultDefinition", ")", "\n", "}" ]
// Handler returns an http.Handler for Swagger-UI resources.
[ "Handler", "returns", "an", "http", ".", "Handler", "for", "Swagger", "-", "UI", "resources", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/swagui.go#L42-L44
151,724
honeycombio/urlshaper
urlshaper.go
Compile
func (p *Pattern) Compile() error { if p.re != nil { // we've already been compiled! return nil } rawRE := p.Pat varRE, err := regexp.Compile("/(:[^/]+)") if err != nil { p.failed = true return err } vars := varRE.FindAllStringSubmatch(p.Pat, -1) for _, varMatch := range vars { varName := strings.Trim(varMatch[0], "/:") regName := fmt.Sprintf("/(?P<%s>[^/]+)", varName) rawRE = strings.Replace(rawRE, varMatch[0], regName, 1) } // handle * at the end of the pattern if strings.HasSuffix(rawRE, "*") { rawRE = strings.TrimSuffix(rawRE, "*") rawRE += ".*" } // anchor the regex to both the beginning and the end rawRE = "^" + rawRE + "$" p.rawRE = rawRE re, err := regexp.Compile(rawRE) if err != nil { p.failed = true return err } p.re = re return nil }
go
func (p *Pattern) Compile() error { if p.re != nil { // we've already been compiled! return nil } rawRE := p.Pat varRE, err := regexp.Compile("/(:[^/]+)") if err != nil { p.failed = true return err } vars := varRE.FindAllStringSubmatch(p.Pat, -1) for _, varMatch := range vars { varName := strings.Trim(varMatch[0], "/:") regName := fmt.Sprintf("/(?P<%s>[^/]+)", varName) rawRE = strings.Replace(rawRE, varMatch[0], regName, 1) } // handle * at the end of the pattern if strings.HasSuffix(rawRE, "*") { rawRE = strings.TrimSuffix(rawRE, "*") rawRE += ".*" } // anchor the regex to both the beginning and the end rawRE = "^" + rawRE + "$" p.rawRE = rawRE re, err := regexp.Compile(rawRE) if err != nil { p.failed = true return err } p.re = re return nil }
[ "func", "(", "p", "*", "Pattern", ")", "Compile", "(", ")", "error", "{", "if", "p", ".", "re", "!=", "nil", "{", "// we've already been compiled!", "return", "nil", "\n", "}", "\n", "rawRE", ":=", "p", ".", "Pat", "\n", "varRE", ",", "err", ":=", ...
// Compile turns the Pattern into a compiled regex that will be used to match // URL patterns
[ "Compile", "turns", "the", "Pattern", "into", "a", "compiled", "regex", "that", "will", "be", "used", "to", "match", "URL", "patterns" ]
2baba9ae5b5faed757d6e4d66054967824a0a1b1
https://github.com/honeycombio/urlshaper/blob/2baba9ae5b5faed757d6e4d66054967824a0a1b1/urlshaper.go#L56-L89
151,725
honeycombio/urlshaper
urlshaper.go
Parse
func (p *Parser) Parse(rawURL string) (*Result, error) { // split out the path and query u, err := url.Parse(rawURL) if err != nil { return nil, err } r := &Result{ URI: rawURL, Path: u.Path, Query: u.RawQuery, QueryFields: u.Query(), PathFields: url.Values{}, } // create the shaped query string var queryShape string // sort the query parameters qKeys := make([]string, 0, len(r.QueryFields)) for k := range r.QueryFields { qKeys = append(qKeys, k) } sort.Strings(qKeys) shapeStrings := make([]string, 0, len(qKeys)) for _, k := range qKeys { for i := 0; i < len(r.QueryFields[k]); i++ { shapeStrings = append(shapeStrings, fmt.Sprintf("%s=?", k)) } } queryShape = strings.Join(shapeStrings, "&") // try and find a shape for the path or use the Path as the shape var pathShape string pathShape, r.PathFields = p.getPathShape(u.Path) // Ok, construct the full shape of the URL fullShape := pathShape if queryShape != "" { fullShape += fmt.Sprintf("?%s", queryShape) } r.PathShape = pathShape r.QueryShape = queryShape r.Shape = fullShape return r, nil }
go
func (p *Parser) Parse(rawURL string) (*Result, error) { // split out the path and query u, err := url.Parse(rawURL) if err != nil { return nil, err } r := &Result{ URI: rawURL, Path: u.Path, Query: u.RawQuery, QueryFields: u.Query(), PathFields: url.Values{}, } // create the shaped query string var queryShape string // sort the query parameters qKeys := make([]string, 0, len(r.QueryFields)) for k := range r.QueryFields { qKeys = append(qKeys, k) } sort.Strings(qKeys) shapeStrings := make([]string, 0, len(qKeys)) for _, k := range qKeys { for i := 0; i < len(r.QueryFields[k]); i++ { shapeStrings = append(shapeStrings, fmt.Sprintf("%s=?", k)) } } queryShape = strings.Join(shapeStrings, "&") // try and find a shape for the path or use the Path as the shape var pathShape string pathShape, r.PathFields = p.getPathShape(u.Path) // Ok, construct the full shape of the URL fullShape := pathShape if queryShape != "" { fullShape += fmt.Sprintf("?%s", queryShape) } r.PathShape = pathShape r.QueryShape = queryShape r.Shape = fullShape return r, nil }
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", "rawURL", "string", ")", "(", "*", "Result", ",", "error", ")", "{", "// split out the path and query", "u", ",", "err", ":=", "url", ".", "Parse", "(", "rawURL", ")", "\n", "if", "err", "!=", "nil"...
// Parse takes a URL string and a list of patterns, attempts to parse, and // and hands back a Result and error
[ "Parse", "takes", "a", "URL", "string", "and", "a", "list", "of", "patterns", "attempts", "to", "parse", "and", "and", "hands", "back", "a", "Result", "and", "error" ]
2baba9ae5b5faed757d6e4d66054967824a0a1b1
https://github.com/honeycombio/urlshaper/blob/2baba9ae5b5faed757d6e4d66054967824a0a1b1/urlshaper.go#L99-L144
151,726
honeycombio/urlshaper
urlshaper.go
getPathShape
func (p *Parser) getPathShape(path string) (string, url.Values) { pathShape := path pathFields := url.Values{} for _, pat := range p.Patterns { if pat.failed { // skip failed patterns continue } // try and compile not-yet-compiled patterns if pat.re == nil { if err := pat.Compile(); err != nil { continue } } matches := pat.re.FindStringSubmatch(path) if matches == nil { // no match, try the next pattern continue } pathShape = pat.Pat if len(matches) == 1 { // no variables in the pattern. All done break } names := pat.re.SubexpNames() for i, val := range matches { if i == 0 { // skip the full string match continue } pathFields.Add(names[i], val) } // since we matched, don't check any more patterns in the list break } return pathShape, pathFields }
go
func (p *Parser) getPathShape(path string) (string, url.Values) { pathShape := path pathFields := url.Values{} for _, pat := range p.Patterns { if pat.failed { // skip failed patterns continue } // try and compile not-yet-compiled patterns if pat.re == nil { if err := pat.Compile(); err != nil { continue } } matches := pat.re.FindStringSubmatch(path) if matches == nil { // no match, try the next pattern continue } pathShape = pat.Pat if len(matches) == 1 { // no variables in the pattern. All done break } names := pat.re.SubexpNames() for i, val := range matches { if i == 0 { // skip the full string match continue } pathFields.Add(names[i], val) } // since we matched, don't check any more patterns in the list break } return pathShape, pathFields }
[ "func", "(", "p", "*", "Parser", ")", "getPathShape", "(", "path", "string", ")", "(", "string", ",", "url", ".", "Values", ")", "{", "pathShape", ":=", "path", "\n", "pathFields", ":=", "url", ".", "Values", "{", "}", "\n", "for", "_", ",", "pat",...
// getPathShape takes a path and does all the pattern matching and extraction // of path variables
[ "getPathShape", "takes", "a", "path", "and", "does", "all", "the", "pattern", "matching", "and", "extraction", "of", "path", "variables" ]
2baba9ae5b5faed757d6e4d66054967824a0a1b1
https://github.com/honeycombio/urlshaper/blob/2baba9ae5b5faed757d6e4d66054967824a0a1b1/urlshaper.go#L148-L184
151,727
codemodus/swagui
suidata3/suidata3.go
New
func New() *SUIData3 { aliases := map[string]string{} return &SUIData3{ as: assets.New(Asset, aliases), index: "index.html", def: "https://petstore.swagger.io/v2/swagger.json", } }
go
func New() *SUIData3 { aliases := map[string]string{} return &SUIData3{ as: assets.New(Asset, aliases), index: "index.html", def: "https://petstore.swagger.io/v2/swagger.json", } }
[ "func", "New", "(", ")", "*", "SUIData3", "{", "aliases", ":=", "map", "[", "string", "]", "string", "{", "}", "\n\n", "return", "&", "SUIData3", "{", "as", ":", "assets", ".", "New", "(", "Asset", ",", "aliases", ")", ",", "index", ":", "\"", "\...
// New sets up a new SUIData3.
[ "New", "sets", "up", "a", "new", "SUIData3", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/suidata3/suidata3.go#L18-L26
151,728
codemodus/swagui
suidata3/suidata3.go
Handler
func (d *SUIData3) Handler(notFound http.Handler, defaultDef string) http.Handler { return suihttp.Handler(d.as, notFound, d.index, d.def, defaultDef) }
go
func (d *SUIData3) Handler(notFound http.Handler, defaultDef string) http.Handler { return suihttp.Handler(d.as, notFound, d.index, d.def, defaultDef) }
[ "func", "(", "d", "*", "SUIData3", ")", "Handler", "(", "notFound", "http", ".", "Handler", ",", "defaultDef", "string", ")", "http", ".", "Handler", "{", "return", "suihttp", ".", "Handler", "(", "d", ".", "as", ",", "notFound", ",", "d", ".", "inde...
// Handler returns an http.Handler which serves Swagger-UI.
[ "Handler", "returns", "an", "http", ".", "Handler", "which", "serves", "Swagger", "-", "UI", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/suidata3/suidata3.go#L29-L31
151,729
codemodus/swagui
internal/suihttp/suihttp.go
Handler
func Handler(as *assets.Assets, notFound http.Handler, index, origDef, newDef string) http.Handler { modtime := time.Now() return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p := r.URL.Path if p != "" && p[0] == '/' { p = p[1:] } var bs []byte var err error switch p { case "", index: bs, err = as.ModifiedAsset(index, origDef, newDef) default: bs, err = as.Asset(p) } if err != nil { notFound.ServeHTTP(w, r) return } http.ServeContent(w, r, p, modtime, bytes.NewReader(bs)) }) }
go
func Handler(as *assets.Assets, notFound http.Handler, index, origDef, newDef string) http.Handler { modtime := time.Now() return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { p := r.URL.Path if p != "" && p[0] == '/' { p = p[1:] } var bs []byte var err error switch p { case "", index: bs, err = as.ModifiedAsset(index, origDef, newDef) default: bs, err = as.Asset(p) } if err != nil { notFound.ServeHTTP(w, r) return } http.ServeContent(w, r, p, modtime, bytes.NewReader(bs)) }) }
[ "func", "Handler", "(", "as", "*", "assets", ".", "Assets", ",", "notFound", "http", ".", "Handler", ",", "index", ",", "origDef", ",", "newDef", "string", ")", "http", ".", "Handler", "{", "modtime", ":=", "time", ".", "Now", "(", ")", "\n\n", "retu...
// Handler returns an http.Handler which serves resources using special handling // for Swagger-UI.
[ "Handler", "returns", "an", "http", ".", "Handler", "which", "serves", "resources", "using", "special", "handling", "for", "Swagger", "-", "UI", "." ]
0012b8119244f3d01cf5104ef392167dd548221b
https://github.com/codemodus/swagui/blob/0012b8119244f3d01cf5104ef392167dd548221b/internal/suihttp/suihttp.go#L13-L38
151,730
b4b4r07/go-colon
colon.go
Parse
func (p *Parser) Parse(str string) (*Results, error) { var rs Results if str == "" { return &rs, ErrInvalid } var ( errStack []error isdir bool first string command string ) items := strings.Split(str, p.Separator) for index, item := range items { args, err := shellwords.Parse(item) if err != nil { errStack = append(errStack, err) } if len(args) == 0 { return &rs, ErrInvalid } first = args[0] isdir = isDir(first) if !isdir { // Discard err in order not to make an error // even if it is not found in your PATH command, _ = exec.LookPath(first) } // Error if it can not be found in your all PATHs // or in the current directory if command == "" && !isExist(first) { err = fmt.Errorf("%s: no such file or directory", first) errStack = append(errStack, err) } rs = append(rs, Result{ Index: index + 1, Item: item, Args: args, Command: command, Errors: errStack, }) } return &rs, nil }
go
func (p *Parser) Parse(str string) (*Results, error) { var rs Results if str == "" { return &rs, ErrInvalid } var ( errStack []error isdir bool first string command string ) items := strings.Split(str, p.Separator) for index, item := range items { args, err := shellwords.Parse(item) if err != nil { errStack = append(errStack, err) } if len(args) == 0 { return &rs, ErrInvalid } first = args[0] isdir = isDir(first) if !isdir { // Discard err in order not to make an error // even if it is not found in your PATH command, _ = exec.LookPath(first) } // Error if it can not be found in your all PATHs // or in the current directory if command == "" && !isExist(first) { err = fmt.Errorf("%s: no such file or directory", first) errStack = append(errStack, err) } rs = append(rs, Result{ Index: index + 1, Item: item, Args: args, Command: command, Errors: errStack, }) } return &rs, nil }
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", "str", "string", ")", "(", "*", "Results", ",", "error", ")", "{", "var", "rs", "Results", "\n", "if", "str", "==", "\"", "\"", "{", "return", "&", "rs", ",", "ErrInvalid", "\n", "}", "\n\n", ...
// Parser parses colon-separated string like PATH
[ "Parser", "parses", "colon", "-", "separated", "string", "like", "PATH" ]
bc5ae99f1c2b6d202bd43ea8258596f0a09e7378
https://github.com/b4b4r07/go-colon/blob/bc5ae99f1c2b6d202bd43ea8258596f0a09e7378/colon.go#L51-L96
151,731
b4b4r07/go-colon
colon.go
Filter
func (rs *Results) Filter(fn func(Result) bool) *Results { results := make(Results, 0) for _, result := range *rs { if fn(result) { results = append(results, result) } } return &results }
go
func (rs *Results) Filter(fn func(Result) bool) *Results { results := make(Results, 0) for _, result := range *rs { if fn(result) { results = append(results, result) } } return &results }
[ "func", "(", "rs", "*", "Results", ")", "Filter", "(", "fn", "func", "(", "Result", ")", "bool", ")", "*", "Results", "{", "results", ":=", "make", "(", "Results", ",", "0", ")", "\n", "for", "_", ",", "result", ":=", "range", "*", "rs", "{", "...
// Filter filters the parse result by condition
[ "Filter", "filters", "the", "parse", "result", "by", "condition" ]
bc5ae99f1c2b6d202bd43ea8258596f0a09e7378
https://github.com/b4b4r07/go-colon/blob/bc5ae99f1c2b6d202bd43ea8258596f0a09e7378/colon.go#L120-L128
151,732
b4b4r07/go-colon
colon.go
Executable
func (rs *Results) Executable() *Results { return rs.Filter(func(r Result) bool { return r.Command != "" }) }
go
func (rs *Results) Executable() *Results { return rs.Filter(func(r Result) bool { return r.Command != "" }) }
[ "func", "(", "rs", "*", "Results", ")", "Executable", "(", ")", "*", "Results", "{", "return", "rs", ".", "Filter", "(", "func", "(", "r", "Result", ")", "bool", "{", "return", "r", ".", "Command", "!=", "\"", "\"", "\n", "}", ")", "\n", "}" ]
// Executable returns objects whose first argument is in PATH
[ "Executable", "returns", "objects", "whose", "first", "argument", "is", "in", "PATH" ]
bc5ae99f1c2b6d202bd43ea8258596f0a09e7378
https://github.com/b4b4r07/go-colon/blob/bc5ae99f1c2b6d202bd43ea8258596f0a09e7378/colon.go#L131-L135
151,733
AreaHQ/go-fixtures
row.go
Init
func (row *Row) Init() { // Initial values row.insertColumnLength = len(row.PK) + len(row.Fields) row.updateColumnLength = len(row.PK) + len(row.Fields) row.pkColumns = make([]string, 0) row.pkValues = make([]interface{}, 0) row.insertColumns = make([]string, 0) row.updateColumns = make([]string, 0) row.insertValues = make([]interface{}, 0) row.updateValues = make([]interface{}, 0) // Get and sort map keys var i int pkKeys := make([]string, len(row.PK)) i = 0 for pkKey := range row.PK { pkKeys[i] = pkKey i++ } sort.Strings(pkKeys) fieldKeys := make([]string, len(row.Fields)) i = 0 for fieldKey := range row.Fields { fieldKeys[i] = fieldKey i++ } sort.Strings(fieldKeys) // Primary keys for _, pkKey := range pkKeys { row.pkColumns = append(row.pkColumns, pkKey) row.pkValues = append(row.pkValues, row.PK[pkKey]) row.insertColumns = append(row.insertColumns, pkKey) row.updateColumns = append(row.updateColumns, pkKey) row.insertValues = append(row.insertValues, row.PK[pkKey]) row.updateValues = append(row.updateValues, row.PK[pkKey]) } // Rest of the fields for _, fieldKey := range fieldKeys { sv, ok := row.Fields[fieldKey].(string) if ok && sv == onInsertNow { row.insertColumns = append(row.insertColumns, fieldKey) row.insertValues = append(row.insertValues, time.Now()) row.updateColumnLength-- continue } if ok && sv == onUpdateNow { row.updateColumns = append(row.updateColumns, fieldKey) row.updateValues = append(row.updateValues, time.Now()) row.insertColumnLength-- continue } row.insertColumns = append(row.insertColumns, fieldKey) row.updateColumns = append(row.updateColumns, fieldKey) row.insertValues = append(row.insertValues, row.Fields[fieldKey]) row.updateValues = append(row.updateValues, row.Fields[fieldKey]) } }
go
func (row *Row) Init() { // Initial values row.insertColumnLength = len(row.PK) + len(row.Fields) row.updateColumnLength = len(row.PK) + len(row.Fields) row.pkColumns = make([]string, 0) row.pkValues = make([]interface{}, 0) row.insertColumns = make([]string, 0) row.updateColumns = make([]string, 0) row.insertValues = make([]interface{}, 0) row.updateValues = make([]interface{}, 0) // Get and sort map keys var i int pkKeys := make([]string, len(row.PK)) i = 0 for pkKey := range row.PK { pkKeys[i] = pkKey i++ } sort.Strings(pkKeys) fieldKeys := make([]string, len(row.Fields)) i = 0 for fieldKey := range row.Fields { fieldKeys[i] = fieldKey i++ } sort.Strings(fieldKeys) // Primary keys for _, pkKey := range pkKeys { row.pkColumns = append(row.pkColumns, pkKey) row.pkValues = append(row.pkValues, row.PK[pkKey]) row.insertColumns = append(row.insertColumns, pkKey) row.updateColumns = append(row.updateColumns, pkKey) row.insertValues = append(row.insertValues, row.PK[pkKey]) row.updateValues = append(row.updateValues, row.PK[pkKey]) } // Rest of the fields for _, fieldKey := range fieldKeys { sv, ok := row.Fields[fieldKey].(string) if ok && sv == onInsertNow { row.insertColumns = append(row.insertColumns, fieldKey) row.insertValues = append(row.insertValues, time.Now()) row.updateColumnLength-- continue } if ok && sv == onUpdateNow { row.updateColumns = append(row.updateColumns, fieldKey) row.updateValues = append(row.updateValues, time.Now()) row.insertColumnLength-- continue } row.insertColumns = append(row.insertColumns, fieldKey) row.updateColumns = append(row.updateColumns, fieldKey) row.insertValues = append(row.insertValues, row.Fields[fieldKey]) row.updateValues = append(row.updateValues, row.Fields[fieldKey]) } }
[ "func", "(", "row", "*", "Row", ")", "Init", "(", ")", "{", "// Initial values", "row", ".", "insertColumnLength", "=", "len", "(", "row", ".", "PK", ")", "+", "len", "(", "row", ".", "Fields", ")", "\n", "row", ".", "updateColumnLength", "=", "len",...
// Init loads internal struct variables
[ "Init", "loads", "internal", "struct", "variables" ]
9384cea840d98fd1d079f6f3335a4e6b40251771
https://github.com/AreaHQ/go-fixtures/blob/9384cea840d98fd1d079f6f3335a4e6b40251771/row.go#L32-L90
151,734
AreaHQ/go-fixtures
row.go
GetInsertColumns
func (row *Row) GetInsertColumns() []string { escapedColumns := make([]string, len(row.insertColumns)) for i, insertColumn := range row.insertColumns { escapedColumns[i] = fmt.Sprintf("\"%s\"", insertColumn) } return escapedColumns }
go
func (row *Row) GetInsertColumns() []string { escapedColumns := make([]string, len(row.insertColumns)) for i, insertColumn := range row.insertColumns { escapedColumns[i] = fmt.Sprintf("\"%s\"", insertColumn) } return escapedColumns }
[ "func", "(", "row", "*", "Row", ")", "GetInsertColumns", "(", ")", "[", "]", "string", "{", "escapedColumns", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "row", ".", "insertColumns", ")", ")", "\n", "for", "i", ",", "insertColumn", ":=", ...
// GetInsertColumns returns a slice of column names for INSERT query
[ "GetInsertColumns", "returns", "a", "slice", "of", "column", "names", "for", "INSERT", "query" ]
9384cea840d98fd1d079f6f3335a4e6b40251771
https://github.com/AreaHQ/go-fixtures/blob/9384cea840d98fd1d079f6f3335a4e6b40251771/row.go#L103-L109
151,735
AreaHQ/go-fixtures
row.go
GetUpdateColumns
func (row *Row) GetUpdateColumns() []string { escapedColumns := make([]string, len(row.updateColumns)) for i, updateColumn := range row.updateColumns { escapedColumns[i] = fmt.Sprintf("\"%s\"", updateColumn) } return escapedColumns }
go
func (row *Row) GetUpdateColumns() []string { escapedColumns := make([]string, len(row.updateColumns)) for i, updateColumn := range row.updateColumns { escapedColumns[i] = fmt.Sprintf("\"%s\"", updateColumn) } return escapedColumns }
[ "func", "(", "row", "*", "Row", ")", "GetUpdateColumns", "(", ")", "[", "]", "string", "{", "escapedColumns", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "row", ".", "updateColumns", ")", ")", "\n", "for", "i", ",", "updateColumn", ":=", ...
// GetUpdateColumns returns a slice of column names for UPDATE query
[ "GetUpdateColumns", "returns", "a", "slice", "of", "column", "names", "for", "UPDATE", "query" ]
9384cea840d98fd1d079f6f3335a4e6b40251771
https://github.com/AreaHQ/go-fixtures/blob/9384cea840d98fd1d079f6f3335a4e6b40251771/row.go#L112-L118
151,736
AreaHQ/go-fixtures
row.go
GetInsertPlaceholders
func (row *Row) GetInsertPlaceholders(driver string) []string { placeholders := make([]string, row.GetInsertColumnsLength()) for i := 0; i < row.GetInsertColumnsLength(); i++ { if driver == postgresDriver { placeholders[i] = fmt.Sprintf("$%d", i+1) } else { placeholders[i] = "?" } } return placeholders }
go
func (row *Row) GetInsertPlaceholders(driver string) []string { placeholders := make([]string, row.GetInsertColumnsLength()) for i := 0; i < row.GetInsertColumnsLength(); i++ { if driver == postgresDriver { placeholders[i] = fmt.Sprintf("$%d", i+1) } else { placeholders[i] = "?" } } return placeholders }
[ "func", "(", "row", "*", "Row", ")", "GetInsertPlaceholders", "(", "driver", "string", ")", "[", "]", "string", "{", "placeholders", ":=", "make", "(", "[", "]", "string", ",", "row", ".", "GetInsertColumnsLength", "(", ")", ")", "\n", "for", "i", ":="...
// GetInsertPlaceholders returns a slice of placeholders for INSERT query
[ "GetInsertPlaceholders", "returns", "a", "slice", "of", "placeholders", "for", "INSERT", "query" ]
9384cea840d98fd1d079f6f3335a4e6b40251771
https://github.com/AreaHQ/go-fixtures/blob/9384cea840d98fd1d079f6f3335a4e6b40251771/row.go#L131-L141
151,737
AreaHQ/go-fixtures
row.go
GetUpdatePlaceholders
func (row *Row) GetUpdatePlaceholders(driver string) []string { placeholders := make([]string, row.GetUpdateColumnsLength()) for i, c := range row.GetUpdateColumns() { if driver == postgresDriver { placeholders[i] = fmt.Sprintf("%s = $%d", c, i+1) } else { placeholders[i] = fmt.Sprintf("%s = ?", c) } } return placeholders }
go
func (row *Row) GetUpdatePlaceholders(driver string) []string { placeholders := make([]string, row.GetUpdateColumnsLength()) for i, c := range row.GetUpdateColumns() { if driver == postgresDriver { placeholders[i] = fmt.Sprintf("%s = $%d", c, i+1) } else { placeholders[i] = fmt.Sprintf("%s = ?", c) } } return placeholders }
[ "func", "(", "row", "*", "Row", ")", "GetUpdatePlaceholders", "(", "driver", "string", ")", "[", "]", "string", "{", "placeholders", ":=", "make", "(", "[", "]", "string", ",", "row", ".", "GetUpdateColumnsLength", "(", ")", ")", "\n", "for", "i", ",",...
// GetUpdatePlaceholders returns a slice of placeholders for UPDATE query
[ "GetUpdatePlaceholders", "returns", "a", "slice", "of", "placeholders", "for", "UPDATE", "query" ]
9384cea840d98fd1d079f6f3335a4e6b40251771
https://github.com/AreaHQ/go-fixtures/blob/9384cea840d98fd1d079f6f3335a4e6b40251771/row.go#L144-L154
151,738
AreaHQ/go-fixtures
row.go
GetWhere
func (row *Row) GetWhere(driver string, i int) string { wheres := make([]string, len(row.PK)) j := i for _, c := range row.pkColumns { if driver == postgresDriver { wheres[i-j] = fmt.Sprintf("%s = $%d", c, i+1) } else { wheres[i-j] = fmt.Sprintf("%s = ?", c) } i++ } return strings.Join(wheres, " AND ") }
go
func (row *Row) GetWhere(driver string, i int) string { wheres := make([]string, len(row.PK)) j := i for _, c := range row.pkColumns { if driver == postgresDriver { wheres[i-j] = fmt.Sprintf("%s = $%d", c, i+1) } else { wheres[i-j] = fmt.Sprintf("%s = ?", c) } i++ } return strings.Join(wheres, " AND ") }
[ "func", "(", "row", "*", "Row", ")", "GetWhere", "(", "driver", "string", ",", "i", "int", ")", "string", "{", "wheres", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "row", ".", "PK", ")", ")", "\n", "j", ":=", "i", "\n", "for", "_...
// GetWhere returns a where condition based on primary key with placeholders
[ "GetWhere", "returns", "a", "where", "condition", "based", "on", "primary", "key", "with", "placeholders" ]
9384cea840d98fd1d079f6f3335a4e6b40251771
https://github.com/AreaHQ/go-fixtures/blob/9384cea840d98fd1d079f6f3335a4e6b40251771/row.go#L157-L169
151,739
git-lfs/wildmatch
wildmatch.go
parseTokens
func parseTokens(dirs []string) []token { if len(dirs) == 0 { return make([]token, 0) } switch dirs[0] { case "": if len(dirs) == 1 { return []token{&component{fns: []componentFn{substring("")}}} } return parseTokens(dirs[1:]) case "**": rest := parseTokens(dirs[1:]) if len(rest) == 0 { // If there are no remaining tokens, return a lone // doubleStar token. return []token{&doubleStar{ Until: nil, }} } // Otherwise, return a doubleStar token that will match greedily // until the first component in the remainder of the pattern, // and then the remainder of the pattern. return append([]token{&doubleStar{ Until: rest[0], }}, rest[1:]...) default: // Ordinarily, simply return the appropriate component, and // continue on. return append([]token{&component{ fns: parseComponent(dirs[0]), }}, parseTokens(dirs[1:])...) } }
go
func parseTokens(dirs []string) []token { if len(dirs) == 0 { return make([]token, 0) } switch dirs[0] { case "": if len(dirs) == 1 { return []token{&component{fns: []componentFn{substring("")}}} } return parseTokens(dirs[1:]) case "**": rest := parseTokens(dirs[1:]) if len(rest) == 0 { // If there are no remaining tokens, return a lone // doubleStar token. return []token{&doubleStar{ Until: nil, }} } // Otherwise, return a doubleStar token that will match greedily // until the first component in the remainder of the pattern, // and then the remainder of the pattern. return append([]token{&doubleStar{ Until: rest[0], }}, rest[1:]...) default: // Ordinarily, simply return the appropriate component, and // continue on. return append([]token{&component{ fns: parseComponent(dirs[0]), }}, parseTokens(dirs[1:])...) } }
[ "func", "parseTokens", "(", "dirs", "[", "]", "string", ")", "[", "]", "token", "{", "if", "len", "(", "dirs", ")", "==", "0", "{", "return", "make", "(", "[", "]", "token", ",", "0", ")", "\n", "}", "\n\n", "switch", "dirs", "[", "0", "]", "...
// parseTokens parses a separated list of patterns into a sequence of // representative Tokens that will compose the pattern when applied in sequence.
[ "parseTokens", "parses", "a", "separated", "list", "of", "patterns", "into", "a", "sequence", "of", "representative", "Tokens", "that", "will", "compose", "the", "pattern", "when", "applied", "in", "sequence", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L144-L179
151,740
git-lfs/wildmatch
wildmatch.go
nonEmpty
func nonEmpty(all []string) (ne []string) { for _, x := range all { if len(x) > 0 { ne = append(ne, x) } } return ne }
go
func nonEmpty(all []string) (ne []string) { for _, x := range all { if len(x) > 0 { ne = append(ne, x) } } return ne }
[ "func", "nonEmpty", "(", "all", "[", "]", "string", ")", "(", "ne", "[", "]", "string", ")", "{", "for", "_", ",", "x", ":=", "range", "all", "{", "if", "len", "(", "x", ")", ">", "0", "{", "ne", "=", "append", "(", "ne", ",", "x", ")", "...
// nonEmpty returns the non-empty strings in "all".
[ "nonEmpty", "returns", "the", "non", "-", "empty", "strings", "in", "all", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L182-L189
151,741
git-lfs/wildmatch
wildmatch.go
Match
func (w *Wildmatch) Match(t string) bool { dirs, ok := w.consume(t, MatchOpts{}) if !ok { return false } return len(dirs) == 0 }
go
func (w *Wildmatch) Match(t string) bool { dirs, ok := w.consume(t, MatchOpts{}) if !ok { return false } return len(dirs) == 0 }
[ "func", "(", "w", "*", "Wildmatch", ")", "Match", "(", "t", "string", ")", "bool", "{", "dirs", ",", "ok", ":=", "w", ".", "consume", "(", "t", ",", "MatchOpts", "{", "}", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "...
// Match returns true if and only if the pattern matched by the receiving // Wildmatch matches the entire filepath "t".
[ "Match", "returns", "true", "if", "and", "only", "if", "the", "pattern", "matched", "by", "the", "receiving", "Wildmatch", "matches", "the", "entire", "filepath", "t", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L193-L199
151,742
git-lfs/wildmatch
wildmatch.go
consume
func (w *Wildmatch) consume(t string, opt MatchOpts) ([]string, bool) { if w.basename { // If the receiving Wildmatch has basename set, the pattern // matches only the basename of the given "t". t = filepath.Base(t) } if w.caseFold { // If the receiving Wildmatch is case insensitive, the pattern // "w.p" will be lower-case. // // To preserve insensitivity, lower the given path "t", as well. t = strings.ToLower(t) } var isDir bool if opt.IsDirectory { isDir = true // Standardize the formation of subject string so directories always // end with '/' if !strings.HasSuffix(t, "/") { t = t + "/" } } else { isDir = strings.HasSuffix(t, string(sep)) } dirs := strings.Split(t, string(sep)) // Git-attribute style matching can never match a directory if w.gitattributes && isDir { return dirs, false } // Match each directory token-wise, allowing each token to consume more // than one directory in the case of the '**' pattern. for _, tok := range w.ts { var ok bool dirs, ok = tok.Consume(dirs, isDir) if !ok { // If a pattern could not match the remainder of the // filepath, return so immediately, along with the paths // that we did successfully manage to match. return dirs, false } } return dirs, true }
go
func (w *Wildmatch) consume(t string, opt MatchOpts) ([]string, bool) { if w.basename { // If the receiving Wildmatch has basename set, the pattern // matches only the basename of the given "t". t = filepath.Base(t) } if w.caseFold { // If the receiving Wildmatch is case insensitive, the pattern // "w.p" will be lower-case. // // To preserve insensitivity, lower the given path "t", as well. t = strings.ToLower(t) } var isDir bool if opt.IsDirectory { isDir = true // Standardize the formation of subject string so directories always // end with '/' if !strings.HasSuffix(t, "/") { t = t + "/" } } else { isDir = strings.HasSuffix(t, string(sep)) } dirs := strings.Split(t, string(sep)) // Git-attribute style matching can never match a directory if w.gitattributes && isDir { return dirs, false } // Match each directory token-wise, allowing each token to consume more // than one directory in the case of the '**' pattern. for _, tok := range w.ts { var ok bool dirs, ok = tok.Consume(dirs, isDir) if !ok { // If a pattern could not match the remainder of the // filepath, return so immediately, along with the paths // that we did successfully manage to match. return dirs, false } } return dirs, true }
[ "func", "(", "w", "*", "Wildmatch", ")", "consume", "(", "t", "string", ",", "opt", "MatchOpts", ")", "(", "[", "]", "string", ",", "bool", ")", "{", "if", "w", ".", "basename", "{", "// If the receiving Wildmatch has basename set, the pattern", "// matches on...
// consume performs the inner match of "t" against the receiver's pattern, and // returns a slice of remaining directory paths, and whether or not there was a // disagreement while matching.
[ "consume", "performs", "the", "inner", "match", "of", "t", "against", "the", "receiver", "s", "pattern", "and", "returns", "a", "slice", "of", "remaining", "directory", "paths", "and", "whether", "or", "not", "there", "was", "a", "disagreement", "while", "ma...
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L212-L260
151,743
git-lfs/wildmatch
wildmatch.go
Consume
func (d *doubleStar) Consume(path []string, isDir bool) ([]string, bool) { if len(path) == 0 { return path, false } // If there are no remaining tokens to match, allow matching the entire // path. if d.Until == nil { return nil, true } for i := len(path); i > 0; i-- { rest, ok := d.Until.Consume(path[i:], false) if ok { return rest, ok } } // If no match has been found, we assume that the '**' token matches the // empty string, and defer pattern matching to the rest of the path. return d.Until.Consume(path, isDir) }
go
func (d *doubleStar) Consume(path []string, isDir bool) ([]string, bool) { if len(path) == 0 { return path, false } // If there are no remaining tokens to match, allow matching the entire // path. if d.Until == nil { return nil, true } for i := len(path); i > 0; i-- { rest, ok := d.Until.Consume(path[i:], false) if ok { return rest, ok } } // If no match has been found, we assume that the '**' token matches the // empty string, and defer pattern matching to the rest of the path. return d.Until.Consume(path, isDir) }
[ "func", "(", "d", "*", "doubleStar", ")", "Consume", "(", "path", "[", "]", "string", ",", "isDir", "bool", ")", "(", "[", "]", "string", ",", "bool", ")", "{", "if", "len", "(", "path", ")", "==", "0", "{", "return", "path", ",", "false", "\n"...
// Consume implements token.Consume as above.
[ "Consume", "implements", "token", ".", "Consume", "as", "above", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L305-L326
151,744
git-lfs/wildmatch
wildmatch.go
String
func (d *doubleStar) String() string { if d.Until == nil { return "**" } return fmt.Sprintf("**/%s", d.Until.String()) }
go
func (d *doubleStar) String() string { if d.Until == nil { return "**" } return fmt.Sprintf("**/%s", d.Until.String()) }
[ "func", "(", "d", "*", "doubleStar", ")", "String", "(", ")", "string", "{", "if", "d", ".", "Until", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "d", ".", "Until", ".", "Strin...
// String implements Component.String.
[ "String", "implements", "Component", ".", "String", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L329-L334
151,745
git-lfs/wildmatch
wildmatch.go
Apply
func (c *cfn) Apply(s string) (rest string, ok bool) { return c.fn(s) }
go
func (c *cfn) Apply(s string) (rest string, ok bool) { return c.fn(s) }
[ "func", "(", "c", "*", "cfn", ")", "Apply", "(", "s", "string", ")", "(", "rest", "string", ",", "ok", "bool", ")", "{", "return", "c", ".", "fn", "(", "s", ")", "\n", "}" ]
// Apply executes the component function as described above.
[ "Apply", "executes", "the", "component", "function", "as", "described", "above", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L352-L354
151,746
git-lfs/wildmatch
wildmatch.go
appendMaybe
func appendMaybe(yes bool, a, b []runeFn, x runeFn) (ax, bx []runeFn) { if yes { return append(a, x), b } return a, append(b, x) }
go
func appendMaybe(yes bool, a, b []runeFn, x runeFn) (ax, bx []runeFn) { if yes { return append(a, x), b } return a, append(b, x) }
[ "func", "appendMaybe", "(", "yes", "bool", ",", "a", ",", "b", "[", "]", "runeFn", ",", "x", "runeFn", ")", "(", "ax", ",", "bx", "[", "]", "runeFn", ")", "{", "if", "yes", "{", "return", "append", "(", "a", ",", "x", ")", ",", "b", "\n", "...
// appendMaybe appends the value "x" to either "a" or "b" depending on "yes".
[ "appendMaybe", "appends", "the", "value", "x", "to", "either", "a", "or", "b", "depending", "on", "yes", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L549-L554
151,747
git-lfs/wildmatch
wildmatch.go
cons
func cons(head componentFn, tail []componentFn) []componentFn { return append([]componentFn{head}, tail...) }
go
func cons(head componentFn, tail []componentFn) []componentFn { return append([]componentFn{head}, tail...) }
[ "func", "cons", "(", "head", "componentFn", ",", "tail", "[", "]", "componentFn", ")", "[", "]", "componentFn", "{", "return", "append", "(", "[", "]", "componentFn", "{", "head", "}", ",", "tail", "...", ")", "\n", "}" ]
// cons prepends the "head" componentFn to the "tail" of componentFn's.
[ "cons", "prepends", "the", "head", "componentFn", "to", "the", "tail", "of", "componentFn", "s", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L557-L559
151,748
git-lfs/wildmatch
wildmatch.go
Consume
func (c *component) Consume(path []string, isDir bool) ([]string, bool) { if len(path) == 0 { return path, false } head := path[0] for _, fn := range c.fns { var ok bool // Apply successively the component functions to make progress // matching the head. if head, ok = fn.Apply(head); !ok { // If any of the functions failed to match, there are // no other paths to match success, so return a failure // immediately. return path, false } } if len(head) > 0 { return append([]string{head}, path[1:]...), false } if len(path) == 1 { // Components can not match directories. If we were matching the // last path in a tree structure, we can only match if it // _wasn't_ a directory. return path[1:], true } return path[1:], true }
go
func (c *component) Consume(path []string, isDir bool) ([]string, bool) { if len(path) == 0 { return path, false } head := path[0] for _, fn := range c.fns { var ok bool // Apply successively the component functions to make progress // matching the head. if head, ok = fn.Apply(head); !ok { // If any of the functions failed to match, there are // no other paths to match success, so return a failure // immediately. return path, false } } if len(head) > 0 { return append([]string{head}, path[1:]...), false } if len(path) == 1 { // Components can not match directories. If we were matching the // last path in a tree structure, we can only match if it // _wasn't_ a directory. return path[1:], true } return path[1:], true }
[ "func", "(", "c", "*", "component", ")", "Consume", "(", "path", "[", "]", "string", ",", "isDir", "bool", ")", "(", "[", "]", "string", ",", "bool", ")", "{", "if", "len", "(", "path", ")", "==", "0", "{", "return", "path", ",", "false", "\n",...
// Consume implements token.Consume as above by applying the above set of // componentFn's in succession to the first element of the path tree.
[ "Consume", "implements", "token", ".", "Consume", "as", "above", "by", "applying", "the", "above", "set", "of", "componentFn", "s", "in", "succession", "to", "the", "first", "element", "of", "the", "path", "tree", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L563-L594
151,749
git-lfs/wildmatch
wildmatch.go
String
func (c *component) String() string { var str string for _, fn := range c.fns { str += fn.String() } return str }
go
func (c *component) String() string { var str string for _, fn := range c.fns { str += fn.String() } return str }
[ "func", "(", "c", "*", "component", ")", "String", "(", ")", "string", "{", "var", "str", "string", "\n\n", "for", "_", ",", "fn", ":=", "range", "c", ".", "fns", "{", "str", "+=", "fn", ".", "String", "(", ")", "\n", "}", "\n", "return", "str"...
// String implements token.String.
[ "String", "implements", "token", ".", "String", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L597-L604
151,750
git-lfs/wildmatch
wildmatch.go
substring
func substring(sub string) componentFn { return &cfn{ fn: func(s string) (rest string, ok bool) { if !strings.HasPrefix(s, sub) { return s, false } return s[len(sub):], true }, str: sub, } }
go
func substring(sub string) componentFn { return &cfn{ fn: func(s string) (rest string, ok bool) { if !strings.HasPrefix(s, sub) { return s, false } return s[len(sub):], true }, str: sub, } }
[ "func", "substring", "(", "sub", "string", ")", "componentFn", "{", "return", "&", "cfn", "{", "fn", ":", "func", "(", "s", "string", ")", "(", "rest", "string", ",", "ok", "bool", ")", "{", "if", "!", "strings", ".", "HasPrefix", "(", "s", ",", ...
// substring returns a componentFn that matches a prefix of "sub".
[ "substring", "returns", "a", "componentFn", "that", "matches", "a", "prefix", "of", "sub", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L607-L617
151,751
git-lfs/wildmatch
wildmatch.go
wildcard
func wildcard(n int, fns []componentFn) componentFn { until := func(s string) (string, bool) { head := s for _, fn := range fns { var ok bool if head, ok = fn.Apply(head); !ok { return s, false } } if len(head) > 0 { return s, false } return "", true } var str string = "*" for _, fn := range fns { str += fn.String() } return &cfn{ fn: func(s string) (rest string, ok bool) { if n > -1 { if n > len(s) { return "", false } return until(s[n:]) } for i := len(s); i > 0; i-- { rest, ok = until(s[i:]) if ok { return rest, ok } } return until(s) }, str: str, } }
go
func wildcard(n int, fns []componentFn) componentFn { until := func(s string) (string, bool) { head := s for _, fn := range fns { var ok bool if head, ok = fn.Apply(head); !ok { return s, false } } if len(head) > 0 { return s, false } return "", true } var str string = "*" for _, fn := range fns { str += fn.String() } return &cfn{ fn: func(s string) (rest string, ok bool) { if n > -1 { if n > len(s) { return "", false } return until(s[n:]) } for i := len(s); i > 0; i-- { rest, ok = until(s[i:]) if ok { return rest, ok } } return until(s) }, str: str, } }
[ "func", "wildcard", "(", "n", "int", ",", "fns", "[", "]", "componentFn", ")", "componentFn", "{", "until", ":=", "func", "(", "s", "string", ")", "(", "string", ",", "bool", ")", "{", "head", ":=", "s", "\n", "for", "_", ",", "fn", ":=", "range"...
// wildcard returns a componentFn that greedily matches until a set of other // component functions no longer matches.
[ "wildcard", "returns", "a", "componentFn", "that", "greedily", "matches", "until", "a", "set", "of", "other", "component", "functions", "no", "longer", "matches", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L621-L662
151,752
git-lfs/wildmatch
wildmatch.go
anyRune
func anyRune(s string) runeFn { return func(r rune) bool { return strings.IndexRune(s, r) > -1 } }
go
func anyRune(s string) runeFn { return func(r rune) bool { return strings.IndexRune(s, r) > -1 } }
[ "func", "anyRune", "(", "s", "string", ")", "runeFn", "{", "return", "func", "(", "r", "rune", ")", "bool", "{", "return", "strings", ".", "IndexRune", "(", "s", ",", "r", ")", ">", "-", "1", "\n", "}", "\n", "}" ]
// anyRune returns true so long as the rune "r" appears in the string "s".
[ "anyRune", "returns", "true", "so", "long", "as", "the", "rune", "r", "appears", "in", "the", "string", "s", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L739-L743
151,753
git-lfs/wildmatch
wildmatch.go
between
func between(a, b rune) runeFn { if b < a { a, b = b, a } return func(r rune) bool { return a <= r && r <= b } }
go
func between(a, b rune) runeFn { if b < a { a, b = b, a } return func(r rune) bool { return a <= r && r <= b } }
[ "func", "between", "(", "a", ",", "b", "rune", ")", "runeFn", "{", "if", "b", "<", "a", "{", "a", ",", "b", "=", "b", ",", "a", "\n", "}", "\n\n", "return", "func", "(", "r", "rune", ")", "bool", "{", "return", "a", "<=", "r", "&&", "r", ...
// between returns true so long as the rune "r" appears between "a" and "b".
[ "between", "returns", "true", "so", "long", "as", "the", "rune", "r", "appears", "between", "a", "and", "b", "." ]
e7e73f3f066b2bdc2470b7b0d768e199269994a0
https://github.com/git-lfs/wildmatch/blob/e7e73f3f066b2bdc2470b7b0d768e199269994a0/wildmatch.go#L746-L754
151,754
badgerodon/penv
penv.go
RegisterDAO
func RegisterDAO(priority int, condition func() bool, dao DAO) { registered = append(registered, registeredDAO{dao, condition, priority}) sort.Sort(registered) }
go
func RegisterDAO(priority int, condition func() bool, dao DAO) { registered = append(registered, registeredDAO{dao, condition, priority}) sort.Sort(registered) }
[ "func", "RegisterDAO", "(", "priority", "int", ",", "condition", "func", "(", ")", "bool", ",", "dao", "DAO", ")", "{", "registered", "=", "append", "(", "registered", ",", "registeredDAO", "{", "dao", ",", "condition", ",", "priority", "}", ")", "\n", ...
// RegisterDAO registers a new data access object. DAOs are evaluted based on // priority and the condition function
[ "RegisterDAO", "registers", "a", "new", "data", "access", "object", ".", "DAOs", "are", "evaluted", "based", "on", "priority", "and", "the", "condition", "function" ]
7a4c6d64fa119b52afe2eb3f0801886bd8785318
https://github.com/badgerodon/penv/blob/7a4c6d64fa119b52afe2eb3f0801886bd8785318/penv.go#L69-L72
151,755
badgerodon/penv
penv.go
UnsetEnv
func UnsetEnv(name string) error { env, err := Load() if err != nil { return fmt.Errorf("failed to load environment: %v", err) } env.Setters = filter(env.Setters, func(nv NameValue) bool { return nv.Name != name }) env.Appenders = filter(env.Appenders, func(nv NameValue) bool { return nv.Name != name }) env.Unsetters = filter(env.Unsetters, func(nv NameValue) bool { return nv.Name != name }) env.Unsetters = append(env.Unsetters, NameValue{name, ""}) err = Save(env) if err != nil { return fmt.Errorf("failed to save environment: %v", err) } return nil }
go
func UnsetEnv(name string) error { env, err := Load() if err != nil { return fmt.Errorf("failed to load environment: %v", err) } env.Setters = filter(env.Setters, func(nv NameValue) bool { return nv.Name != name }) env.Appenders = filter(env.Appenders, func(nv NameValue) bool { return nv.Name != name }) env.Unsetters = filter(env.Unsetters, func(nv NameValue) bool { return nv.Name != name }) env.Unsetters = append(env.Unsetters, NameValue{name, ""}) err = Save(env) if err != nil { return fmt.Errorf("failed to save environment: %v", err) } return nil }
[ "func", "UnsetEnv", "(", "name", "string", ")", "error", "{", "env", ",", "err", ":=", "Load", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "env", ".", "Setter...
// UnsetEnv permanently unsets an environment variable
[ "UnsetEnv", "permanently", "unsets", "an", "environment", "variable" ]
7a4c6d64fa119b52afe2eb3f0801886bd8785318
https://github.com/badgerodon/penv/blob/7a4c6d64fa119b52afe2eb3f0801886bd8785318/penv.go#L146-L167
151,756
ory/osin-storage
storage/postgres/postgres.go
CreateSchemas
func (s *Storage) CreateSchemas() error { for k, schema := range schemas { if _, err := s.db.Exec(schema); err != nil { log.Printf("Error creating schema %d: %s", k, schema) return err } } return nil }
go
func (s *Storage) CreateSchemas() error { for k, schema := range schemas { if _, err := s.db.Exec(schema); err != nil { log.Printf("Error creating schema %d: %s", k, schema) return err } } return nil }
[ "func", "(", "s", "*", "Storage", ")", "CreateSchemas", "(", ")", "error", "{", "for", "k", ",", "schema", ":=", "range", "schemas", "{", "if", "_", ",", "err", ":=", "s", ".", "db", ".", "Exec", "(", "schema", ")", ";", "err", "!=", "nil", "{"...
// CreateSchemas creates the schemata, if they do not exist yet in the database. Returns an error if something went wrong.
[ "CreateSchemas", "creates", "the", "schemata", "if", "they", "do", "not", "exist", "yet", "in", "the", "database", ".", "Returns", "an", "error", "if", "something", "went", "wrong", "." ]
aa4920ab894adc94763e04a23f8bc11d171c5d45
https://github.com/ory/osin-storage/blob/aa4920ab894adc94763e04a23f8bc11d171c5d45/storage/postgres/postgres.go#L55-L63
151,757
keybase/go-merkle-tree
mem.go
CommitRoot
func (m *MemEngine) CommitRoot(_ context.Context, prev Hash, curr Hash, txinfo TxInfo) error { m.root = curr return nil }
go
func (m *MemEngine) CommitRoot(_ context.Context, prev Hash, curr Hash, txinfo TxInfo) error { m.root = curr return nil }
[ "func", "(", "m", "*", "MemEngine", ")", "CommitRoot", "(", "_", "context", ".", "Context", ",", "prev", "Hash", ",", "curr", "Hash", ",", "txinfo", "TxInfo", ")", "error", "{", "m", ".", "root", "=", "curr", "\n", "return", "nil", "\n", "}" ]
// CommitRoot "commits" the root ot the blessed memory slot
[ "CommitRoot", "commits", "the", "root", "ot", "the", "blessed", "memory", "slot" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/mem.go#L26-L29
151,758
keybase/go-merkle-tree
mem.go
Hash
func (m *MemEngine) Hash(_ context.Context, d []byte) Hash { sum := sha512.Sum512(d) return Hash(sum[:]) }
go
func (m *MemEngine) Hash(_ context.Context, d []byte) Hash { sum := sha512.Sum512(d) return Hash(sum[:]) }
[ "func", "(", "m", "*", "MemEngine", ")", "Hash", "(", "_", "context", ".", "Context", ",", "d", "[", "]", "byte", ")", "Hash", "{", "sum", ":=", "sha512", ".", "Sum512", "(", "d", ")", "\n", "return", "Hash", "(", "sum", "[", ":", "]", ")", "...
// Hash runs SHA512
[ "Hash", "runs", "SHA512" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/mem.go#L32-L35
151,759
keybase/go-merkle-tree
mem.go
LookupNode
func (m *MemEngine) LookupNode(_ context.Context, h Hash) (b []byte, err error) { return m.nodes[hex.EncodeToString(h)], nil }
go
func (m *MemEngine) LookupNode(_ context.Context, h Hash) (b []byte, err error) { return m.nodes[hex.EncodeToString(h)], nil }
[ "func", "(", "m", "*", "MemEngine", ")", "LookupNode", "(", "_", "context", ".", "Context", ",", "h", "Hash", ")", "(", "b", "[", "]", "byte", ",", "err", "error", ")", "{", "return", "m", ".", "nodes", "[", "hex", ".", "EncodeToString", "(", "h"...
// LookupNode looks up a MerkleTree node by hash
[ "LookupNode", "looks", "up", "a", "MerkleTree", "node", "by", "hash" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/mem.go#L38-L40
151,760
keybase/go-merkle-tree
mem.go
LookupRoot
func (m *MemEngine) LookupRoot(_ context.Context) (Hash, error) { return m.root, nil }
go
func (m *MemEngine) LookupRoot(_ context.Context) (Hash, error) { return m.root, nil }
[ "func", "(", "m", "*", "MemEngine", ")", "LookupRoot", "(", "_", "context", ".", "Context", ")", "(", "Hash", ",", "error", ")", "{", "return", "m", ".", "root", ",", "nil", "\n", "}" ]
// LookupRoot fetches the root of the in-memory tree back out
[ "LookupRoot", "fetches", "the", "root", "of", "the", "in", "-", "memory", "tree", "back", "out" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/mem.go#L43-L45
151,761
keybase/go-merkle-tree
mem.go
StoreNode
func (m *MemEngine) StoreNode(_ context.Context, key Hash, b []byte) error { m.nodes[hex.EncodeToString(key)] = b return nil }
go
func (m *MemEngine) StoreNode(_ context.Context, key Hash, b []byte) error { m.nodes[hex.EncodeToString(key)] = b return nil }
[ "func", "(", "m", "*", "MemEngine", ")", "StoreNode", "(", "_", "context", ".", "Context", ",", "key", "Hash", ",", "b", "[", "]", "byte", ")", "error", "{", "m", ".", "nodes", "[", "hex", ".", "EncodeToString", "(", "key", ")", "]", "=", "b", ...
// StoreNode stores the given node under the given key.
[ "StoreNode", "stores", "the", "given", "node", "under", "the", "given", "key", "." ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/mem.go#L48-L51
151,762
keybase/go-merkle-tree
sorted_map.go
NewSortedMapFromList
func NewSortedMapFromList(l []KeyValuePair) *SortedMap { ret := NewSortedMapFromSortedList(l) ret.sort() return ret }
go
func NewSortedMapFromList(l []KeyValuePair) *SortedMap { ret := NewSortedMapFromSortedList(l) ret.sort() return ret }
[ "func", "NewSortedMapFromList", "(", "l", "[", "]", "KeyValuePair", ")", "*", "SortedMap", "{", "ret", ":=", "NewSortedMapFromSortedList", "(", "l", ")", "\n", "ret", ".", "sort", "(", ")", "\n", "return", "ret", "\n", "}" ]
// NewSortedMapFromList makes a sorted map from an unsorted list // of KeyValuePairs
[ "NewSortedMapFromList", "makes", "a", "sorted", "map", "from", "an", "unsorted", "list", "of", "KeyValuePairs" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/sorted_map.go#L30-L34
151,763
keybase/go-merkle-tree
tree.go
NewTree
func NewTree(e StorageEngine, c Config) *Tree { return &Tree{eng: e, cfg: c} }
go
func NewTree(e StorageEngine, c Config) *Tree { return &Tree{eng: e, cfg: c} }
[ "func", "NewTree", "(", "e", "StorageEngine", ",", "c", "Config", ")", "*", "Tree", "{", "return", "&", "Tree", "{", "eng", ":", "e", ",", "cfg", ":", "c", "}", "\n", "}" ]
// NewTree makes a new tree
[ "NewTree", "makes", "a", "new", "tree" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/tree.go#L18-L20
151,764
keybase/go-merkle-tree
tree.go
Find
func (t *Tree) Find(ctx context.Context, h Hash) (ret interface{}, root Hash, err error) { return t.findTyped(ctx, h, false) }
go
func (t *Tree) Find(ctx context.Context, h Hash) (ret interface{}, root Hash, err error) { return t.findTyped(ctx, h, false) }
[ "func", "(", "t", "*", "Tree", ")", "Find", "(", "ctx", "context", ".", "Context", ",", "h", "Hash", ")", "(", "ret", "interface", "{", "}", ",", "root", "Hash", ",", "err", "error", ")", "{", "return", "t", ".", "findTyped", "(", "ctx", ",", "...
// Find the hash in the tree. Return the value stored at the leaf under // that hash, or nil if not found. Return an error if there was an // internal problem.
[ "Find", "the", "hash", "in", "the", "tree", ".", "Return", "the", "value", "stored", "at", "the", "leaf", "under", "that", "hash", "or", "nil", "if", "not", "found", ".", "Return", "an", "error", "if", "there", "was", "an", "internal", "problem", "." ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/tree.go#L184-L186
151,765
keybase/go-merkle-tree
tree.go
findUnsafe
func (t *Tree) findUnsafe(ctx context.Context, h Hash) (ret interface{}, root Hash, err error) { return t.findTyped(ctx, h, true) }
go
func (t *Tree) findUnsafe(ctx context.Context, h Hash) (ret interface{}, root Hash, err error) { return t.findTyped(ctx, h, true) }
[ "func", "(", "t", "*", "Tree", ")", "findUnsafe", "(", "ctx", "context", ".", "Context", ",", "h", "Hash", ")", "(", "ret", "interface", "{", "}", ",", "root", "Hash", ",", "err", "error", ")", "{", "return", "t", ".", "findTyped", "(", "ctx", ",...
// findUnsafe shouldn't be used, since it will skip hash comparisons // at interior nodes. It's mainly here for testing.
[ "findUnsafe", "shouldn", "t", "be", "used", "since", "it", "will", "skip", "hash", "comparisons", "at", "interior", "nodes", ".", "It", "s", "mainly", "here", "for", "testing", "." ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/tree.go#L190-L192
151,766
keybase/go-merkle-tree
tree.go
Upsert
func (t *Tree) Upsert(ctx context.Context, kvp KeyValuePair, txinfo TxInfo) (err error) { t.Lock() defer t.Unlock() root, err := t.eng.LookupRoot(ctx) if err != nil { return err } prevRoot := root var last *Node var path path var level Level var curr *Node // Root might be nil if we're upserting into an empty tree if root != nil { _, curr, err = t.lookupNode(ctx, root) if err != nil { return err } } // Find the path from the key up to the root; // find by walking down from the root. for curr != nil { prefix, index := t.cfg.prefixAndIndexAtLevel(level, kvp.Key) path.push(step{p: prefix, n: curr, l: level, i: index}) level++ last = curr if curr.Type == nodeTypeLeaf { break } nxt, err := curr.findChildByIndex(index) if err != nil { return err } if nxt == nil { break } _, curr, err = t.lookupNode(ctx, nxt) if err != nil { return err } } // Figure out what to store at the node where we stopped going down the path. var sm *SortedMap if last == nil || last.Type == nodeTypeINode { sm = newSortedMapFromKeyAndValue(kvp) level = 0 } else if val2 := last.findValueInLeaf(kvp.Key); val2 == nil || !deepEqual(val2, kvp.Value) { sm = newSortedMapFromNode(last).replace(kvp) level = path.len() - 1 } else { return nil } // Make a new subtree out of our new node. hsh, err := t.hashTreeRecursive(ctx, level, sm, prevRoot) if err != nil { return err } path.reverse() for _, step := range path.steps { if step.n.Type != nodeTypeINode { continue } sm := newChildPointerMapFromNode(step.n).set(step.i, hsh) var nodeExported []byte hsh, _, nodeExported, err = sm.exportToNode(t.cfg.hasher, prevRoot, step.l) if err != nil { return err } err = t.eng.StoreNode(ctx, hsh, nodeExported) if err != nil { return err } } err = t.eng.CommitRoot(ctx, prevRoot, hsh, txinfo) return err }
go
func (t *Tree) Upsert(ctx context.Context, kvp KeyValuePair, txinfo TxInfo) (err error) { t.Lock() defer t.Unlock() root, err := t.eng.LookupRoot(ctx) if err != nil { return err } prevRoot := root var last *Node var path path var level Level var curr *Node // Root might be nil if we're upserting into an empty tree if root != nil { _, curr, err = t.lookupNode(ctx, root) if err != nil { return err } } // Find the path from the key up to the root; // find by walking down from the root. for curr != nil { prefix, index := t.cfg.prefixAndIndexAtLevel(level, kvp.Key) path.push(step{p: prefix, n: curr, l: level, i: index}) level++ last = curr if curr.Type == nodeTypeLeaf { break } nxt, err := curr.findChildByIndex(index) if err != nil { return err } if nxt == nil { break } _, curr, err = t.lookupNode(ctx, nxt) if err != nil { return err } } // Figure out what to store at the node where we stopped going down the path. var sm *SortedMap if last == nil || last.Type == nodeTypeINode { sm = newSortedMapFromKeyAndValue(kvp) level = 0 } else if val2 := last.findValueInLeaf(kvp.Key); val2 == nil || !deepEqual(val2, kvp.Value) { sm = newSortedMapFromNode(last).replace(kvp) level = path.len() - 1 } else { return nil } // Make a new subtree out of our new node. hsh, err := t.hashTreeRecursive(ctx, level, sm, prevRoot) if err != nil { return err } path.reverse() for _, step := range path.steps { if step.n.Type != nodeTypeINode { continue } sm := newChildPointerMapFromNode(step.n).set(step.i, hsh) var nodeExported []byte hsh, _, nodeExported, err = sm.exportToNode(t.cfg.hasher, prevRoot, step.l) if err != nil { return err } err = t.eng.StoreNode(ctx, hsh, nodeExported) if err != nil { return err } } err = t.eng.CommitRoot(ctx, prevRoot, hsh, txinfo) return err }
[ "func", "(", "t", "*", "Tree", ")", "Upsert", "(", "ctx", "context", ".", "Context", ",", "kvp", "KeyValuePair", ",", "txinfo", "TxInfo", ")", "(", "err", "error", ")", "{", "t", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "Unlock", "(", ")",...
// Upsert inserts or updates the leaf with the given KeyValuePair // information. It will associate the given transaction info // if specified.
[ "Upsert", "inserts", "or", "updates", "the", "leaf", "with", "the", "given", "KeyValuePair", "information", ".", "It", "will", "associate", "the", "given", "transaction", "info", "if", "specified", "." ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/tree.go#L217-L302
151,767
sidbusy/weixinmp
accesstoken.go
Fresh
func (this *AccessToken) Fresh() (string, error) { if this.TmpName == "" { this.TmpName = this.AppId + "-accesstoken.tmp" } if this.LckName == "" { this.LckName = this.TmpName + ".lck" } for { if this.locked() { time.Sleep(time.Second) continue } break } fi, err := os.Stat(this.TmpName) if err != nil && !os.IsExist(err) { return this.fetchAndStore() } expires := fi.ModTime().Add(2 * time.Hour).Unix() if expires <= time.Now().Unix() { return this.fetchAndStore() } tmp, err := os.Open(this.TmpName) if err != nil { return "", err } defer tmp.Close() data, err := ioutil.ReadAll(tmp) if err != nil { return "", err } return string(data), nil }
go
func (this *AccessToken) Fresh() (string, error) { if this.TmpName == "" { this.TmpName = this.AppId + "-accesstoken.tmp" } if this.LckName == "" { this.LckName = this.TmpName + ".lck" } for { if this.locked() { time.Sleep(time.Second) continue } break } fi, err := os.Stat(this.TmpName) if err != nil && !os.IsExist(err) { return this.fetchAndStore() } expires := fi.ModTime().Add(2 * time.Hour).Unix() if expires <= time.Now().Unix() { return this.fetchAndStore() } tmp, err := os.Open(this.TmpName) if err != nil { return "", err } defer tmp.Close() data, err := ioutil.ReadAll(tmp) if err != nil { return "", err } return string(data), nil }
[ "func", "(", "this", "*", "AccessToken", ")", "Fresh", "(", ")", "(", "string", ",", "error", ")", "{", "if", "this", ".", "TmpName", "==", "\"", "\"", "{", "this", ".", "TmpName", "=", "this", ".", "AppId", "+", "\"", "\"", "\n", "}", "\n", "i...
// get fresh access_token string
[ "get", "fresh", "access_token", "string" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/accesstoken.go#L20-L52
151,768
sidbusy/weixinmp
weixinmp.go
ReplyTextMsg
func (this *Weixinmp) ReplyTextMsg(rw http.ResponseWriter, content string) error { var msg textMsg msg.MsgType = "text" msg.Content = content return this.replyMsg(rw, &msg) }
go
func (this *Weixinmp) ReplyTextMsg(rw http.ResponseWriter, content string) error { var msg textMsg msg.MsgType = "text" msg.Content = content return this.replyMsg(rw, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "ReplyTextMsg", "(", "rw", "http", ".", "ResponseWriter", ",", "content", "string", ")", "error", "{", "var", "msg", "textMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Content", "=", ...
// reply text message
[ "reply", "text", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L145-L150
151,769
sidbusy/weixinmp
weixinmp.go
ReplyImageMsg
func (this *Weixinmp) ReplyImageMsg(rw http.ResponseWriter, mediaId string) error { var msg imageMsg msg.MsgType = "image" msg.Image.MediaId = mediaId return this.replyMsg(rw, &msg) }
go
func (this *Weixinmp) ReplyImageMsg(rw http.ResponseWriter, mediaId string) error { var msg imageMsg msg.MsgType = "image" msg.Image.MediaId = mediaId return this.replyMsg(rw, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "ReplyImageMsg", "(", "rw", "http", ".", "ResponseWriter", ",", "mediaId", "string", ")", "error", "{", "var", "msg", "imageMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Image", ".", ...
// reply image message
[ "reply", "image", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L153-L158
151,770
sidbusy/weixinmp
weixinmp.go
ReplyVoiceMsg
func (this *Weixinmp) ReplyVoiceMsg(rw http.ResponseWriter, mediaId string) error { var msg voiceMsg msg.MsgType = "voice" msg.Voice.MediaId = mediaId return this.replyMsg(rw, &msg) }
go
func (this *Weixinmp) ReplyVoiceMsg(rw http.ResponseWriter, mediaId string) error { var msg voiceMsg msg.MsgType = "voice" msg.Voice.MediaId = mediaId return this.replyMsg(rw, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "ReplyVoiceMsg", "(", "rw", "http", ".", "ResponseWriter", ",", "mediaId", "string", ")", "error", "{", "var", "msg", "voiceMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Voice", ".", ...
// reply voice message
[ "reply", "voice", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L161-L166
151,771
sidbusy/weixinmp
weixinmp.go
ReplyVideoMsg
func (this *Weixinmp) ReplyVideoMsg(rw http.ResponseWriter, video *Video) error { var msg videoMsg msg.MsgType = "video" msg.Video = video return this.replyMsg(rw, &msg) }
go
func (this *Weixinmp) ReplyVideoMsg(rw http.ResponseWriter, video *Video) error { var msg videoMsg msg.MsgType = "video" msg.Video = video return this.replyMsg(rw, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "ReplyVideoMsg", "(", "rw", "http", ".", "ResponseWriter", ",", "video", "*", "Video", ")", "error", "{", "var", "msg", "videoMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Video", "=...
// reply video message
[ "reply", "video", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L169-L174
151,772
sidbusy/weixinmp
weixinmp.go
ReplyMusicMsg
func (this *Weixinmp) ReplyMusicMsg(rw http.ResponseWriter, music *Music) error { var msg musicMsg msg.MsgType = "music" msg.Music = music return this.replyMsg(rw, &msg) }
go
func (this *Weixinmp) ReplyMusicMsg(rw http.ResponseWriter, music *Music) error { var msg musicMsg msg.MsgType = "music" msg.Music = music return this.replyMsg(rw, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "ReplyMusicMsg", "(", "rw", "http", ".", "ResponseWriter", ",", "music", "*", "Music", ")", "error", "{", "var", "msg", "musicMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Music", "=...
// reply music message
[ "reply", "music", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L177-L182
151,773
sidbusy/weixinmp
weixinmp.go
ReplyNewsMsg
func (this *Weixinmp) ReplyNewsMsg(rw http.ResponseWriter, articles *[]Article) error { var msg newsMsg msg.MsgType = "news" msg.ArticleCount = len(*articles) msg.Articles.Item = articles return this.replyMsg(rw, &msg) }
go
func (this *Weixinmp) ReplyNewsMsg(rw http.ResponseWriter, articles *[]Article) error { var msg newsMsg msg.MsgType = "news" msg.ArticleCount = len(*articles) msg.Articles.Item = articles return this.replyMsg(rw, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "ReplyNewsMsg", "(", "rw", "http", ".", "ResponseWriter", ",", "articles", "*", "[", "]", "Article", ")", "error", "{", "var", "msg", "newsMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", "."...
// reply news message
[ "reply", "news", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L185-L191
151,774
sidbusy/weixinmp
weixinmp.go
SendTextMsg
func (this *Weixinmp) SendTextMsg(touser string, content string) error { var msg textMsg msg.MsgType = "text" msg.Text.Content = content return this.sendMsg(touser, &msg) }
go
func (this *Weixinmp) SendTextMsg(touser string, content string) error { var msg textMsg msg.MsgType = "text" msg.Text.Content = content return this.sendMsg(touser, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "SendTextMsg", "(", "touser", "string", ",", "content", "string", ")", "error", "{", "var", "msg", "textMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Text", ".", "Content", "=", "con...
// send text message
[ "send", "text", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L210-L215
151,775
sidbusy/weixinmp
weixinmp.go
SendImageMsg
func (this *Weixinmp) SendImageMsg(touser string, mediaId string) error { var msg imageMsg msg.MsgType = "image" msg.Image.MediaId = mediaId return this.sendMsg(touser, &msg) }
go
func (this *Weixinmp) SendImageMsg(touser string, mediaId string) error { var msg imageMsg msg.MsgType = "image" msg.Image.MediaId = mediaId return this.sendMsg(touser, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "SendImageMsg", "(", "touser", "string", ",", "mediaId", "string", ")", "error", "{", "var", "msg", "imageMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Image", ".", "MediaId", "=", "...
// send image message
[ "send", "image", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L218-L223
151,776
sidbusy/weixinmp
weixinmp.go
SendVoiceMsg
func (this *Weixinmp) SendVoiceMsg(touser string, mediaId string) error { var msg voiceMsg msg.MsgType = "voice" msg.Voice.MediaId = mediaId return this.sendMsg(touser, &msg) }
go
func (this *Weixinmp) SendVoiceMsg(touser string, mediaId string) error { var msg voiceMsg msg.MsgType = "voice" msg.Voice.MediaId = mediaId return this.sendMsg(touser, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "SendVoiceMsg", "(", "touser", "string", ",", "mediaId", "string", ")", "error", "{", "var", "msg", "voiceMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Voice", ".", "MediaId", "=", "...
// send voice message
[ "send", "voice", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L226-L231
151,777
sidbusy/weixinmp
weixinmp.go
SendVideoMsg
func (this *Weixinmp) SendVideoMsg(touser string, video *Video) error { var msg videoMsg msg.MsgType = "video" msg.Video = video return this.sendMsg(touser, &msg) }
go
func (this *Weixinmp) SendVideoMsg(touser string, video *Video) error { var msg videoMsg msg.MsgType = "video" msg.Video = video return this.sendMsg(touser, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "SendVideoMsg", "(", "touser", "string", ",", "video", "*", "Video", ")", "error", "{", "var", "msg", "videoMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Video", "=", "video", "\n", ...
// send video message
[ "send", "video", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L234-L239
151,778
sidbusy/weixinmp
weixinmp.go
SendMusicMsg
func (this *Weixinmp) SendMusicMsg(touser string, music *Music) error { var msg musicMsg msg.MsgType = "music" msg.Music = music return this.sendMsg(touser, &msg) }
go
func (this *Weixinmp) SendMusicMsg(touser string, music *Music) error { var msg musicMsg msg.MsgType = "music" msg.Music = music return this.sendMsg(touser, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "SendMusicMsg", "(", "touser", "string", ",", "music", "*", "Music", ")", "error", "{", "var", "msg", "musicMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Music", "=", "music", "\n", ...
// send music message
[ "send", "music", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L242-L247
151,779
sidbusy/weixinmp
weixinmp.go
SendNewsMsg
func (this *Weixinmp) SendNewsMsg(touser string, articles *[]Article) error { var msg newsMsg msg.MsgType = "news" msg.Articles.Item = articles return this.sendMsg(touser, &msg) }
go
func (this *Weixinmp) SendNewsMsg(touser string, articles *[]Article) error { var msg newsMsg msg.MsgType = "news" msg.Articles.Item = articles return this.sendMsg(touser, &msg) }
[ "func", "(", "this", "*", "Weixinmp", ")", "SendNewsMsg", "(", "touser", "string", ",", "articles", "*", "[", "]", "Article", ")", "error", "{", "var", "msg", "newsMsg", "\n", "msg", ".", "MsgType", "=", "\"", "\"", "\n", "msg", ".", "Articles", ".",...
// send news message
[ "send", "news", "message" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L250-L255
151,780
sidbusy/weixinmp
weixinmp.go
CreateQRScene
func (this *Weixinmp) CreateQRScene(sceneId int64) (string, error) { var inf qrScene inf.ActionName = "QR_SCENE" inf.ActionInfo.Scene.SceneId = sceneId return this.createQRCode(&inf) }
go
func (this *Weixinmp) CreateQRScene(sceneId int64) (string, error) { var inf qrScene inf.ActionName = "QR_SCENE" inf.ActionInfo.Scene.SceneId = sceneId return this.createQRCode(&inf) }
[ "func", "(", "this", "*", "Weixinmp", ")", "CreateQRScene", "(", "sceneId", "int64", ")", "(", "string", ",", "error", ")", "{", "var", "inf", "qrScene", "\n", "inf", ".", "ActionName", "=", "\"", "\"", "\n", "inf", ".", "ActionInfo", ".", "Scene", "...
// create permanent qrcode
[ "create", "permanent", "qrcode" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L350-L355
151,781
sidbusy/weixinmp
weixinmp.go
CreateQRLimitScene
func (this *Weixinmp) CreateQRLimitScene(expireSeconds, sceneId int64) (string, error) { var inf qrScene inf.ExpireSeconds = expireSeconds inf.ActionName = "QR_LIMIT_SCENE" inf.ActionInfo.Scene.SceneId = sceneId return this.createQRCode(&inf) }
go
func (this *Weixinmp) CreateQRLimitScene(expireSeconds, sceneId int64) (string, error) { var inf qrScene inf.ExpireSeconds = expireSeconds inf.ActionName = "QR_LIMIT_SCENE" inf.ActionInfo.Scene.SceneId = sceneId return this.createQRCode(&inf) }
[ "func", "(", "this", "*", "Weixinmp", ")", "CreateQRLimitScene", "(", "expireSeconds", ",", "sceneId", "int64", ")", "(", "string", ",", "error", ")", "{", "var", "inf", "qrScene", "\n", "inf", ".", "ExpireSeconds", "=", "expireSeconds", "\n", "inf", ".", ...
// create temporary qrcode
[ "create", "temporary", "qrcode" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L358-L364
151,782
sidbusy/weixinmp
weixinmp.go
DownloadMediaFile
func (this *Weixinmp) DownloadMediaFile(mediaId, fileName string) error { url := fmt.Sprintf("%sget?media_id=%s&access_token=", MediaUrlPrefix, mediaId) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return err } resp, err := http.Get(url + token) if err != nil { if i < retryNum-1 { continue } return err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { if i < retryNum-1 { continue } return err } // json if resp.Header.Get("Content-Type") == "text/plain" { var rtn response if err := json.Unmarshal(data, &rtn); err != nil { if i < retryNum-1 { continue } return err } if i < retryNum-1 { continue } return errors.New(fmt.Sprintf("%d %s", rtn.ErrCode, rtn.ErrMsg)) } // media f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, os.ModePerm) if err != nil { if i < retryNum-1 { continue } return err } defer f.Close() if _, err := f.Write(data); err != nil { if i < retryNum-1 { continue } return err } break // success } return nil }
go
func (this *Weixinmp) DownloadMediaFile(mediaId, fileName string) error { url := fmt.Sprintf("%sget?media_id=%s&access_token=", MediaUrlPrefix, mediaId) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return err } resp, err := http.Get(url + token) if err != nil { if i < retryNum-1 { continue } return err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { if i < retryNum-1 { continue } return err } // json if resp.Header.Get("Content-Type") == "text/plain" { var rtn response if err := json.Unmarshal(data, &rtn); err != nil { if i < retryNum-1 { continue } return err } if i < retryNum-1 { continue } return errors.New(fmt.Sprintf("%d %s", rtn.ErrCode, rtn.ErrMsg)) } // media f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, os.ModePerm) if err != nil { if i < retryNum-1 { continue } return err } defer f.Close() if _, err := f.Write(data); err != nil { if i < retryNum-1 { continue } return err } break // success } return nil }
[ "func", "(", "this", "*", "Weixinmp", ")", "DownloadMediaFile", "(", "mediaId", ",", "fileName", "string", ")", "error", "{", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "MediaUrlPrefix", ",", "mediaId", ")", "\n", "// retry", "for", "i", ...
// download media to file
[ "download", "media", "to", "file" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L397-L455
151,783
sidbusy/weixinmp
weixinmp.go
UploadMediaFile
func (this *Weixinmp) UploadMediaFile(mediaType, fileName string) (string, error) { var buf bytes.Buffer bw := multipart.NewWriter(&buf) defer bw.Close() f, err := os.Open(fileName) if err != nil { return "", err } defer f.Close() fw, err := bw.CreateFormFile("filename", f.Name()) if err != nil { return "", err } if _, err := io.Copy(fw, f); err != nil { return "", err } f.Close() bw.Close() url := fmt.Sprintf("%supload?type=%s&access_token=", MediaUrlPrefix, mediaType) mime := bw.FormDataContentType() mediaId := "" // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return "", err } rtn, err := post(url+token, mime, &buf) if err != nil { if i < retryNum-1 { continue } return "", err } mediaId = rtn.MediaId break // success } return mediaId, nil }
go
func (this *Weixinmp) UploadMediaFile(mediaType, fileName string) (string, error) { var buf bytes.Buffer bw := multipart.NewWriter(&buf) defer bw.Close() f, err := os.Open(fileName) if err != nil { return "", err } defer f.Close() fw, err := bw.CreateFormFile("filename", f.Name()) if err != nil { return "", err } if _, err := io.Copy(fw, f); err != nil { return "", err } f.Close() bw.Close() url := fmt.Sprintf("%supload?type=%s&access_token=", MediaUrlPrefix, mediaType) mime := bw.FormDataContentType() mediaId := "" // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return "", err } rtn, err := post(url+token, mime, &buf) if err != nil { if i < retryNum-1 { continue } return "", err } mediaId = rtn.MediaId break // success } return mediaId, nil }
[ "func", "(", "this", "*", "Weixinmp", ")", "UploadMediaFile", "(", "mediaType", ",", "fileName", "string", ")", "(", "string", ",", "error", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "bw", ":=", "multipart", ".", "NewWriter", "(", "&", "buf...
// upload media to file
[ "upload", "media", "to", "file" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L458-L499
151,784
sidbusy/weixinmp
weixinmp.go
CreateCustomMenu
func (this *Weixinmp) CreateCustomMenu(btn *[]Button) error { var menu struct { Button *[]Button `json:"button"` } menu.Button = btn data, err := json.Marshal(&menu) if err != nil { return err } buf := bytes.NewBuffer(data) url := fmt.Sprintf("%smenu/create?access_token=", UrlPrefix) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return err } if _, err := post(url+token, "text/plain", buf); err != nil { if i < retryNum-1 { continue } return err } break // success } return nil }
go
func (this *Weixinmp) CreateCustomMenu(btn *[]Button) error { var menu struct { Button *[]Button `json:"button"` } menu.Button = btn data, err := json.Marshal(&menu) if err != nil { return err } buf := bytes.NewBuffer(data) url := fmt.Sprintf("%smenu/create?access_token=", UrlPrefix) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return err } if _, err := post(url+token, "text/plain", buf); err != nil { if i < retryNum-1 { continue } return err } break // success } return nil }
[ "func", "(", "this", "*", "Weixinmp", ")", "CreateCustomMenu", "(", "btn", "*", "[", "]", "Button", ")", "error", "{", "var", "menu", "struct", "{", "Button", "*", "[", "]", "Button", "`json:\"button\"`", "\n", "}", "\n", "menu", ".", "Button", "=", ...
// create custom menu
[ "create", "custom", "menu" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L510-L539
151,785
sidbusy/weixinmp
weixinmp.go
GetCustomMenu
func (this *Weixinmp) GetCustomMenu() ([]Button, error) { var menu struct { Menu struct { Button []Button `json:"button"` } `json:"menu"` } url := fmt.Sprintf("%smenu/get?access_token=", UrlPrefix) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return nil, err } resp, err := http.Get(url + token) if err != nil { if i < retryNum-1 { continue } return nil, err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { if i < retryNum-1 { continue } return nil, err } // has error? var rtn response if err := json.Unmarshal(data, &rtn); err != nil { if i < retryNum-1 { continue } return nil, err } // yes if rtn.ErrCode != 0 { if i < retryNum-1 { continue } return nil, errors.New(fmt.Sprintf("%d %s", rtn.ErrCode, rtn.ErrMsg)) } // no if err := json.Unmarshal(data, &menu); err != nil { if i < retryNum-1 { continue } return nil, err } break // success } return menu.Menu.Button, nil }
go
func (this *Weixinmp) GetCustomMenu() ([]Button, error) { var menu struct { Menu struct { Button []Button `json:"button"` } `json:"menu"` } url := fmt.Sprintf("%smenu/get?access_token=", UrlPrefix) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return nil, err } resp, err := http.Get(url + token) if err != nil { if i < retryNum-1 { continue } return nil, err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { if i < retryNum-1 { continue } return nil, err } // has error? var rtn response if err := json.Unmarshal(data, &rtn); err != nil { if i < retryNum-1 { continue } return nil, err } // yes if rtn.ErrCode != 0 { if i < retryNum-1 { continue } return nil, errors.New(fmt.Sprintf("%d %s", rtn.ErrCode, rtn.ErrMsg)) } // no if err := json.Unmarshal(data, &menu); err != nil { if i < retryNum-1 { continue } return nil, err } break // success } return menu.Menu.Button, nil }
[ "func", "(", "this", "*", "Weixinmp", ")", "GetCustomMenu", "(", ")", "(", "[", "]", "Button", ",", "error", ")", "{", "var", "menu", "struct", "{", "Menu", "struct", "{", "Button", "[", "]", "Button", "`json:\"button\"`", "\n", "}", "`json:\"menu\"`", ...
// get custom menu
[ "get", "custom", "menu" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L542-L598
151,786
sidbusy/weixinmp
weixinmp.go
DeleteCustomMenu
func (this *Weixinmp) DeleteCustomMenu() error { url := UrlPrefix + "menu/delete?access_token=" // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return err } if _, err := get(url + token); err != nil { if i < retryNum-1 { continue } return err } break // success } return nil }
go
func (this *Weixinmp) DeleteCustomMenu() error { url := UrlPrefix + "menu/delete?access_token=" // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return err } if _, err := get(url + token); err != nil { if i < retryNum-1 { continue } return err } break // success } return nil }
[ "func", "(", "this", "*", "Weixinmp", ")", "DeleteCustomMenu", "(", ")", "error", "{", "url", ":=", "UrlPrefix", "+", "\"", "\"", "\n", "// retry", "for", "i", ":=", "0", ";", "i", "<", "retryNum", ";", "i", "++", "{", "token", ",", "err", ":=", ...
// delete custom menu
[ "delete", "custom", "menu" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L601-L621
151,787
sidbusy/weixinmp
weixinmp.go
GetUserInfo
func (this *Weixinmp) GetUserInfo(openId string) (UserInfo, error) { var uinf UserInfo url := fmt.Sprintf("%suser/info?lang=zh_CN&openid=%s&access_token=", UrlPrefix, openId) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return uinf, err } resp, err := http.Get(url + token) if err != nil { if i < retryNum-1 { continue } return uinf, err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { if i < retryNum-1 { continue } return uinf, err } // has error? var rtn response if err := json.Unmarshal(data, &rtn); err != nil { if i < retryNum-1 { continue } return uinf, err } // yes if rtn.ErrCode != 0 { if i < retryNum-1 { continue } return uinf, errors.New(fmt.Sprintf("%d %s", rtn.ErrCode, rtn.ErrMsg)) } // no if err := json.Unmarshal(data, &uinf); err != nil { if i < retryNum-1 { continue } return uinf, err } break // success } return uinf, nil }
go
func (this *Weixinmp) GetUserInfo(openId string) (UserInfo, error) { var uinf UserInfo url := fmt.Sprintf("%suser/info?lang=zh_CN&openid=%s&access_token=", UrlPrefix, openId) // retry for i := 0; i < retryNum; i++ { token, err := this.AccessToken.Fresh() if err != nil { if i < retryNum-1 { continue } return uinf, err } resp, err := http.Get(url + token) if err != nil { if i < retryNum-1 { continue } return uinf, err } defer resp.Body.Close() data, err := ioutil.ReadAll(resp.Body) if err != nil { if i < retryNum-1 { continue } return uinf, err } // has error? var rtn response if err := json.Unmarshal(data, &rtn); err != nil { if i < retryNum-1 { continue } return uinf, err } // yes if rtn.ErrCode != 0 { if i < retryNum-1 { continue } return uinf, errors.New(fmt.Sprintf("%d %s", rtn.ErrCode, rtn.ErrMsg)) } // no if err := json.Unmarshal(data, &uinf); err != nil { if i < retryNum-1 { continue } return uinf, err } break // success } return uinf, nil }
[ "func", "(", "this", "*", "Weixinmp", ")", "GetUserInfo", "(", "openId", "string", ")", "(", "UserInfo", ",", "error", ")", "{", "var", "uinf", "UserInfo", "\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "UrlPrefix", ",", "openId", ")...
// get user info
[ "get", "user", "info" ]
60f690ec753ac5e3c6385c7bb5e6998d4c493bfe
https://github.com/sidbusy/weixinmp/blob/60f690ec753ac5e3c6385c7bb5e6998d4c493bfe/weixinmp.go#L637-L689
151,788
jupp0r/go-priority-queue
priorty_queue.go
Insert
func (p *PriorityQueue) Insert(v interface{}, priority float64) { _, ok := p.lookup[v] if ok { return } newItem := &item{ value: v, priority: priority, } heap.Push(p.itemHeap, newItem) p.lookup[v] = newItem }
go
func (p *PriorityQueue) Insert(v interface{}, priority float64) { _, ok := p.lookup[v] if ok { return } newItem := &item{ value: v, priority: priority, } heap.Push(p.itemHeap, newItem) p.lookup[v] = newItem }
[ "func", "(", "p", "*", "PriorityQueue", ")", "Insert", "(", "v", "interface", "{", "}", ",", "priority", "float64", ")", "{", "_", ",", "ok", ":=", "p", ".", "lookup", "[", "v", "]", "\n", "if", "ok", "{", "return", "\n", "}", "\n\n", "newItem", ...
// Insert inserts a new element into the queue. No action is performed on duplicate elements.
[ "Insert", "inserts", "a", "new", "element", "into", "the", "queue", ".", "No", "action", "is", "performed", "on", "duplicate", "elements", "." ]
ab1073853bdeba13dfbd3bcd4330958e11bf0c2c
https://github.com/jupp0r/go-priority-queue/blob/ab1073853bdeba13dfbd3bcd4330958e11bf0c2c/priorty_queue.go#L34-L46
151,789
jupp0r/go-priority-queue
priorty_queue.go
Pop
func (p *PriorityQueue) Pop() (interface{}, error) { if len(*p.itemHeap) == 0 { return nil, errors.New("empty queue") } item := heap.Pop(p.itemHeap).(*item) delete(p.lookup, item.value) return item.value, nil }
go
func (p *PriorityQueue) Pop() (interface{}, error) { if len(*p.itemHeap) == 0 { return nil, errors.New("empty queue") } item := heap.Pop(p.itemHeap).(*item) delete(p.lookup, item.value) return item.value, nil }
[ "func", "(", "p", "*", "PriorityQueue", ")", "Pop", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "len", "(", "*", "p", ".", "itemHeap", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", "...
// Pop removes the element with the highest priority from the queue and returns it. // In case of an empty queue, an error is returned.
[ "Pop", "removes", "the", "element", "with", "the", "highest", "priority", "from", "the", "queue", "and", "returns", "it", ".", "In", "case", "of", "an", "empty", "queue", "an", "error", "is", "returned", "." ]
ab1073853bdeba13dfbd3bcd4330958e11bf0c2c
https://github.com/jupp0r/go-priority-queue/blob/ab1073853bdeba13dfbd3bcd4330958e11bf0c2c/priorty_queue.go#L50-L58
151,790
jupp0r/go-priority-queue
priorty_queue.go
UpdatePriority
func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority float64) { item, ok := p.lookup[x] if !ok { return } item.priority = newPriority heap.Fix(p.itemHeap, item.index) }
go
func (p *PriorityQueue) UpdatePriority(x interface{}, newPriority float64) { item, ok := p.lookup[x] if !ok { return } item.priority = newPriority heap.Fix(p.itemHeap, item.index) }
[ "func", "(", "p", "*", "PriorityQueue", ")", "UpdatePriority", "(", "x", "interface", "{", "}", ",", "newPriority", "float64", ")", "{", "item", ",", "ok", ":=", "p", ".", "lookup", "[", "x", "]", "\n", "if", "!", "ok", "{", "return", "\n", "}", ...
// UpdatePriority changes the priority of a given item. // If the specified item is not present in the queue, no action is performed.
[ "UpdatePriority", "changes", "the", "priority", "of", "a", "given", "item", ".", "If", "the", "specified", "item", "is", "not", "present", "in", "the", "queue", "no", "action", "is", "performed", "." ]
ab1073853bdeba13dfbd3bcd4330958e11bf0c2c
https://github.com/jupp0r/go-priority-queue/blob/ab1073853bdeba13dfbd3bcd4330958e11bf0c2c/priorty_queue.go#L62-L70
151,791
keybase/go-merkle-tree
hash.go
Len
func (h Hash) Len() int { ret := len(h) for _, c := range h { if c == 0 { ret-- } else { break } } return ret }
go
func (h Hash) Len() int { ret := len(h) for _, c := range h { if c == 0 { ret-- } else { break } } return ret }
[ "func", "(", "h", "Hash", ")", "Len", "(", ")", "int", "{", "ret", ":=", "len", "(", "h", ")", "\n", "for", "_", ",", "c", ":=", "range", "h", "{", "if", "c", "==", "0", "{", "ret", "--", "\n", "}", "else", "{", "break", "\n", "}", "\n", ...
// Len returns the number of bytes in the hash, but after shifting off // leading 0s from the length size of the hash
[ "Len", "returns", "the", "number", "of", "bytes", "in", "the", "hash", "but", "after", "shifting", "off", "leading", "0s", "from", "the", "length", "size", "of", "the", "hash" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/hash.go#L9-L19
151,792
keybase/go-merkle-tree
hash.go
Hash
func (s SHA512Hasher) Hash(b []byte) Hash { tmp := sha512.Sum512(b) return Hash(tmp[:]) }
go
func (s SHA512Hasher) Hash(b []byte) Hash { tmp := sha512.Sum512(b) return Hash(tmp[:]) }
[ "func", "(", "s", "SHA512Hasher", ")", "Hash", "(", "b", "[", "]", "byte", ")", "Hash", "{", "tmp", ":=", "sha512", ".", "Sum512", "(", "b", ")", "\n", "return", "Hash", "(", "tmp", "[", ":", "]", ")", "\n", "}" ]
// Hash the data
[ "Hash", "the", "data" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/hash.go#L56-L59
151,793
keybase/go-merkle-tree
node.go
MarshalJSON
func (h Hash) MarshalJSON() ([]byte, error) { if len(h) == 0 { return []byte("\"\""), nil } return []byte("\"" + hex.EncodeToString(h)[0:8] + "\""), nil }
go
func (h Hash) MarshalJSON() ([]byte, error) { if len(h) == 0 { return []byte("\"\""), nil } return []byte("\"" + hex.EncodeToString(h)[0:8] + "\""), nil }
[ "func", "(", "h", "Hash", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "len", "(", "h", ")", "==", "0", "{", "return", "[", "]", "byte", "(", "\"", "\\\"", "\\\"", "\"", ")", ",", "nil", "\n", "}", "\n"...
// MarshalJSON prints out a hash for debugging purposes. Not recommended for actual // JSONing
[ "MarshalJSON", "prints", "out", "a", "hash", "for", "debugging", "purposes", ".", "Not", "recommended", "for", "actual", "JSONing" ]
90288bcf8366442e1d29ad22356fae3f2e8254a5
https://github.com/keybase/go-merkle-tree/blob/90288bcf8366442e1d29ad22356fae3f2e8254a5/node.go#L33-L38
151,794
ulule/gostorages
base.go
Path
func (s *BaseStorage) Path(filepath string) string { return path.Join(s.Location, filepath) }
go
func (s *BaseStorage) Path(filepath string) string { return path.Join(s.Location, filepath) }
[ "func", "(", "s", "*", "BaseStorage", ")", "Path", "(", "filepath", "string", ")", "string", "{", "return", "path", ".", "Join", "(", "s", ".", "Location", ",", "filepath", ")", "\n", "}" ]
// Path joins the given file to the storage path
[ "Path", "joins", "the", "given", "file", "to", "the", "storage", "path" ]
e2229fc2f445b6a607e1fa0a1fe2d0f7cad8a97c
https://github.com/ulule/gostorages/blob/e2229fc2f445b6a607e1fa0a1fe2d0f7cad8a97c/base.go#L55-L57
151,795
cgrates/ltcache
transcache.go
NewTransCache
func NewTransCache(cfg map[string]*CacheConfig) (tc *TransCache) { if _, has := cfg[DefaultCacheInstance]; !has { // Default always created cfg[DefaultCacheInstance] = &CacheConfig{MaxItems: -1} } tc = &TransCache{ cache: make(map[string]*Cache), cfg: cfg, transactionBuffer: make(map[string][]*transactionItem), } for cacheID, chCfg := range cfg { tc.cache[cacheID] = NewCache(chCfg.MaxItems, chCfg.TTL, chCfg.StaticTTL, chCfg.OnEvicted) } return }
go
func NewTransCache(cfg map[string]*CacheConfig) (tc *TransCache) { if _, has := cfg[DefaultCacheInstance]; !has { // Default always created cfg[DefaultCacheInstance] = &CacheConfig{MaxItems: -1} } tc = &TransCache{ cache: make(map[string]*Cache), cfg: cfg, transactionBuffer: make(map[string][]*transactionItem), } for cacheID, chCfg := range cfg { tc.cache[cacheID] = NewCache(chCfg.MaxItems, chCfg.TTL, chCfg.StaticTTL, chCfg.OnEvicted) } return }
[ "func", "NewTransCache", "(", "cfg", "map", "[", "string", "]", "*", "CacheConfig", ")", "(", "tc", "*", "TransCache", ")", "{", "if", "_", ",", "has", ":=", "cfg", "[", "DefaultCacheInstance", "]", ";", "!", "has", "{", "// Default always created", "cfg...
// NewTransCache instantiates a new TransCache
[ "NewTransCache", "instantiates", "a", "new", "TransCache" ]
92fb7fa77cca400b55d805e4a6d625443027c7f5
https://github.com/cgrates/ltcache/blob/92fb7fa77cca400b55d805e4a6d625443027c7f5/transcache.go#L65-L78
151,796
cgrates/ltcache
transcache.go
cacheInstance
func (tc *TransCache) cacheInstance(chID string) (c *Cache) { var ok bool if c, ok = tc.cache[chID]; !ok { c = tc.cache[DefaultCacheInstance] } return }
go
func (tc *TransCache) cacheInstance(chID string) (c *Cache) { var ok bool if c, ok = tc.cache[chID]; !ok { c = tc.cache[DefaultCacheInstance] } return }
[ "func", "(", "tc", "*", "TransCache", ")", "cacheInstance", "(", "chID", "string", ")", "(", "c", "*", "Cache", ")", "{", "var", "ok", "bool", "\n", "if", "c", ",", "ok", "=", "tc", ".", "cache", "[", "chID", "]", ";", "!", "ok", "{", "c", "=...
// cacheInstance returns a specific cache instance based on ID or default
[ "cacheInstance", "returns", "a", "specific", "cache", "instance", "based", "on", "ID", "or", "default" ]
92fb7fa77cca400b55d805e4a6d625443027c7f5
https://github.com/cgrates/ltcache/blob/92fb7fa77cca400b55d805e4a6d625443027c7f5/transcache.go#L92-L98
151,797
cgrates/ltcache
transcache.go
BeginTransaction
func (tc *TransCache) BeginTransaction() (transID string) { transID = GenUUID() tc.transBufMux.Lock() tc.transactionBuffer[transID] = make([]*transactionItem, 0) tc.transBufMux.Unlock() return transID }
go
func (tc *TransCache) BeginTransaction() (transID string) { transID = GenUUID() tc.transBufMux.Lock() tc.transactionBuffer[transID] = make([]*transactionItem, 0) tc.transBufMux.Unlock() return transID }
[ "func", "(", "tc", "*", "TransCache", ")", "BeginTransaction", "(", ")", "(", "transID", "string", ")", "{", "transID", "=", "GenUUID", "(", ")", "\n", "tc", ".", "transBufMux", ".", "Lock", "(", ")", "\n", "tc", ".", "transactionBuffer", "[", "transID...
// BeginTransaction initializes a new transaction into transactions buffer
[ "BeginTransaction", "initializes", "a", "new", "transaction", "into", "transactions", "buffer" ]
92fb7fa77cca400b55d805e4a6d625443027c7f5
https://github.com/cgrates/ltcache/blob/92fb7fa77cca400b55d805e4a6d625443027c7f5/transcache.go#L101-L107
151,798
cgrates/ltcache
transcache.go
RollbackTransaction
func (tc *TransCache) RollbackTransaction(transID string) { tc.transBufMux.Lock() delete(tc.transactionBuffer, transID) tc.transBufMux.Unlock() }
go
func (tc *TransCache) RollbackTransaction(transID string) { tc.transBufMux.Lock() delete(tc.transactionBuffer, transID) tc.transBufMux.Unlock() }
[ "func", "(", "tc", "*", "TransCache", ")", "RollbackTransaction", "(", "transID", "string", ")", "{", "tc", ".", "transBufMux", ".", "Lock", "(", ")", "\n", "delete", "(", "tc", ".", "transactionBuffer", ",", "transID", ")", "\n", "tc", ".", "transBufMux...
// RollbackTransaction destroys a transaction from transactions buffer
[ "RollbackTransaction", "destroys", "a", "transaction", "from", "transactions", "buffer" ]
92fb7fa77cca400b55d805e4a6d625443027c7f5
https://github.com/cgrates/ltcache/blob/92fb7fa77cca400b55d805e4a6d625443027c7f5/transcache.go#L110-L114
151,799
cgrates/ltcache
transcache.go
CommitTransaction
func (tc *TransCache) CommitTransaction(transID string) { tc.transactionMux.Lock() tc.transBufMux.Lock() tc.cacheMux.Lock() // apply all transactioned items in one shot for _, item := range tc.transactionBuffer[transID] { switch item.verb { case AddItem: tc.Set(item.cacheID, item.itemID, item.value, item.groupIDs, true, transID) case RemoveItem: tc.Remove(item.cacheID, item.itemID, true, transID) case RemoveGroup: if len(item.groupIDs) >= 1 { tc.RemoveGroup(item.cacheID, item.groupIDs[0], true, transID) } } } tc.cacheMux.Unlock() delete(tc.transactionBuffer, transID) tc.transBufMux.Unlock() tc.transactionMux.Unlock() }
go
func (tc *TransCache) CommitTransaction(transID string) { tc.transactionMux.Lock() tc.transBufMux.Lock() tc.cacheMux.Lock() // apply all transactioned items in one shot for _, item := range tc.transactionBuffer[transID] { switch item.verb { case AddItem: tc.Set(item.cacheID, item.itemID, item.value, item.groupIDs, true, transID) case RemoveItem: tc.Remove(item.cacheID, item.itemID, true, transID) case RemoveGroup: if len(item.groupIDs) >= 1 { tc.RemoveGroup(item.cacheID, item.groupIDs[0], true, transID) } } } tc.cacheMux.Unlock() delete(tc.transactionBuffer, transID) tc.transBufMux.Unlock() tc.transactionMux.Unlock() }
[ "func", "(", "tc", "*", "TransCache", ")", "CommitTransaction", "(", "transID", "string", ")", "{", "tc", ".", "transactionMux", ".", "Lock", "(", ")", "\n", "tc", ".", "transBufMux", ".", "Lock", "(", ")", "\n", "tc", ".", "cacheMux", ".", "Lock", "...
// CommitTransaction executes the actions in a transaction buffer
[ "CommitTransaction", "executes", "the", "actions", "in", "a", "transaction", "buffer" ]
92fb7fa77cca400b55d805e4a6d625443027c7f5
https://github.com/cgrates/ltcache/blob/92fb7fa77cca400b55d805e4a6d625443027c7f5/transcache.go#L117-L137