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
143,300
libp2p/go-libp2p-kbucket
table.go
NewRoutingTable
func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m pstore.Metrics) *RoutingTable { rt := &RoutingTable{ Buckets: []*Bucket{newBucket()}, bucketsize: bucketsize, local: localID, maxLatency: latency, metrics: m, PeerRemoved: func(peer.ID) {}, PeerAdded: func(peer.ID...
go
func NewRoutingTable(bucketsize int, localID ID, latency time.Duration, m pstore.Metrics) *RoutingTable { rt := &RoutingTable{ Buckets: []*Bucket{newBucket()}, bucketsize: bucketsize, local: localID, maxLatency: latency, metrics: m, PeerRemoved: func(peer.ID) {}, PeerAdded: func(peer.ID...
[ "func", "NewRoutingTable", "(", "bucketsize", "int", ",", "localID", "ID", ",", "latency", "time", ".", "Duration", ",", "m", "pstore", ".", "Metrics", ")", "*", "RoutingTable", "{", "rt", ":=", "&", "RoutingTable", "{", "Buckets", ":", "[", "]", "*", ...
// NewRoutingTable creates a new routing table with a given bucketsize, local ID, and latency tolerance.
[ "NewRoutingTable", "creates", "a", "new", "routing", "table", "with", "a", "given", "bucketsize", "local", "ID", "and", "latency", "tolerance", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L45-L57
143,301
libp2p/go-libp2p-kbucket
table.go
Update
func (rt *RoutingTable) Update(p peer.ID) (evicted peer.ID, err error) { peerID := ConvertPeerID(p) cpl := CommonPrefixLen(peerID, rt.local) rt.tabLock.Lock() defer rt.tabLock.Unlock() bucketID := cpl if bucketID >= len(rt.Buckets) { bucketID = len(rt.Buckets) - 1 } bucket := rt.Buckets[bucketID] if bucket...
go
func (rt *RoutingTable) Update(p peer.ID) (evicted peer.ID, err error) { peerID := ConvertPeerID(p) cpl := CommonPrefixLen(peerID, rt.local) rt.tabLock.Lock() defer rt.tabLock.Unlock() bucketID := cpl if bucketID >= len(rt.Buckets) { bucketID = len(rt.Buckets) - 1 } bucket := rt.Buckets[bucketID] if bucket...
[ "func", "(", "rt", "*", "RoutingTable", ")", "Update", "(", "p", "peer", ".", "ID", ")", "(", "evicted", "peer", ".", "ID", ",", "err", "error", ")", "{", "peerID", ":=", "ConvertPeerID", "(", "p", ")", "\n", "cpl", ":=", "CommonPrefixLen", "(", "p...
// Update adds or moves the given peer to the front of its respective bucket
[ "Update", "adds", "or", "moves", "the", "given", "peer", "to", "the", "front", "of", "its", "respective", "bucket" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L60-L111
143,302
libp2p/go-libp2p-kbucket
table.go
Remove
func (rt *RoutingTable) Remove(p peer.ID) { rt.tabLock.Lock() defer rt.tabLock.Unlock() peerID := ConvertPeerID(p) cpl := CommonPrefixLen(peerID, rt.local) bucketID := cpl if bucketID >= len(rt.Buckets) { bucketID = len(rt.Buckets) - 1 } bucket := rt.Buckets[bucketID] if bucket.Remove(p) { rt.PeerRemoved...
go
func (rt *RoutingTable) Remove(p peer.ID) { rt.tabLock.Lock() defer rt.tabLock.Unlock() peerID := ConvertPeerID(p) cpl := CommonPrefixLen(peerID, rt.local) bucketID := cpl if bucketID >= len(rt.Buckets) { bucketID = len(rt.Buckets) - 1 } bucket := rt.Buckets[bucketID] if bucket.Remove(p) { rt.PeerRemoved...
[ "func", "(", "rt", "*", "RoutingTable", ")", "Remove", "(", "p", "peer", ".", "ID", ")", "{", "rt", ".", "tabLock", ".", "Lock", "(", ")", "\n", "defer", "rt", ".", "tabLock", ".", "Unlock", "(", ")", "\n", "peerID", ":=", "ConvertPeerID", "(", "...
// Remove deletes a peer from the routing table. This is to be used // when we are sure a node has disconnected completely.
[ "Remove", "deletes", "a", "peer", "from", "the", "routing", "table", ".", "This", "is", "to", "be", "used", "when", "we", "are", "sure", "a", "node", "has", "disconnected", "completely", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L115-L130
143,303
libp2p/go-libp2p-kbucket
table.go
Find
func (rt *RoutingTable) Find(id peer.ID) peer.ID { srch := rt.NearestPeers(ConvertPeerID(id), 1) if len(srch) == 0 || srch[0] != id { return "" } return srch[0] }
go
func (rt *RoutingTable) Find(id peer.ID) peer.ID { srch := rt.NearestPeers(ConvertPeerID(id), 1) if len(srch) == 0 || srch[0] != id { return "" } return srch[0] }
[ "func", "(", "rt", "*", "RoutingTable", ")", "Find", "(", "id", "peer", ".", "ID", ")", "peer", ".", "ID", "{", "srch", ":=", "rt", ".", "NearestPeers", "(", "ConvertPeerID", "(", "id", ")", ",", "1", ")", "\n", "if", "len", "(", "srch", ")", "...
// Find a specific peer by ID or return nil
[ "Find", "a", "specific", "peer", "by", "ID", "or", "return", "nil" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L148-L154
143,304
libp2p/go-libp2p-kbucket
table.go
NearestPeer
func (rt *RoutingTable) NearestPeer(id ID) peer.ID { peers := rt.NearestPeers(id, 1) if len(peers) > 0 { return peers[0] } log.Debugf("NearestPeer: Returning nil, table size = %d", rt.Size()) return "" }
go
func (rt *RoutingTable) NearestPeer(id ID) peer.ID { peers := rt.NearestPeers(id, 1) if len(peers) > 0 { return peers[0] } log.Debugf("NearestPeer: Returning nil, table size = %d", rt.Size()) return "" }
[ "func", "(", "rt", "*", "RoutingTable", ")", "NearestPeer", "(", "id", "ID", ")", "peer", ".", "ID", "{", "peers", ":=", "rt", ".", "NearestPeers", "(", "id", ",", "1", ")", "\n", "if", "len", "(", "peers", ")", ">", "0", "{", "return", "peers", ...
// NearestPeer returns a single peer that is nearest to the given ID
[ "NearestPeer", "returns", "a", "single", "peer", "that", "is", "nearest", "to", "the", "given", "ID" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L157-L165
143,305
libp2p/go-libp2p-kbucket
table.go
NearestPeers
func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID { cpl := CommonPrefixLen(id, rt.local) // It's assumed that this also protects the buckets. rt.tabLock.RLock() // Get bucket at cpl index or last bucket var bucket *Bucket if cpl >= len(rt.Buckets) { cpl = len(rt.Buckets) - 1 } bucket = rt.Buc...
go
func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID { cpl := CommonPrefixLen(id, rt.local) // It's assumed that this also protects the buckets. rt.tabLock.RLock() // Get bucket at cpl index or last bucket var bucket *Bucket if cpl >= len(rt.Buckets) { cpl = len(rt.Buckets) - 1 } bucket = rt.Buc...
[ "func", "(", "rt", "*", "RoutingTable", ")", "NearestPeers", "(", "id", "ID", ",", "count", "int", ")", "[", "]", "peer", ".", "ID", "{", "cpl", ":=", "CommonPrefixLen", "(", "id", ",", "rt", ".", "local", ")", "\n\n", "// It's assumed that this also pro...
// NearestPeers returns a list of the 'count' closest peers to the given ID
[ "NearestPeers", "returns", "a", "list", "of", "the", "count", "closest", "peers", "to", "the", "given", "ID" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L168-L211
143,306
libp2p/go-libp2p-kbucket
table.go
Size
func (rt *RoutingTable) Size() int { var tot int rt.tabLock.RLock() for _, buck := range rt.Buckets { tot += buck.Len() } rt.tabLock.RUnlock() return tot }
go
func (rt *RoutingTable) Size() int { var tot int rt.tabLock.RLock() for _, buck := range rt.Buckets { tot += buck.Len() } rt.tabLock.RUnlock() return tot }
[ "func", "(", "rt", "*", "RoutingTable", ")", "Size", "(", ")", "int", "{", "var", "tot", "int", "\n", "rt", ".", "tabLock", ".", "RLock", "(", ")", "\n", "for", "_", ",", "buck", ":=", "range", "rt", ".", "Buckets", "{", "tot", "+=", "buck", "....
// Size returns the total number of peers in the routing table
[ "Size", "returns", "the", "total", "number", "of", "peers", "in", "the", "routing", "table" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L214-L222
143,307
libp2p/go-libp2p-kbucket
table.go
ListPeers
func (rt *RoutingTable) ListPeers() []peer.ID { var peers []peer.ID rt.tabLock.RLock() for _, buck := range rt.Buckets { peers = append(peers, buck.Peers()...) } rt.tabLock.RUnlock() return peers }
go
func (rt *RoutingTable) ListPeers() []peer.ID { var peers []peer.ID rt.tabLock.RLock() for _, buck := range rt.Buckets { peers = append(peers, buck.Peers()...) } rt.tabLock.RUnlock() return peers }
[ "func", "(", "rt", "*", "RoutingTable", ")", "ListPeers", "(", ")", "[", "]", "peer", ".", "ID", "{", "var", "peers", "[", "]", "peer", ".", "ID", "\n", "rt", ".", "tabLock", ".", "RLock", "(", ")", "\n", "for", "_", ",", "buck", ":=", "range",...
// ListPeers takes a RoutingTable and returns a list of all peers from all buckets in the table.
[ "ListPeers", "takes", "a", "RoutingTable", "and", "returns", "a", "list", "of", "all", "peers", "from", "all", "buckets", "in", "the", "table", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L225-L233
143,308
libp2p/go-libp2p-kbucket
table.go
Print
func (rt *RoutingTable) Print() { fmt.Printf("Routing Table, bs = %d, Max latency = %d\n", rt.bucketsize, rt.maxLatency) rt.tabLock.RLock() for i, b := range rt.Buckets { fmt.Printf("\tbucket: %d\n", i) b.lk.RLock() for e := b.list.Front(); e != nil; e = e.Next() { p := e.Value.(peer.ID) fmt.Printf("\t...
go
func (rt *RoutingTable) Print() { fmt.Printf("Routing Table, bs = %d, Max latency = %d\n", rt.bucketsize, rt.maxLatency) rt.tabLock.RLock() for i, b := range rt.Buckets { fmt.Printf("\tbucket: %d\n", i) b.lk.RLock() for e := b.list.Front(); e != nil; e = e.Next() { p := e.Value.(peer.ID) fmt.Printf("\t...
[ "func", "(", "rt", "*", "RoutingTable", ")", "Print", "(", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "rt", ".", "bucketsize", ",", "rt", ".", "maxLatency", ")", "\n", "rt", ".", "tabLock", ".", "RLock", "(", ")", "\n\n", "for",...
// Print prints a descriptive statement about the provided RoutingTable
[ "Print", "prints", "a", "descriptive", "statement", "about", "the", "provided", "RoutingTable" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/table.go#L236-L251
143,309
libp2p/go-libp2p-kbucket
keyspace/xor.go
Key
func (s *xorKeySpace) Key(id []byte) Key { hash := sha256.Sum256(id) key := hash[:] return Key{ Space: s, Original: id, Bytes: key, } }
go
func (s *xorKeySpace) Key(id []byte) Key { hash := sha256.Sum256(id) key := hash[:] return Key{ Space: s, Original: id, Bytes: key, } }
[ "func", "(", "s", "*", "xorKeySpace", ")", "Key", "(", "id", "[", "]", "byte", ")", "Key", "{", "hash", ":=", "sha256", ".", "Sum256", "(", "id", ")", "\n", "key", ":=", "hash", "[", ":", "]", "\n", "return", "Key", "{", "Space", ":", "s", ",...
// Key converts an identifier into a Key in this space.
[ "Key", "converts", "an", "identifier", "into", "a", "Key", "in", "this", "space", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/keyspace/xor.go#L21-L29
143,310
libp2p/go-libp2p-kbucket
keyspace/xor.go
Equal
func (s *xorKeySpace) Equal(k1, k2 Key) bool { return bytes.Equal(k1.Bytes, k2.Bytes) }
go
func (s *xorKeySpace) Equal(k1, k2 Key) bool { return bytes.Equal(k1.Bytes, k2.Bytes) }
[ "func", "(", "s", "*", "xorKeySpace", ")", "Equal", "(", "k1", ",", "k2", "Key", ")", "bool", "{", "return", "bytes", ".", "Equal", "(", "k1", ".", "Bytes", ",", "k2", ".", "Bytes", ")", "\n", "}" ]
// Equal returns whether keys are equal in this key space
[ "Equal", "returns", "whether", "keys", "are", "equal", "in", "this", "key", "space" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/keyspace/xor.go#L32-L34
143,311
libp2p/go-libp2p-kbucket
keyspace/xor.go
Distance
func (s *xorKeySpace) Distance(k1, k2 Key) *big.Int { // XOR the keys k3 := u.XOR(k1.Bytes, k2.Bytes) // interpret it as an integer dist := big.NewInt(0).SetBytes(k3) return dist }
go
func (s *xorKeySpace) Distance(k1, k2 Key) *big.Int { // XOR the keys k3 := u.XOR(k1.Bytes, k2.Bytes) // interpret it as an integer dist := big.NewInt(0).SetBytes(k3) return dist }
[ "func", "(", "s", "*", "xorKeySpace", ")", "Distance", "(", "k1", ",", "k2", "Key", ")", "*", "big", ".", "Int", "{", "// XOR the keys", "k3", ":=", "u", ".", "XOR", "(", "k1", ".", "Bytes", ",", "k2", ".", "Bytes", ")", "\n\n", "// interpret it as...
// Distance returns the distance metric in this key space
[ "Distance", "returns", "the", "distance", "metric", "in", "this", "key", "space" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/keyspace/xor.go#L37-L44
143,312
libp2p/go-libp2p-kbucket
keyspace/xor.go
Less
func (s *xorKeySpace) Less(k1, k2 Key) bool { return bytes.Compare(k1.Bytes, k2.Bytes) < 0 }
go
func (s *xorKeySpace) Less(k1, k2 Key) bool { return bytes.Compare(k1.Bytes, k2.Bytes) < 0 }
[ "func", "(", "s", "*", "xorKeySpace", ")", "Less", "(", "k1", ",", "k2", "Key", ")", "bool", "{", "return", "bytes", ".", "Compare", "(", "k1", ".", "Bytes", ",", "k2", ".", "Bytes", ")", "<", "0", "\n", "}" ]
// Less returns whether the first key is smaller than the second.
[ "Less", "returns", "whether", "the", "first", "key", "is", "smaller", "than", "the", "second", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/keyspace/xor.go#L47-L49
143,313
libp2p/go-libp2p-kbucket
keyspace/xor.go
ZeroPrefixLen
func ZeroPrefixLen(id []byte) int { for i, b := range id { if b != 0 { return i*8 + bits.LeadingZeros8(uint8(b)) } } return len(id) * 8 }
go
func ZeroPrefixLen(id []byte) int { for i, b := range id { if b != 0 { return i*8 + bits.LeadingZeros8(uint8(b)) } } return len(id) * 8 }
[ "func", "ZeroPrefixLen", "(", "id", "[", "]", "byte", ")", "int", "{", "for", "i", ",", "b", ":=", "range", "id", "{", "if", "b", "!=", "0", "{", "return", "i", "*", "8", "+", "bits", ".", "LeadingZeros8", "(", "uint8", "(", "b", ")", ")", "\...
// ZeroPrefixLen returns the number of consecutive zeroes in a byte slice.
[ "ZeroPrefixLen", "returns", "the", "number", "of", "consecutive", "zeroes", "in", "a", "byte", "slice", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/keyspace/xor.go#L52-L59
143,314
libp2p/go-libp2p-kbucket
util.go
Closer
func Closer(a, b peer.ID, key string) bool { aid := ConvertPeerID(a) bid := ConvertPeerID(b) tgt := ConvertKey(key) adist := xor(aid, tgt) bdist := xor(bid, tgt) return adist.less(bdist) }
go
func Closer(a, b peer.ID, key string) bool { aid := ConvertPeerID(a) bid := ConvertPeerID(b) tgt := ConvertKey(key) adist := xor(aid, tgt) bdist := xor(bid, tgt) return adist.less(bdist) }
[ "func", "Closer", "(", "a", ",", "b", "peer", ".", "ID", ",", "key", "string", ")", "bool", "{", "aid", ":=", "ConvertPeerID", "(", "a", ")", "\n", "bid", ":=", "ConvertPeerID", "(", "b", ")", "\n", "tgt", ":=", "ConvertKey", "(", "key", ")", "\n...
// Closer returns true if a is closer to key than b is
[ "Closer", "returns", "true", "if", "a", "is", "closer", "to", "key", "than", "b", "is" ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/util.go#L54-L62
143,315
libp2p/go-libp2p-kbucket
sorting.go
appendPeer
func (pds *peerDistanceSorter) appendPeer(p peer.ID) { pds.peers = append(pds.peers, peerDistance{ p: p, distance: xor(pds.target, ConvertPeerID(p)), }) }
go
func (pds *peerDistanceSorter) appendPeer(p peer.ID) { pds.peers = append(pds.peers, peerDistance{ p: p, distance: xor(pds.target, ConvertPeerID(p)), }) }
[ "func", "(", "pds", "*", "peerDistanceSorter", ")", "appendPeer", "(", "p", "peer", ".", "ID", ")", "{", "pds", ".", "peers", "=", "append", "(", "pds", ".", "peers", ",", "peerDistance", "{", "p", ":", "p", ",", "distance", ":", "xor", "(", "pds",...
// Append the peer.ID to the sorter's slice. It may no longer be sorted.
[ "Append", "the", "peer", ".", "ID", "to", "the", "sorter", "s", "slice", ".", "It", "may", "no", "longer", "be", "sorted", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/sorting.go#L29-L34
143,316
libp2p/go-libp2p-kbucket
sorting.go
appendPeersFromList
func (pds *peerDistanceSorter) appendPeersFromList(l *list.List) { for e := l.Front(); e != nil; e = e.Next() { pds.appendPeer(e.Value.(peer.ID)) } }
go
func (pds *peerDistanceSorter) appendPeersFromList(l *list.List) { for e := l.Front(); e != nil; e = e.Next() { pds.appendPeer(e.Value.(peer.ID)) } }
[ "func", "(", "pds", "*", "peerDistanceSorter", ")", "appendPeersFromList", "(", "l", "*", "list", ".", "List", ")", "{", "for", "e", ":=", "l", ".", "Front", "(", ")", ";", "e", "!=", "nil", ";", "e", "=", "e", ".", "Next", "(", ")", "{", "pds"...
// Append the peer.ID values in the list to the sorter's slice. It may no longer be sorted.
[ "Append", "the", "peer", ".", "ID", "values", "in", "the", "list", "to", "the", "sorter", "s", "slice", ".", "It", "may", "no", "longer", "be", "sorted", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/sorting.go#L37-L41
143,317
libp2p/go-libp2p-kbucket
sorting.go
SortClosestPeers
func SortClosestPeers(peers []peer.ID, target ID) []peer.ID { sorter := peerDistanceSorter{ peers: make([]peerDistance, 0, len(peers)), target: target, } for _, p := range peers { sorter.appendPeer(p) } sorter.sort() out := make([]peer.ID, 0, sorter.Len()) for _, p := range sorter.peers { out = append(o...
go
func SortClosestPeers(peers []peer.ID, target ID) []peer.ID { sorter := peerDistanceSorter{ peers: make([]peerDistance, 0, len(peers)), target: target, } for _, p := range peers { sorter.appendPeer(p) } sorter.sort() out := make([]peer.ID, 0, sorter.Len()) for _, p := range sorter.peers { out = append(o...
[ "func", "SortClosestPeers", "(", "peers", "[", "]", "peer", ".", "ID", ",", "target", "ID", ")", "[", "]", "peer", ".", "ID", "{", "sorter", ":=", "peerDistanceSorter", "{", "peers", ":", "make", "(", "[", "]", "peerDistance", ",", "0", ",", "len", ...
// Sort the given peers by their ascending distance from the target. A new slice is returned.
[ "Sort", "the", "given", "peers", "by", "their", "ascending", "distance", "from", "the", "target", ".", "A", "new", "slice", "is", "returned", "." ]
80d3b4761e24ef72711a669657ce38cd6d996d02
https://github.com/libp2p/go-libp2p-kbucket/blob/80d3b4761e24ef72711a669657ce38cd6d996d02/sorting.go#L48-L62
143,318
martini-contrib/cors
cors.go
Allow
func Allow(opts *Options) http.HandlerFunc { // Allow default headers if nothing is specified. if len(opts.AllowHeaders) == 0 { opts.AllowHeaders = defaultAllowHeaders } for _, origin := range opts.AllowOrigins { pattern := regexp.QuoteMeta(origin) pattern = strings.Replace(pattern, "\\*", ".*", -1) patter...
go
func Allow(opts *Options) http.HandlerFunc { // Allow default headers if nothing is specified. if len(opts.AllowHeaders) == 0 { opts.AllowHeaders = defaultAllowHeaders } for _, origin := range opts.AllowOrigins { pattern := regexp.QuoteMeta(origin) pattern = strings.Replace(pattern, "\\*", ".*", -1) patter...
[ "func", "Allow", "(", "opts", "*", "Options", ")", "http", ".", "HandlerFunc", "{", "// Allow default headers if nothing is specified.", "if", "len", "(", "opts", ".", "AllowHeaders", ")", "==", "0", "{", "opts", ".", "AllowHeaders", "=", "defaultAllowHeaders", ...
// Allow enables CORS for requests those match the provided options.
[ "Allow", "enables", "CORS", "for", "requests", "those", "match", "the", "provided", "options", "." ]
553b9208d353a39b0850c02355f478ba020c86d7
https://github.com/martini-contrib/cors/blob/553b9208d353a39b0850c02355f478ba020c86d7/cors.go#L169-L208
143,319
bsphere/le_go
le.go
Output
func (logger *Logger) Output(calldepth int, s string) error { _, err := logger.Write([]byte(s)) return err }
go
func (logger *Logger) Output(calldepth int, s string) error { _, err := logger.Write([]byte(s)) return err }
[ "func", "(", "logger", "*", "Logger", ")", "Output", "(", "calldepth", "int", ",", "s", "string", ")", "error", "{", "_", ",", "err", ":=", "logger", ".", "Write", "(", "[", "]", "byte", "(", "s", ")", ")", "\n\n", "return", "err", "\n", "}" ]
// Output does the actual writing to the TCP connection
[ "Output", "does", "the", "actual", "writing", "to", "the", "TCP", "connection" ]
7a984a84b5492ae539b79b62fb4a10afc63c7bcf
https://github.com/bsphere/le_go/blob/7a984a84b5492ae539b79b62fb4a10afc63c7bcf/le.go#L129-L133
143,320
bsphere/le_go
le.go
Printf
func (logger *Logger) Printf(format string, v ...interface{}) { logger.Output(2, fmt.Sprintf(format, v...)) }
go
func (logger *Logger) Printf(format string, v ...interface{}) { logger.Output(2, fmt.Sprintf(format, v...)) }
[ "func", "(", "logger", "*", "Logger", ")", "Printf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "logger", ".", "Output", "(", "2", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", "...", ")", ")", "\n", "}" ]
// Printf logs a formatted message
[ "Printf", "logs", "a", "formatted", "message" ]
7a984a84b5492ae539b79b62fb4a10afc63c7bcf
https://github.com/bsphere/le_go/blob/7a984a84b5492ae539b79b62fb4a10afc63c7bcf/le.go#L167-L169
143,321
bsphere/le_go
le.go
Write
func (logger *Logger) Write(p []byte) (n int, err error) { if err := logger.ensureOpenConnection(); err != nil { return 0, err } logger.mu.Lock() defer logger.mu.Unlock() logger.makeBuf(p) return logger.conn.Write(logger.buf) }
go
func (logger *Logger) Write(p []byte) (n int, err error) { if err := logger.ensureOpenConnection(); err != nil { return 0, err } logger.mu.Lock() defer logger.mu.Unlock() logger.makeBuf(p) return logger.conn.Write(logger.buf) }
[ "func", "(", "logger", "*", "Logger", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "err", ":=", "logger", ".", "ensureOpenConnection", "(", ")", ";", "err", "!=", "nil", "{", "return", "0", ...
// Write writes a bytes array to the Logentries TCP connection, // it adds the access token and prefix and also replaces // line breaks with the unicode \u2028 character
[ "Write", "writes", "a", "bytes", "array", "to", "the", "Logentries", "TCP", "connection", "it", "adds", "the", "access", "token", "and", "prefix", "and", "also", "replaces", "line", "breaks", "with", "the", "unicode", "\\", "u2028", "character" ]
7a984a84b5492ae539b79b62fb4a10afc63c7bcf
https://github.com/bsphere/le_go/blob/7a984a84b5492ae539b79b62fb4a10afc63c7bcf/le.go#L189-L200
143,322
bsphere/le_go
le.go
makeBuf
func (logger *Logger) makeBuf(p []byte) { count := strings.Count(string(p), lineSep) p = []byte(strings.Replace(string(p), lineSep, "\u2028", count-1)) logger.buf = logger.buf[:0] logger.buf = append(logger.buf, (logger.token + " ")...) logger.buf = append(logger.buf, (logger.prefix + " ")...) logger.buf = appen...
go
func (logger *Logger) makeBuf(p []byte) { count := strings.Count(string(p), lineSep) p = []byte(strings.Replace(string(p), lineSep, "\u2028", count-1)) logger.buf = logger.buf[:0] logger.buf = append(logger.buf, (logger.token + " ")...) logger.buf = append(logger.buf, (logger.prefix + " ")...) logger.buf = appen...
[ "func", "(", "logger", "*", "Logger", ")", "makeBuf", "(", "p", "[", "]", "byte", ")", "{", "count", ":=", "strings", ".", "Count", "(", "string", "(", "p", ")", ",", "lineSep", ")", "\n", "p", "=", "[", "]", "byte", "(", "strings", ".", "Repla...
// makeBuf constructs the logger buffer // it is not safe to be used from within multiple concurrent goroutines
[ "makeBuf", "constructs", "the", "logger", "buffer", "it", "is", "not", "safe", "to", "be", "used", "from", "within", "multiple", "concurrent", "goroutines" ]
7a984a84b5492ae539b79b62fb4a10afc63c7bcf
https://github.com/bsphere/le_go/blob/7a984a84b5492ae539b79b62fb4a10afc63c7bcf/le.go#L204-L216
143,323
client9/reopen
reopen.go
reopen
func (f *FileWriter) reopen() error { if f.f != nil { f.f.Close() f.f = nil } newf, err := os.OpenFile(f.name, os.O_WRONLY|os.O_APPEND|os.O_CREATE, f.mode) if err != nil { f.f = nil return err } f.f = newf return nil }
go
func (f *FileWriter) reopen() error { if f.f != nil { f.f.Close() f.f = nil } newf, err := os.OpenFile(f.name, os.O_WRONLY|os.O_APPEND|os.O_CREATE, f.mode) if err != nil { f.f = nil return err } f.f = newf return nil }
[ "func", "(", "f", "*", "FileWriter", ")", "reopen", "(", ")", "error", "{", "if", "f", ".", "f", "!=", "nil", "{", "f", ".", "f", ".", "Close", "(", ")", "\n", "f", ".", "f", "=", "nil", "\n", "}", "\n", "newf", ",", "err", ":=", "os", "....
// mutex free version
[ "mutex", "free", "version" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L46-L59
143,324
client9/reopen
reopen.go
Reopen
func (f *FileWriter) Reopen() error { f.mu.Lock() err := f.reopen() f.mu.Unlock() return err }
go
func (f *FileWriter) Reopen() error { f.mu.Lock() err := f.reopen() f.mu.Unlock() return err }
[ "func", "(", "f", "*", "FileWriter", ")", "Reopen", "(", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "err", ":=", "f", ".", "reopen", "(", ")", "\n", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "err", "\n", ...
// Reopen the file
[ "Reopen", "the", "file" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L62-L67
143,325
client9/reopen
reopen.go
Write
func (f *FileWriter) Write(p []byte) (int, error) { f.mu.Lock() n, err := f.f.Write(p) f.mu.Unlock() return n, err }
go
func (f *FileWriter) Write(p []byte) (int, error) { f.mu.Lock() n, err := f.f.Write(p) f.mu.Unlock() return n, err }
[ "func", "(", "f", "*", "FileWriter", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "n", ",", "err", ":=", "f", ".", "f", ".", "Write", "(", "p", ")", "\n", ...
// Write implements the stander io.Writer interface
[ "Write", "implements", "the", "stander", "io", ".", "Writer", "interface" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L70-L75
143,326
client9/reopen
reopen.go
NewFileWriterMode
func NewFileWriterMode(name string, mode os.FileMode) (*FileWriter, error) { writer := FileWriter{ f: nil, name: name, mode: mode, } err := writer.reopen() if err != nil { return nil, err } return &writer, nil }
go
func NewFileWriterMode(name string, mode os.FileMode) (*FileWriter, error) { writer := FileWriter{ f: nil, name: name, mode: mode, } err := writer.reopen() if err != nil { return nil, err } return &writer, nil }
[ "func", "NewFileWriterMode", "(", "name", "string", ",", "mode", "os", ".", "FileMode", ")", "(", "*", "FileWriter", ",", "error", ")", "{", "writer", ":=", "FileWriter", "{", "f", ":", "nil", ",", "name", ":", "name", ",", "mode", ":", "mode", ",", ...
// NewFileWriterMode opens a Reopener file with a specific permission
[ "NewFileWriterMode", "opens", "a", "Reopener", "file", "with", "a", "specific", "permission" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L85-L96
143,327
client9/reopen
reopen.go
Reopen
func (bw *BufferedFileWriter) Reopen() error { bw.mu.Lock() bw.bufWriter.Flush() // use non-mutex version since we are using this one err := bw.origWriter.reopen() bw.bufWriter.Reset(io.Writer(bw.origWriter)) bw.mu.Unlock() return err }
go
func (bw *BufferedFileWriter) Reopen() error { bw.mu.Lock() bw.bufWriter.Flush() // use non-mutex version since we are using this one err := bw.origWriter.reopen() bw.bufWriter.Reset(io.Writer(bw.origWriter)) bw.mu.Unlock() return err }
[ "func", "(", "bw", "*", "BufferedFileWriter", ")", "Reopen", "(", ")", "error", "{", "bw", ".", "mu", ".", "Lock", "(", ")", "\n", "bw", ".", "bufWriter", ".", "Flush", "(", ")", "\n\n", "// use non-mutex version since we are using this one", "err", ":=", ...
// Reopen implement Reopener
[ "Reopen", "implement", "Reopener" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L108-L119
143,328
client9/reopen
reopen.go
Close
func (bw *BufferedFileWriter) Close() error { bw.quitChan <- true bw.mu.Lock() bw.done = true bw.bufWriter.Flush() bw.origWriter.f.Close() bw.mu.Unlock() return nil }
go
func (bw *BufferedFileWriter) Close() error { bw.quitChan <- true bw.mu.Lock() bw.done = true bw.bufWriter.Flush() bw.origWriter.f.Close() bw.mu.Unlock() return nil }
[ "func", "(", "bw", "*", "BufferedFileWriter", ")", "Close", "(", ")", "error", "{", "bw", ".", "quitChan", "<-", "true", "\n", "bw", ".", "mu", ".", "Lock", "(", ")", "\n", "bw", ".", "done", "=", "true", "\n", "bw", ".", "bufWriter", ".", "Flush...
// Close flushes the internal buffer and closes the destination file
[ "Close", "flushes", "the", "internal", "buffer", "and", "closes", "the", "destination", "file" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L122-L130
143,329
client9/reopen
reopen.go
Flush
func (bw *BufferedFileWriter) Flush() { bw.mu.Lock() // could add check if bw.done already // should never happen bw.bufWriter.Flush() bw.origWriter.f.Sync() bw.mu.Unlock() }
go
func (bw *BufferedFileWriter) Flush() { bw.mu.Lock() // could add check if bw.done already // should never happen bw.bufWriter.Flush() bw.origWriter.f.Sync() bw.mu.Unlock() }
[ "func", "(", "bw", "*", "BufferedFileWriter", ")", "Flush", "(", ")", "{", "bw", ".", "mu", ".", "Lock", "(", ")", "\n", "// could add check if bw.done already", "// should never happen", "bw", ".", "bufWriter", ".", "Flush", "(", ")", "\n", "bw", ".", "o...
// Flush flushes the buffer.
[ "Flush", "flushes", "the", "buffer", "." ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L149-L156
143,330
client9/reopen
reopen.go
flushDaemon
func (bw *BufferedFileWriter) flushDaemon(interval time.Duration) { ticker := time.NewTicker(interval) for { select { case <-bw.quitChan: ticker.Stop() return case <-ticker.C: bw.Flush() } } }
go
func (bw *BufferedFileWriter) flushDaemon(interval time.Duration) { ticker := time.NewTicker(interval) for { select { case <-bw.quitChan: ticker.Stop() return case <-ticker.C: bw.Flush() } } }
[ "func", "(", "bw", "*", "BufferedFileWriter", ")", "flushDaemon", "(", "interval", "time", ".", "Duration", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "interval", ")", "\n", "for", "{", "select", "{", "case", "<-", "bw", ".", "quitChan", ...
// flushDaemon periodically flushes the log file buffers.
[ "flushDaemon", "periodically", "flushes", "the", "log", "file", "buffers", "." ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L159-L170
143,331
client9/reopen
reopen.go
NewBufferedFileWriterSize
func NewBufferedFileWriterSize(w *FileWriter, size int, flush time.Duration) *BufferedFileWriter { bw := BufferedFileWriter{ quitChan: make(chan bool, 1), origWriter: w, bufWriter: bufio.NewWriterSize(w, size), } go bw.flushDaemon(flush) return &bw }
go
func NewBufferedFileWriterSize(w *FileWriter, size int, flush time.Duration) *BufferedFileWriter { bw := BufferedFileWriter{ quitChan: make(chan bool, 1), origWriter: w, bufWriter: bufio.NewWriterSize(w, size), } go bw.flushDaemon(flush) return &bw }
[ "func", "NewBufferedFileWriterSize", "(", "w", "*", "FileWriter", ",", "size", "int", ",", "flush", "time", ".", "Duration", ")", "*", "BufferedFileWriter", "{", "bw", ":=", "BufferedFileWriter", "{", "quitChan", ":", "make", "(", "chan", "bool", ",", "1", ...
// NewBufferedFileWriterSize opens a buffered file with the given size that is periodically // flushed on the given interval.
[ "NewBufferedFileWriterSize", "opens", "a", "buffered", "file", "with", "the", "given", "size", "that", "is", "periodically", "flushed", "on", "the", "given", "interval", "." ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L183-L191
143,332
client9/reopen
reopen.go
Reopen
func (t *multiReopenWriter) Reopen() error { for _, w := range t.writers { err := w.Reopen() if err != nil { return err } } return nil }
go
func (t *multiReopenWriter) Reopen() error { for _, w := range t.writers { err := w.Reopen() if err != nil { return err } } return nil }
[ "func", "(", "t", "*", "multiReopenWriter", ")", "Reopen", "(", ")", "error", "{", "for", "_", ",", "w", ":=", "range", "t", ".", "writers", "{", "err", ":=", "w", ".", "Reopen", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "...
// Reopen reopens all child Reopeners
[ "Reopen", "reopens", "all", "child", "Reopeners" ]
dbabf56e0beda57421ccdf6c7431a75a7d8a1562
https://github.com/client9/reopen/blob/dbabf56e0beda57421ccdf6c7431a75a7d8a1562/reopen.go#L198-L206
143,333
writeas/go-strip-markdown
strip.go
Strip
func Strip(s string) string { res := s res = listLeadersReg.ReplaceAllString(res, "$1") res = headerReg.ReplaceAllString(res, "\n") res = strikeReg.ReplaceAllString(res, "") res = codeReg.ReplaceAllString(res, "") res = emphReg.ReplaceAllString(res, "$1") res = emphReg2.ReplaceAllString(res, "$1") res = emphR...
go
func Strip(s string) string { res := s res = listLeadersReg.ReplaceAllString(res, "$1") res = headerReg.ReplaceAllString(res, "\n") res = strikeReg.ReplaceAllString(res, "") res = codeReg.ReplaceAllString(res, "") res = emphReg.ReplaceAllString(res, "$1") res = emphReg2.ReplaceAllString(res, "$1") res = emphR...
[ "func", "Strip", "(", "s", "string", ")", "string", "{", "res", ":=", "s", "\n", "res", "=", "listLeadersReg", ".", "ReplaceAllString", "(", "res", ",", "\"", "\"", ")", "\n\n", "res", "=", "headerReg", ".", "ReplaceAllString", "(", "res", ",", "\"", ...
// Strip returns the given string sans any Markdown. // Where necessary, elements are replaced with their best textual forms, so // for example, hyperlinks are stripped of their URL and become only the link // text, and images lose their URL and become only the alt text.
[ "Strip", "returns", "the", "given", "string", "sans", "any", "Markdown", ".", "Where", "necessary", "elements", "are", "replaced", "with", "their", "best", "textual", "forms", "so", "for", "example", "hyperlinks", "are", "stripped", "of", "their", "URL", "and"...
5f8ba69e46917bcbf78b212886edbd4825d2bddd
https://github.com/writeas/go-strip-markdown/blob/5f8ba69e46917bcbf78b212886edbd4825d2bddd/strip.go#L39-L66
143,334
waigani/diffparser
diffparser.go
Changed
func (d *Diff) Changed() map[string][]int { dFiles := make(map[string][]int) for _, f := range d.Files { if f.Mode == DELETED { continue } for _, h := range f.Hunks { for _, dl := range h.NewRange.Lines { if dl.Mode == ADDED { // TODO(waigani) return removed dFiles[f.NewName] = append(dFiles[f....
go
func (d *Diff) Changed() map[string][]int { dFiles := make(map[string][]int) for _, f := range d.Files { if f.Mode == DELETED { continue } for _, h := range f.Hunks { for _, dl := range h.NewRange.Lines { if dl.Mode == ADDED { // TODO(waigani) return removed dFiles[f.NewName] = append(dFiles[f....
[ "func", "(", "d", "*", "Diff", ")", "Changed", "(", ")", "map", "[", "string", "]", "[", "]", "int", "{", "dFiles", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "int", ")", "\n\n", "for", "_", ",", "f", ":=", "range", "d", ".", "...
// Changed returns a map of filename to lines changed in that file. Deleted // files are ignored.
[ "Changed", "returns", "a", "map", "of", "filename", "to", "lines", "changed", "in", "that", "file", ".", "Deleted", "files", "are", "ignored", "." ]
1f7065f429b5b53c5029e3a6c198aab00f6a32c4
https://github.com/waigani/diffparser/blob/1f7065f429b5b53c5029e3a6c198aab00f6a32c4/diffparser.go#L89-L107
143,335
waigani/diffparser
diffparser.go
Parse
func Parse(diffString string) (*Diff, error) { var diff Diff diff.Raw = diffString lines := strings.Split(diffString, "\n") var file *DiffFile var hunk *DiffHunk var ADDEDCount int var REMOVEDCount int var inHunk bool oldFilePrefix := "--- a/" newFilePrefix := "+++ b/" var diffPosCount int var firstHunkIn...
go
func Parse(diffString string) (*Diff, error) { var diff Diff diff.Raw = diffString lines := strings.Split(diffString, "\n") var file *DiffFile var hunk *DiffHunk var ADDEDCount int var REMOVEDCount int var inHunk bool oldFilePrefix := "--- a/" newFilePrefix := "+++ b/" var diffPosCount int var firstHunkIn...
[ "func", "Parse", "(", "diffString", "string", ")", "(", "*", "Diff", ",", "error", ")", "{", "var", "diff", "Diff", "\n", "diff", ".", "Raw", "=", "diffString", "\n", "lines", ":=", "strings", ".", "Split", "(", "diffString", ",", "\"", "\\n", "\"", ...
// Parse takes a diff, such as produced by "git diff", and parses it into a // Diff struct.
[ "Parse", "takes", "a", "diff", "such", "as", "produced", "by", "git", "diff", "and", "parses", "it", "into", "a", "Diff", "struct", "." ]
1f7065f429b5b53c5029e3a6c198aab00f6a32c4
https://github.com/waigani/diffparser/blob/1f7065f429b5b53c5029e3a6c198aab00f6a32c4/diffparser.go#L131-L281
143,336
asticode/go-astilog
writer.go
NewWriter
func NewWriter(fs ...WriterFunc) *Writer { return &Writer{ buffer: &bytes.Buffer{}, fs: fs, } }
go
func NewWriter(fs ...WriterFunc) *Writer { return &Writer{ buffer: &bytes.Buffer{}, fs: fs, } }
[ "func", "NewWriter", "(", "fs", "...", "WriterFunc", ")", "*", "Writer", "{", "return", "&", "Writer", "{", "buffer", ":", "&", "bytes", ".", "Buffer", "{", "}", ",", "fs", ":", "fs", ",", "}", "\n", "}" ]
// NewWriter creates a new writer
[ "NewWriter", "creates", "a", "new", "writer" ]
cb0086bd6346b09c0bb168dc05d235321443d6d2
https://github.com/asticode/go-astilog/blob/cb0086bd6346b09c0bb168dc05d235321443d6d2/writer.go#L32-L37
143,337
ory/common
rand/numeric/int.go
Int64
func Int64() (i int64) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
go
func Int64() (i int64) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
[ "func", "Int64", "(", ")", "(", "i", "int64", ")", "{", "randomBits", "(", "r", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "r", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "i", ")", "...
// Int64 creates a random 64 bit integer using crypto.rand
[ "Int64", "creates", "a", "random", "64", "bit", "integer", "using", "crypto", ".", "rand" ]
1a6879dc80f2da8d4693fdf2a3956931a463a238
https://github.com/ory/common/blob/1a6879dc80f2da8d4693fdf2a3956931a463a238/rand/numeric/int.go#L16-L21
143,338
ory/common
rand/numeric/int.go
UInt64
func UInt64() (i uint64) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
go
func UInt64() (i uint64) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
[ "func", "UInt64", "(", ")", "(", "i", "uint64", ")", "{", "randomBits", "(", "r", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "r", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "i", ")", ...
// UInt64 creates a random 64 bit unsigned integer using crypto.rand
[ "UInt64", "creates", "a", "random", "64", "bit", "unsigned", "integer", "using", "crypto", ".", "rand" ]
1a6879dc80f2da8d4693fdf2a3956931a463a238
https://github.com/ory/common/blob/1a6879dc80f2da8d4693fdf2a3956931a463a238/rand/numeric/int.go#L24-L29
143,339
ory/common
rand/numeric/int.go
Int32
func Int32() (i int32) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
go
func Int32() (i int32) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
[ "func", "Int32", "(", ")", "(", "i", "int32", ")", "{", "randomBits", "(", "r", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "r", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "i", ")", "...
// Int32 creates a random 32 bit integer using crypto.rand
[ "Int32", "creates", "a", "random", "32", "bit", "integer", "using", "crypto", ".", "rand" ]
1a6879dc80f2da8d4693fdf2a3956931a463a238
https://github.com/ory/common/blob/1a6879dc80f2da8d4693fdf2a3956931a463a238/rand/numeric/int.go#L32-L37
143,340
ory/common
rand/numeric/int.go
UInt32
func UInt32() (i uint32) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
go
func UInt32() (i uint32) { randomBits(r) buf := bytes.NewBuffer(r) binary.Read(buf, binary.LittleEndian, &i) return i }
[ "func", "UInt32", "(", ")", "(", "i", "uint32", ")", "{", "randomBits", "(", "r", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "r", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "i", ")", ...
// UInt32 creates a random 32 bit unsigned integer using crypto.rand
[ "UInt32", "creates", "a", "random", "32", "bit", "unsigned", "integer", "using", "crypto", ".", "rand" ]
1a6879dc80f2da8d4693fdf2a3956931a463a238
https://github.com/ory/common/blob/1a6879dc80f2da8d4693fdf2a3956931a463a238/rand/numeric/int.go#L40-L45
143,341
ory/common
rand/numeric/int.go
randomBits
func randomBits(b []byte) { if _, err := io.ReadFull(rander, b); err != nil { panic(err.Error()) // rand should never fail } }
go
func randomBits(b []byte) { if _, err := io.ReadFull(rander, b); err != nil { panic(err.Error()) // rand should never fail } }
[ "func", "randomBits", "(", "b", "[", "]", "byte", ")", "{", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "rander", ",", "b", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ".", "Error", "(", ")", ")", "// rand should never fa...
// randomBits completely fills slice b with random data.
[ "randomBits", "completely", "fills", "slice", "b", "with", "random", "data", "." ]
1a6879dc80f2da8d4693fdf2a3956931a463a238
https://github.com/ory/common/blob/1a6879dc80f2da8d4693fdf2a3956931a463a238/rand/numeric/int.go#L48-L52
143,342
cybozu-go/log
reopen.go
NewReopenWriter
func NewReopenWriter(opener Opener, sig ...os.Signal) (io.Writer, error) { w, err := opener.Open() if err != nil { return nil, err } c := make(chan os.Signal, 1) signal.Notify(c, sig...) r := &reopenWriter{ writer: w, } reopen := func() { r.lock.Lock() defer r.lock.Unlock() if r.writer != nil { err...
go
func NewReopenWriter(opener Opener, sig ...os.Signal) (io.Writer, error) { w, err := opener.Open() if err != nil { return nil, err } c := make(chan os.Signal, 1) signal.Notify(c, sig...) r := &reopenWriter{ writer: w, } reopen := func() { r.lock.Lock() defer r.lock.Unlock() if r.writer != nil { err...
[ "func", "NewReopenWriter", "(", "opener", "Opener", ",", "sig", "...", "os", ".", "Signal", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "w", ",", "err", ":=", "opener", ".", "Open", "(", ")", "\n", "if", "err", "!=", "nil", "{", "retur...
// NewReopenWriter constructs a io.Writer that reopens inner io.WriteCloser // when signals are received.
[ "NewReopenWriter", "constructs", "a", "io", ".", "Writer", "that", "reopens", "inner", "io", ".", "WriteCloser", "when", "signals", "are", "received", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/reopen.go#L26-L62
143,343
cybozu-go/log
reopen.go
Write
func (r *reopenWriter) Write(p []byte) (n int, err error) { r.lock.Lock() defer r.lock.Unlock() if r.lastErr != nil { err = fmt.Errorf("unusable due to %v", r.lastErr) return } return r.writer.Write(p) }
go
func (r *reopenWriter) Write(p []byte) (n int, err error) { r.lock.Lock() defer r.lock.Unlock() if r.lastErr != nil { err = fmt.Errorf("unusable due to %v", r.lastErr) return } return r.writer.Write(p) }
[ "func", "(", "r", "*", "reopenWriter", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "r", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "lock", ".", "Unlock", "(", ")", "\n", "...
// Write calles inner writes. // If some error has happened when re-opening, this reports the error.
[ "Write", "calles", "inner", "writes", ".", "If", "some", "error", "has", "happened", "when", "re", "-", "opening", "this", "reports", "the", "error", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/reopen.go#L66-L74
143,344
cybozu-go/log
reopen.go
NewFileReopener
func NewFileReopener(filename string, sig ...os.Signal) (io.Writer, error) { return NewReopenWriter(fileOpener(filename), sig...) }
go
func NewFileReopener(filename string, sig ...os.Signal) (io.Writer, error) { return NewReopenWriter(fileOpener(filename), sig...) }
[ "func", "NewFileReopener", "(", "filename", "string", ",", "sig", "...", "os", ".", "Signal", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "return", "NewReopenWriter", "(", "fileOpener", "(", "filename", ")", ",", "sig", "...", ")", "\n", "}"...
// NewFileReopener returns io.Writer that will reopen the named file // when signals are received.
[ "NewFileReopener", "returns", "io", ".", "Writer", "that", "will", "reopen", "the", "named", "file", "when", "signals", "are", "received", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/reopen.go#L116-L118
143,345
cybozu-go/log
formatter.go
ReservedKey
func ReservedKey(k string) bool { switch k { case FnTopic, FnLoggedAt, FnSeverity, FnUtsname, FnMessage: return true } return false }
go
func ReservedKey(k string) bool { switch k { case FnTopic, FnLoggedAt, FnSeverity, FnUtsname, FnMessage: return true } return false }
[ "func", "ReservedKey", "(", "k", "string", ")", "bool", "{", "switch", "k", "{", "case", "FnTopic", ",", "FnLoggedAt", ",", "FnSeverity", ",", "FnUtsname", ",", "FnMessage", ":", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ReservedKey returns true if k is a field name reserved for log formatters.
[ "ReservedKey", "returns", "true", "if", "k", "is", "a", "field", "name", "reserved", "for", "log", "formatters", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/formatter.go#L33-L39
143,346
cybozu-go/log
default.go
Critical
func Critical(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvCritical, msg, fields) }
go
func Critical(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvCritical, msg, fields) }
[ "func", "Critical", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "defaultLogger", ".", "Log", "(", "LvCritical", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Critical outputs a critical log using the default logger. // fields can be nil.
[ "Critical", "outputs", "a", "critical", "log", "using", "the", "default", "logger", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/default.go#L42-L44
143,347
cybozu-go/log
default.go
Error
func Error(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvError, msg, fields) }
go
func Error(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvError, msg, fields) }
[ "func", "Error", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "defaultLogger", ".", "Log", "(", "LvError", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Error outputs an error log using the default logger. // fields can be nil.
[ "Error", "outputs", "an", "error", "log", "using", "the", "default", "logger", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/default.go#L48-L50
143,348
cybozu-go/log
default.go
Warn
func Warn(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvWarn, msg, fields) }
go
func Warn(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvWarn, msg, fields) }
[ "func", "Warn", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "defaultLogger", ".", "Log", "(", "LvWarn", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Warn outputs a warning log using the default logger. // fields can be nil.
[ "Warn", "outputs", "a", "warning", "log", "using", "the", "default", "logger", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/default.go#L54-L56
143,349
cybozu-go/log
default.go
Info
func Info(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvInfo, msg, fields) }
go
func Info(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvInfo, msg, fields) }
[ "func", "Info", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "defaultLogger", ".", "Log", "(", "LvInfo", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Info outputs an informational log using the default logger. // fields can be nil.
[ "Info", "outputs", "an", "informational", "log", "using", "the", "default", "logger", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/default.go#L60-L62
143,350
cybozu-go/log
default.go
Debug
func Debug(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvDebug, msg, fields) }
go
func Debug(msg string, fields map[string]interface{}) error { return defaultLogger.Log(LvDebug, msg, fields) }
[ "func", "Debug", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "defaultLogger", ".", "Log", "(", "LvDebug", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Debug outputs a debug log using the default logger. // fields can be nil.
[ "Debug", "outputs", "a", "debug", "log", "using", "the", "default", "logger", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/default.go#L66-L68
143,351
cybozu-go/log
logger.go
SetTopic
func (l *Logger) SetTopic(topic string) { if len(topic) == 0 { panic("Empty tag") } l.topic.Store(topic) }
go
func (l *Logger) SetTopic(topic string) { if len(topic) == 0 { panic("Empty tag") } l.topic.Store(topic) }
[ "func", "(", "l", "*", "Logger", ")", "SetTopic", "(", "topic", "string", ")", "{", "if", "len", "(", "topic", ")", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "l", ".", "topic", ".", "Store", "(", "topic", ")", "\n", "}...
// SetTopic sets a new topic for the logger. // topic must not be empty. Too long topic may be shortened automatically.
[ "SetTopic", "sets", "a", "new", "topic", "for", "the", "logger", ".", "topic", "must", "not", "be", "empty", ".", "Too", "long", "topic", "may", "be", "shortened", "automatically", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L106-L112
143,352
cybozu-go/log
logger.go
SetThreshold
func (l *Logger) SetThreshold(level int) { atomic.StoreInt32(&l.threshold, int32(level)) }
go
func (l *Logger) SetThreshold(level int) { atomic.StoreInt32(&l.threshold, int32(level)) }
[ "func", "(", "l", "*", "Logger", ")", "SetThreshold", "(", "level", "int", ")", "{", "atomic", ".", "StoreInt32", "(", "&", "l", ".", "threshold", ",", "int32", "(", "level", ")", ")", "\n", "}" ]
// SetThreshold sets the threshold for the logger. // level must be a pre-defined constant such as LvInfo.
[ "SetThreshold", "sets", "the", "threshold", "for", "the", "logger", ".", "level", "must", "be", "a", "pre", "-", "defined", "constant", "such", "as", "LvInfo", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L133-L135
143,353
cybozu-go/log
logger.go
SetThresholdByName
func (l *Logger) SetThresholdByName(n string) error { var level int switch n { case "critical", "crit": level = LvCritical case "error": level = LvError case "warning", "warn": level = LvWarn case "information", "info": level = LvInfo case "debug": level = LvDebug default: return fmt.Errorf("No such...
go
func (l *Logger) SetThresholdByName(n string) error { var level int switch n { case "critical", "crit": level = LvCritical case "error": level = LvError case "warning", "warn": level = LvWarn case "information", "info": level = LvInfo case "debug": level = LvDebug default: return fmt.Errorf("No such...
[ "func", "(", "l", "*", "Logger", ")", "SetThresholdByName", "(", "n", "string", ")", "error", "{", "var", "level", "int", "\n", "switch", "n", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "level", "=", "LvCritical", "\n", "case", "\"", "\"", ":",...
// SetThresholdByName sets the threshold for the logger by the level name.
[ "SetThresholdByName", "sets", "the", "threshold", "for", "the", "logger", "by", "the", "level", "name", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L138-L156
143,354
cybozu-go/log
logger.go
SetDefaults
func (l *Logger) SetDefaults(d map[string]interface{}) error { for key := range d { if !IsValidKey(key) { return ErrInvalidKey } } l.defaults.Store(d) return nil }
go
func (l *Logger) SetDefaults(d map[string]interface{}) error { for key := range d { if !IsValidKey(key) { return ErrInvalidKey } } l.defaults.Store(d) return nil }
[ "func", "(", "l", "*", "Logger", ")", "SetDefaults", "(", "d", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "for", "key", ":=", "range", "d", "{", "if", "!", "IsValidKey", "(", "key", ")", "{", "return", "ErrInvalidKey", "\n...
// SetDefaults sets default field values for the logger. // Setting nil effectively clear the defaults.
[ "SetDefaults", "sets", "default", "field", "values", "for", "the", "logger", ".", "Setting", "nil", "effectively", "clear", "the", "defaults", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L160-L169
143,355
cybozu-go/log
logger.go
SetErrorHandler
func (l *Logger) SetErrorHandler(h func(error) error) { l.errorHandler.Store(h) }
go
func (l *Logger) SetErrorHandler(h func(error) error) { l.errorHandler.Store(h) }
[ "func", "(", "l", "*", "Logger", ")", "SetErrorHandler", "(", "h", "func", "(", "error", ")", "error", ")", "{", "l", ".", "errorHandler", ".", "Store", "(", "h", ")", "\n", "}" ]
// SetErrorHandler sets error handler. // // The handler will be called if the underlying Writer's Write // returns non-nil error. If h is nil, no handler will be called.
[ "SetErrorHandler", "sets", "error", "handler", ".", "The", "handler", "will", "be", "called", "if", "the", "underlying", "Writer", "s", "Write", "returns", "non", "-", "nil", "error", ".", "If", "h", "is", "nil", "no", "handler", "will", "be", "called", ...
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L190-L192
143,356
cybozu-go/log
logger.go
handleError
func (l *Logger) handleError(err error) error { h := l.errorHandler.Load().(func(error) error) if h == nil { return err } return h(err) }
go
func (l *Logger) handleError(err error) error { h := l.errorHandler.Load().(func(error) error) if h == nil { return err } return h(err) }
[ "func", "(", "l", "*", "Logger", ")", "handleError", "(", "err", "error", ")", "error", "{", "h", ":=", "l", ".", "errorHandler", ".", "Load", "(", ")", ".", "(", "func", "(", "error", ")", "error", ")", "\n", "if", "h", "==", "nil", "{", "retu...
// Formatter returns the current log formatter.
[ "Formatter", "returns", "the", "current", "log", "formatter", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L195-L201
143,357
cybozu-go/log
logger.go
Writer
func (l *Logger) Writer(severity int) io.Writer { logfunc := func(p []byte) (n int, err error) { for len(p) > 0 { eol := bytes.IndexByte(p, '\n') if eol == -1 { return } ln := eol + 1 err = l.Log(severity, string(p[:eol]), nil) if err != nil { return } n += ln p = p[ln:] } retu...
go
func (l *Logger) Writer(severity int) io.Writer { logfunc := func(p []byte) (n int, err error) { for len(p) > 0 { eol := bytes.IndexByte(p, '\n') if eol == -1 { return } ln := eol + 1 err = l.Log(severity, string(p[:eol]), nil) if err != nil { return } n += ln p = p[ln:] } retu...
[ "func", "(", "l", "*", "Logger", ")", "Writer", "(", "severity", "int", ")", "io", ".", "Writer", "{", "logfunc", ":=", "func", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "for", "len", "(", "p", ")", ">",...
// Writer returns an io.Writer. // Each line written in the writer will be logged to the logger // with the given severity.
[ "Writer", "returns", "an", "io", ".", "Writer", ".", "Each", "line", "written", "in", "the", "writer", "will", "be", "logged", "to", "the", "logger", "with", "the", "given", "severity", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L245-L267
143,358
cybozu-go/log
logger.go
Log
func (l *Logger) Log(severity int, msg string, fields map[string]interface{}) error { if severity > l.Threshold() { return nil } // format the message before acquiring mutex for better concurrency. t := time.Now() buf := pool.Get().([]byte) defer pool.Put(buf) b, err := l.Formatter().Format(buf, l, t, severi...
go
func (l *Logger) Log(severity int, msg string, fields map[string]interface{}) error { if severity > l.Threshold() { return nil } // format the message before acquiring mutex for better concurrency. t := time.Now() buf := pool.Get().([]byte) defer pool.Put(buf) b, err := l.Formatter().Format(buf, l, t, severi...
[ "func", "(", "l", "*", "Logger", ")", "Log", "(", "severity", "int", ",", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "if", "severity", ">", "l", ".", "Threshold", "(", ")", "{", "return", ...
// Log outputs a log message with additional fields. // fields can be nil.
[ "Log", "outputs", "a", "log", "message", "with", "additional", "fields", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L271-L302
143,359
cybozu-go/log
logger.go
Critical
func (l *Logger) Critical(msg string, fields map[string]interface{}) error { return l.Log(LvCritical, msg, fields) }
go
func (l *Logger) Critical(msg string, fields map[string]interface{}) error { return l.Log(LvCritical, msg, fields) }
[ "func", "(", "l", "*", "Logger", ")", "Critical", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "Log", "(", "LvCritical", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Critical outputs a critical log. // fields can be nil.
[ "Critical", "outputs", "a", "critical", "log", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L306-L308
143,360
cybozu-go/log
logger.go
Error
func (l *Logger) Error(msg string, fields map[string]interface{}) error { return l.Log(LvError, msg, fields) }
go
func (l *Logger) Error(msg string, fields map[string]interface{}) error { return l.Log(LvError, msg, fields) }
[ "func", "(", "l", "*", "Logger", ")", "Error", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "Log", "(", "LvError", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Error outputs an error log. // fields can be nil.
[ "Error", "outputs", "an", "error", "log", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L312-L314
143,361
cybozu-go/log
logger.go
Warn
func (l *Logger) Warn(msg string, fields map[string]interface{}) error { return l.Log(LvWarn, msg, fields) }
go
func (l *Logger) Warn(msg string, fields map[string]interface{}) error { return l.Log(LvWarn, msg, fields) }
[ "func", "(", "l", "*", "Logger", ")", "Warn", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "Log", "(", "LvWarn", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Warn outputs a warning log. // fields can be nil.
[ "Warn", "outputs", "a", "warning", "log", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L318-L320
143,362
cybozu-go/log
logger.go
Info
func (l *Logger) Info(msg string, fields map[string]interface{}) error { return l.Log(LvInfo, msg, fields) }
go
func (l *Logger) Info(msg string, fields map[string]interface{}) error { return l.Log(LvInfo, msg, fields) }
[ "func", "(", "l", "*", "Logger", ")", "Info", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "Log", "(", "LvInfo", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Info outputs an informational log. // fields can be nil.
[ "Info", "outputs", "an", "informational", "log", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L324-L326
143,363
cybozu-go/log
logger.go
Debug
func (l *Logger) Debug(msg string, fields map[string]interface{}) error { return l.Log(LvDebug, msg, fields) }
go
func (l *Logger) Debug(msg string, fields map[string]interface{}) error { return l.Log(LvDebug, msg, fields) }
[ "func", "(", "l", "*", "Logger", ")", "Debug", "(", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "return", "l", ".", "Log", "(", "LvDebug", ",", "msg", ",", "fields", ")", "\n", "}" ]
// Debug outputs a debug log. // fields can be nil.
[ "Debug", "outputs", "a", "debug", "log", ".", "fields", "can", "be", "nil", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L330-L332
143,364
cybozu-go/log
logger.go
WriteThrough
func (l *Logger) WriteThrough(data []byte) error { l.mu.Lock() defer l.mu.Unlock() _, err := l.output.Write(data) if err == nil { return nil } err = l.handleError(err) if err == nil { return nil } return errors.Wrap(err, "Logger.WriteThrough") }
go
func (l *Logger) WriteThrough(data []byte) error { l.mu.Lock() defer l.mu.Unlock() _, err := l.output.Write(data) if err == nil { return nil } err = l.handleError(err) if err == nil { return nil } return errors.Wrap(err, "Logger.WriteThrough") }
[ "func", "(", "l", "*", "Logger", ")", "WriteThrough", "(", "data", "[", "]", "byte", ")", "error", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "_", ",", "err", ":=", "l", ".", ...
// WriteThrough writes data through to the underlying writer.
[ "WriteThrough", "writes", "data", "through", "to", "the", "underlying", "writer", "." ]
b1c4e3c97a27a943216245a95f4ff0b58bd82bc9
https://github.com/cybozu-go/log/blob/b1c4e3c97a27a943216245a95f4ff0b58bd82bc9/logger.go#L335-L348
143,365
yookoala/realpath
realpath.go
Realpath
func Realpath(fpath string) (string, error) { if len(fpath) == 0 { return "", os.ErrInvalid } if !filepath.IsAbs(fpath) { pwd, err := os.Getwd() if err != nil { return "", err } fpath = filepath.Join(pwd, fpath) } path := []byte(fpath) nlinks := 0 start := 1 prev := 1 for start < len(path) { ...
go
func Realpath(fpath string) (string, error) { if len(fpath) == 0 { return "", os.ErrInvalid } if !filepath.IsAbs(fpath) { pwd, err := os.Getwd() if err != nil { return "", err } fpath = filepath.Join(pwd, fpath) } path := []byte(fpath) nlinks := 0 start := 1 prev := 1 for start < len(path) { ...
[ "func", "Realpath", "(", "fpath", "string", ")", "(", "string", ",", "error", ")", "{", "if", "len", "(", "fpath", ")", "==", "0", "{", "return", "\"", "\"", ",", "os", ".", "ErrInvalid", "\n", "}", "\n\n", "if", "!", "filepath", ".", "IsAbs", "(...
// Realpath returns the real path of a given file in the os
[ "Realpath", "returns", "the", "real", "path", "of", "a", "given", "file", "in", "the", "os" ]
d19ef9c409d9817c1e685775e53d361b03eabbc8
https://github.com/yookoala/realpath/blob/d19ef9c409d9817c1e685775e53d361b03eabbc8/realpath.go#L15-L90
143,366
yookoala/realpath
realpath.go
isSymlink
func isSymlink(fi os.FileInfo) bool { return fi.Mode()&os.ModeSymlink == os.ModeSymlink }
go
func isSymlink(fi os.FileInfo) bool { return fi.Mode()&os.ModeSymlink == os.ModeSymlink }
[ "func", "isSymlink", "(", "fi", "os", ".", "FileInfo", ")", "bool", "{", "return", "fi", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "==", "os", ".", "ModeSymlink", "\n", "}" ]
// test if a link is symbolic link
[ "test", "if", "a", "link", "is", "symbolic", "link" ]
d19ef9c409d9817c1e685775e53d361b03eabbc8
https://github.com/yookoala/realpath/blob/d19ef9c409d9817c1e685775e53d361b03eabbc8/realpath.go#L93-L95
143,367
yookoala/realpath
realpath.go
switchSymlinkCom
func switchSymlinkCom(path []byte, start int, link, after string) []byte { if link[0] == os.PathSeparator { // Absolute links return []byte(filepath.Join(link, after)) } // Relative links return []byte(filepath.Join(string(path[0:start]), link, after)) }
go
func switchSymlinkCom(path []byte, start int, link, after string) []byte { if link[0] == os.PathSeparator { // Absolute links return []byte(filepath.Join(link, after)) } // Relative links return []byte(filepath.Join(string(path[0:start]), link, after)) }
[ "func", "switchSymlinkCom", "(", "path", "[", "]", "byte", ",", "start", "int", ",", "link", ",", "after", "string", ")", "[", "]", "byte", "{", "if", "link", "[", "0", "]", "==", "os", ".", "PathSeparator", "{", "// Absolute links", "return", "[", "...
// switch a symbolic link component to its real path
[ "switch", "a", "symbolic", "link", "component", "to", "its", "real", "path" ]
d19ef9c409d9817c1e685775e53d361b03eabbc8
https://github.com/yookoala/realpath/blob/d19ef9c409d9817c1e685775e53d361b03eabbc8/realpath.go#L98-L107
143,368
yookoala/realpath
realpath.go
nextComponent
func nextComponent(path []byte, start int) []byte { v := bytes.IndexByte(path[start:], os.PathSeparator) if v < 0 { return path } return path[0 : start+v] }
go
func nextComponent(path []byte, start int) []byte { v := bytes.IndexByte(path[start:], os.PathSeparator) if v < 0 { return path } return path[0 : start+v] }
[ "func", "nextComponent", "(", "path", "[", "]", "byte", ",", "start", "int", ")", "[", "]", "byte", "{", "v", ":=", "bytes", ".", "IndexByte", "(", "path", "[", "start", ":", "]", ",", "os", ".", "PathSeparator", ")", "\n", "if", "v", "<", "0", ...
// get the next component
[ "get", "the", "next", "component" ]
d19ef9c409d9817c1e685775e53d361b03eabbc8
https://github.com/yookoala/realpath/blob/d19ef9c409d9817c1e685775e53d361b03eabbc8/realpath.go#L110-L116
143,369
Unknwon/paginater
paginater.go
New
func New(total, pagingNum, current, numPages int) *Paginater { if pagingNum <= 0 { pagingNum = 1 } if current <= 0 { current = 1 } p := &Paginater{total, pagingNum, current, numPages} if p.current > p.TotalPages() { p.current = p.TotalPages() } return p }
go
func New(total, pagingNum, current, numPages int) *Paginater { if pagingNum <= 0 { pagingNum = 1 } if current <= 0 { current = 1 } p := &Paginater{total, pagingNum, current, numPages} if p.current > p.TotalPages() { p.current = p.TotalPages() } return p }
[ "func", "New", "(", "total", ",", "pagingNum", ",", "current", ",", "numPages", "int", ")", "*", "Paginater", "{", "if", "pagingNum", "<=", "0", "{", "pagingNum", "=", "1", "\n", "}", "\n", "if", "current", "<=", "0", "{", "current", "=", "1", "\n"...
// New initialize a new pagination calculation and returns a Paginater as result.
[ "New", "initialize", "a", "new", "pagination", "calculation", "and", "returns", "a", "Paginater", "as", "result", "." ]
45e5d631308ea359946e761484147982c978d0df
https://github.com/Unknwon/paginater/blob/45e5d631308ea359946e761484147982c978d0df/paginater.go#L27-L39
143,370
Unknwon/paginater
paginater.go
HasNext
func (p *Paginater) HasNext() bool { return p.total > p.current*p.pagingNum }
go
func (p *Paginater) HasNext() bool { return p.total > p.current*p.pagingNum }
[ "func", "(", "p", "*", "Paginater", ")", "HasNext", "(", ")", "bool", "{", "return", "p", ".", "total", ">", "p", ".", "current", "*", "p", ".", "pagingNum", "\n", "}" ]
// HasNext returns true if there is a next page relative to current page.
[ "HasNext", "returns", "true", "if", "there", "is", "a", "next", "page", "relative", "to", "current", "page", "." ]
45e5d631308ea359946e761484147982c978d0df
https://github.com/Unknwon/paginater/blob/45e5d631308ea359946e761484147982c978d0df/paginater.go#L59-L61
143,371
Unknwon/paginater
paginater.go
IsLast
func (p *Paginater) IsLast() bool { if p.total == 0 { return true } return p.total > (p.current-1)*p.pagingNum && !p.HasNext() }
go
func (p *Paginater) IsLast() bool { if p.total == 0 { return true } return p.total > (p.current-1)*p.pagingNum && !p.HasNext() }
[ "func", "(", "p", "*", "Paginater", ")", "IsLast", "(", ")", "bool", "{", "if", "p", ".", "total", "==", "0", "{", "return", "true", "\n", "}", "\n", "return", "p", ".", "total", ">", "(", "p", ".", "current", "-", "1", ")", "*", "p", ".", ...
// IsLast returns true if current page is the last page.
[ "IsLast", "returns", "true", "if", "current", "page", "is", "the", "last", "page", "." ]
45e5d631308ea359946e761484147982c978d0df
https://github.com/Unknwon/paginater/blob/45e5d631308ea359946e761484147982c978d0df/paginater.go#L71-L76
143,372
Unknwon/paginater
paginater.go
TotalPages
func (p *Paginater) TotalPages() int { if p.total == 0 { return 1 } if p.total%p.pagingNum == 0 { return p.total / p.pagingNum } return p.total/p.pagingNum + 1 }
go
func (p *Paginater) TotalPages() int { if p.total == 0 { return 1 } if p.total%p.pagingNum == 0 { return p.total / p.pagingNum } return p.total/p.pagingNum + 1 }
[ "func", "(", "p", "*", "Paginater", ")", "TotalPages", "(", ")", "int", "{", "if", "p", ".", "total", "==", "0", "{", "return", "1", "\n", "}", "\n", "if", "p", ".", "total", "%", "p", ".", "pagingNum", "==", "0", "{", "return", "p", ".", "to...
// TotalPage returns number of total pages.
[ "TotalPage", "returns", "number", "of", "total", "pages", "." ]
45e5d631308ea359946e761484147982c978d0df
https://github.com/Unknwon/paginater/blob/45e5d631308ea359946e761484147982c978d0df/paginater.go#L84-L92
143,373
Unknwon/paginater
paginater.go
Pages
func (p *Paginater) Pages() []*Page { if p.numPages == 0 { return []*Page{} } else if p.numPages == 1 && p.TotalPages() == 1 { // Only show current page. return []*Page{{1, true}} } // Total page number is less or equal. if p.TotalPages() <= p.numPages { pages := make([]*Page, p.TotalPages()) for i := r...
go
func (p *Paginater) Pages() []*Page { if p.numPages == 0 { return []*Page{} } else if p.numPages == 1 && p.TotalPages() == 1 { // Only show current page. return []*Page{{1, true}} } // Total page number is less or equal. if p.TotalPages() <= p.numPages { pages := make([]*Page, p.TotalPages()) for i := r...
[ "func", "(", "p", "*", "Paginater", ")", "Pages", "(", ")", "[", "]", "*", "Page", "{", "if", "p", ".", "numPages", "==", "0", "{", "return", "[", "]", "*", "Page", "{", "}", "\n", "}", "else", "if", "p", ".", "numPages", "==", "1", "&&", "...
// Pages returns a list of nearby page numbers relative to current page. // If value is -1 means "..." that more pages are not showing.
[ "Pages", "returns", "a", "list", "of", "nearby", "page", "numbers", "relative", "to", "current", "page", ".", "If", "value", "is", "-", "1", "means", "...", "that", "more", "pages", "are", "not", "showing", "." ]
45e5d631308ea359946e761484147982c978d0df
https://github.com/Unknwon/paginater/blob/45e5d631308ea359946e761484147982c978d0df/paginater.go#L127-L197
143,374
lytics/slackhook
slackhook.go
Simple
func (c *Client) Simple(msg string) error { return c.Send(&Message{Text: msg}) }
go
func (c *Client) Simple(msg string) error { return c.Send(&Message{Text: msg}) }
[ "func", "(", "c", "*", "Client", ")", "Simple", "(", "msg", "string", ")", "error", "{", "return", "c", ".", "Send", "(", "&", "Message", "{", "Text", ":", "msg", "}", ")", "\n", "}" ]
// Simple text message.
[ "Simple", "text", "message", "." ]
a52fd449b27dcdd75cf069c5d6ac5749653d801a
https://github.com/lytics/slackhook/blob/a52fd449b27dcdd75cf069c5d6ac5749653d801a/slackhook.go#L73-L75
143,375
lytics/slackhook
slackhook.go
Send
func (c *Client) Send(msg *Message) error { buf, err := json.Marshal(msg) if err != nil { return err } resp, err := c.HTTPClient.Post(c.url, "application/json", bytes.NewReader(buf)) if err != nil { return err } defer resp.Body.Close() // Discard response body to reuse connection io.Copy(ioutil.Discard, r...
go
func (c *Client) Send(msg *Message) error { buf, err := json.Marshal(msg) if err != nil { return err } resp, err := c.HTTPClient.Post(c.url, "application/json", bytes.NewReader(buf)) if err != nil { return err } defer resp.Body.Close() // Discard response body to reuse connection io.Copy(ioutil.Discard, r...
[ "func", "(", "c", "*", "Client", ")", "Send", "(", "msg", "*", "Message", ")", "error", "{", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "resp", ",", ...
// Send a Message.
[ "Send", "a", "Message", "." ]
a52fd449b27dcdd75cf069c5d6ac5749653d801a
https://github.com/lytics/slackhook/blob/a52fd449b27dcdd75cf069c5d6ac5749653d801a/slackhook.go#L78-L96
143,376
mattevans/dinero
dinero.go
NewClient
func NewClient(oxrAppID string) *Client { // Init new http.Client. httpClient := http.DefaultClient // Parse BE URL. baseURL, _ := url.Parse(backendURL) c := &Client{ client: httpClient, BackendURL: baseURL, UserAgent: userAgent, AppID: oxrAppID, } c.Update = &UpdateService{client: c} c.Rat...
go
func NewClient(oxrAppID string) *Client { // Init new http.Client. httpClient := http.DefaultClient // Parse BE URL. baseURL, _ := url.Parse(backendURL) c := &Client{ client: httpClient, BackendURL: baseURL, UserAgent: userAgent, AppID: oxrAppID, } c.Update = &UpdateService{client: c} c.Rat...
[ "func", "NewClient", "(", "oxrAppID", "string", ")", "*", "Client", "{", "// Init new http.Client.", "httpClient", ":=", "http", ".", "DefaultClient", "\n\n", "// Parse BE URL.", "baseURL", ",", "_", ":=", "url", ".", "Parse", "(", "backendURL", ")", "\n\n", "...
// NewClient creates a new Client with the appropriate connection details and // services used for communicating with the API.
[ "NewClient", "creates", "a", "new", "Client", "with", "the", "appropriate", "connection", "details", "and", "services", "used", "for", "communicating", "with", "the", "API", "." ]
804165704b35b65c4b56d0ac295f509d0cd3bc90
https://github.com/mattevans/dinero/blob/804165704b35b65c4b56d0ac295f509d0cd3bc90/dinero.go#L58-L76
143,377
mattevans/dinero
dinero.go
NewRequest
func (c *Client) NewRequest(method, urlPath string, body interface{}) (*http.Request, error) { // Append out OXR App ID to URL, :-( urlPath = fmt.Sprintf("%s&app_id=%s", urlPath, c.AppID) // Parse our URL. rel, err := url.Parse(urlPath) if err != nil { return nil, err } // Resolve to absolute URI. u := c.Ba...
go
func (c *Client) NewRequest(method, urlPath string, body interface{}) (*http.Request, error) { // Append out OXR App ID to URL, :-( urlPath = fmt.Sprintf("%s&app_id=%s", urlPath, c.AppID) // Parse our URL. rel, err := url.Parse(urlPath) if err != nil { return nil, err } // Resolve to absolute URI. u := c.Ba...
[ "func", "(", "c", "*", "Client", ")", "NewRequest", "(", "method", ",", "urlPath", "string", ",", "body", "interface", "{", "}", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "// Append out OXR App ID to URL, :-(", "urlPath", "=", "fmt", ...
// NewRequest creates an API request. A relative URL can be provided in urlPath, // which will be resolved to the BackendURL of the Client.
[ "NewRequest", "creates", "an", "API", "request", ".", "A", "relative", "URL", "can", "be", "provided", "in", "urlPath", "which", "will", "be", "resolved", "to", "the", "BackendURL", "of", "the", "Client", "." ]
804165704b35b65c4b56d0ac295f509d0cd3bc90
https://github.com/mattevans/dinero/blob/804165704b35b65c4b56d0ac295f509d0cd3bc90/dinero.go#L80-L111
143,378
mattevans/dinero
cache.go
Get
func (s *CacheService) Get(base string) *RatesStore { // Is our cache expired? if s.IsExpired(base) { return nil } // Use stored results. return cache[base] }
go
func (s *CacheService) Get(base string) *RatesStore { // Is our cache expired? if s.IsExpired(base) { return nil } // Use stored results. return cache[base] }
[ "func", "(", "s", "*", "CacheService", ")", "Get", "(", "base", "string", ")", "*", "RatesStore", "{", "// Is our cache expired?", "if", "s", ".", "IsExpired", "(", "base", ")", "{", "return", "nil", "\n", "}", "\n\n", "// Use stored results.", "return", "...
// Get will return our stored in-memory forex rates, if we have them.
[ "Get", "will", "return", "our", "stored", "in", "-", "memory", "forex", "rates", "if", "we", "have", "them", "." ]
804165704b35b65c4b56d0ac295f509d0cd3bc90
https://github.com/mattevans/dinero/blob/804165704b35b65c4b56d0ac295f509d0cd3bc90/cache.go#L15-L23
143,379
mattevans/dinero
cache.go
Store
func (s *CacheService) Store(base string, rates map[string]float64) { // No cache? Initalize it. if cache == nil { cache = map[string]*RatesStore{} } // Store tn := time.Now() cache[base] = &RatesStore{ Rates: rates, UpdatedAt: &tn, Base: base, } }
go
func (s *CacheService) Store(base string, rates map[string]float64) { // No cache? Initalize it. if cache == nil { cache = map[string]*RatesStore{} } // Store tn := time.Now() cache[base] = &RatesStore{ Rates: rates, UpdatedAt: &tn, Base: base, } }
[ "func", "(", "s", "*", "CacheService", ")", "Store", "(", "base", "string", ",", "rates", "map", "[", "string", "]", "float64", ")", "{", "// No cache? Initalize it.", "if", "cache", "==", "nil", "{", "cache", "=", "map", "[", "string", "]", "*", "Rate...
// Store will save our forex rates to a RatesStore.
[ "Store", "will", "save", "our", "forex", "rates", "to", "a", "RatesStore", "." ]
804165704b35b65c4b56d0ac295f509d0cd3bc90
https://github.com/mattevans/dinero/blob/804165704b35b65c4b56d0ac295f509d0cd3bc90/cache.go#L26-L39
143,380
mattevans/dinero
cache.go
IsExpired
func (s *CacheService) IsExpired(base string) bool { // No cache? bail. if cache[base] == nil || (len(cache[base].Rates) <= 0) { return true } // Expired cache? bail. lastUpdated := cache[base].UpdatedAt if lastUpdated != nil && lastUpdated.Add(cacheTTL).Before(time.Now()) { return true } return false }
go
func (s *CacheService) IsExpired(base string) bool { // No cache? bail. if cache[base] == nil || (len(cache[base].Rates) <= 0) { return true } // Expired cache? bail. lastUpdated := cache[base].UpdatedAt if lastUpdated != nil && lastUpdated.Add(cacheTTL).Before(time.Now()) { return true } return false }
[ "func", "(", "s", "*", "CacheService", ")", "IsExpired", "(", "base", "string", ")", "bool", "{", "// No cache? bail.", "if", "cache", "[", "base", "]", "==", "nil", "||", "(", "len", "(", "cache", "[", "base", "]", ".", "Rates", ")", "<=", "0", ")...
// IsExpired checks if we have stored cache and that it isn't expired.
[ "IsExpired", "checks", "if", "we", "have", "stored", "cache", "and", "that", "it", "isn", "t", "expired", "." ]
804165704b35b65c4b56d0ac295f509d0cd3bc90
https://github.com/mattevans/dinero/blob/804165704b35b65c4b56d0ac295f509d0cd3bc90/cache.go#L42-L55
143,381
mattevans/dinero
rates.go
All
func (s *RatesService) All() (*RatesStore, error) { // No base currency provided, let them know! if baseCurrency == "" { return nil, errors.New("Please set a base currency.") } // If we have cached results, use them. results := s.client.Cache.Get(baseCurrency) if results != nil { return results, nil } // ...
go
func (s *RatesService) All() (*RatesStore, error) { // No base currency provided, let them know! if baseCurrency == "" { return nil, errors.New("Please set a base currency.") } // If we have cached results, use them. results := s.client.Cache.Get(baseCurrency) if results != nil { return results, nil } // ...
[ "func", "(", "s", "*", "RatesService", ")", "All", "(", ")", "(", "*", "RatesStore", ",", "error", ")", "{", "// No base currency provided, let them know!", "if", "baseCurrency", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"",...
// All will build and execute request to fetch the latest rates for given base // currency either from the in-memory cache or OXR API.
[ "All", "will", "build", "and", "execute", "request", "to", "fetch", "the", "latest", "rates", "for", "given", "base", "currency", "either", "from", "the", "in", "-", "memory", "cache", "or", "OXR", "API", "." ]
804165704b35b65c4b56d0ac295f509d0cd3bc90
https://github.com/mattevans/dinero/blob/804165704b35b65c4b56d0ac295f509d0cd3bc90/rates.go#L33-L52
143,382
qor/sorting
callbacks.go
RegisterCallbacks
func RegisterCallbacks(db *gorm.DB) { if db.Callback().Create().Get("sorting:initalize_position") == nil { db.Callback().Create().Before("gorm:create").Register("sorting:initalize_position", initalizePosition) } if db.Callback().Delete().Get("sorting:reorder_positions") == nil { db.Callback().Delete().After("gor...
go
func RegisterCallbacks(db *gorm.DB) { if db.Callback().Create().Get("sorting:initalize_position") == nil { db.Callback().Create().Before("gorm:create").Register("sorting:initalize_position", initalizePosition) } if db.Callback().Delete().Get("sorting:reorder_positions") == nil { db.Callback().Delete().After("gor...
[ "func", "RegisterCallbacks", "(", "db", "*", "gorm", ".", "DB", ")", "{", "if", "db", ".", "Callback", "(", ")", ".", "Create", "(", ")", ".", "Get", "(", "\"", "\"", ")", "==", "nil", "{", "db", ".", "Callback", "(", ")", ".", "Create", "(", ...
// RegisterCallbacks register callbacks into gorm db instance
[ "RegisterCallbacks", "register", "callbacks", "into", "gorm", "db", "instance" ]
128455f72088d2aaaccdc8ed006dc94746a1038b
https://github.com/qor/sorting/blob/128455f72088d2aaaccdc8ed006dc94746a1038b/callbacks.go#L81-L91
143,383
qor/sorting
sorting.go
MoveUp
func MoveUp(db *gorm.DB, value sortingInterface, pos int) error { return move(db, value, -pos) }
go
func MoveUp(db *gorm.DB, value sortingInterface, pos int) error { return move(db, value, -pos) }
[ "func", "MoveUp", "(", "db", "*", "gorm", ".", "DB", ",", "value", "sortingInterface", ",", "pos", "int", ")", "error", "{", "return", "move", "(", "db", ",", "value", ",", "-", "pos", ")", "\n", "}" ]
// MoveUp move position up
[ "MoveUp", "move", "position", "up" ]
128455f72088d2aaaccdc8ed006dc94746a1038b
https://github.com/qor/sorting/blob/128455f72088d2aaaccdc8ed006dc94746a1038b/sorting.go#L131-L133
143,384
qor/sorting
sorting.go
MoveTo
func MoveTo(db *gorm.DB, value sortingInterface, pos int) error { return move(db, value, pos-value.GetPosition()) }
go
func MoveTo(db *gorm.DB, value sortingInterface, pos int) error { return move(db, value, pos-value.GetPosition()) }
[ "func", "MoveTo", "(", "db", "*", "gorm", ".", "DB", ",", "value", "sortingInterface", ",", "pos", "int", ")", "error", "{", "return", "move", "(", "db", ",", "value", ",", "pos", "-", "value", ".", "GetPosition", "(", ")", ")", "\n", "}" ]
// MoveTo move position to
[ "MoveTo", "move", "position", "to" ]
128455f72088d2aaaccdc8ed006dc94746a1038b
https://github.com/qor/sorting/blob/128455f72088d2aaaccdc8ed006dc94746a1038b/sorting.go#L141-L143
143,385
qor/sorting
controller.go
ConfigureQorResourceBeforeInitialize
func (s *Sorting) ConfigureQorResourceBeforeInitialize(res resource.Resourcer) { if res, ok := res.(*admin.Resource); ok { res.UseTheme("sorting") if res.Permission == nil { res.Permission = roles.NewPermission() } role := res.Permission.Role if _, ok := role.Get("sorting_mode"); !ok { role.Register(...
go
func (s *Sorting) ConfigureQorResourceBeforeInitialize(res resource.Resourcer) { if res, ok := res.(*admin.Resource); ok { res.UseTheme("sorting") if res.Permission == nil { res.Permission = roles.NewPermission() } role := res.Permission.Role if _, ok := role.Get("sorting_mode"); !ok { role.Register(...
[ "func", "(", "s", "*", "Sorting", ")", "ConfigureQorResourceBeforeInitialize", "(", "res", "resource", ".", "Resourcer", ")", "{", "if", "res", ",", "ok", ":=", "res", ".", "(", "*", "admin", ".", "Resource", ")", ";", "ok", "{", "res", ".", "UseTheme"...
// ConfigureQorResource configure sorting for qor admin
[ "ConfigureQorResource", "configure", "sorting", "for", "qor", "admin" ]
128455f72088d2aaaccdc8ed006dc94746a1038b
https://github.com/qor/sorting/blob/128455f72088d2aaaccdc8ed006dc94746a1038b/controller.go#L45-L86
143,386
pelletier/go-buffruneio
buffruneio.go
NewReader
func NewReader(input io.Reader) *Reader { return &Reader{ input: bufio.NewReader(input), } }
go
func NewReader(input io.Reader) *Reader { return &Reader{ input: bufio.NewReader(input), } }
[ "func", "NewReader", "(", "input", "io", ".", "Reader", ")", "*", "Reader", "{", "return", "&", "Reader", "{", "input", ":", "bufio", ".", "NewReader", "(", "input", ")", ",", "}", "\n", "}" ]
// NewReader returns a new Reader reading the given input.
[ "NewReader", "returns", "a", "new", "Reader", "reading", "the", "given", "input", "." ]
25c428535bd3f55a16f149a9daebd3fa4c5a562b
https://github.com/pelletier/go-buffruneio/blob/25c428535bd3f55a16f149a9daebd3fa4c5a562b/buffruneio.go#L25-L29
143,387
pelletier/go-buffruneio
buffruneio.go
feedBuffer
func (rd *Reader) feedBuffer() error { if rd.buffer == nil { rd.buffer = make([]rune, 0, 256) } r, size, err := rd.input.ReadRune() if err != nil { if err != io.EOF { return err } r = EOF } if r == utf8.RuneError && size == 1 { r = badRune } rd.buffer = append(rd.buffer, r) return nil }
go
func (rd *Reader) feedBuffer() error { if rd.buffer == nil { rd.buffer = make([]rune, 0, 256) } r, size, err := rd.input.ReadRune() if err != nil { if err != io.EOF { return err } r = EOF } if r == utf8.RuneError && size == 1 { r = badRune } rd.buffer = append(rd.buffer, r) return nil }
[ "func", "(", "rd", "*", "Reader", ")", "feedBuffer", "(", ")", "error", "{", "if", "rd", ".", "buffer", "==", "nil", "{", "rd", ".", "buffer", "=", "make", "(", "[", "]", "rune", ",", "0", ",", "256", ")", "\n", "}", "\n", "r", ",", "size", ...
// feedBuffer adds a rune to the buffer. // If EOF is reached, it adds EOF to the buffer and returns nil. // If a different error is encountered, it returns the error without // adding to the buffer.
[ "feedBuffer", "adds", "a", "rune", "to", "the", "buffer", ".", "If", "EOF", "is", "reached", "it", "adds", "EOF", "to", "the", "buffer", "and", "returns", "nil", ".", "If", "a", "different", "error", "is", "encountered", "it", "returns", "the", "error", ...
25c428535bd3f55a16f149a9daebd3fa4c5a562b
https://github.com/pelletier/go-buffruneio/blob/25c428535bd3f55a16f149a9daebd3fa4c5a562b/buffruneio.go#L38-L54
143,388
pelletier/go-buffruneio
buffruneio.go
ReadRune
func (rd *Reader) ReadRune() (rune, int, error) { if rd.current >= len(rd.buffer) { if err := rd.feedBuffer(); err != nil { return EOF, 0, err } } r := rd.buffer[rd.current] rd.current++ if r == badRune { return utf8.RuneError, 1, nil } if r == EOF { return EOF, 0, nil } return r, utf8.RuneLen(r), n...
go
func (rd *Reader) ReadRune() (rune, int, error) { if rd.current >= len(rd.buffer) { if err := rd.feedBuffer(); err != nil { return EOF, 0, err } } r := rd.buffer[rd.current] rd.current++ if r == badRune { return utf8.RuneError, 1, nil } if r == EOF { return EOF, 0, nil } return r, utf8.RuneLen(r), n...
[ "func", "(", "rd", "*", "Reader", ")", "ReadRune", "(", ")", "(", "rune", ",", "int", ",", "error", ")", "{", "if", "rd", ".", "current", ">=", "len", "(", "rd", ".", "buffer", ")", "{", "if", "err", ":=", "rd", ".", "feedBuffer", "(", ")", "...
// ReadRune reads and returns the next rune from the input. // The rune is also saved in an internal buffer, in case UnreadRune is called. // To avoid unbounded buffer growth, the caller must call Forget at appropriate intervals. // // At end of file, ReadRune returns EOF, 0, nil. // On read errors other than io.EOF, R...
[ "ReadRune", "reads", "and", "returns", "the", "next", "rune", "from", "the", "input", ".", "The", "rune", "is", "also", "saved", "in", "an", "internal", "buffer", "in", "case", "UnreadRune", "is", "called", ".", "To", "avoid", "unbounded", "buffer", "growt...
25c428535bd3f55a16f149a9daebd3fa4c5a562b
https://github.com/pelletier/go-buffruneio/blob/25c428535bd3f55a16f149a9daebd3fa4c5a562b/buffruneio.go#L62-L77
143,389
pelletier/go-buffruneio
buffruneio.go
UnreadRune
func (rd *Reader) UnreadRune() error { if rd.current == 0 { return ErrNoRuneToUnread } rd.current-- return nil }
go
func (rd *Reader) UnreadRune() error { if rd.current == 0 { return ErrNoRuneToUnread } rd.current-- return nil }
[ "func", "(", "rd", "*", "Reader", ")", "UnreadRune", "(", ")", "error", "{", "if", "rd", ".", "current", "==", "0", "{", "return", "ErrNoRuneToUnread", "\n", "}", "\n", "rd", ".", "current", "--", "\n", "return", "nil", "\n", "}" ]
// UnreadRune rewinds the input by one rune, undoing the effect of a single ReadRune call. // UnreadRune may be called multiple times to rewind a sequence of ReadRune calls, // up to the last time Forget was called or the beginning of the input. // // If there are no ReadRune calls left to undo, UnreadRune returns ErrN...
[ "UnreadRune", "rewinds", "the", "input", "by", "one", "rune", "undoing", "the", "effect", "of", "a", "single", "ReadRune", "call", ".", "UnreadRune", "may", "be", "called", "multiple", "times", "to", "rewind", "a", "sequence", "of", "ReadRune", "calls", "up"...
25c428535bd3f55a16f149a9daebd3fa4c5a562b
https://github.com/pelletier/go-buffruneio/blob/25c428535bd3f55a16f149a9daebd3fa4c5a562b/buffruneio.go#L84-L90
143,390
pelletier/go-buffruneio
buffruneio.go
Forget
func (rd *Reader) Forget() { n := copy(rd.buffer, rd.buffer[rd.current:]) rd.current = 0 rd.buffer = rd.buffer[:n] }
go
func (rd *Reader) Forget() { n := copy(rd.buffer, rd.buffer[rd.current:]) rd.current = 0 rd.buffer = rd.buffer[:n] }
[ "func", "(", "rd", "*", "Reader", ")", "Forget", "(", ")", "{", "n", ":=", "copy", "(", "rd", ".", "buffer", ",", "rd", ".", "buffer", "[", "rd", ".", "current", ":", "]", ")", "\n", "rd", ".", "current", "=", "0", "\n", "rd", ".", "buffer", ...
// Forget discards buffered runes before the current input position. // Calling Forget makes it impossible to UnreadRune earlier than the current input position // but is necessary to avoid unbounded buffer growth.
[ "Forget", "discards", "buffered", "runes", "before", "the", "current", "input", "position", ".", "Calling", "Forget", "makes", "it", "impossible", "to", "UnreadRune", "earlier", "than", "the", "current", "input", "position", "but", "is", "necessary", "to", "avoi...
25c428535bd3f55a16f149a9daebd3fa4c5a562b
https://github.com/pelletier/go-buffruneio/blob/25c428535bd3f55a16f149a9daebd3fa4c5a562b/buffruneio.go#L95-L99
143,391
pelletier/go-buffruneio
buffruneio.go
PeekRunes
func (rd *Reader) PeekRunes(n int) []rune { for len(rd.buffer)-rd.current < n && !rd.haveEOF() { if err := rd.feedBuffer(); err != nil { break } } res := make([]rune, 0, n) for i := 0; i < n; i++ { if rd.current + i >= len(rd.buffer) { // reached end of buffer before reading as much as we wanted bre...
go
func (rd *Reader) PeekRunes(n int) []rune { for len(rd.buffer)-rd.current < n && !rd.haveEOF() { if err := rd.feedBuffer(); err != nil { break } } res := make([]rune, 0, n) for i := 0; i < n; i++ { if rd.current + i >= len(rd.buffer) { // reached end of buffer before reading as much as we wanted bre...
[ "func", "(", "rd", "*", "Reader", ")", "PeekRunes", "(", "n", "int", ")", "[", "]", "rune", "{", "for", "len", "(", "rd", ".", "buffer", ")", "-", "rd", ".", "current", "<", "n", "&&", "!", "rd", ".", "haveEOF", "(", ")", "{", "if", "err", ...
// PeekRunes returns the next n runes in the input, // without advancing the current input position. // // If the input has fewer than n runes and then returns // an io.EOF error, PeekRune returns a slice containing // the available runes followed by EOF. // On other hand, if the input ends early with a non-io.EOF erro...
[ "PeekRunes", "returns", "the", "next", "n", "runes", "in", "the", "input", "without", "advancing", "the", "current", "input", "position", ".", "If", "the", "input", "has", "fewer", "than", "n", "runes", "and", "then", "returns", "an", "io", ".", "EOF", "...
25c428535bd3f55a16f149a9daebd3fa4c5a562b
https://github.com/pelletier/go-buffruneio/blob/25c428535bd3f55a16f149a9daebd3fa4c5a562b/buffruneio.go#L110-L133
143,392
containerd/typeurl
types.go
TypeURL
func TypeURL(v interface{}) (string, error) { mu.Lock() u, ok := registry[tryDereference(v)] mu.Unlock() if !ok { // fallback to the proto registry if it is a proto message pb, ok := v.(proto.Message) if !ok { return "", errors.Wrapf(ErrNotFound, "type %s", reflect.TypeOf(v)) } return proto.MessageName...
go
func TypeURL(v interface{}) (string, error) { mu.Lock() u, ok := registry[tryDereference(v)] mu.Unlock() if !ok { // fallback to the proto registry if it is a proto message pb, ok := v.(proto.Message) if !ok { return "", errors.Wrapf(ErrNotFound, "type %s", reflect.TypeOf(v)) } return proto.MessageName...
[ "func", "TypeURL", "(", "v", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "mu", ".", "Lock", "(", ")", "\n", "u", ",", "ok", ":=", "registry", "[", "tryDereference", "(", "v", ")", "]", "\n", "mu", ".", "Unlock", "(", ")",...
// TypeURL returns the type url for a registred type
[ "TypeURL", "returns", "the", "type", "url", "for", "a", "registred", "type" ]
2a93cfde8c20b23de8eb84a5adbc234ddf7a9e8d
https://github.com/containerd/typeurl/blob/2a93cfde8c20b23de8eb84a5adbc234ddf7a9e8d/types.go#L55-L68
143,393
mixer/clock
mock.go
Now
func (m *MockClock) Now() time.Time { m.cond.L.Lock() defer m.cond.L.Unlock() return m.now }
go
func (m *MockClock) Now() time.Time { m.cond.L.Lock() defer m.cond.L.Unlock() return m.now }
[ "func", "(", "m", "*", "MockClock", ")", "Now", "(", ")", "time", ".", "Time", "{", "m", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "return", "m", ".", "now", "\...
// Now returns the current local time.
[ "Now", "returns", "the", "current", "local", "time", "." ]
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L21-L26
143,394
mixer/clock
mock.go
After
func (m *MockClock) After(d time.Duration) <-chan time.Time { ch := make(chan time.Time, 1) target := m.Now().Add(d) go func() { for { m.cond.L.Lock() if !target.After(m.now) { now := m.now m.cond.L.Unlock() ch <- now return } m.cond.Wait() m.cond.L.Unlock() } }() return ch }
go
func (m *MockClock) After(d time.Duration) <-chan time.Time { ch := make(chan time.Time, 1) target := m.Now().Add(d) go func() { for { m.cond.L.Lock() if !target.After(m.now) { now := m.now m.cond.L.Unlock() ch <- now return } m.cond.Wait() m.cond.L.Unlock() } }() return ch }
[ "func", "(", "m", "*", "MockClock", ")", "After", "(", "d", "time", ".", "Duration", ")", "<-", "chan", "time", ".", "Time", "{", "ch", ":=", "make", "(", "chan", "time", ".", "Time", ",", "1", ")", "\n", "target", ":=", "m", ".", "Now", "(", ...
// After waits for the duration to elapse and then sends the current time on the returned channel.
[ "After", "waits", "for", "the", "duration", "to", "elapse", "and", "then", "sends", "the", "current", "time", "on", "the", "returned", "channel", "." ]
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L29-L49
143,395
mixer/clock
mock.go
Tick
func (m *MockClock) Tick(d time.Duration) <-chan time.Time { return m.NewTicker(d).Chan() }
go
func (m *MockClock) Tick(d time.Duration) <-chan time.Time { return m.NewTicker(d).Chan() }
[ "func", "(", "m", "*", "MockClock", ")", "Tick", "(", "d", "time", ".", "Duration", ")", "<-", "chan", "time", ".", "Time", "{", "return", "m", ".", "NewTicker", "(", "d", ")", ".", "Chan", "(", ")", "\n", "}" ]
// Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks".
[ "Tick", "is", "a", "convenience", "wrapper", "for", "NewTicker", "providing", "access", "to", "the", "ticking", "channel", "only", ".", "While", "Tick", "is", "useful", "for", "clients", "that", "have", "no", "need", "to", "shut", "down", "the", "Ticker", ...
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L57-L59
143,396
mixer/clock
mock.go
NewTimer
func (m *MockClock) NewTimer(d time.Duration) Timer { t := NewMockTimer(m) t.Reset(d) return t }
go
func (m *MockClock) NewTimer(d time.Duration) Timer { t := NewMockTimer(m) t.Reset(d) return t }
[ "func", "(", "m", "*", "MockClock", ")", "NewTimer", "(", "d", "time", ".", "Duration", ")", "Timer", "{", "t", ":=", "NewMockTimer", "(", "m", ")", "\n", "t", ".", "Reset", "(", "d", ")", "\n", "return", "t", "\n", "}" ]
// NewTimer creates a new mock Timer that will send the current time on its channel after at least duration d.
[ "NewTimer", "creates", "a", "new", "mock", "Timer", "that", "will", "send", "the", "current", "time", "on", "its", "channel", "after", "at", "least", "duration", "d", "." ]
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L73-L77
143,397
mixer/clock
mock.go
Since
func (m *MockClock) Since(t time.Time) time.Duration { return m.Now().Sub(t) }
go
func (m *MockClock) Since(t time.Time) time.Duration { return m.Now().Sub(t) }
[ "func", "(", "m", "*", "MockClock", ")", "Since", "(", "t", "time", ".", "Time", ")", "time", ".", "Duration", "{", "return", "m", ".", "Now", "(", ")", ".", "Sub", "(", "t", ")", "\n", "}" ]
// Since returns the time elapsed since t.
[ "Since", "returns", "the", "time", "elapsed", "since", "t", "." ]
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L86-L88
143,398
mixer/clock
mock.go
SetTime
func (m *MockClock) SetTime(t time.Time) { m.cond.L.Lock() defer m.cond.L.Unlock() assertFuture(m.now, t) m.now = t m.cond.Broadcast() }
go
func (m *MockClock) SetTime(t time.Time) { m.cond.L.Lock() defer m.cond.L.Unlock() assertFuture(m.now, t) m.now = t m.cond.Broadcast() }
[ "func", "(", "m", "*", "MockClock", ")", "SetTime", "(", "t", "time", ".", "Time", ")", "{", "m", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "assertFuture", "(", "...
// SetTime sets the mock clock's time to the given absolute time.
[ "SetTime", "sets", "the", "mock", "clock", "s", "time", "to", "the", "given", "absolute", "time", "." ]
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L91-L98
143,399
mixer/clock
mock.go
AddTime
func (m *MockClock) AddTime(d time.Duration) { m.cond.L.Lock() defer m.cond.L.Unlock() assertFuture(m.now, m.now.Add(d)) m.now = m.now.Add(d) m.cond.Broadcast() }
go
func (m *MockClock) AddTime(d time.Duration) { m.cond.L.Lock() defer m.cond.L.Unlock() assertFuture(m.now, m.now.Add(d)) m.now = m.now.Add(d) m.cond.Broadcast() }
[ "func", "(", "m", "*", "MockClock", ")", "AddTime", "(", "d", "time", ".", "Duration", ")", "{", "m", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "cond", ".", "L", ".", "Unlock", "(", ")", "\n\n", "assertFuture", "(",...
// AddTime adds the given time duration to the clock.
[ "AddTime", "adds", "the", "given", "time", "duration", "to", "the", "clock", "." ]
baedf07da667049457ab9dca9218b263b113964b
https://github.com/mixer/clock/blob/baedf07da667049457ab9dca9218b263b113964b/mock.go#L101-L108