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
5,100
gocraft/health
healthd/poll.go
poll
func poll(stream *health.Stream, hostPort string, responses chan<- *pollResponse) { job := stream.NewJob("poll") var body []byte var err error response := &pollResponse{ HostPort: hostPort, Timestamp: now(), } start := time.Now() client := &http.Client{ Timeout: 5 * time.Second, } resp, err := client.Get(metricsUrl(hostPort)) if err != nil { response.Err = job.EventErr("poll.client.get", err) goto POLL_FINISH } defer resp.Body.Close() body, err = ioutil.ReadAll(resp.Body) response.Nanos = time.Since(start).Nanoseconds() // don't mock b/c we need duration response.Code = resp.StatusCode if err != nil { // ioutil.ReadAll. We're checking here b/c we still want to capture nanos/code response.Err = job.EventErr("poll.ioutil.read_all", err) goto POLL_FINISH } if err := json.Unmarshal(body, &response.HealthAggregationsResponse); err != nil { response.Err = job.EventErr("poll.json.unmarshall", err) goto POLL_FINISH } POLL_FINISH: if response.Err != nil { job.CompleteKv(health.Error, health.Kvs{"host_port": hostPort}) } else { job.CompleteKv(health.Success, health.Kvs{"host_port": hostPort}) } responses <- response }
go
func poll(stream *health.Stream, hostPort string, responses chan<- *pollResponse) { job := stream.NewJob("poll") var body []byte var err error response := &pollResponse{ HostPort: hostPort, Timestamp: now(), } start := time.Now() client := &http.Client{ Timeout: 5 * time.Second, } resp, err := client.Get(metricsUrl(hostPort)) if err != nil { response.Err = job.EventErr("poll.client.get", err) goto POLL_FINISH } defer resp.Body.Close() body, err = ioutil.ReadAll(resp.Body) response.Nanos = time.Since(start).Nanoseconds() // don't mock b/c we need duration response.Code = resp.StatusCode if err != nil { // ioutil.ReadAll. We're checking here b/c we still want to capture nanos/code response.Err = job.EventErr("poll.ioutil.read_all", err) goto POLL_FINISH } if err := json.Unmarshal(body, &response.HealthAggregationsResponse); err != nil { response.Err = job.EventErr("poll.json.unmarshall", err) goto POLL_FINISH } POLL_FINISH: if response.Err != nil { job.CompleteKv(health.Error, health.Kvs{"host_port": hostPort}) } else { job.CompleteKv(health.Success, health.Kvs{"host_port": hostPort}) } responses <- response }
[ "func", "poll", "(", "stream", "*", "health", ".", "Stream", ",", "hostPort", "string", ",", "responses", "chan", "<-", "*", "pollResponse", ")", "{", "job", ":=", "stream", ".", "NewJob", "(", "\"", "\"", ")", "\n\n", "var", "body", "[", "]", "byte"...
// poll checks a server
[ "poll", "checks", "a", "server" ]
8675af27fef0dc5c973d0957f1b1b50ffac513f9
https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/healthd/poll.go#L23-L70
5,101
gocraft/health
sinks/bugsnag/api.go
Notify
func Notify(config *Config, jobName string, eventName string, err error, trace *stack.Trace, kvs map[string]string) error { // Make a struct that serializes to the JSON needed for the API request to bugsnag p := newPayload(config, jobName, eventName, err, trace, kvs) // JSON serialize it data, err := json.MarshalIndent(p, "", "\t") if err != nil { return err } // Post it to the server: client := http.Client{} resp, err := client.Post(config.Endpoint, "application/json", bytes.NewBuffer(data)) if err != nil { return err } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } if string(body) != "OK" { return fmt.Errorf("response from bugsnag wasn't 'OK'") } return nil }
go
func Notify(config *Config, jobName string, eventName string, err error, trace *stack.Trace, kvs map[string]string) error { // Make a struct that serializes to the JSON needed for the API request to bugsnag p := newPayload(config, jobName, eventName, err, trace, kvs) // JSON serialize it data, err := json.MarshalIndent(p, "", "\t") if err != nil { return err } // Post it to the server: client := http.Client{} resp, err := client.Post(config.Endpoint, "application/json", bytes.NewBuffer(data)) if err != nil { return err } body, err := ioutil.ReadAll(resp.Body) if err != nil { return err } if string(body) != "OK" { return fmt.Errorf("response from bugsnag wasn't 'OK'") } return nil }
[ "func", "Notify", "(", "config", "*", "Config", ",", "jobName", "string", ",", "eventName", "string", ",", "err", "error", ",", "trace", "*", "stack", ".", "Trace", ",", "kvs", "map", "[", "string", "]", "string", ")", "error", "{", "// Make a struct tha...
// Notify will send the error and stack trace to Bugsnag. Note that this doesn't take advantage of all of Bugsnag's capabilities.
[ "Notify", "will", "send", "the", "error", "and", "stack", "trace", "to", "Bugsnag", ".", "Note", "that", "this", "doesn", "t", "take", "advantage", "of", "all", "of", "Bugsnag", "s", "capabilities", "." ]
8675af27fef0dc5c973d0957f1b1b50ffac513f9
https://github.com/gocraft/health/blob/8675af27fef0dc5c973d0957f1b1b50ffac513f9/sinks/bugsnag/api.go#L98-L124
5,102
fukata/golang-stats-api-handler
handler.go
Handler
func Handler(w http.ResponseWriter, r *http.Request) { values := r.URL.Query() for _, c := range []string{"1", "true"} { if values.Get("pp") == c { prettyPrint = true } } var jsonBytes []byte var jsonErr error if prettyPrint { jsonBytes, jsonErr = json.MarshalIndent(GetStats(), "", " ") } else { jsonBytes, jsonErr = json.Marshal(GetStats()) } var body string if jsonErr != nil { body = jsonErr.Error() } else { body = string(jsonBytes) } if newLineTerm { body += "\n" } headers := make(map[string]string) headers["Content-Type"] = "application/json" headers["Content-Length"] = strconv.Itoa(len(body)) for name, value := range headers { w.Header().Set(name, value) } if jsonErr != nil { w.WriteHeader(http.StatusInternalServerError) } else { w.WriteHeader(http.StatusOK) } io.WriteString(w, body) }
go
func Handler(w http.ResponseWriter, r *http.Request) { values := r.URL.Query() for _, c := range []string{"1", "true"} { if values.Get("pp") == c { prettyPrint = true } } var jsonBytes []byte var jsonErr error if prettyPrint { jsonBytes, jsonErr = json.MarshalIndent(GetStats(), "", " ") } else { jsonBytes, jsonErr = json.Marshal(GetStats()) } var body string if jsonErr != nil { body = jsonErr.Error() } else { body = string(jsonBytes) } if newLineTerm { body += "\n" } headers := make(map[string]string) headers["Content-Type"] = "application/json" headers["Content-Length"] = strconv.Itoa(len(body)) for name, value := range headers { w.Header().Set(name, value) } if jsonErr != nil { w.WriteHeader(http.StatusInternalServerError) } else { w.WriteHeader(http.StatusOK) } io.WriteString(w, body) }
[ "func", "Handler", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "values", ":=", "r", ".", "URL", ".", "Query", "(", ")", "\n", "for", "_", ",", "c", ":=", "range", "[", "]", "string", "{", "\"", "\""...
// Handler returns activity status of Go.
[ "Handler", "returns", "activity", "status", "of", "Go", "." ]
ab9f90f16caab828afda479fd34bfbbbba2efcee
https://github.com/fukata/golang-stats-api-handler/blob/ab9f90f16caab828afda479fd34bfbbbba2efcee/handler.go#L160-L200
5,103
jetstack/vault-unsealer
pkg/vault/vault.go
New
func New(k kv.Service, cl *api.Client, config Config) (Vault, error) { if config.SecretShares < config.SecretThreshold { return nil, errors.New("the secret threshold can't be bigger than the shares") } return &vault{ keyStore: k, cl: cl, config: &config, }, nil }
go
func New(k kv.Service, cl *api.Client, config Config) (Vault, error) { if config.SecretShares < config.SecretThreshold { return nil, errors.New("the secret threshold can't be bigger than the shares") } return &vault{ keyStore: k, cl: cl, config: &config, }, nil }
[ "func", "New", "(", "k", "kv", ".", "Service", ",", "cl", "*", "api", ".", "Client", ",", "config", "Config", ")", "(", "Vault", ",", "error", ")", "{", "if", "config", ".", "SecretShares", "<", "config", ".", "SecretThreshold", "{", "return", "nil",...
// New returns a new vault Vault, or an error.
[ "New", "returns", "a", "new", "vault", "Vault", "or", "an", "error", "." ]
59b05dd56dd01367f28666c577bdaeadc212e5c8
https://github.com/jetstack/vault-unsealer/blob/59b05dd56dd01367f28666c577bdaeadc212e5c8/pkg/vault/vault.go#L53-L64
5,104
tchap/go-patricia
patricia/patricia.go
NewTrie
func NewTrie(options ...Option) *Trie { trie := &Trie{} for _, opt := range options { opt(trie) } if trie.maxPrefixPerNode <= 0 { trie.maxPrefixPerNode = DefaultMaxPrefixPerNode } if trie.maxChildrenPerSparseNode <= 0 { trie.maxChildrenPerSparseNode = DefaultMaxChildrenPerSparseNode } trie.children = newSparseChildList(trie.maxChildrenPerSparseNode) return trie }
go
func NewTrie(options ...Option) *Trie { trie := &Trie{} for _, opt := range options { opt(trie) } if trie.maxPrefixPerNode <= 0 { trie.maxPrefixPerNode = DefaultMaxPrefixPerNode } if trie.maxChildrenPerSparseNode <= 0 { trie.maxChildrenPerSparseNode = DefaultMaxChildrenPerSparseNode } trie.children = newSparseChildList(trie.maxChildrenPerSparseNode) return trie }
[ "func", "NewTrie", "(", "options", "...", "Option", ")", "*", "Trie", "{", "trie", ":=", "&", "Trie", "{", "}", "\n\n", "for", "_", ",", "opt", ":=", "range", "options", "{", "opt", "(", "trie", ")", "\n", "}", "\n\n", "if", "trie", ".", "maxPref...
// Trie constructor.
[ "Trie", "constructor", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L50-L66
5,105
tchap/go-patricia
patricia/patricia.go
Clone
func (trie *Trie) Clone() *Trie { return &Trie{ prefix: append(Prefix(nil), trie.prefix...), item: trie.item, maxPrefixPerNode: trie.maxPrefixPerNode, maxChildrenPerSparseNode: trie.maxChildrenPerSparseNode, children: trie.children.clone(), } }
go
func (trie *Trie) Clone() *Trie { return &Trie{ prefix: append(Prefix(nil), trie.prefix...), item: trie.item, maxPrefixPerNode: trie.maxPrefixPerNode, maxChildrenPerSparseNode: trie.maxChildrenPerSparseNode, children: trie.children.clone(), } }
[ "func", "(", "trie", "*", "Trie", ")", "Clone", "(", ")", "*", "Trie", "{", "return", "&", "Trie", "{", "prefix", ":", "append", "(", "Prefix", "(", "nil", ")", ",", "trie", ".", "prefix", "...", ")", ",", "item", ":", "trie", ".", "item", ",",...
// Clone makes a copy of an existing trie. // Items stored in both tries become shared, obviously.
[ "Clone", "makes", "a", "copy", "of", "an", "existing", "trie", ".", "Items", "stored", "in", "both", "tries", "become", "shared", "obviously", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L82-L90
5,106
tchap/go-patricia
patricia/patricia.go
Insert
func (trie *Trie) Insert(key Prefix, item Item) (inserted bool) { return trie.put(key, item, false) }
go
func (trie *Trie) Insert(key Prefix, item Item) (inserted bool) { return trie.put(key, item, false) }
[ "func", "(", "trie", "*", "Trie", ")", "Insert", "(", "key", "Prefix", ",", "item", "Item", ")", "(", "inserted", "bool", ")", "{", "return", "trie", ".", "put", "(", "key", ",", "item", ",", "false", ")", "\n", "}" ]
// Insert inserts a new item into the trie using the given prefix. Insert does // not replace existing items. It returns false if an item was already in place.
[ "Insert", "inserts", "a", "new", "item", "into", "the", "trie", "using", "the", "given", "prefix", ".", "Insert", "does", "not", "replace", "existing", "items", ".", "It", "returns", "false", "if", "an", "item", "was", "already", "in", "place", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L99-L101
5,107
tchap/go-patricia
patricia/patricia.go
Set
func (trie *Trie) Set(key Prefix, item Item) { trie.put(key, item, true) }
go
func (trie *Trie) Set(key Prefix, item Item) { trie.put(key, item, true) }
[ "func", "(", "trie", "*", "Trie", ")", "Set", "(", "key", "Prefix", ",", "item", "Item", ")", "{", "trie", ".", "put", "(", "key", ",", "item", ",", "true", ")", "\n", "}" ]
// Set works much like Insert, but it always sets the item, possibly replacing // the item previously inserted.
[ "Set", "works", "much", "like", "Insert", "but", "it", "always", "sets", "the", "item", "possibly", "replacing", "the", "item", "previously", "inserted", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L105-L107
5,108
tchap/go-patricia
patricia/patricia.go
Get
func (trie *Trie) Get(key Prefix) (item Item) { _, node, found, leftover := trie.findSubtree(key) if !found || len(leftover) != 0 { return nil } return node.item }
go
func (trie *Trie) Get(key Prefix) (item Item) { _, node, found, leftover := trie.findSubtree(key) if !found || len(leftover) != 0 { return nil } return node.item }
[ "func", "(", "trie", "*", "Trie", ")", "Get", "(", "key", "Prefix", ")", "(", "item", "Item", ")", "{", "_", ",", "node", ",", "found", ",", "leftover", ":=", "trie", ".", "findSubtree", "(", "key", ")", "\n", "if", "!", "found", "||", "len", "...
// Get returns the item located at key. // // This method is a bit dangerous, because Get can as well end up in an internal // node that is not really representing any user-defined value. So when nil is // a valid value being used, it is not possible to tell if the value was inserted // into the tree by the user or not. A possible workaround for this is not to use // nil interface as a valid value, even using zero value of any type is enough // to prevent this bad behaviour.
[ "Get", "returns", "the", "item", "located", "at", "key", ".", "This", "method", "is", "a", "bit", "dangerous", "because", "Get", "can", "as", "well", "end", "up", "in", "an", "internal", "node", "that", "is", "not", "really", "representing", "any", "user...
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L117-L123
5,109
tchap/go-patricia
patricia/patricia.go
MatchSubtree
func (trie *Trie) MatchSubtree(key Prefix) (matched bool) { _, _, matched, _ = trie.findSubtree(key) return }
go
func (trie *Trie) MatchSubtree(key Prefix) (matched bool) { _, _, matched, _ = trie.findSubtree(key) return }
[ "func", "(", "trie", "*", "Trie", ")", "MatchSubtree", "(", "key", "Prefix", ")", "(", "matched", "bool", ")", "{", "_", ",", "_", ",", "matched", ",", "_", "=", "trie", ".", "findSubtree", "(", "key", ")", "\n", "return", "\n", "}" ]
// MatchSubtree returns true when there is a subtree representing extensions // to key, that is if there are any keys in the tree which have key as prefix.
[ "MatchSubtree", "returns", "true", "when", "there", "is", "a", "subtree", "representing", "extensions", "to", "key", "that", "is", "if", "there", "are", "any", "keys", "in", "the", "tree", "which", "have", "key", "as", "prefix", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L133-L136
5,110
tchap/go-patricia
patricia/patricia.go
Visit
func (trie *Trie) Visit(visitor VisitorFunc) error { return trie.walk(nil, visitor) }
go
func (trie *Trie) Visit(visitor VisitorFunc) error { return trie.walk(nil, visitor) }
[ "func", "(", "trie", "*", "Trie", ")", "Visit", "(", "visitor", "VisitorFunc", ")", "error", "{", "return", "trie", ".", "walk", "(", "nil", ",", "visitor", ")", "\n", "}" ]
// Visit calls visitor on every node containing a non-nil item // in alphabetical order. // // If an error is returned from visitor, the function stops visiting the tree // and returns that error, unless it is a special error - SkipSubtree. In that // case Visit skips the subtree represented by the current node and continues // elsewhere.
[ "Visit", "calls", "visitor", "on", "every", "node", "containing", "a", "non", "-", "nil", "item", "in", "alphabetical", "order", ".", "If", "an", "error", "is", "returned", "from", "visitor", "the", "function", "stops", "visiting", "the", "tree", "and", "r...
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L145-L147
5,111
tchap/go-patricia
patricia/patricia.go
VisitSubtree
func (trie *Trie) VisitSubtree(prefix Prefix, visitor VisitorFunc) error { // Nil prefix not allowed. if prefix == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return nil } // Locate the relevant subtree. _, root, found, leftover := trie.findSubtree(prefix) if !found { return nil } prefix = append(prefix, leftover...) // Visit it. return root.walk(prefix, visitor) }
go
func (trie *Trie) VisitSubtree(prefix Prefix, visitor VisitorFunc) error { // Nil prefix not allowed. if prefix == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return nil } // Locate the relevant subtree. _, root, found, leftover := trie.findSubtree(prefix) if !found { return nil } prefix = append(prefix, leftover...) // Visit it. return root.walk(prefix, visitor) }
[ "func", "(", "trie", "*", "Trie", ")", "VisitSubtree", "(", "prefix", "Prefix", ",", "visitor", "VisitorFunc", ")", "error", "{", "// Nil prefix not allowed.", "if", "prefix", "==", "nil", "{", "panic", "(", "ErrNilPrefix", ")", "\n", "}", "\n\n", "// Empty ...
// VisitSubtree works much like Visit, but it only visits nodes matching prefix.
[ "VisitSubtree", "works", "much", "like", "Visit", "but", "it", "only", "visits", "nodes", "matching", "prefix", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L165-L185
5,112
tchap/go-patricia
patricia/patricia.go
VisitPrefixes
func (trie *Trie) VisitPrefixes(key Prefix, visitor VisitorFunc) error { // Nil key not allowed. if key == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return nil } // Walk the path matching key prefixes. node := trie prefix := key offset := 0 for { // Compute what part of prefix matches. common := node.longestCommonPrefixLength(key) key = key[common:] offset += common // Partial match means that there is no subtree matching prefix. if common < len(node.prefix) { return nil } // Call the visitor. if item := node.item; item != nil { if err := visitor(prefix[:offset], item); err != nil { return err } } if len(key) == 0 { // This node represents key, we are finished. return nil } // There is some key suffix left, move to the children. child := node.children.next(key[0]) if child == nil { // There is nowhere to continue, return. return nil } node = child } }
go
func (trie *Trie) VisitPrefixes(key Prefix, visitor VisitorFunc) error { // Nil key not allowed. if key == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return nil } // Walk the path matching key prefixes. node := trie prefix := key offset := 0 for { // Compute what part of prefix matches. common := node.longestCommonPrefixLength(key) key = key[common:] offset += common // Partial match means that there is no subtree matching prefix. if common < len(node.prefix) { return nil } // Call the visitor. if item := node.item; item != nil { if err := visitor(prefix[:offset], item); err != nil { return err } } if len(key) == 0 { // This node represents key, we are finished. return nil } // There is some key suffix left, move to the children. child := node.children.next(key[0]) if child == nil { // There is nowhere to continue, return. return nil } node = child } }
[ "func", "(", "trie", "*", "Trie", ")", "VisitPrefixes", "(", "key", "Prefix", ",", "visitor", "VisitorFunc", ")", "error", "{", "// Nil key not allowed.", "if", "key", "==", "nil", "{", "panic", "(", "ErrNilPrefix", ")", "\n", "}", "\n\n", "// Empty trie mus...
// VisitPrefixes visits only nodes that represent prefixes of key. // To say the obvious, returning SkipSubtree from visitor makes no sense here.
[ "VisitPrefixes", "visits", "only", "nodes", "that", "represent", "prefixes", "of", "key", ".", "To", "say", "the", "obvious", "returning", "SkipSubtree", "from", "visitor", "makes", "no", "sense", "here", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L189-L236
5,113
tchap/go-patricia
patricia/patricia.go
Delete
func (trie *Trie) Delete(key Prefix) (deleted bool) { // Nil prefix not allowed. if key == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return false } // Find the relevant node. path, found, _ := trie.findSubtreePath(key) if !found { return false } node := path[len(path)-1] var parent *Trie if len(path) != 1 { parent = path[len(path)-2] } // If the item is already set to nil, there is nothing to do. if node.item == nil { return false } // Delete the item. node.item = nil // Initialise i before goto. // Will be used later in a loop. i := len(path) - 1 // In case there are some child nodes, we cannot drop the whole subtree. // We can try to compact nodes, though. if node.children.length() != 0 { goto Compact } // In case we are at the root, just reset it and we are done. if parent == nil { node.reset() return true } // We can drop a subtree. // Find the first ancestor that has its value set or it has 2 or more child nodes. // That will be the node where to drop the subtree at. for ; i >= 0; i-- { if current := path[i]; current.item != nil || current.children.length() >= 2 { break } } // Handle the case when there is no such node. // In other words, we can reset the whole tree. if i == -1 { path[0].reset() return true } // We can just remove the subtree here. node = path[i] if i == 0 { parent = nil } else { parent = path[i-1] } // i+1 is always a valid index since i is never pointing to the last node. // The loop above skips at least the last node since we are sure that the item // is set to nil and it has no children, othewise we would be compacting instead. node.children.remove(path[i+1].prefix[0]) Compact: // The node is set to the first non-empty ancestor, // so try to compact since that might be possible now. if compacted := node.compact(); compacted != node { if parent == nil { *node = *compacted } else { parent.children.replace(node.prefix[0], compacted) *parent = *parent.compact() } } return true }
go
func (trie *Trie) Delete(key Prefix) (deleted bool) { // Nil prefix not allowed. if key == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return false } // Find the relevant node. path, found, _ := trie.findSubtreePath(key) if !found { return false } node := path[len(path)-1] var parent *Trie if len(path) != 1 { parent = path[len(path)-2] } // If the item is already set to nil, there is nothing to do. if node.item == nil { return false } // Delete the item. node.item = nil // Initialise i before goto. // Will be used later in a loop. i := len(path) - 1 // In case there are some child nodes, we cannot drop the whole subtree. // We can try to compact nodes, though. if node.children.length() != 0 { goto Compact } // In case we are at the root, just reset it and we are done. if parent == nil { node.reset() return true } // We can drop a subtree. // Find the first ancestor that has its value set or it has 2 or more child nodes. // That will be the node where to drop the subtree at. for ; i >= 0; i-- { if current := path[i]; current.item != nil || current.children.length() >= 2 { break } } // Handle the case when there is no such node. // In other words, we can reset the whole tree. if i == -1 { path[0].reset() return true } // We can just remove the subtree here. node = path[i] if i == 0 { parent = nil } else { parent = path[i-1] } // i+1 is always a valid index since i is never pointing to the last node. // The loop above skips at least the last node since we are sure that the item // is set to nil and it has no children, othewise we would be compacting instead. node.children.remove(path[i+1].prefix[0]) Compact: // The node is set to the first non-empty ancestor, // so try to compact since that might be possible now. if compacted := node.compact(); compacted != node { if parent == nil { *node = *compacted } else { parent.children.replace(node.prefix[0], compacted) *parent = *parent.compact() } } return true }
[ "func", "(", "trie", "*", "Trie", ")", "Delete", "(", "key", "Prefix", ")", "(", "deleted", "bool", ")", "{", "// Nil prefix not allowed.", "if", "key", "==", "nil", "{", "panic", "(", "ErrNilPrefix", ")", "\n", "}", "\n\n", "// Empty trie must be handled ex...
// Delete deletes the item represented by the given prefix. // // True is returned if the matching node was found and deleted.
[ "Delete", "deletes", "the", "item", "represented", "by", "the", "given", "prefix", ".", "True", "is", "returned", "if", "the", "matching", "node", "was", "found", "and", "deleted", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L241-L329
5,114
tchap/go-patricia
patricia/patricia.go
DeleteSubtree
func (trie *Trie) DeleteSubtree(prefix Prefix) (deleted bool) { // Nil prefix not allowed. if prefix == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return false } // Locate the relevant subtree. parent, root, found, _ := trie.findSubtree(prefix) if !found { return false } // If we are in the root of the trie, reset the trie. if parent == nil { root.reset() return true } // Otherwise remove the root node from its parent. parent.children.remove(root.prefix[0]) return true }
go
func (trie *Trie) DeleteSubtree(prefix Prefix) (deleted bool) { // Nil prefix not allowed. if prefix == nil { panic(ErrNilPrefix) } // Empty trie must be handled explicitly. if trie.prefix == nil { return false } // Locate the relevant subtree. parent, root, found, _ := trie.findSubtree(prefix) if !found { return false } // If we are in the root of the trie, reset the trie. if parent == nil { root.reset() return true } // Otherwise remove the root node from its parent. parent.children.remove(root.prefix[0]) return true }
[ "func", "(", "trie", "*", "Trie", ")", "DeleteSubtree", "(", "prefix", "Prefix", ")", "(", "deleted", "bool", ")", "{", "// Nil prefix not allowed.", "if", "prefix", "==", "nil", "{", "panic", "(", "ErrNilPrefix", ")", "\n", "}", "\n\n", "// Empty trie must ...
// DeleteSubtree finds the subtree exactly matching prefix and deletes it. // // True is returned if the subtree was found and deleted.
[ "DeleteSubtree", "finds", "the", "subtree", "exactly", "matching", "prefix", "and", "deletes", "it", ".", "True", "is", "returned", "if", "the", "subtree", "was", "found", "and", "deleted", "." ]
a7f0089c6f496e8e70402f61733606daa326cac5
https://github.com/tchap/go-patricia/blob/a7f0089c6f496e8e70402f61733606daa326cac5/patricia/patricia.go#L334-L360
5,115
vanng822/go-premailer
premailer/premailer_from_file.go
NewPremailerFromFile
func NewPremailerFromFile(filename string, options *Options) (Premailer, error) { fd, err := os.Open(filename) if err != nil { return nil, err } defer fd.Close() d, err := goquery.NewDocumentFromReader(fd) if err != nil { return nil, err } return NewPremailer(d, options), nil }
go
func NewPremailerFromFile(filename string, options *Options) (Premailer, error) { fd, err := os.Open(filename) if err != nil { return nil, err } defer fd.Close() d, err := goquery.NewDocumentFromReader(fd) if err != nil { return nil, err } return NewPremailer(d, options), nil }
[ "func", "NewPremailerFromFile", "(", "filename", "string", ",", "options", "*", "Options", ")", "(", "Premailer", ",", "error", ")", "{", "fd", ",", "err", ":=", "os", ".", "Open", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// NewPremailerFromFile take an filename // Read the content of this file // and create a goquery.Document // and then create and Premailer instance.
[ "NewPremailerFromFile", "take", "an", "filename", "Read", "the", "content", "of", "this", "file", "and", "create", "a", "goquery", ".", "Document", "and", "then", "create", "and", "Premailer", "instance", "." ]
5591781d799634cb6cf5363794f8df1eb4b8070c
https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer_from_file.go#L13-L24
5,116
vanng822/go-premailer
premailer/premailer_from_string.go
NewPremailerFromString
func NewPremailerFromString(doc string, options *Options) (Premailer, error) { read := strings.NewReader(doc) d, err := goquery.NewDocumentFromReader(read) if err != nil { return nil, err } return NewPremailer(d, options), nil }
go
func NewPremailerFromString(doc string, options *Options) (Premailer, error) { read := strings.NewReader(doc) d, err := goquery.NewDocumentFromReader(read) if err != nil { return nil, err } return NewPremailer(d, options), nil }
[ "func", "NewPremailerFromString", "(", "doc", "string", ",", "options", "*", "Options", ")", "(", "Premailer", ",", "error", ")", "{", "read", ":=", "strings", ".", "NewReader", "(", "doc", ")", "\n", "d", ",", "err", ":=", "goquery", ".", "NewDocumentFr...
// NewPremailerFromString take in a document in string format // and create a goquery.Document // and then create and Premailer instance.
[ "NewPremailerFromString", "take", "in", "a", "document", "in", "string", "format", "and", "create", "a", "goquery", ".", "Document", "and", "then", "create", "and", "Premailer", "instance", "." ]
5591781d799634cb6cf5363794f8df1eb4b8070c
https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer_from_string.go#L12-L19
5,117
vanng822/go-premailer
premailer/premailer_from_bytes.go
NewPremailerFromBytes
func NewPremailerFromBytes(doc []byte, options *Options) (Premailer, error) { read := bytes.NewReader(doc) d, err := goquery.NewDocumentFromReader(read) if err != nil { return nil, err } return NewPremailer(d, options), nil }
go
func NewPremailerFromBytes(doc []byte, options *Options) (Premailer, error) { read := bytes.NewReader(doc) d, err := goquery.NewDocumentFromReader(read) if err != nil { return nil, err } return NewPremailer(d, options), nil }
[ "func", "NewPremailerFromBytes", "(", "doc", "[", "]", "byte", ",", "options", "*", "Options", ")", "(", "Premailer", ",", "error", ")", "{", "read", ":=", "bytes", ".", "NewReader", "(", "doc", ")", "\n", "d", ",", "err", ":=", "goquery", ".", "NewD...
// NewPremailerFromBytes take in a document in byte // and create a goquery.Document // and then create and Premailer instance.
[ "NewPremailerFromBytes", "take", "in", "a", "document", "in", "byte", "and", "create", "a", "goquery", ".", "Document", "and", "then", "create", "and", "Premailer", "instance", "." ]
5591781d799634cb6cf5363794f8df1eb4b8070c
https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer_from_bytes.go#L12-L19
5,118
vanng822/go-premailer
premailer/premailer.go
NewPremailer
func NewPremailer(doc *goquery.Document, options *Options) Premailer { pr := premailer{} pr.doc = doc pr.rules = make([]*styleRule, 0) pr.allRules = make([][]*css.CSSRule, 0) pr.leftover = make([]*css.CSSRule, 0) pr.elements = make(map[string]*elementRules) pr.elIdAttr = "pr-el-id" if options == nil { options = NewOptions() } pr.options = options return &pr }
go
func NewPremailer(doc *goquery.Document, options *Options) Premailer { pr := premailer{} pr.doc = doc pr.rules = make([]*styleRule, 0) pr.allRules = make([][]*css.CSSRule, 0) pr.leftover = make([]*css.CSSRule, 0) pr.elements = make(map[string]*elementRules) pr.elIdAttr = "pr-el-id" if options == nil { options = NewOptions() } pr.options = options return &pr }
[ "func", "NewPremailer", "(", "doc", "*", "goquery", ".", "Document", ",", "options", "*", "Options", ")", "Premailer", "{", "pr", ":=", "premailer", "{", "}", "\n", "pr", ".", "doc", "=", "doc", "\n", "pr", ".", "rules", "=", "make", "(", "[", "]",...
// NewPremailer return a new instance of Premailer // It take a Document as argument and it shouldn't be nil
[ "NewPremailer", "return", "a", "new", "instance", "of", "Premailer", "It", "take", "a", "Document", "as", "argument", "and", "it", "shouldn", "t", "be", "nil" ]
5591781d799634cb6cf5363794f8df1eb4b8070c
https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer.go#L45-L58
5,119
vanng822/go-premailer
premailer/premailer.go
Transform
func (pr *premailer) Transform() (string, error) { if !pr.processed { pr.collectRules() pr.sortRules() pr.collectElements() pr.applyInline() pr.addLeftover() pr.processed = true } return pr.doc.Html() }
go
func (pr *premailer) Transform() (string, error) { if !pr.processed { pr.collectRules() pr.sortRules() pr.collectElements() pr.applyInline() pr.addLeftover() pr.processed = true } return pr.doc.Html() }
[ "func", "(", "pr", "*", "premailer", ")", "Transform", "(", ")", "(", "string", ",", "error", ")", "{", "if", "!", "pr", ".", "processed", "{", "pr", ".", "collectRules", "(", ")", "\n", "pr", ".", "sortRules", "(", ")", "\n", "pr", ".", "collect...
// Transform process and inlining css // It start to collect the rules in the document style tags // Calculate specificity and sort the rules based on that // It then collects the affected elements // And applies the rules on those // The leftover rules will put back into a style element
[ "Transform", "process", "and", "inlining", "css", "It", "start", "to", "collect", "the", "rules", "in", "the", "document", "style", "tags", "Calculate", "specificity", "and", "sort", "the", "rules", "based", "on", "that", "It", "then", "collects", "the", "af...
5591781d799634cb6cf5363794f8df1eb4b8070c
https://github.com/vanng822/go-premailer/blob/5591781d799634cb6cf5363794f8df1eb4b8070c/premailer/premailer.go#L199-L209
5,120
gobwas/httphead
httphead.go
String
func (f SelectFlag) String() string { var flags [2]string var n int if f&SelectCopy != 0 { flags[n] = "copy" n++ } if f&SelectUnique != 0 { flags[n] = "unique" n++ } return "[" + strings.Join(flags[:n], "|") + "]" }
go
func (f SelectFlag) String() string { var flags [2]string var n int if f&SelectCopy != 0 { flags[n] = "copy" n++ } if f&SelectUnique != 0 { flags[n] = "unique" n++ } return "[" + strings.Join(flags[:n], "|") + "]" }
[ "func", "(", "f", "SelectFlag", ")", "String", "(", ")", "string", "{", "var", "flags", "[", "2", "]", "string", "\n", "var", "n", "int", "\n", "if", "f", "&", "SelectCopy", "!=", "0", "{", "flags", "[", "n", "]", "=", "\"", "\"", "\n", "n", ...
// String represetns flag as string.
[ "String", "represetns", "flag", "as", "string", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/httphead.go#L66-L78
5,121
gobwas/httphead
head.go
ParseResponseLine
func ParseResponseLine(line []byte) (r ResponseLine, ok bool) { var ( proto []byte status []byte ) proto, status, r.Reason = split3(line, ' ') if major, minor, ok := ParseVersion(proto); ok { r.Version.Major = major r.Version.Minor = minor } else { return r, false } if n, ok := IntFromASCII(status); ok { r.Status = n } else { return r, false } // TODO(gobwas): parse here r.Reason fot TEXT rule: // TEXT = <any OCTET except CTLs, // but including LWS> return r, true }
go
func ParseResponseLine(line []byte) (r ResponseLine, ok bool) { var ( proto []byte status []byte ) proto, status, r.Reason = split3(line, ' ') if major, minor, ok := ParseVersion(proto); ok { r.Version.Major = major r.Version.Minor = minor } else { return r, false } if n, ok := IntFromASCII(status); ok { r.Status = n } else { return r, false } // TODO(gobwas): parse here r.Reason fot TEXT rule: // TEXT = <any OCTET except CTLs, // but including LWS> return r, true }
[ "func", "ParseResponseLine", "(", "line", "[", "]", "byte", ")", "(", "r", "ResponseLine", ",", "ok", "bool", ")", "{", "var", "(", "proto", "[", "]", "byte", "\n", "status", "[", "]", "byte", "\n", ")", "\n", "proto", ",", "status", ",", "r", "....
// ParseResponseLine parses first response line into ResponseLine struct.
[ "ParseResponseLine", "parses", "first", "response", "line", "into", "ResponseLine", "struct", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L72-L93
5,122
gobwas/httphead
head.go
ParseVersion
func ParseVersion(bts []byte) (major, minor int, ok bool) { switch { case bytes.Equal(bts, httpVersion11): return 1, 1, true case bytes.Equal(bts, httpVersion10): return 1, 0, true case len(bts) < 8: return case !bytes.Equal(bts[:5], httpVersionPrefix): return } bts = bts[5:] dot := bytes.IndexByte(bts, '.') if dot == -1 { return } major, ok = IntFromASCII(bts[:dot]) if !ok { return } minor, ok = IntFromASCII(bts[dot+1:]) if !ok { return } return major, minor, true }
go
func ParseVersion(bts []byte) (major, minor int, ok bool) { switch { case bytes.Equal(bts, httpVersion11): return 1, 1, true case bytes.Equal(bts, httpVersion10): return 1, 0, true case len(bts) < 8: return case !bytes.Equal(bts[:5], httpVersionPrefix): return } bts = bts[5:] dot := bytes.IndexByte(bts, '.') if dot == -1 { return } major, ok = IntFromASCII(bts[:dot]) if !ok { return } minor, ok = IntFromASCII(bts[dot+1:]) if !ok { return } return major, minor, true }
[ "func", "ParseVersion", "(", "bts", "[", "]", "byte", ")", "(", "major", ",", "minor", "int", ",", "ok", "bool", ")", "{", "switch", "{", "case", "bytes", ".", "Equal", "(", "bts", ",", "httpVersion11", ")", ":", "return", "1", ",", "1", ",", "tr...
// ParseVersion parses major and minor version of HTTP protocol. // It returns parsed values and true if parse is ok.
[ "ParseVersion", "parses", "major", "and", "minor", "version", "of", "HTTP", "protocol", ".", "It", "returns", "parsed", "values", "and", "true", "if", "parse", "is", "ok", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L103-L131
5,123
gobwas/httphead
head.go
ParseHeaderLine
func ParseHeaderLine(line []byte) (k, v []byte, ok bool) { colon := bytes.IndexByte(line, ':') if colon == -1 { return } k = trim(line[:colon]) for _, c := range k { if !OctetTypes[c].IsToken() { return nil, nil, false } } v = trim(line[colon+1:]) return k, v, true }
go
func ParseHeaderLine(line []byte) (k, v []byte, ok bool) { colon := bytes.IndexByte(line, ':') if colon == -1 { return } k = trim(line[:colon]) for _, c := range k { if !OctetTypes[c].IsToken() { return nil, nil, false } } v = trim(line[colon+1:]) return k, v, true }
[ "func", "ParseHeaderLine", "(", "line", "[", "]", "byte", ")", "(", "k", ",", "v", "[", "]", "byte", ",", "ok", "bool", ")", "{", "colon", ":=", "bytes", ".", "IndexByte", "(", "line", ",", "':'", ")", "\n", "if", "colon", "==", "-", "1", "{", ...
// ParseHeaderLine parses HTTP header as key-value pair. It returns parsed // values and true if parse is ok.
[ "ParseHeaderLine", "parses", "HTTP", "header", "as", "key", "-", "value", "pair", ".", "It", "returns", "parsed", "values", "and", "true", "if", "parse", "is", "ok", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L180-L193
5,124
gobwas/httphead
head.go
IntFromASCII
func IntFromASCII(bts []byte) (ret int, ok bool) { // ASCII numbers all start with the high-order bits 0011. // If you see that, and the next bits are 0-9 (0000 - 1001) you can grab those // bits and interpret them directly as an integer. var n int if n = len(bts); n < 1 { return 0, false } for i := 0; i < n; i++ { if bts[i]&0xf0 != 0x30 { return 0, false } ret += int(bts[i]&0xf) * pow(10, n-i-1) } return ret, true }
go
func IntFromASCII(bts []byte) (ret int, ok bool) { // ASCII numbers all start with the high-order bits 0011. // If you see that, and the next bits are 0-9 (0000 - 1001) you can grab those // bits and interpret them directly as an integer. var n int if n = len(bts); n < 1 { return 0, false } for i := 0; i < n; i++ { if bts[i]&0xf0 != 0x30 { return 0, false } ret += int(bts[i]&0xf) * pow(10, n-i-1) } return ret, true }
[ "func", "IntFromASCII", "(", "bts", "[", "]", "byte", ")", "(", "ret", "int", ",", "ok", "bool", ")", "{", "// ASCII numbers all start with the high-order bits 0011.", "// If you see that, and the next bits are 0-9 (0000 - 1001) you can grab those", "// bits and interpret them di...
// IntFromASCII converts ascii encoded decimal numeric value from HTTP entities // to an integer.
[ "IntFromASCII", "converts", "ascii", "encoded", "decimal", "numeric", "value", "from", "HTTP", "entities", "to", "an", "integer", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/head.go#L197-L212
5,125
gobwas/httphead
option.go
Size
func (opt Option) Size() int { return len(opt.Name) + opt.Parameters.bytes }
go
func (opt Option) Size() int { return len(opt.Name) + opt.Parameters.bytes }
[ "func", "(", "opt", "Option", ")", "Size", "(", ")", "int", "{", "return", "len", "(", "opt", ".", "Name", ")", "+", "opt", ".", "Parameters", ".", "bytes", "\n", "}" ]
// Size returns number of bytes need to be allocated for use in opt.Copy.
[ "Size", "returns", "number", "of", "bytes", "need", "to", "be", "allocated", "for", "use", "in", "opt", ".", "Copy", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L15-L17
5,126
gobwas/httphead
option.go
String
func (opt Option) String() string { return "{" + string(opt.Name) + " " + opt.Parameters.String() + "}" }
go
func (opt Option) String() string { return "{" + string(opt.Name) + " " + opt.Parameters.String() + "}" }
[ "func", "(", "opt", "Option", ")", "String", "(", ")", "string", "{", "return", "\"", "\"", "+", "string", "(", "opt", ".", "Name", ")", "+", "\"", "\"", "+", "opt", ".", "Parameters", ".", "String", "(", ")", "+", "\"", "\"", "\n", "}" ]
// String represents option as a string.
[ "String", "represents", "option", "as", "a", "string", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L29-L31
5,127
gobwas/httphead
option.go
NewOption
func NewOption(name string, params map[string]string) Option { p := Parameters{} for k, v := range params { p.Set([]byte(k), []byte(v)) } return Option{ Name: []byte(name), Parameters: p, } }
go
func NewOption(name string, params map[string]string) Option { p := Parameters{} for k, v := range params { p.Set([]byte(k), []byte(v)) } return Option{ Name: []byte(name), Parameters: p, } }
[ "func", "NewOption", "(", "name", "string", ",", "params", "map", "[", "string", "]", "string", ")", "Option", "{", "p", ":=", "Parameters", "{", "}", "\n", "for", "k", ",", "v", ":=", "range", "params", "{", "p", ".", "Set", "(", "[", "]", "byte...
// NewOption creates named option with given parameters.
[ "NewOption", "creates", "named", "option", "with", "given", "parameters", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L34-L43
5,128
gobwas/httphead
option.go
Equal
func (opt Option) Equal(b Option) bool { if bytes.Equal(opt.Name, b.Name) { return opt.Parameters.Equal(b.Parameters) } return false }
go
func (opt Option) Equal(b Option) bool { if bytes.Equal(opt.Name, b.Name) { return opt.Parameters.Equal(b.Parameters) } return false }
[ "func", "(", "opt", "Option", ")", "Equal", "(", "b", "Option", ")", "bool", "{", "if", "bytes", ".", "Equal", "(", "opt", ".", "Name", ",", "b", ".", "Name", ")", "{", "return", "opt", ".", "Parameters", ".", "Equal", "(", "b", ".", "Parameters"...
// Equal reports whether option is equal to b.
[ "Equal", "reports", "whether", "option", "is", "equal", "to", "b", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L46-L51
5,129
gobwas/httphead
option.go
Equal
func (p Parameters) Equal(b Parameters) bool { switch { case p.dyn == nil && b.dyn == nil: case p.dyn != nil && b.dyn != nil: default: return false } ad, bd := p.data(), b.data() if len(ad) != len(bd) { return false } sort.Sort(pairs(ad)) sort.Sort(pairs(bd)) for i := 0; i < len(ad); i++ { av, bv := ad[i], bd[i] if !bytes.Equal(av.key, bv.key) || !bytes.Equal(av.value, bv.value) { return false } } return true }
go
func (p Parameters) Equal(b Parameters) bool { switch { case p.dyn == nil && b.dyn == nil: case p.dyn != nil && b.dyn != nil: default: return false } ad, bd := p.data(), b.data() if len(ad) != len(bd) { return false } sort.Sort(pairs(ad)) sort.Sort(pairs(bd)) for i := 0; i < len(ad); i++ { av, bv := ad[i], bd[i] if !bytes.Equal(av.key, bv.key) || !bytes.Equal(av.value, bv.value) { return false } } return true }
[ "func", "(", "p", "Parameters", ")", "Equal", "(", "b", "Parameters", ")", "bool", "{", "switch", "{", "case", "p", ".", "dyn", "==", "nil", "&&", "b", ".", "dyn", "==", "nil", ":", "case", "p", ".", "dyn", "!=", "nil", "&&", "b", ".", "dyn", ...
// Equal reports whether a equal to b.
[ "Equal", "reports", "whether", "a", "equal", "to", "b", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L62-L85
5,130
gobwas/httphead
option.go
Get
func (p *Parameters) Get(key string) (value []byte, ok bool) { for _, v := range p.data() { if string(v.key) == key { return v.value, true } } return nil, false }
go
func (p *Parameters) Get(key string) (value []byte, ok bool) { for _, v := range p.data() { if string(v.key) == key { return v.value, true } } return nil, false }
[ "func", "(", "p", "*", "Parameters", ")", "Get", "(", "key", "string", ")", "(", "value", "[", "]", "byte", ",", "ok", "bool", ")", "{", "for", "_", ",", "v", ":=", "range", "p", ".", "data", "(", ")", "{", "if", "string", "(", "v", ".", "k...
// Get returns value by key and flag about existence such value.
[ "Get", "returns", "value", "by", "key", "and", "flag", "about", "existence", "such", "value", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L114-L121
5,131
gobwas/httphead
option.go
Set
func (p *Parameters) Set(key, value []byte) { p.bytes += len(key) + len(value) if p.pos < len(p.arr) { p.arr[p.pos] = pair{key, value} p.pos++ return } if p.dyn == nil { p.dyn = make([]pair, len(p.arr), len(p.arr)+1) copy(p.dyn, p.arr[:]) } p.dyn = append(p.dyn, pair{key, value}) }
go
func (p *Parameters) Set(key, value []byte) { p.bytes += len(key) + len(value) if p.pos < len(p.arr) { p.arr[p.pos] = pair{key, value} p.pos++ return } if p.dyn == nil { p.dyn = make([]pair, len(p.arr), len(p.arr)+1) copy(p.dyn, p.arr[:]) } p.dyn = append(p.dyn, pair{key, value}) }
[ "func", "(", "p", "*", "Parameters", ")", "Set", "(", "key", ",", "value", "[", "]", "byte", ")", "{", "p", ".", "bytes", "+=", "len", "(", "key", ")", "+", "len", "(", "value", ")", "\n\n", "if", "p", ".", "pos", "<", "len", "(", "p", ".",...
// Set sets value by key.
[ "Set", "sets", "value", "by", "key", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L124-L138
5,132
gobwas/httphead
option.go
ForEach
func (p *Parameters) ForEach(cb func(k, v []byte) bool) { for _, v := range p.data() { if !cb(v.key, v.value) { break } } }
go
func (p *Parameters) ForEach(cb func(k, v []byte) bool) { for _, v := range p.data() { if !cb(v.key, v.value) { break } } }
[ "func", "(", "p", "*", "Parameters", ")", "ForEach", "(", "cb", "func", "(", "k", ",", "v", "[", "]", "byte", ")", "bool", ")", "{", "for", "_", ",", "v", ":=", "range", "p", ".", "data", "(", ")", "{", "if", "!", "cb", "(", "v", ".", "ke...
// ForEach iterates over parameters key-value pairs and calls cb for each one.
[ "ForEach", "iterates", "over", "parameters", "key", "-", "value", "pairs", "and", "calls", "cb", "for", "each", "one", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L141-L147
5,133
gobwas/httphead
option.go
String
func (p *Parameters) String() (ret string) { ret = "[" for i, v := range p.data() { if i > 0 { ret += " " } ret += string(v.key) + ":" + string(v.value) } return ret + "]" }
go
func (p *Parameters) String() (ret string) { ret = "[" for i, v := range p.data() { if i > 0 { ret += " " } ret += string(v.key) + ":" + string(v.value) } return ret + "]" }
[ "func", "(", "p", "*", "Parameters", ")", "String", "(", ")", "(", "ret", "string", ")", "{", "ret", "=", "\"", "\"", "\n", "for", "i", ",", "v", ":=", "range", "p", ".", "data", "(", ")", "{", "if", "i", ">", "0", "{", "ret", "+=", "\"", ...
// String represents parameters as a string.
[ "String", "represents", "parameters", "as", "a", "string", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/option.go#L150-L159
5,134
gobwas/httphead
cookie.go
Scan
func (c CookieScanner) Scan(data []byte, it func(name, value []byte) bool) bool { lexer := &Scanner{data: data} const ( statePair = iota stateBefore ) state := statePair for lexer.Buffered() > 0 { switch state { case stateBefore: // Pairs separated by ";" and space, according to the RFC6265: // cookie-pair *( ";" SP cookie-pair ) // // Cookie pairs MUST be separated by (";" SP). So our only option // here is to fail as syntax error. a, b := lexer.Peek2() if a != ';' { return false } state = statePair advance := 1 if b == ' ' { advance++ } else if c.Strict { return false } lexer.Advance(advance) case statePair: if !lexer.FetchUntil(';') { return false } var value []byte name := lexer.Bytes() if i := bytes.IndexByte(name, '='); i != -1 { value = name[i+1:] name = name[:i] } else if c.Strict { if !c.BreakOnPairError { goto nextPair } return false } if !c.Strict { trimLeft(name) } if !c.DisableNameValidation && !ValidCookieName(name) { if !c.BreakOnPairError { goto nextPair } return false } if !c.Strict { value = trimRight(value) } value = stripQuotes(value) if !c.DisableValueValidation && !ValidCookieValue(value, c.Strict) { if !c.BreakOnPairError { goto nextPair } return false } if !it(name, value) { return true } nextPair: state = stateBefore } } return true }
go
func (c CookieScanner) Scan(data []byte, it func(name, value []byte) bool) bool { lexer := &Scanner{data: data} const ( statePair = iota stateBefore ) state := statePair for lexer.Buffered() > 0 { switch state { case stateBefore: // Pairs separated by ";" and space, according to the RFC6265: // cookie-pair *( ";" SP cookie-pair ) // // Cookie pairs MUST be separated by (";" SP). So our only option // here is to fail as syntax error. a, b := lexer.Peek2() if a != ';' { return false } state = statePair advance := 1 if b == ' ' { advance++ } else if c.Strict { return false } lexer.Advance(advance) case statePair: if !lexer.FetchUntil(';') { return false } var value []byte name := lexer.Bytes() if i := bytes.IndexByte(name, '='); i != -1 { value = name[i+1:] name = name[:i] } else if c.Strict { if !c.BreakOnPairError { goto nextPair } return false } if !c.Strict { trimLeft(name) } if !c.DisableNameValidation && !ValidCookieName(name) { if !c.BreakOnPairError { goto nextPair } return false } if !c.Strict { value = trimRight(value) } value = stripQuotes(value) if !c.DisableValueValidation && !ValidCookieValue(value, c.Strict) { if !c.BreakOnPairError { goto nextPair } return false } if !it(name, value) { return true } nextPair: state = stateBefore } } return true }
[ "func", "(", "c", "CookieScanner", ")", "Scan", "(", "data", "[", "]", "byte", ",", "it", "func", "(", "name", ",", "value", "[", "]", "byte", ")", "bool", ")", "bool", "{", "lexer", ":=", "&", "Scanner", "{", "data", ":", "data", "}", "\n\n", ...
// Scan maps data to name and value pairs. Usually data represents value of the // Cookie header.
[ "Scan", "maps", "data", "to", "name", "and", "value", "pairs", ".", "Usually", "data", "represents", "value", "of", "the", "Cookie", "header", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/cookie.go#L49-L131
5,135
gobwas/httphead
cookie.go
ValidCookieName
func ValidCookieName(name []byte) bool { for _, c := range name { if !OctetTypes[c].IsToken() { return false } } return true }
go
func ValidCookieName(name []byte) bool { for _, c := range name { if !OctetTypes[c].IsToken() { return false } } return true }
[ "func", "ValidCookieName", "(", "name", "[", "]", "byte", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "name", "{", "if", "!", "OctetTypes", "[", "c", "]", ".", "IsToken", "(", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", ...
// ValidCookieName reports wheter given bytes is a valid RFC2616 "token" bytes.
[ "ValidCookieName", "reports", "wheter", "given", "bytes", "is", "a", "valid", "RFC2616", "token", "bytes", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/cookie.go#L170-L177
5,136
gobwas/httphead
lexer.go
Next
func (l *Scanner) Next() bool { c, ok := l.nextChar() if !ok { return false } switch c { case '"': // quoted-string; return l.fetchQuotedString() case '(': // comment; return l.fetchComment() case '\\', ')': // unexpected chars; l.err = true return false default: return l.fetchToken() } }
go
func (l *Scanner) Next() bool { c, ok := l.nextChar() if !ok { return false } switch c { case '"': // quoted-string; return l.fetchQuotedString() case '(': // comment; return l.fetchComment() case '\\', ')': // unexpected chars; l.err = true return false default: return l.fetchToken() } }
[ "func", "(", "l", "*", "Scanner", ")", "Next", "(", ")", "bool", "{", "c", ",", "ok", ":=", "l", ".", "nextChar", "(", ")", "\n", "if", "!", "ok", "{", "return", "false", "\n", "}", "\n", "switch", "c", "{", "case", "'\"'", ":", "// quoted-stri...
// Next scans for next token. It returns true on successful scanning, and false // on error or EOF.
[ "Next", "scans", "for", "next", "token", ".", "It", "returns", "true", "on", "successful", "scanning", "and", "false", "on", "error", "or", "EOF", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L44-L63
5,137
gobwas/httphead
lexer.go
FetchUntil
func (l *Scanner) FetchUntil(c byte) bool { l.resetItem() if l.pos == len(l.data) { return false } return l.fetchOctet(c) }
go
func (l *Scanner) FetchUntil(c byte) bool { l.resetItem() if l.pos == len(l.data) { return false } return l.fetchOctet(c) }
[ "func", "(", "l", "*", "Scanner", ")", "FetchUntil", "(", "c", "byte", ")", "bool", "{", "l", ".", "resetItem", "(", ")", "\n", "if", "l", ".", "pos", "==", "len", "(", "l", ".", "data", ")", "{", "return", "false", "\n", "}", "\n", "return", ...
// FetchUntil fetches ItemOctet from current scanner position to first // occurence of the c or to the end of the underlying data.
[ "FetchUntil", "fetches", "ItemOctet", "from", "current", "scanner", "position", "to", "first", "occurence", "of", "the", "c", "or", "to", "the", "end", "of", "the", "underlying", "data", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L67-L73
5,138
gobwas/httphead
lexer.go
Peek
func (l *Scanner) Peek() byte { if l.pos == len(l.data) { return 0 } return l.data[l.pos] }
go
func (l *Scanner) Peek() byte { if l.pos == len(l.data) { return 0 } return l.data[l.pos] }
[ "func", "(", "l", "*", "Scanner", ")", "Peek", "(", ")", "byte", "{", "if", "l", ".", "pos", "==", "len", "(", "l", ".", "data", ")", "{", "return", "0", "\n", "}", "\n", "return", "l", ".", "data", "[", "l", ".", "pos", "]", "\n", "}" ]
// Peek reads byte at current position without advancing it. On end of data it // returns 0.
[ "Peek", "reads", "byte", "at", "current", "position", "without", "advancing", "it", ".", "On", "end", "of", "data", "it", "returns", "0", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L77-L82
5,139
gobwas/httphead
lexer.go
Peek2
func (l *Scanner) Peek2() (a, b byte) { if l.pos == len(l.data) { return 0, 0 } if l.pos+1 == len(l.data) { return l.data[l.pos], 0 } return l.data[l.pos], l.data[l.pos+1] }
go
func (l *Scanner) Peek2() (a, b byte) { if l.pos == len(l.data) { return 0, 0 } if l.pos+1 == len(l.data) { return l.data[l.pos], 0 } return l.data[l.pos], l.data[l.pos+1] }
[ "func", "(", "l", "*", "Scanner", ")", "Peek2", "(", ")", "(", "a", ",", "b", "byte", ")", "{", "if", "l", ".", "pos", "==", "len", "(", "l", ".", "data", ")", "{", "return", "0", ",", "0", "\n", "}", "\n", "if", "l", ".", "pos", "+", "...
// Peek2 reads two first bytes at current position without advancing it. // If there not enough data it returs 0.
[ "Peek2", "reads", "two", "first", "bytes", "at", "current", "position", "without", "advancing", "it", ".", "If", "there", "not", "enough", "data", "it", "returs", "0", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L86-L94
5,140
gobwas/httphead
lexer.go
Advance
func (l *Scanner) Advance(n int) bool { l.pos += n if l.pos > len(l.data) { l.pos = len(l.data) return false } return true }
go
func (l *Scanner) Advance(n int) bool { l.pos += n if l.pos > len(l.data) { l.pos = len(l.data) return false } return true }
[ "func", "(", "l", "*", "Scanner", ")", "Advance", "(", "n", "int", ")", "bool", "{", "l", ".", "pos", "+=", "n", "\n", "if", "l", ".", "pos", ">", "len", "(", "l", ".", "data", ")", "{", "l", ".", "pos", "=", "len", "(", "l", ".", "data",...
// Advance moves current position index at n bytes. It returns true on // successful move.
[ "Advance", "moves", "current", "position", "index", "at", "n", "bytes", ".", "It", "returns", "true", "on", "successful", "move", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L103-L110
5,141
gobwas/httphead
lexer.go
Skip
func (l *Scanner) Skip(c byte) { if l.err { return } // Reset scanner state. l.resetItem() if i := bytes.IndexByte(l.data[l.pos:], c); i == -1 { // Reached the end of data. l.pos = len(l.data) } else { l.pos += i + 1 } }
go
func (l *Scanner) Skip(c byte) { if l.err { return } // Reset scanner state. l.resetItem() if i := bytes.IndexByte(l.data[l.pos:], c); i == -1 { // Reached the end of data. l.pos = len(l.data) } else { l.pos += i + 1 } }
[ "func", "(", "l", "*", "Scanner", ")", "Skip", "(", "c", "byte", ")", "{", "if", "l", ".", "err", "{", "return", "\n", "}", "\n", "// Reset scanner state.", "l", ".", "resetItem", "(", ")", "\n\n", "if", "i", ":=", "bytes", ".", "IndexByte", "(", ...
// Skip skips all bytes until first occurence of c.
[ "Skip", "skips", "all", "bytes", "until", "first", "occurence", "of", "c", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L113-L126
5,142
gobwas/httphead
lexer.go
SkipEscaped
func (l *Scanner) SkipEscaped(c byte) { if l.err { return } // Reset scanner state. l.resetItem() if i := ScanUntil(l.data[l.pos:], c); i == -1 { // Reached the end of data. l.pos = len(l.data) } else { l.pos += i + 1 } }
go
func (l *Scanner) SkipEscaped(c byte) { if l.err { return } // Reset scanner state. l.resetItem() if i := ScanUntil(l.data[l.pos:], c); i == -1 { // Reached the end of data. l.pos = len(l.data) } else { l.pos += i + 1 } }
[ "func", "(", "l", "*", "Scanner", ")", "SkipEscaped", "(", "c", "byte", ")", "{", "if", "l", ".", "err", "{", "return", "\n", "}", "\n", "// Reset scanner state.", "l", ".", "resetItem", "(", ")", "\n\n", "if", "i", ":=", "ScanUntil", "(", "l", "."...
// SkipEscaped skips all bytes until first occurence of non-escaped c.
[ "SkipEscaped", "skips", "all", "bytes", "until", "first", "occurence", "of", "non", "-", "escaped", "c", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L129-L142
5,143
gobwas/httphead
lexer.go
ScanUntil
func ScanUntil(data []byte, c byte) (n int) { for { i := bytes.IndexByte(data[n:], c) if i == -1 { return -1 } n += i if n == 0 || data[n-1] != '\\' { break } n++ } return }
go
func ScanUntil(data []byte, c byte) (n int) { for { i := bytes.IndexByte(data[n:], c) if i == -1 { return -1 } n += i if n == 0 || data[n-1] != '\\' { break } n++ } return }
[ "func", "ScanUntil", "(", "data", "[", "]", "byte", ",", "c", "byte", ")", "(", "n", "int", ")", "{", "for", "{", "i", ":=", "bytes", ".", "IndexByte", "(", "data", "[", "n", ":", "]", ",", "c", ")", "\n", "if", "i", "==", "-", "1", "{", ...
// ScanUntil scans for first non-escaped character c in given data. // It returns index of matched c and -1 if c is not found.
[ "ScanUntil", "scans", "for", "first", "non", "-", "escaped", "character", "c", "in", "given", "data", ".", "It", "returns", "index", "of", "matched", "c", "and", "-", "1", "if", "c", "is", "not", "found", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L236-L249
5,144
gobwas/httphead
lexer.go
ScanPairGreedy
func ScanPairGreedy(data []byte, open, close byte) (n int) { var m int opened := 1 for { i := bytes.IndexByte(data[n:], close) if i == -1 { return -1 } n += i // If found index is not escaped then it is the end. if n == 0 || data[n-1] != '\\' { opened-- } for m < i { j := bytes.IndexByte(data[m:i], open) if j == -1 { break } m += j + 1 opened++ } if opened == 0 { break } n++ m = n } return }
go
func ScanPairGreedy(data []byte, open, close byte) (n int) { var m int opened := 1 for { i := bytes.IndexByte(data[n:], close) if i == -1 { return -1 } n += i // If found index is not escaped then it is the end. if n == 0 || data[n-1] != '\\' { opened-- } for m < i { j := bytes.IndexByte(data[m:i], open) if j == -1 { break } m += j + 1 opened++ } if opened == 0 { break } n++ m = n } return }
[ "func", "ScanPairGreedy", "(", "data", "[", "]", "byte", ",", "open", ",", "close", "byte", ")", "(", "n", "int", ")", "{", "var", "m", "int", "\n", "opened", ":=", "1", "\n", "for", "{", "i", ":=", "bytes", ".", "IndexByte", "(", "data", "[", ...
// ScanPairGreedy scans for complete pair of opening and closing chars in greedy manner. // Note that first opening byte must not be present in data.
[ "ScanPairGreedy", "scans", "for", "complete", "pair", "of", "opening", "and", "closing", "chars", "in", "greedy", "manner", ".", "Note", "that", "first", "opening", "byte", "must", "not", "be", "present", "in", "data", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L253-L284
5,145
gobwas/httphead
lexer.go
RemoveByte
func RemoveByte(data []byte, c byte) []byte { j := bytes.IndexByte(data, c) if j == -1 { return data } n := len(data) - 1 // If character is present, than allocate slice with n-1 capacity. That is, // resulting bytes could be at most n-1 length. result := make([]byte, n) k := copy(result, data[:j]) for i := j + 1; i < n; { j = bytes.IndexByte(data[i:], c) if j != -1 { k += copy(result[k:], data[i:i+j]) i = i + j + 1 } else { k += copy(result[k:], data[i:]) break } } return result[:k] }
go
func RemoveByte(data []byte, c byte) []byte { j := bytes.IndexByte(data, c) if j == -1 { return data } n := len(data) - 1 // If character is present, than allocate slice with n-1 capacity. That is, // resulting bytes could be at most n-1 length. result := make([]byte, n) k := copy(result, data[:j]) for i := j + 1; i < n; { j = bytes.IndexByte(data[i:], c) if j != -1 { k += copy(result[k:], data[i:i+j]) i = i + j + 1 } else { k += copy(result[k:], data[i:]) break } } return result[:k] }
[ "func", "RemoveByte", "(", "data", "[", "]", "byte", ",", "c", "byte", ")", "[", "]", "byte", "{", "j", ":=", "bytes", ".", "IndexByte", "(", "data", ",", "c", ")", "\n", "if", "j", "==", "-", "1", "{", "return", "data", "\n", "}", "\n\n", "n...
// RemoveByte returns data without c. If c is not present in data it returns // the same slice. If not, it copies data without c.
[ "RemoveByte", "returns", "data", "without", "c", ".", "If", "c", "is", "not", "present", "in", "data", "it", "returns", "the", "same", "slice", ".", "If", "not", "it", "copies", "data", "without", "c", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L288-L313
5,146
gobwas/httphead
lexer.go
SkipSpace
func SkipSpace(p []byte) (n int) { for len(p) > 0 { switch { case len(p) >= 3 && p[0] == '\r' && p[1] == '\n' && OctetTypes[p[2]].IsSpace(): p = p[3:] n += 3 case OctetTypes[p[0]].IsSpace(): p = p[1:] n++ default: return } } return }
go
func SkipSpace(p []byte) (n int) { for len(p) > 0 { switch { case len(p) >= 3 && p[0] == '\r' && p[1] == '\n' && OctetTypes[p[2]].IsSpace(): p = p[3:] n += 3 case OctetTypes[p[0]].IsSpace(): p = p[1:] n++ default: return } } return }
[ "func", "SkipSpace", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ")", "{", "for", "len", "(", "p", ")", ">", "0", "{", "switch", "{", "case", "len", "(", "p", ")", ">=", "3", "&&", "p", "[", "0", "]", "==", "'\\r'", "&&", "p", "[", ...
// SkipSpace skips spaces and lws-sequences from p. // It returns number ob bytes skipped.
[ "SkipSpace", "skips", "spaces", "and", "lws", "-", "sequences", "from", "p", ".", "It", "returns", "number", "ob", "bytes", "skipped", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L317-L334
5,147
gobwas/httphead
lexer.go
ScanToken
func ScanToken(p []byte) (n int, t ItemType) { if len(p) == 0 { return 0, ItemUndef } c := p[0] switch { case OctetTypes[c].IsSeparator(): return 1, ItemSeparator case OctetTypes[c].IsToken(): for n = 1; n < len(p); n++ { c := p[n] if !OctetTypes[c].IsToken() { break } } return n, ItemToken default: return -1, ItemUndef } }
go
func ScanToken(p []byte) (n int, t ItemType) { if len(p) == 0 { return 0, ItemUndef } c := p[0] switch { case OctetTypes[c].IsSeparator(): return 1, ItemSeparator case OctetTypes[c].IsToken(): for n = 1; n < len(p); n++ { c := p[n] if !OctetTypes[c].IsToken() { break } } return n, ItemToken default: return -1, ItemUndef } }
[ "func", "ScanToken", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "t", "ItemType", ")", "{", "if", "len", "(", "p", ")", "==", "0", "{", "return", "0", ",", "ItemUndef", "\n", "}", "\n\n", "c", ":=", "p", "[", "0", "]", "\n", "swi...
// ScanToken scan for next token in p. It returns length of the token and its // type. It do not trim p.
[ "ScanToken", "scan", "for", "next", "token", "in", "p", ".", "It", "returns", "length", "of", "the", "token", "and", "its", "type", ".", "It", "do", "not", "trim", "p", "." ]
2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5
https://github.com/gobwas/httphead/blob/2c6c146eadee0b69f856f87e3e9f1d0cd6aad2f5/lexer.go#L338-L360
5,148
couchbase/vellum
levenshtein2/parametric_dfa.go
isPrefixSink
func (pdfa *ParametricDFA) isPrefixSink(state ParametricState, queryLen uint32) bool { if state.isDeadEnd() { return true } remOffset := queryLen - state.offset if remOffset < pdfa.diameter { stateDistances := pdfa.distance[pdfa.diameter*state.shapeID:] prefixDistance := stateDistances[remOffset] if prefixDistance > pdfa.maxDistance { return false } for _, d := range stateDistances { if d < prefixDistance { return false } } return true } return false }
go
func (pdfa *ParametricDFA) isPrefixSink(state ParametricState, queryLen uint32) bool { if state.isDeadEnd() { return true } remOffset := queryLen - state.offset if remOffset < pdfa.diameter { stateDistances := pdfa.distance[pdfa.diameter*state.shapeID:] prefixDistance := stateDistances[remOffset] if prefixDistance > pdfa.maxDistance { return false } for _, d := range stateDistances { if d < prefixDistance { return false } } return true } return false }
[ "func", "(", "pdfa", "*", "ParametricDFA", ")", "isPrefixSink", "(", "state", "ParametricState", ",", "queryLen", "uint32", ")", "bool", "{", "if", "state", ".", "isDeadEnd", "(", ")", "{", "return", "true", "\n", "}", "\n\n", "remOffset", ":=", "queryLen"...
// Returns true iff whatever characters come afterward, // we will never reach a shorter distance
[ "Returns", "true", "iff", "whatever", "characters", "come", "afterward", "we", "will", "never", "reach", "a", "shorter", "distance" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein2/parametric_dfa.go#L118-L139
5,149
couchbase/vellum
levenshtein/levenshtein.go
New
func New(query string, distance int) (*Levenshtein, error) { lev := &dynamicLevenshtein{ query: query, distance: uint(distance), } dfabuilder := newDfaBuilder(lev) dfa, err := dfabuilder.build() if err != nil { return nil, err } return &Levenshtein{ prog: lev, dfa: dfa, }, nil }
go
func New(query string, distance int) (*Levenshtein, error) { lev := &dynamicLevenshtein{ query: query, distance: uint(distance), } dfabuilder := newDfaBuilder(lev) dfa, err := dfabuilder.build() if err != nil { return nil, err } return &Levenshtein{ prog: lev, dfa: dfa, }, nil }
[ "func", "New", "(", "query", "string", ",", "distance", "int", ")", "(", "*", "Levenshtein", ",", "error", ")", "{", "lev", ":=", "&", "dynamicLevenshtein", "{", "query", ":", "query", ",", "distance", ":", "uint", "(", "distance", ")", ",", "}", "\n...
// New creates a new Levenshtein automaton for the specified // query string and edit distance.
[ "New", "creates", "a", "new", "Levenshtein", "automaton", "for", "the", "specified", "query", "string", "and", "edit", "distance", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein/levenshtein.go#L39-L53
5,150
couchbase/vellum
levenshtein/levenshtein.go
Accept
func (l *Levenshtein) Accept(s int, b byte) int { if s < len(l.dfa.states) { return l.dfa.states[s].next[b] } return 0 }
go
func (l *Levenshtein) Accept(s int, b byte) int { if s < len(l.dfa.states) { return l.dfa.states[s].next[b] } return 0 }
[ "func", "(", "l", "*", "Levenshtein", ")", "Accept", "(", "s", "int", ",", "b", "byte", ")", "int", "{", "if", "s", "<", "len", "(", "l", ".", "dfa", ".", "states", ")", "{", "return", "l", ".", "dfa", ".", "states", "[", "s", "]", ".", "ne...
// Accept returns the new state, resulting from the transite byte b // when currently in the state s.
[ "Accept", "returns", "the", "new", "state", "resulting", "from", "the", "transite", "byte", "b", "when", "currently", "in", "the", "state", "s", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein/levenshtein.go#L85-L90
5,151
couchbase/vellum
builder.go
newBuilder
func newBuilder(w io.Writer, opts *BuilderOpts) (*Builder, error) { if opts == nil { opts = defaultBuilderOpts } builderNodePool := &builderNodePool{} rv := &Builder{ unfinished: newUnfinishedNodes(builderNodePool), registry: newRegistry(builderNodePool, opts.RegistryTableSize, opts.RegistryMRUSize), builderNodePool: builderNodePool, opts: opts, lastAddr: noneAddr, } var err error rv.encoder, err = loadEncoder(opts.Encoder, w) if err != nil { return nil, err } err = rv.encoder.start() if err != nil { return nil, err } return rv, nil }
go
func newBuilder(w io.Writer, opts *BuilderOpts) (*Builder, error) { if opts == nil { opts = defaultBuilderOpts } builderNodePool := &builderNodePool{} rv := &Builder{ unfinished: newUnfinishedNodes(builderNodePool), registry: newRegistry(builderNodePool, opts.RegistryTableSize, opts.RegistryMRUSize), builderNodePool: builderNodePool, opts: opts, lastAddr: noneAddr, } var err error rv.encoder, err = loadEncoder(opts.Encoder, w) if err != nil { return nil, err } err = rv.encoder.start() if err != nil { return nil, err } return rv, nil }
[ "func", "newBuilder", "(", "w", "io", ".", "Writer", ",", "opts", "*", "BuilderOpts", ")", "(", "*", "Builder", ",", "error", ")", "{", "if", "opts", "==", "nil", "{", "opts", "=", "defaultBuilderOpts", "\n", "}", "\n", "builderNodePool", ":=", "&", ...
// NewBuilder returns a new Builder which will stream out the // underlying representation to the provided Writer as the set is built.
[ "NewBuilder", "returns", "a", "new", "Builder", "which", "will", "stream", "out", "the", "underlying", "representation", "to", "the", "provided", "Writer", "as", "the", "set", "is", "built", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L49-L72
5,152
couchbase/vellum
builder.go
Close
func (b *Builder) Close() error { err := b.compileFrom(0) if err != nil { return err } root := b.unfinished.popRoot() rootAddr, err := b.compile(root) if err != nil { return err } return b.encoder.finish(b.len, rootAddr) }
go
func (b *Builder) Close() error { err := b.compileFrom(0) if err != nil { return err } root := b.unfinished.popRoot() rootAddr, err := b.compile(root) if err != nil { return err } return b.encoder.finish(b.len, rootAddr) }
[ "func", "(", "b", "*", "Builder", ")", "Close", "(", ")", "error", "{", "err", ":=", "b", ".", "compileFrom", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "root", ":=", "b", ".", "unfinished", ".", "popR...
// Close MUST be called after inserting all values.
[ "Close", "MUST", "be", "called", "after", "inserting", "all", "values", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L124-L135
5,153
couchbase/vellum
builder.go
get
func (u *unfinishedNodes) get() *builderNodeUnfinished { if len(u.stack) < len(u.cache) { return &u.cache[len(u.stack)] } // full now allocate a new one return &builderNodeUnfinished{} }
go
func (u *unfinishedNodes) get() *builderNodeUnfinished { if len(u.stack) < len(u.cache) { return &u.cache[len(u.stack)] } // full now allocate a new one return &builderNodeUnfinished{} }
[ "func", "(", "u", "*", "unfinishedNodes", ")", "get", "(", ")", "*", "builderNodeUnfinished", "{", "if", "len", "(", "u", ".", "stack", ")", "<", "len", "(", "u", ".", "cache", ")", "{", "return", "&", "u", ".", "cache", "[", "len", "(", "u", "...
// get new builderNodeUnfinished, reusing cache if possible
[ "get", "new", "builderNodeUnfinished", "reusing", "cache", "if", "possible" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L208-L214
5,154
couchbase/vellum
builder.go
put
func (u *unfinishedNodes) put() { if len(u.stack) >= len(u.cache) { return // do nothing, not part of cache } u.cache[len(u.stack)] = builderNodeUnfinished{} }
go
func (u *unfinishedNodes) put() { if len(u.stack) >= len(u.cache) { return // do nothing, not part of cache } u.cache[len(u.stack)] = builderNodeUnfinished{} }
[ "func", "(", "u", "*", "unfinishedNodes", ")", "put", "(", ")", "{", "if", "len", "(", "u", ".", "stack", ")", ">=", "len", "(", "u", ".", "cache", ")", "{", "return", "\n", "// do nothing, not part of cache", "}", "\n", "u", ".", "cache", "[", "le...
// return builderNodeUnfinished, clearing it for reuse
[ "return", "builderNodeUnfinished", "clearing", "it", "for", "reuse" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L217-L223
5,155
couchbase/vellum
builder.go
reset
func (n *builderNode) reset() { n.final = false n.finalOutput = 0 for i := range n.trans { n.trans[i] = emptyTransition } n.trans = n.trans[:0] n.next = nil }
go
func (n *builderNode) reset() { n.final = false n.finalOutput = 0 for i := range n.trans { n.trans[i] = emptyTransition } n.trans = n.trans[:0] n.next = nil }
[ "func", "(", "n", "*", "builderNode", ")", "reset", "(", ")", "{", "n", ".", "final", "=", "false", "\n", "n", ".", "finalOutput", "=", "0", "\n", "for", "i", ":=", "range", "n", ".", "trans", "{", "n", ".", "trans", "[", "i", "]", "=", "empt...
// reset resets the receiver builderNode to a re-usable state.
[ "reset", "resets", "the", "receiver", "builderNode", "to", "a", "re", "-", "usable", "state", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/builder.go#L361-L369
5,156
couchbase/vellum
merge_iterator.go
NewMergeIterator
func NewMergeIterator(itrs []Iterator, f MergeFunc) (*MergeIterator, error) { rv := &MergeIterator{ itrs: itrs, f: f, currKs: make([][]byte, len(itrs)), currVs: make([]uint64, len(itrs)), lowIdxs: make([]int, 0, len(itrs)), mergeV: make([]uint64, 0, len(itrs)), } rv.init() if rv.lowK == nil { return rv, ErrIteratorDone } return rv, nil }
go
func NewMergeIterator(itrs []Iterator, f MergeFunc) (*MergeIterator, error) { rv := &MergeIterator{ itrs: itrs, f: f, currKs: make([][]byte, len(itrs)), currVs: make([]uint64, len(itrs)), lowIdxs: make([]int, 0, len(itrs)), mergeV: make([]uint64, 0, len(itrs)), } rv.init() if rv.lowK == nil { return rv, ErrIteratorDone } return rv, nil }
[ "func", "NewMergeIterator", "(", "itrs", "[", "]", "Iterator", ",", "f", "MergeFunc", ")", "(", "*", "MergeIterator", ",", "error", ")", "{", "rv", ":=", "&", "MergeIterator", "{", "itrs", ":", "itrs", ",", "f", ":", "f", ",", "currKs", ":", "make", ...
// NewMergeIterator creates a new MergeIterator over the provided slice of // Iterators and with the specified MergeFunc to resolve duplicate keys.
[ "NewMergeIterator", "creates", "a", "new", "MergeIterator", "over", "the", "provided", "slice", "of", "Iterators", "and", "with", "the", "specified", "MergeFunc", "to", "resolve", "duplicate", "keys", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L47-L61
5,157
couchbase/vellum
merge_iterator.go
Close
func (m *MergeIterator) Close() error { var rv error for i := range m.itrs { // close all iterators, return first error if any err := m.itrs[i].Close() if rv == nil { rv = err } } return rv }
go
func (m *MergeIterator) Close() error { var rv error for i := range m.itrs { // close all iterators, return first error if any err := m.itrs[i].Close() if rv == nil { rv = err } } return rv }
[ "func", "(", "m", "*", "MergeIterator", ")", "Close", "(", ")", "error", "{", "var", "rv", "error", "\n", "for", "i", ":=", "range", "m", ".", "itrs", "{", "// close all iterators, return first error if any", "err", ":=", "m", ".", "itrs", "[", "i", "]",...
// Close will attempt to close all the underlying Iterators. If any errors // are encountered, the first will be returned.
[ "Close", "will", "attempt", "to", "close", "all", "the", "underlying", "Iterators", ".", "If", "any", "errors", "are", "encountered", "the", "first", "will", "be", "returned", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L147-L157
5,158
couchbase/vellum
merge_iterator.go
MergeMin
func MergeMin(vals []uint64) uint64 { rv := vals[0] for _, v := range vals[1:] { if v < rv { rv = v } } return rv }
go
func MergeMin(vals []uint64) uint64 { rv := vals[0] for _, v := range vals[1:] { if v < rv { rv = v } } return rv }
[ "func", "MergeMin", "(", "vals", "[", "]", "uint64", ")", "uint64", "{", "rv", ":=", "vals", "[", "0", "]", "\n", "for", "_", ",", "v", ":=", "range", "vals", "[", "1", ":", "]", "{", "if", "v", "<", "rv", "{", "rv", "=", "v", "\n", "}", ...
// MergeMin chooses the minimum value
[ "MergeMin", "chooses", "the", "minimum", "value" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L160-L168
5,159
couchbase/vellum
merge_iterator.go
MergeMax
func MergeMax(vals []uint64) uint64 { rv := vals[0] for _, v := range vals[1:] { if v > rv { rv = v } } return rv }
go
func MergeMax(vals []uint64) uint64 { rv := vals[0] for _, v := range vals[1:] { if v > rv { rv = v } } return rv }
[ "func", "MergeMax", "(", "vals", "[", "]", "uint64", ")", "uint64", "{", "rv", ":=", "vals", "[", "0", "]", "\n", "for", "_", ",", "v", ":=", "range", "vals", "[", "1", ":", "]", "{", "if", "v", ">", "rv", "{", "rv", "=", "v", "\n", "}", ...
// MergeMax chooses the maximum value
[ "MergeMax", "chooses", "the", "maximum", "value" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L171-L179
5,160
couchbase/vellum
merge_iterator.go
MergeSum
func MergeSum(vals []uint64) uint64 { rv := vals[0] for _, v := range vals[1:] { rv += v } return rv }
go
func MergeSum(vals []uint64) uint64 { rv := vals[0] for _, v := range vals[1:] { rv += v } return rv }
[ "func", "MergeSum", "(", "vals", "[", "]", "uint64", ")", "uint64", "{", "rv", ":=", "vals", "[", "0", "]", "\n", "for", "_", ",", "v", ":=", "range", "vals", "[", "1", ":", "]", "{", "rv", "+=", "v", "\n", "}", "\n", "return", "rv", "\n", ...
// MergeSum sums the values
[ "MergeSum", "sums", "the", "values" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/merge_iterator.go#L182-L188
5,161
couchbase/vellum
levenshtein2/levenshtein.go
NewLevenshteinAutomatonBuilder
func NewLevenshteinAutomatonBuilder(maxDistance uint8, transposition bool) (*LevenshteinAutomatonBuilder, error) { lnfa := newLevenshtein(maxDistance, transposition) pdfa, err := fromNfa(lnfa) if err != nil { return nil, err } return &LevenshteinAutomatonBuilder{pDfa: pdfa}, nil }
go
func NewLevenshteinAutomatonBuilder(maxDistance uint8, transposition bool) (*LevenshteinAutomatonBuilder, error) { lnfa := newLevenshtein(maxDistance, transposition) pdfa, err := fromNfa(lnfa) if err != nil { return nil, err } return &LevenshteinAutomatonBuilder{pDfa: pdfa}, nil }
[ "func", "NewLevenshteinAutomatonBuilder", "(", "maxDistance", "uint8", ",", "transposition", "bool", ")", "(", "*", "LevenshteinAutomatonBuilder", ",", "error", ")", "{", "lnfa", ":=", "newLevenshtein", "(", "maxDistance", ",", "transposition", ")", "\n\n", "pdfa", ...
// NewLevenshteinAutomatonBuilder creates a // reusable, threadsafe Levenshtein automaton builder. // `maxDistance` - maximum distance considered by the automaton. // `transposition` - assign a distance of 1 for transposition // // Building this automaton builder is computationally intensive. // While it takes only a few milliseconds for `d=2`, it grows // exponentially with `d`. It is only reasonable to `d <= 5`.
[ "NewLevenshteinAutomatonBuilder", "creates", "a", "reusable", "threadsafe", "Levenshtein", "automaton", "builder", ".", "maxDistance", "-", "maximum", "distance", "considered", "by", "the", "automaton", ".", "transposition", "-", "assign", "a", "distance", "of", "1", ...
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein2/levenshtein.go#L41-L51
5,162
couchbase/vellum
levenshtein2/levenshtein.go
BuildDfa
func (lab *LevenshteinAutomatonBuilder) BuildDfa(query string, fuzziness uint8) (*DFA, error) { return lab.pDfa.buildDfa(query, fuzziness, false) }
go
func (lab *LevenshteinAutomatonBuilder) BuildDfa(query string, fuzziness uint8) (*DFA, error) { return lab.pDfa.buildDfa(query, fuzziness, false) }
[ "func", "(", "lab", "*", "LevenshteinAutomatonBuilder", ")", "BuildDfa", "(", "query", "string", ",", "fuzziness", "uint8", ")", "(", "*", "DFA", ",", "error", ")", "{", "return", "lab", ".", "pDfa", ".", "buildDfa", "(", "query", ",", "fuzziness", ",", ...
// BuildDfa builds the levenshtein automaton for serving // queries with a given edit distance.
[ "BuildDfa", "builds", "the", "levenshtein", "automaton", "for", "serving", "queries", "with", "a", "given", "edit", "distance", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/levenshtein2/levenshtein.go#L55-L58
5,163
couchbase/vellum
utf8/utf8.go
NewSequences
func NewSequences(start, end rune) (Sequences, error) { rv, _, err := NewSequencesPrealloc(start, end, nil, nil, nil, nil) return rv, err }
go
func NewSequences(start, end rune) (Sequences, error) { rv, _, err := NewSequencesPrealloc(start, end, nil, nil, nil, nil) return rv, err }
[ "func", "NewSequences", "(", "start", ",", "end", "rune", ")", "(", "Sequences", ",", "error", ")", "{", "rv", ",", "_", ",", "err", ":=", "NewSequencesPrealloc", "(", "start", ",", "end", ",", "nil", ",", "nil", ",", "nil", ",", "nil", ")", "\n", ...
// NewSequences constructs a collection of Sequence which describe the // byte ranges covered between the start and end runes.
[ "NewSequences", "constructs", "a", "collection", "of", "Sequence", "which", "describe", "the", "byte", "ranges", "covered", "between", "the", "start", "and", "end", "runes", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L27-L30
5,164
couchbase/vellum
utf8/utf8.go
SequenceFromEncodedRange
func SequenceFromEncodedRange(start, end []byte) (Sequence, error) { if len(start) != len(end) { return nil, fmt.Errorf("byte slices must be the same length") } switch len(start) { case 2: return Sequence{ Range{start[0], end[0]}, Range{start[1], end[1]}, }, nil case 3: return Sequence{ Range{start[0], end[0]}, Range{start[1], end[1]}, Range{start[2], end[2]}, }, nil case 4: return Sequence{ Range{start[0], end[0]}, Range{start[1], end[1]}, Range{start[2], end[2]}, Range{start[3], end[3]}, }, nil } return nil, fmt.Errorf("invalid encoded byte length") }
go
func SequenceFromEncodedRange(start, end []byte) (Sequence, error) { if len(start) != len(end) { return nil, fmt.Errorf("byte slices must be the same length") } switch len(start) { case 2: return Sequence{ Range{start[0], end[0]}, Range{start[1], end[1]}, }, nil case 3: return Sequence{ Range{start[0], end[0]}, Range{start[1], end[1]}, Range{start[2], end[2]}, }, nil case 4: return Sequence{ Range{start[0], end[0]}, Range{start[1], end[1]}, Range{start[2], end[2]}, Range{start[3], end[3]}, }, nil } return nil, fmt.Errorf("invalid encoded byte length") }
[ "func", "SequenceFromEncodedRange", "(", "start", ",", "end", "[", "]", "byte", ")", "(", "Sequence", ",", "error", ")", "{", "if", "len", "(", "start", ")", "!=", "len", "(", "end", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", ...
// SequenceFromEncodedRange creates sequence from the encoded bytes
[ "SequenceFromEncodedRange", "creates", "sequence", "from", "the", "encoded", "bytes" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L118-L144
5,165
couchbase/vellum
utf8/utf8.go
Matches
func (u Sequence) Matches(bytes []byte) bool { if len(bytes) < len(u) { return false } for i := 0; i < len(u); i++ { if !u[i].matches(bytes[i]) { return false } } return true }
go
func (u Sequence) Matches(bytes []byte) bool { if len(bytes) < len(u) { return false } for i := 0; i < len(u); i++ { if !u[i].matches(bytes[i]) { return false } } return true }
[ "func", "(", "u", "Sequence", ")", "Matches", "(", "bytes", "[", "]", "byte", ")", "bool", "{", "if", "len", "(", "bytes", ")", "<", "len", "(", "u", ")", "{", "return", "false", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", ...
// Matches checks to see if the provided byte slice matches the Sequence
[ "Matches", "checks", "to", "see", "if", "the", "provided", "byte", "slice", "matches", "the", "Sequence" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L147-L157
5,166
couchbase/vellum
utf8/utf8.go
split
func (s *scalarRange) split() (scalarRange, scalarRange) { if s.start < 0xe000 && s.end > 0xd7ff { return scalarRange{ start: s.start, end: 0xd7ff, }, scalarRange{ start: 0xe000, end: s.end, } } return nilScalarRange, nilScalarRange }
go
func (s *scalarRange) split() (scalarRange, scalarRange) { if s.start < 0xe000 && s.end > 0xd7ff { return scalarRange{ start: s.start, end: 0xd7ff, }, scalarRange{ start: 0xe000, end: s.end, } } return nilScalarRange, nilScalarRange }
[ "func", "(", "s", "*", "scalarRange", ")", "split", "(", ")", "(", "scalarRange", ",", "scalarRange", ")", "{", "if", "s", ".", "start", "<", "0xe000", "&&", "s", ".", "end", ">", "0xd7ff", "{", "return", "scalarRange", "{", "start", ":", "s", ".",...
// split this scalar range if it overlaps with a surrogate codepoint
[ "split", "this", "scalar", "range", "if", "it", "overlaps", "with", "a", "surrogate", "codepoint" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L208-L220
5,167
couchbase/vellum
utf8/utf8.go
encode
func (s *scalarRange) encode(start, end []byte) (int, int) { n := utf8.EncodeRune(start, s.start) m := utf8.EncodeRune(end, s.end) return n, m }
go
func (s *scalarRange) encode(start, end []byte) (int, int) { n := utf8.EncodeRune(start, s.start) m := utf8.EncodeRune(end, s.end) return n, m }
[ "func", "(", "s", "*", "scalarRange", ")", "encode", "(", "start", ",", "end", "[", "]", "byte", ")", "(", "int", ",", "int", ")", "{", "n", ":=", "utf8", ".", "EncodeRune", "(", "start", ",", "s", ".", "start", ")", "\n", "m", ":=", "utf8", ...
// start and end MUST have capacity for utf8.UTFMax bytes
[ "start", "and", "end", "MUST", "have", "capacity", "for", "utf8", ".", "UTFMax", "bytes" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/utf8/utf8.go#L237-L241
5,168
couchbase/vellum
fst_iterator.go
pointTo
func (i *FSTIterator) pointTo(key []byte) error { // tried to seek before start if bytes.Compare(key, i.startKeyInclusive) < 0 { key = i.startKeyInclusive } // tried to see past end if i.endKeyExclusive != nil && bytes.Compare(key, i.endKeyExclusive) > 0 { key = i.endKeyExclusive } // reset any state, pointTo always starts over i.statesStack = i.statesStack[:0] i.keysStack = i.keysStack[:0] i.keysPosStack = i.keysPosStack[:0] i.valsStack = i.valsStack[:0] i.autStatesStack = i.autStatesStack[:0] root, err := i.f.decoder.stateAt(i.f.decoder.getRoot(), nil) if err != nil { return err } autStart := i.aut.Start() maxQ := -1 // root is always part of the path i.statesStack = append(i.statesStack, root) i.autStatesStack = append(i.autStatesStack, autStart) for j := 0; j < len(key); j++ { keyJ := key[j] curr := i.statesStack[len(i.statesStack)-1] autCurr := i.autStatesStack[len(i.autStatesStack)-1] pos, nextAddr, nextVal := curr.TransitionFor(keyJ) if nextAddr == noneAddr { // needed transition doesn't exist // find last trans before the one we needed for q := curr.NumTransitions() - 1; q >= 0; q-- { if curr.TransitionAt(q) < keyJ { maxQ = q break } } break } autNext := i.aut.Accept(autCurr, keyJ) next, err := i.f.decoder.stateAt(nextAddr, nil) if err != nil { return err } i.statesStack = append(i.statesStack, next) i.keysStack = append(i.keysStack, keyJ) i.keysPosStack = append(i.keysPosStack, pos) i.valsStack = append(i.valsStack, nextVal) i.autStatesStack = append(i.autStatesStack, autNext) continue } if !i.statesStack[len(i.statesStack)-1].Final() || !i.aut.IsMatch(i.autStatesStack[len(i.autStatesStack)-1]) || bytes.Compare(i.keysStack, key) < 0 { return i.next(maxQ) } return nil }
go
func (i *FSTIterator) pointTo(key []byte) error { // tried to seek before start if bytes.Compare(key, i.startKeyInclusive) < 0 { key = i.startKeyInclusive } // tried to see past end if i.endKeyExclusive != nil && bytes.Compare(key, i.endKeyExclusive) > 0 { key = i.endKeyExclusive } // reset any state, pointTo always starts over i.statesStack = i.statesStack[:0] i.keysStack = i.keysStack[:0] i.keysPosStack = i.keysPosStack[:0] i.valsStack = i.valsStack[:0] i.autStatesStack = i.autStatesStack[:0] root, err := i.f.decoder.stateAt(i.f.decoder.getRoot(), nil) if err != nil { return err } autStart := i.aut.Start() maxQ := -1 // root is always part of the path i.statesStack = append(i.statesStack, root) i.autStatesStack = append(i.autStatesStack, autStart) for j := 0; j < len(key); j++ { keyJ := key[j] curr := i.statesStack[len(i.statesStack)-1] autCurr := i.autStatesStack[len(i.autStatesStack)-1] pos, nextAddr, nextVal := curr.TransitionFor(keyJ) if nextAddr == noneAddr { // needed transition doesn't exist // find last trans before the one we needed for q := curr.NumTransitions() - 1; q >= 0; q-- { if curr.TransitionAt(q) < keyJ { maxQ = q break } } break } autNext := i.aut.Accept(autCurr, keyJ) next, err := i.f.decoder.stateAt(nextAddr, nil) if err != nil { return err } i.statesStack = append(i.statesStack, next) i.keysStack = append(i.keysStack, keyJ) i.keysPosStack = append(i.keysPosStack, pos) i.valsStack = append(i.valsStack, nextVal) i.autStatesStack = append(i.autStatesStack, autNext) continue } if !i.statesStack[len(i.statesStack)-1].Final() || !i.aut.IsMatch(i.autStatesStack[len(i.autStatesStack)-1]) || bytes.Compare(i.keysStack, key) < 0 { return i.next(maxQ) } return nil }
[ "func", "(", "i", "*", "FSTIterator", ")", "pointTo", "(", "key", "[", "]", "byte", ")", "error", "{", "// tried to seek before start", "if", "bytes", ".", "Compare", "(", "key", ",", "i", ".", "startKeyInclusive", ")", "<", "0", "{", "key", "=", "i", ...
// pointTo attempts to point us to the specified location
[ "pointTo", "attempts", "to", "point", "us", "to", "the", "specified", "location" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst_iterator.go#L94-L163
5,169
couchbase/vellum
regexp/regexp.go
NewWithLimit
func NewWithLimit(expr string, size uint) (*Regexp, error) { parsed, err := syntax.Parse(expr, syntax.Perl) if err != nil { return nil, err } return NewParsedWithLimit(expr, parsed, size) }
go
func NewWithLimit(expr string, size uint) (*Regexp, error) { parsed, err := syntax.Parse(expr, syntax.Perl) if err != nil { return nil, err } return NewParsedWithLimit(expr, parsed, size) }
[ "func", "NewWithLimit", "(", "expr", "string", ",", "size", "uint", ")", "(", "*", "Regexp", ",", "error", ")", "{", "parsed", ",", "err", ":=", "syntax", ".", "Parse", "(", "expr", ",", "syntax", ".", "Perl", ")", "\n", "if", "err", "!=", "nil", ...
// NewRegexpWithLimit creates a new Regular Expression automaton with // the specified expression. The size of the compiled finite state // automaton exceeds the user specified size, ErrCompiledTooBig will be // returned.
[ "NewRegexpWithLimit", "creates", "a", "new", "Regular", "Expression", "automaton", "with", "the", "specified", "expression", ".", "The", "size", "of", "the", "compiled", "finite", "state", "automaton", "exceeds", "the", "user", "specified", "size", "ErrCompiledTooBi...
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/regexp/regexp.go#L59-L65
5,170
couchbase/vellum
regexp/regexp.go
Accept
func (r *Regexp) Accept(s int, b byte) int { if s < len(r.dfa.states) { return r.dfa.states[s].next[b] } return 0 }
go
func (r *Regexp) Accept(s int, b byte) int { if s < len(r.dfa.states) { return r.dfa.states[s].next[b] } return 0 }
[ "func", "(", "r", "*", "Regexp", ")", "Accept", "(", "s", "int", ",", "b", "byte", ")", "int", "{", "if", "s", "<", "len", "(", "r", ".", "dfa", ".", "states", ")", "{", "return", "r", ".", "dfa", ".", "states", "[", "s", "]", ".", "next", ...
// Accept returns the new state, resulting from the transition byte b // when currently in the state s.
[ "Accept", "returns", "the", "new", "state", "resulting", "from", "the", "transition", "byte", "b", "when", "currently", "in", "the", "state", "s", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/regexp/regexp.go#L114-L119
5,171
couchbase/vellum
fst.go
Contains
func (f *FST) Contains(val []byte) (bool, error) { _, exists, err := f.Get(val) return exists, err }
go
func (f *FST) Contains(val []byte) (bool, error) { _, exists, err := f.Get(val) return exists, err }
[ "func", "(", "f", "*", "FST", ")", "Contains", "(", "val", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "_", ",", "exists", ",", "err", ":=", "f", ".", "Get", "(", "val", ")", "\n", "return", "exists", ",", "err", "\n", "}" ]
// Contains returns true if this FST contains the specified key.
[ "Contains", "returns", "true", "if", "this", "FST", "contains", "the", "specified", "key", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L58-L61
5,172
couchbase/vellum
fst.go
IsMatch
func (f *FST) IsMatch(addr int) bool { match, _ := f.IsMatchWithVal(addr) return match }
go
func (f *FST) IsMatch(addr int) bool { match, _ := f.IsMatchWithVal(addr) return match }
[ "func", "(", "f", "*", "FST", ")", "IsMatch", "(", "addr", "int", ")", "bool", "{", "match", ",", "_", ":=", "f", ".", "IsMatchWithVal", "(", "addr", ")", "\n", "return", "match", "\n", "}" ]
// IsMatch returns if this state is a matching state in this Automaton
[ "IsMatch", "returns", "if", "this", "state", "is", "a", "matching", "state", "in", "this", "Automaton" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L134-L137
5,173
couchbase/vellum
fst.go
CanMatch
func (f *FST) CanMatch(addr int) bool { if addr == noneAddr { return false } return true }
go
func (f *FST) CanMatch(addr int) bool { if addr == noneAddr { return false } return true }
[ "func", "(", "f", "*", "FST", ")", "CanMatch", "(", "addr", "int", ")", "bool", "{", "if", "addr", "==", "noneAddr", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// CanMatch returns if this state can ever transition to a matching state // in this Automaton
[ "CanMatch", "returns", "if", "this", "state", "can", "ever", "transition", "to", "a", "matching", "state", "in", "this", "Automaton" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L141-L146
5,174
couchbase/vellum
fst.go
Accept
func (f *FST) Accept(addr int, b byte) int { next, _ := f.AcceptWithVal(addr, b) return next }
go
func (f *FST) Accept(addr int, b byte) int { next, _ := f.AcceptWithVal(addr, b) return next }
[ "func", "(", "f", "*", "FST", ")", "Accept", "(", "addr", "int", ",", "b", "byte", ")", "int", "{", "next", ",", "_", ":=", "f", ".", "AcceptWithVal", "(", "addr", ",", "b", ")", "\n", "return", "next", "\n", "}" ]
// Accept returns the next state for this Automaton on input of byte b
[ "Accept", "returns", "the", "next", "state", "for", "this", "Automaton", "on", "input", "of", "byte", "b" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L155-L158
5,175
couchbase/vellum
fst.go
IsMatchWithVal
func (f *FST) IsMatchWithVal(addr int) (bool, uint64) { s, err := f.decoder.stateAt(addr, nil) if err != nil { return false, 0 } return s.Final(), s.FinalOutput() }
go
func (f *FST) IsMatchWithVal(addr int) (bool, uint64) { s, err := f.decoder.stateAt(addr, nil) if err != nil { return false, 0 } return s.Final(), s.FinalOutput() }
[ "func", "(", "f", "*", "FST", ")", "IsMatchWithVal", "(", "addr", "int", ")", "(", "bool", ",", "uint64", ")", "{", "s", ",", "err", ":=", "f", ".", "decoder", ".", "stateAt", "(", "addr", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", ...
// IsMatchWithVal returns if this state is a matching state in this Automaton // and also returns the final output value for this state
[ "IsMatchWithVal", "returns", "if", "this", "state", "is", "a", "matching", "state", "in", "this", "Automaton", "and", "also", "returns", "the", "final", "output", "value", "for", "this", "state" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L162-L168
5,176
couchbase/vellum
fst.go
AcceptWithVal
func (f *FST) AcceptWithVal(addr int, b byte) (int, uint64) { s, err := f.decoder.stateAt(addr, nil) if err != nil { return noneAddr, 0 } _, next, output := s.TransitionFor(b) return next, output }
go
func (f *FST) AcceptWithVal(addr int, b byte) (int, uint64) { s, err := f.decoder.stateAt(addr, nil) if err != nil { return noneAddr, 0 } _, next, output := s.TransitionFor(b) return next, output }
[ "func", "(", "f", "*", "FST", ")", "AcceptWithVal", "(", "addr", "int", ",", "b", "byte", ")", "(", "int", ",", "uint64", ")", "{", "s", ",", "err", ":=", "f", ".", "decoder", ".", "stateAt", "(", "addr", ",", "nil", ")", "\n", "if", "err", "...
// AcceptWithVal returns the next state for this Automaton on input of byte b // and also returns the output value for the transition
[ "AcceptWithVal", "returns", "the", "next", "state", "for", "this", "Automaton", "on", "input", "of", "byte", "b", "and", "also", "returns", "the", "output", "value", "for", "the", "transition" ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L172-L179
5,177
couchbase/vellum
fst.go
Debug
func (f *FST) Debug(callback func(int, interface{}) error) error { addr := f.decoder.getRoot() set := bitset.New(uint(addr)) stack := addrStack{addr} stateNumber := 0 stack, addr = stack[:len(stack)-1], stack[len(stack)-1] for addr != noneAddr { if set.Test(uint(addr)) { stack, addr = stack.Pop() continue } set.Set(uint(addr)) state, err := f.decoder.stateAt(addr, nil) if err != nil { return err } err = callback(stateNumber, state) if err != nil { return err } for i := 0; i < state.NumTransitions(); i++ { tchar := state.TransitionAt(i) _, dest, _ := state.TransitionFor(tchar) stack = append(stack, dest) } stateNumber++ stack, addr = stack.Pop() } return nil }
go
func (f *FST) Debug(callback func(int, interface{}) error) error { addr := f.decoder.getRoot() set := bitset.New(uint(addr)) stack := addrStack{addr} stateNumber := 0 stack, addr = stack[:len(stack)-1], stack[len(stack)-1] for addr != noneAddr { if set.Test(uint(addr)) { stack, addr = stack.Pop() continue } set.Set(uint(addr)) state, err := f.decoder.stateAt(addr, nil) if err != nil { return err } err = callback(stateNumber, state) if err != nil { return err } for i := 0; i < state.NumTransitions(); i++ { tchar := state.TransitionAt(i) _, dest, _ := state.TransitionFor(tchar) stack = append(stack, dest) } stateNumber++ stack, addr = stack.Pop() } return nil }
[ "func", "(", "f", "*", "FST", ")", "Debug", "(", "callback", "func", "(", "int", ",", "interface", "{", "}", ")", "error", ")", "error", "{", "addr", ":=", "f", ".", "decoder", ".", "getRoot", "(", ")", "\n", "set", ":=", "bitset", ".", "New", ...
// Debug is only intended for debug purposes, it simply asks the underlying // decoder visit each state, and pass it to the provided callback.
[ "Debug", "is", "only", "intended", "for", "debug", "purposes", "it", "simply", "asks", "the", "underlying", "decoder", "visit", "each", "state", "and", "pass", "it", "to", "the", "provided", "callback", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/fst.go#L196-L228
5,178
couchbase/vellum
vellum.go
New
func New(w io.Writer, opts *BuilderOpts) (*Builder, error) { return newBuilder(w, opts) }
go
func New(w io.Writer, opts *BuilderOpts) (*Builder, error) { return newBuilder(w, opts) }
[ "func", "New", "(", "w", "io", ".", "Writer", ",", "opts", "*", "BuilderOpts", ")", "(", "*", "Builder", ",", "error", ")", "{", "return", "newBuilder", "(", "w", ",", "opts", ")", "\n", "}" ]
// New returns a new Builder which will stream out the // underlying representation to the provided Writer as the set is built.
[ "New", "returns", "a", "new", "Builder", "which", "will", "stream", "out", "the", "underlying", "representation", "to", "the", "provided", "Writer", "as", "the", "set", "is", "built", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/vellum.go#L64-L66
5,179
couchbase/vellum
vellum.go
Merge
func Merge(w io.Writer, opts *BuilderOpts, itrs []Iterator, f MergeFunc) error { builder, err := New(w, opts) if err != nil { return err } itr, err := NewMergeIterator(itrs, f) for err == nil { k, v := itr.Current() err = builder.Insert(k, v) if err != nil { return err } err = itr.Next() } if err != nil && err != ErrIteratorDone { return err } err = itr.Close() if err != nil { return err } err = builder.Close() if err != nil { return err } return nil }
go
func Merge(w io.Writer, opts *BuilderOpts, itrs []Iterator, f MergeFunc) error { builder, err := New(w, opts) if err != nil { return err } itr, err := NewMergeIterator(itrs, f) for err == nil { k, v := itr.Current() err = builder.Insert(k, v) if err != nil { return err } err = itr.Next() } if err != nil && err != ErrIteratorDone { return err } err = itr.Close() if err != nil { return err } err = builder.Close() if err != nil { return err } return nil }
[ "func", "Merge", "(", "w", "io", ".", "Writer", ",", "opts", "*", "BuilderOpts", ",", "itrs", "[", "]", "Iterator", ",", "f", "MergeFunc", ")", "error", "{", "builder", ",", "err", ":=", "New", "(", "w", ",", "opts", ")", "\n", "if", "err", "!=",...
// Merge will iterate through the provided Iterators, merge duplicate keys // with the provided MergeFunc, and build a new FST to the provided Writer.
[ "Merge", "will", "iterate", "through", "the", "provided", "Iterators", "merge", "duplicate", "keys", "with", "the", "provided", "MergeFunc", "and", "build", "a", "new", "FST", "to", "the", "provided", "Writer", "." ]
462e86d8716b36a1397b30ef77fb11105065a232
https://github.com/couchbase/vellum/blob/462e86d8716b36a1397b30ef77fb11105065a232/vellum.go#L80-L111
5,180
go-chassis/go-archaius
core/config-manager/configurationmanager.go
NewConfigurationManager
func NewConfigurationManager(dispatcher core.Dispatcher) core.ConfigMgr { configMgr := new(ConfigurationManager) configMgr.dispatcher = dispatcher configMgr.Sources = make(map[string]core.ConfigSource) configMgr.ConfigurationMap = make(map[string]string) //configMgr.logger = cLogger return configMgr }
go
func NewConfigurationManager(dispatcher core.Dispatcher) core.ConfigMgr { configMgr := new(ConfigurationManager) configMgr.dispatcher = dispatcher configMgr.Sources = make(map[string]core.ConfigSource) configMgr.ConfigurationMap = make(map[string]string) //configMgr.logger = cLogger return configMgr }
[ "func", "NewConfigurationManager", "(", "dispatcher", "core", ".", "Dispatcher", ")", "core", ".", "ConfigMgr", "{", "configMgr", ":=", "new", "(", "ConfigurationManager", ")", "\n", "configMgr", ".", "dispatcher", "=", "dispatcher", "\n", "configMgr", ".", "Sou...
// NewConfigurationManager creates an object of ConfigurationManager
[ "NewConfigurationManager", "creates", "an", "object", "of", "ConfigurationManager" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L53-L61
5,181
go-chassis/go-archaius
core/config-manager/configurationmanager.go
Cleanup
func (configMgr *ConfigurationManager) Cleanup() { // cleanup all dynamic handler configMgr.sourceMapMux.Lock() defer configMgr.sourceMapMux.Unlock() for _, source := range configMgr.Sources { if source.GetSourceName() == filesource.FileConfigSourceConst { source.Cleanup() delete(configMgr.Sources, source.GetSourceName()) } } }
go
func (configMgr *ConfigurationManager) Cleanup() { // cleanup all dynamic handler configMgr.sourceMapMux.Lock() defer configMgr.sourceMapMux.Unlock() for _, source := range configMgr.Sources { if source.GetSourceName() == filesource.FileConfigSourceConst { source.Cleanup() delete(configMgr.Sources, source.GetSourceName()) } } }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "Cleanup", "(", ")", "{", "// cleanup all dynamic handler", "configMgr", ".", "sourceMapMux", ".", "Lock", "(", ")", "\n", "defer", "configMgr", ".", "sourceMapMux", ".", "Unlock", "(", ")", "\n", "fo...
// Cleanup close and cleanup config manager channel
[ "Cleanup", "close", "and", "cleanup", "config", "manager", "channel" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L64-L74
5,182
go-chassis/go-archaius
core/config-manager/configurationmanager.go
Unmarshal
func (configMgr *ConfigurationManager) Unmarshal(obj interface{}) error { rv := reflect.ValueOf(obj) // only pointers are accepted if rv.Kind() != reflect.Ptr || rv.IsNil() { err := errors.New("invalid object supplied") openlogging.GetLogger().Error("invalid object supplied: " + err.Error()) return err } return configMgr.unmarshal(rv, doNotConsiderTag) }
go
func (configMgr *ConfigurationManager) Unmarshal(obj interface{}) error { rv := reflect.ValueOf(obj) // only pointers are accepted if rv.Kind() != reflect.Ptr || rv.IsNil() { err := errors.New("invalid object supplied") openlogging.GetLogger().Error("invalid object supplied: " + err.Error()) return err } return configMgr.unmarshal(rv, doNotConsiderTag) }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "Unmarshal", "(", "obj", "interface", "{", "}", ")", "error", "{", "rv", ":=", "reflect", ".", "ValueOf", "(", "obj", ")", "\n", "// only pointers are accepted", "if", "rv", ".", "Kind", "(", ")",...
// Unmarshal deserailize config into object
[ "Unmarshal", "deserailize", "config", "into", "object" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L77-L87
5,183
go-chassis/go-archaius
core/config-manager/configurationmanager.go
AddSource
func (configMgr *ConfigurationManager) AddSource(source core.ConfigSource, priority int) error { if source == nil || source.GetSourceName() == "" { err := errors.New("nil or invalid source supplied") openlogging.GetLogger().Error("nil or invalid source supplied: " + err.Error()) return err } configMgr.sourceMapMux.Lock() sourceName := source.GetSourceName() _, ok := configMgr.Sources[sourceName] if ok { err := errors.New("duplicate source supplied") openlogging.GetLogger().Error("duplicate source supplied: " + err.Error()) configMgr.sourceMapMux.Unlock() return err } configMgr.Sources[sourceName] = source configMgr.sourceMapMux.Unlock() err := configMgr.pullSourceConfigs(sourceName) if err != nil { err = fmt.Errorf("fail to load configuration of %s source: %s", sourceName, err) openlogging.Error(err.Error()) return err } openlogging.Info("invoke dynamic handler:" + source.GetSourceName()) go source.DynamicConfigHandler(configMgr) return nil }
go
func (configMgr *ConfigurationManager) AddSource(source core.ConfigSource, priority int) error { if source == nil || source.GetSourceName() == "" { err := errors.New("nil or invalid source supplied") openlogging.GetLogger().Error("nil or invalid source supplied: " + err.Error()) return err } configMgr.sourceMapMux.Lock() sourceName := source.GetSourceName() _, ok := configMgr.Sources[sourceName] if ok { err := errors.New("duplicate source supplied") openlogging.GetLogger().Error("duplicate source supplied: " + err.Error()) configMgr.sourceMapMux.Unlock() return err } configMgr.Sources[sourceName] = source configMgr.sourceMapMux.Unlock() err := configMgr.pullSourceConfigs(sourceName) if err != nil { err = fmt.Errorf("fail to load configuration of %s source: %s", sourceName, err) openlogging.Error(err.Error()) return err } openlogging.Info("invoke dynamic handler:" + source.GetSourceName()) go source.DynamicConfigHandler(configMgr) return nil }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "AddSource", "(", "source", "core", ".", "ConfigSource", ",", "priority", "int", ")", "error", "{", "if", "source", "==", "nil", "||", "source", ".", "GetSourceName", "(", ")", "==", "\"", "\"", ...
// AddSource adds a source to configurationManager
[ "AddSource", "adds", "a", "source", "to", "configurationManager" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L90-L121
5,184
go-chassis/go-archaius
core/config-manager/configurationmanager.go
GetConfigurations
func (configMgr *ConfigurationManager) GetConfigurations() map[string]interface{} { config := make(map[string]interface{}, 0) configMgr.configMapMux.Lock() defer configMgr.configMapMux.Unlock() for key, sourceName := range configMgr.ConfigurationMap { sValue := configMgr.configValueBySource(key, sourceName) if sValue == nil { continue } config[key] = sValue } return config }
go
func (configMgr *ConfigurationManager) GetConfigurations() map[string]interface{} { config := make(map[string]interface{}, 0) configMgr.configMapMux.Lock() defer configMgr.configMapMux.Unlock() for key, sourceName := range configMgr.ConfigurationMap { sValue := configMgr.configValueBySource(key, sourceName) if sValue == nil { continue } config[key] = sValue } return config }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "GetConfigurations", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "config", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "0", ")", "\n\n", "con...
// GetConfigurations returns all the configurationkeys
[ "GetConfigurations", "returns", "all", "the", "configurationkeys" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L176-L191
5,185
go-chassis/go-archaius
core/config-manager/configurationmanager.go
GetConfigurationsByDimensionInfo
func (configMgr *ConfigurationManager) GetConfigurationsByDimensionInfo(dimensionInfo string) (map[string]interface{}, error) { config := make(map[string]interface{}, 0) configMgr.configMapMux.Lock() defer configMgr.configMapMux.Unlock() for key, sourceName := range configMgr.ConfigurationMap { sValue := configMgr.configValueBySourceAndDimensionInfo(key, sourceName, dimensionInfo) if sValue == nil { continue } config[key] = sValue } return config, nil }
go
func (configMgr *ConfigurationManager) GetConfigurationsByDimensionInfo(dimensionInfo string) (map[string]interface{}, error) { config := make(map[string]interface{}, 0) configMgr.configMapMux.Lock() defer configMgr.configMapMux.Unlock() for key, sourceName := range configMgr.ConfigurationMap { sValue := configMgr.configValueBySourceAndDimensionInfo(key, sourceName, dimensionInfo) if sValue == nil { continue } config[key] = sValue } return config, nil }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "GetConfigurationsByDimensionInfo", "(", "dimensionInfo", "string", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "config", ":=", "make", "(", "map", "[", "stri...
// GetConfigurationsByDimensionInfo returns list of all the configuration for a particular dimensionInfo
[ "GetConfigurationsByDimensionInfo", "returns", "list", "of", "all", "the", "configuration", "for", "a", "particular", "dimensionInfo" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L194-L209
5,186
go-chassis/go-archaius
core/config-manager/configurationmanager.go
AddDimensionInfo
func (configMgr *ConfigurationManager) AddDimensionInfo(dimensionInfo string) (map[string]string, error) { config := make(map[string]string, 0) config, er := configMgr.addDimensionInfo(dimensionInfo) if er != nil { openlogging.GetLogger().Errorf("failed to do add dimension info %s", er) return config, er } err := configMgr.pullSourceConfigsByDI("ConfigCenterSource", dimensionInfo) if err != nil { openlogging.GetLogger().Errorf("fail to load configuration of ConfigCenterSource source%s", err) return nil, err } return config, nil }
go
func (configMgr *ConfigurationManager) AddDimensionInfo(dimensionInfo string) (map[string]string, error) { config := make(map[string]string, 0) config, er := configMgr.addDimensionInfo(dimensionInfo) if er != nil { openlogging.GetLogger().Errorf("failed to do add dimension info %s", er) return config, er } err := configMgr.pullSourceConfigsByDI("ConfigCenterSource", dimensionInfo) if err != nil { openlogging.GetLogger().Errorf("fail to load configuration of ConfigCenterSource source%s", err) return nil, err } return config, nil }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "AddDimensionInfo", "(", "dimensionInfo", "string", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "config", ":=", "make", "(", "map", "[", "string", "]", "string", ",", ...
// AddDimensionInfo adds the dimensionInfo to the list of which configurations needs to be pulled
[ "AddDimensionInfo", "adds", "the", "dimensionInfo", "to", "the", "list", "of", "which", "configurations", "needs", "to", "be", "pulled" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L212-L228
5,187
go-chassis/go-archaius
core/config-manager/configurationmanager.go
Refresh
func (configMgr *ConfigurationManager) Refresh(sourceName string) error { err := configMgr.pullSourceConfigs(sourceName) if err != nil { openlogging.GetLogger().Errorf("fail to load configuration of %s source: %s", sourceName, err) errorMsg := "fail to load configuration of" + sourceName + " source" return errors.New(errorMsg) } return nil }
go
func (configMgr *ConfigurationManager) Refresh(sourceName string) error { err := configMgr.pullSourceConfigs(sourceName) if err != nil { openlogging.GetLogger().Errorf("fail to load configuration of %s source: %s", sourceName, err) errorMsg := "fail to load configuration of" + sourceName + " source" return errors.New(errorMsg) } return nil }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "Refresh", "(", "sourceName", "string", ")", "error", "{", "err", ":=", "configMgr", ".", "pullSourceConfigs", "(", "sourceName", ")", "\n", "if", "err", "!=", "nil", "{", "openlogging", ".", "GetLo...
// Refresh refreshes the full configurations of all the dimnesionInfos
[ "Refresh", "refreshes", "the", "full", "configurations", "of", "all", "the", "dimnesionInfos" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L231-L239
5,188
go-chassis/go-archaius
core/config-manager/configurationmanager.go
IsKeyExist
func (configMgr *ConfigurationManager) IsKeyExist(key string) bool { configMgr.configMapMux.Lock() defer configMgr.configMapMux.Unlock() if _, ok := configMgr.ConfigurationMap[key]; ok { return true } return false }
go
func (configMgr *ConfigurationManager) IsKeyExist(key string) bool { configMgr.configMapMux.Lock() defer configMgr.configMapMux.Unlock() if _, ok := configMgr.ConfigurationMap[key]; ok { return true } return false }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "IsKeyExist", "(", "key", "string", ")", "bool", "{", "configMgr", ".", "configMapMux", ".", "Lock", "(", ")", "\n", "defer", "configMgr", ".", "configMapMux", ".", "Unlock", "(", ")", "\n\n", "if...
// IsKeyExist check if key exsist in cache
[ "IsKeyExist", "check", "if", "key", "exsist", "in", "cache" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L295-L304
5,189
go-chassis/go-archaius
core/config-manager/configurationmanager.go
GetConfigurationsByKey
func (configMgr *ConfigurationManager) GetConfigurationsByKey(key string) interface{} { configMgr.configMapMux.Lock() sourceName, ok := configMgr.ConfigurationMap[key] configMgr.configMapMux.Unlock() if !ok { return nil } return configMgr.configValueBySource(key, sourceName) }
go
func (configMgr *ConfigurationManager) GetConfigurationsByKey(key string) interface{} { configMgr.configMapMux.Lock() sourceName, ok := configMgr.ConfigurationMap[key] configMgr.configMapMux.Unlock() if !ok { return nil } return configMgr.configValueBySource(key, sourceName) }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "GetConfigurationsByKey", "(", "key", "string", ")", "interface", "{", "}", "{", "configMgr", ".", "configMapMux", ".", "Lock", "(", ")", "\n", "sourceName", ",", "ok", ":=", "configMgr", ".", "Conf...
// GetConfigurationsByKey returns the value for a particluar key from cache
[ "GetConfigurationsByKey", "returns", "the", "value", "for", "a", "particluar", "key", "from", "cache" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L307-L316
5,190
go-chassis/go-archaius
core/config-manager/configurationmanager.go
GetConfigurationsByKeyAndDimensionInfo
func (configMgr *ConfigurationManager) GetConfigurationsByKeyAndDimensionInfo(dimensionInfo, key string) interface{} { configMgr.configMapMux.Lock() sourceName, ok := configMgr.ConfigurationMap[key] configMgr.configMapMux.Unlock() if !ok { return nil } return configMgr.configValueBySourceAndDimensionInfo(key, sourceName, dimensionInfo) }
go
func (configMgr *ConfigurationManager) GetConfigurationsByKeyAndDimensionInfo(dimensionInfo, key string) interface{} { configMgr.configMapMux.Lock() sourceName, ok := configMgr.ConfigurationMap[key] configMgr.configMapMux.Unlock() if !ok { return nil } return configMgr.configValueBySourceAndDimensionInfo(key, sourceName, dimensionInfo) }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "GetConfigurationsByKeyAndDimensionInfo", "(", "dimensionInfo", ",", "key", "string", ")", "interface", "{", "}", "{", "configMgr", ".", "configMapMux", ".", "Lock", "(", ")", "\n", "sourceName", ",", "...
// GetConfigurationsByKeyAndDimensionInfo returns the key value for a particular dimensionInfo
[ "GetConfigurationsByKeyAndDimensionInfo", "returns", "the", "key", "value", "for", "a", "particular", "dimensionInfo" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L319-L329
5,191
go-chassis/go-archaius
core/config-manager/configurationmanager.go
OnEvent
func (configMgr *ConfigurationManager) OnEvent(event *core.Event) { err := configMgr.updateEvent(event) if err != nil { openlogging.GetLogger().Error("failed in updating event with error: " + err.Error()) } }
go
func (configMgr *ConfigurationManager) OnEvent(event *core.Event) { err := configMgr.updateEvent(event) if err != nil { openlogging.GetLogger().Error("failed in updating event with error: " + err.Error()) } }
[ "func", "(", "configMgr", "*", "ConfigurationManager", ")", "OnEvent", "(", "event", "*", "core", ".", "Event", ")", "{", "err", ":=", "configMgr", ".", "updateEvent", "(", "event", ")", "\n", "if", "err", "!=", "nil", "{", "openlogging", ".", "GetLogger...
// OnEvent Triggers actions when an event is generated
[ "OnEvent", "Triggers", "actions", "when", "an", "event", "is", "generated" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/config-manager/configurationmanager.go#L439-L444
5,192
go-chassis/go-archaius
options.go
WithDefaultFileHandler
func WithDefaultFileHandler(handler filesource.FileHandler) Option { return func(options *Options) { options.FileHandler = handler } }
go
func WithDefaultFileHandler(handler filesource.FileHandler) Option { return func(options *Options) { options.FileHandler = handler } }
[ "func", "WithDefaultFileHandler", "(", "handler", "filesource", ".", "FileHandler", ")", "Option", "{", "return", "func", "(", "options", "*", "Options", ")", "{", "options", ".", "FileHandler", "=", "handler", "\n", "}", "\n", "}" ]
//WithDefaultFileHandler let user custom handler //you can decide how to convert file into kv pairs
[ "WithDefaultFileHandler", "let", "user", "custom", "handler", "you", "can", "decide", "how", "to", "convert", "file", "into", "kv", "pairs" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/options.go#L72-L76
5,193
go-chassis/go-archaius
options.go
WithConfigCenterSource
func WithConfigCenterSource(cci ConfigCenterInfo, c config.Client) Option { return func(options *Options) { options.ConfigCenterInfo = cci options.ConfigClient = c } }
go
func WithConfigCenterSource(cci ConfigCenterInfo, c config.Client) Option { return func(options *Options) { options.ConfigCenterInfo = cci options.ConfigClient = c } }
[ "func", "WithConfigCenterSource", "(", "cci", "ConfigCenterInfo", ",", "c", "config", ".", "Client", ")", "Option", "{", "return", "func", "(", "options", "*", "Options", ")", "{", "options", ".", "ConfigCenterInfo", "=", "cci", "\n", "options", ".", "Config...
//WithConfigCenterSource accept the information for initiating a config center source, //ConfigCenterInfo is required if you want to use config center source //client is optional,if client is nil, archaius will create one based on ConfigCenterInfo //config client will be injected into config source as a client to interact with a config server
[ "WithConfigCenterSource", "accept", "the", "information", "for", "initiating", "a", "config", "center", "source", "ConfigCenterInfo", "is", "required", "if", "you", "want", "to", "use", "config", "center", "source", "client", "is", "optional", "if", "client", "is"...
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/options.go#L82-L87
5,194
go-chassis/go-archaius
options.go
WithFileHandler
func WithFileHandler(h filesource.FileHandler) FileOption { return func(options *FileOptions) { options.Handler = h } }
go
func WithFileHandler(h filesource.FileHandler) FileOption { return func(options *FileOptions) { options.Handler = h } }
[ "func", "WithFileHandler", "(", "h", "filesource", ".", "FileHandler", ")", "FileOption", "{", "return", "func", "(", "options", "*", "FileOptions", ")", "{", "options", ".", "Handler", "=", "h", "\n", "}", "\n\n", "}" ]
//WithFileHandler use custom handler
[ "WithFileHandler", "use", "custom", "handler" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/options.go#L121-L126
5,195
go-chassis/go-archaius
sources/commandline-source/commandlineconfigurationsource.go
NewCommandlineConfigSource
func NewCommandlineConfigSource() core.ConfigSource { cmdlineConfig := new(CommandLineConfigurationSource) cmdlineConfig.priority = commandlinePriority config, err := cmdlineConfig.pullCmdLineConfig() if err != nil { openlogging.GetLogger().Error("failed to initialize commandline configurations:" + err.Error()) return cmdlineConfig } cmdlineConfig.Configurations = config return cmdlineConfig }
go
func NewCommandlineConfigSource() core.ConfigSource { cmdlineConfig := new(CommandLineConfigurationSource) cmdlineConfig.priority = commandlinePriority config, err := cmdlineConfig.pullCmdLineConfig() if err != nil { openlogging.GetLogger().Error("failed to initialize commandline configurations:" + err.Error()) return cmdlineConfig } cmdlineConfig.Configurations = config return cmdlineConfig }
[ "func", "NewCommandlineConfigSource", "(", ")", "core", ".", "ConfigSource", "{", "cmdlineConfig", ":=", "new", "(", "CommandLineConfigurationSource", ")", "\n", "cmdlineConfig", ".", "priority", "=", "commandlinePriority", "\n", "config", ",", "err", ":=", "cmdline...
//NewCommandlineConfigSource defines a fucntion used for creating configuration source
[ "NewCommandlineConfigSource", "defines", "a", "fucntion", "used", "for", "creating", "configuration", "source" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/commandline-source/commandlineconfigurationsource.go#L45-L56
5,196
go-chassis/go-archaius
sources/commandline-source/commandlineconfigurationsource.go
GetConfigurations
func (confSrc *CommandLineConfigurationSource) GetConfigurations() (map[string]interface{}, error) { configMap := make(map[string]interface{}) confSrc.Lock() defer confSrc.Unlock() for key, value := range confSrc.Configurations { configMap[key] = value } return configMap, nil }
go
func (confSrc *CommandLineConfigurationSource) GetConfigurations() (map[string]interface{}, error) { configMap := make(map[string]interface{}) confSrc.Lock() defer confSrc.Unlock() for key, value := range confSrc.Configurations { configMap[key] = value } return configMap, nil }
[ "func", "(", "confSrc", "*", "CommandLineConfigurationSource", ")", "GetConfigurations", "(", ")", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "configMap", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", ...
//GetConfigurations gets particular configuration
[ "GetConfigurations", "gets", "particular", "configuration" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/sources/commandline-source/commandlineconfigurationsource.go#L79-L89
5,197
go-chassis/go-archaius
core/event-system/eventsystem.go
NewDispatcher
func NewDispatcher() core.Dispatcher { dis := new(dispatcher) //dis.Logger = logger dis.listeners = make(map[string][]core.EventListener) return dis }
go
func NewDispatcher() core.Dispatcher { dis := new(dispatcher) //dis.Logger = logger dis.listeners = make(map[string][]core.EventListener) return dis }
[ "func", "NewDispatcher", "(", ")", "core", ".", "Dispatcher", "{", "dis", ":=", "new", "(", "dispatcher", ")", "\n", "//dis.Logger = logger", "dis", ".", "listeners", "=", "make", "(", "map", "[", "string", "]", "[", "]", "core", ".", "EventListener", ")...
// NewDispatcher is a new dispatcher for listeners
[ "NewDispatcher", "is", "a", "new", "dispatcher", "for", "listeners" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/event-system/eventsystem.go#L37-L42
5,198
go-chassis/go-archaius
core/event-system/eventsystem.go
RegisterListener
func (dis *dispatcher) RegisterListener(listenerObj core.EventListener, keys ...string) error { if listenerObj == nil { err := errors.New("nil listener") openlogging.GetLogger().Error("nil listener supplied:" + err.Error()) return errors.New("nil listener") } for _, key := range keys { listenerList, ok := dis.listeners[key] if !ok { listenerList = make([]core.EventListener, 0) } // for duplicate registration for _, listener := range listenerList { if listener == listenerObj { return nil } } // append new listener listenerList = append(listenerList, listenerObj) // assign latest listener list dis.listeners[key] = listenerList } return nil }
go
func (dis *dispatcher) RegisterListener(listenerObj core.EventListener, keys ...string) error { if listenerObj == nil { err := errors.New("nil listener") openlogging.GetLogger().Error("nil listener supplied:" + err.Error()) return errors.New("nil listener") } for _, key := range keys { listenerList, ok := dis.listeners[key] if !ok { listenerList = make([]core.EventListener, 0) } // for duplicate registration for _, listener := range listenerList { if listener == listenerObj { return nil } } // append new listener listenerList = append(listenerList, listenerObj) // assign latest listener list dis.listeners[key] = listenerList } return nil }
[ "func", "(", "dis", "*", "dispatcher", ")", "RegisterListener", "(", "listenerObj", "core", ".", "EventListener", ",", "keys", "...", "string", ")", "error", "{", "if", "listenerObj", "==", "nil", "{", "err", ":=", "errors", ".", "New", "(", "\"", "\"", ...
// RegisterListener registers listener for particular configuration
[ "RegisterListener", "registers", "listener", "for", "particular", "configuration" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/event-system/eventsystem.go#L45-L72
5,199
go-chassis/go-archaius
core/event-system/eventsystem.go
UnRegisterListener
func (dis *dispatcher) UnRegisterListener(listenerObj core.EventListener, keys ...string) error { if listenerObj == nil { return errors.New("nil listener") } for _, key := range keys { listenerList, ok := dis.listeners[key] if !ok { continue } newListenerList := make([]core.EventListener, 0) // remove listener for _, listener := range listenerList { if listener == listenerObj { continue } newListenerList = append(newListenerList, listener) } // assign latest listener list dis.listeners[key] = newListenerList } return nil }
go
func (dis *dispatcher) UnRegisterListener(listenerObj core.EventListener, keys ...string) error { if listenerObj == nil { return errors.New("nil listener") } for _, key := range keys { listenerList, ok := dis.listeners[key] if !ok { continue } newListenerList := make([]core.EventListener, 0) // remove listener for _, listener := range listenerList { if listener == listenerObj { continue } newListenerList = append(newListenerList, listener) } // assign latest listener list dis.listeners[key] = newListenerList } return nil }
[ "func", "(", "dis", "*", "dispatcher", ")", "UnRegisterListener", "(", "listenerObj", "core", ".", "EventListener", ",", "keys", "...", "string", ")", "error", "{", "if", "listenerObj", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", "...
// UnRegisterListener un-register listener for a particular configuration
[ "UnRegisterListener", "un", "-", "register", "listener", "for", "a", "particular", "configuration" ]
5b479bcb10437daee44d1d77af651939c6d92541
https://github.com/go-chassis/go-archaius/blob/5b479bcb10437daee44d1d77af651939c6d92541/core/event-system/eventsystem.go#L75-L99