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
154,100
pdf/golifx
protocol/v2.go
GetLocations
func (p *V2) GetLocations() ([]common.Location, error) { p.RLock() defer p.RUnlock() if len(p.locations) == 0 { return nil, common.ErrNotFound } locations := make([]common.Location, len(p.locations)) i := 0 for _, location := range p.locations { locations[i] = location i++ } return locations, nil }
go
func (p *V2) GetLocations() ([]common.Location, error) { p.RLock() defer p.RUnlock() if len(p.locations) == 0 { return nil, common.ErrNotFound } locations := make([]common.Location, len(p.locations)) i := 0 for _, location := range p.locations { locations[i] = location i++ } return locations, nil }
[ "func", "(", "p", "*", "V2", ")", "GetLocations", "(", ")", "(", "[", "]", "common", ".", "Location", ",", "error", ")", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "if", "len", "(", "p", ".", "locati...
// GetLocations returns a slice of all locations known to the protocol, or // common.ErrNotFound if no locations are currently known.
[ "GetLocations", "returns", "a", "slice", "of", "all", "locations", "known", "to", "the", "protocol", "or", "common", ".", "ErrNotFound", "if", "no", "locations", "are", "currently", "known", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L305-L319
154,101
pdf/golifx
protocol/v2.go
GetDevices
func (p *V2) GetDevices() ([]common.Device, error) { p.RLock() defer p.RUnlock() if len(p.devices) == 0 { return nil, common.ErrNotFound } devices := make([]common.Device, len(p.devices)) i := 0 for _, device := range p.devices { devices[i] = device i++ } return devices, nil }
go
func (p *V2) GetDevices() ([]common.Device, error) { p.RLock() defer p.RUnlock() if len(p.devices) == 0 { return nil, common.ErrNotFound } devices := make([]common.Device, len(p.devices)) i := 0 for _, device := range p.devices { devices[i] = device i++ } return devices, nil }
[ "func", "(", "p", "*", "V2", ")", "GetDevices", "(", ")", "(", "[", "]", "common", ".", "Device", ",", "error", ")", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "if", "len", "(", "p", ".", "devices", ...
// GetDevices returns a slice of all devices known to the protocol, or // common.ErrNotFound if no devices are currently known.
[ "GetDevices", "returns", "a", "slice", "of", "all", "devices", "known", "to", "the", "protocol", "or", "common", ".", "ErrNotFound", "if", "no", "devices", "are", "currently", "known", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L341-L355
154,102
pdf/golifx
protocol/v2.go
classifyDevice
func (p *V2) classifyDevice(dev device.GenericDevice) device.GenericDevice { common.Log.Debugf("Attempting to determine device type for: %d", dev.ID()) product, err := dev.GetProduct() if err != nil { common.Log.Errorf("Error retrieving device hardware product: %v", err) return dev } defer dev.SetProvisional(false) if product == nil { common.Log.Debugf("Unknown product: %d", dev.ID()) return dev } if product.Supports(device.FeatureLight) { p.Lock() d := dev.(*device.Device) d.Lock() l := &device.Light{Device: d} common.Log.Debugf("Device is a light: %d", l.ID()) // Replace the known dev with our constructed light p.devices[l.ID()] = l d.Unlock() p.Unlock() return l } common.Log.Debugf("Device is not a light: %d", dev.ID()) return dev }
go
func (p *V2) classifyDevice(dev device.GenericDevice) device.GenericDevice { common.Log.Debugf("Attempting to determine device type for: %d", dev.ID()) product, err := dev.GetProduct() if err != nil { common.Log.Errorf("Error retrieving device hardware product: %v", err) return dev } defer dev.SetProvisional(false) if product == nil { common.Log.Debugf("Unknown product: %d", dev.ID()) return dev } if product.Supports(device.FeatureLight) { p.Lock() d := dev.(*device.Device) d.Lock() l := &device.Light{Device: d} common.Log.Debugf("Device is a light: %d", l.ID()) // Replace the known dev with our constructed light p.devices[l.ID()] = l d.Unlock() p.Unlock() return l } common.Log.Debugf("Device is not a light: %d", dev.ID()) return dev }
[ "func", "(", "p", "*", "V2", ")", "classifyDevice", "(", "dev", "device", ".", "GenericDevice", ")", "device", ".", "GenericDevice", "{", "common", ".", "Log", ".", "Debugf", "(", "\"", "\"", ",", "dev", ".", "ID", "(", ")", ")", "\n", "product", "...
// classifyDevice either constructs a device.Light from the passed dev, or returns // the dev untouched
[ "classifyDevice", "either", "constructs", "a", "device", ".", "Light", "from", "the", "passed", "dev", "or", "returns", "the", "dev", "untouched" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L639-L669
154,103
pdf/golifx
protocol/v2/device/device.go
Close
func (d *Device) Close() error { d.Lock() defer d.Unlock() select { case <-d.quitChan: return common.ErrClosed default: close(d.quitChan) for seq, res := range d.responseMap { select { case res.ch <- &packet.Response{Error: common.ErrClosed}: case <-res.done: default: close(res.done) } res.wg.Wait() close(res.ch) delete(d.responseMap, seq) } } return d.SubscriptionProvider.Close() }
go
func (d *Device) Close() error { d.Lock() defer d.Unlock() select { case <-d.quitChan: return common.ErrClosed default: close(d.quitChan) for seq, res := range d.responseMap { select { case res.ch <- &packet.Response{Error: common.ErrClosed}: case <-res.done: default: close(res.done) } res.wg.Wait() close(res.ch) delete(d.responseMap, seq) } } return d.SubscriptionProvider.Close() }
[ "func", "(", "d", "*", "Device", ")", "Close", "(", ")", "error", "{", "d", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "Unlock", "(", ")", "\n\n", "select", "{", "case", "<-", "d", ".", "quitChan", ":", "return", "common", ".", "ErrClosed", ...
// Close cleans up Device resources
[ "Close", "cleans", "up", "Device", "resources" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2/device/device.go#L717-L740
154,104
nickvanw/ircx
sender.go
Send
func (m serverSender) Send(msg *irc.Message) error { level.Debug(m.logger()).Log("action", "send", "message", msg.String()) return m.writer.Encode(msg) }
go
func (m serverSender) Send(msg *irc.Message) error { level.Debug(m.logger()).Log("action", "send", "message", msg.String()) return m.writer.Encode(msg) }
[ "func", "(", "m", "serverSender", ")", "Send", "(", "msg", "*", "irc", ".", "Message", ")", "error", "{", "level", ".", "Debug", "(", "m", ".", "logger", "(", ")", ")", ".", "Log", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "msg"...
// Send sends the specified message
[ "Send", "sends", "the", "specified", "message" ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/sender.go#L24-L27
154,105
d2g/dhcp4server
server.go
New
func New(ip net.IP, l leasepool.LeasePool, options ...func(*Server) error) (*Server, error) { s := Server{ ip: ip, defaultGateway: ip, dnsServers: []net.IP{net.IPv4(208, 67, 222, 222), net.IPv4(208, 67, 220, 220)}, //OPENDNS subnetMask: net.IPv4(255, 255, 255, 0), leaseDuration: 24 * time.Hour, leasePool: l, laddr: net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 67}, raddr: net.UDPAddr{IP: net.IPv4bcast, Port: 68}, } err := s.setOptions(options...) if err != nil { return &s, err } return &s, err }
go
func New(ip net.IP, l leasepool.LeasePool, options ...func(*Server) error) (*Server, error) { s := Server{ ip: ip, defaultGateway: ip, dnsServers: []net.IP{net.IPv4(208, 67, 222, 222), net.IPv4(208, 67, 220, 220)}, //OPENDNS subnetMask: net.IPv4(255, 255, 255, 0), leaseDuration: 24 * time.Hour, leasePool: l, laddr: net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 67}, raddr: net.UDPAddr{IP: net.IPv4bcast, Port: 68}, } err := s.setOptions(options...) if err != nil { return &s, err } return &s, err }
[ "func", "New", "(", "ip", "net", ".", "IP", ",", "l", "leasepool", ".", "LeasePool", ",", "options", "...", "func", "(", "*", "Server", ")", "error", ")", "(", "*", "Server", ",", "error", ")", "{", "s", ":=", "Server", "{", "ip", ":", "ip", ",...
// Create A New Server
[ "Create", "A", "New", "Server" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L46-L64
154,106
d2g/dhcp4server
server.go
IP
func IP(i net.IP) func(*Server) error { return func(s *Server) error { s.ip = i return nil } return nil }
go
func IP(i net.IP) func(*Server) error { return func(s *Server) error { s.ip = i return nil } return nil }
[ "func", "IP", "(", "i", "net", ".", "IP", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "ip", "=", "i", "\n", "return", "nil", "\n", "}", "\n", "return", "nil", "\n...
// Set the Server IP
[ "Set", "the", "Server", "IP" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L76-L82
154,107
d2g/dhcp4server
server.go
DefaultGateway
func DefaultGateway(r net.IP) func(*Server) error { return func(s *Server) error { s.defaultGateway = r return nil } }
go
func DefaultGateway(r net.IP) func(*Server) error { return func(s *Server) error { s.defaultGateway = r return nil } }
[ "func", "DefaultGateway", "(", "r", "net", ".", "IP", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "defaultGateway", "=", "r", "\n", "return", "nil", "\n", "}", "\n", ...
// Set the Default Gateway Address.
[ "Set", "the", "Default", "Gateway", "Address", "." ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L85-L90
154,108
d2g/dhcp4server
server.go
DNSServers
func DNSServers(dnss []net.IP) func(*Server) error { return func(s *Server) error { s.dnsServers = dnss return nil } }
go
func DNSServers(dnss []net.IP) func(*Server) error { return func(s *Server) error { s.dnsServers = dnss return nil } }
[ "func", "DNSServers", "(", "dnss", "[", "]", "net", ".", "IP", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "dnsServers", "=", "dnss", "\n", "return", "nil", "\n", "}"...
// Set the DNS servers.
[ "Set", "the", "DNS", "servers", "." ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L93-L98
154,109
d2g/dhcp4server
server.go
SubnetMask
func SubnetMask(m net.IP) func(*Server) error { return func(s *Server) error { s.subnetMask = m return nil } }
go
func SubnetMask(m net.IP) func(*Server) error { return func(s *Server) error { s.subnetMask = m return nil } }
[ "func", "SubnetMask", "(", "m", "net", ".", "IP", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "subnetMask", "=", "m", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Set the Subnet Mask
[ "Set", "the", "Subnet", "Mask" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L101-L106
154,110
d2g/dhcp4server
server.go
LeaseDuration
func LeaseDuration(d time.Duration) func(*Server) error { return func(s *Server) error { s.leaseDuration = d return nil } }
go
func LeaseDuration(d time.Duration) func(*Server) error { return func(s *Server) error { s.leaseDuration = d return nil } }
[ "func", "LeaseDuration", "(", "d", "time", ".", "Duration", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "leaseDuration", "=", "d", "\n", "return", "nil", "\n", "}", "\n...
// Set Lease Duration
[ "Set", "Lease", "Duration" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L109-L114
154,111
d2g/dhcp4server
server.go
IgnoreIPs
func IgnoreIPs(ips []net.IP) func(*Server) error { return func(s *Server) error { s.ignoreIPs = ips return nil } }
go
func IgnoreIPs(ips []net.IP) func(*Server) error { return func(s *Server) error { s.ignoreIPs = ips return nil } }
[ "func", "IgnoreIPs", "(", "ips", "[", "]", "net", ".", "IP", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "ignoreIPs", "=", "ips", "\n", "return", "nil", "\n", "}", ...
// Set Ignore IPs
[ "Set", "Ignore", "IPs" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L117-L122
154,112
d2g/dhcp4server
server.go
IgnoreHardwareAddresses
func IgnoreHardwareAddresses(h []net.HardwareAddr) func(*Server) error { return func(s *Server) error { s.ignoreHardwareAddress = h return nil } }
go
func IgnoreHardwareAddresses(h []net.HardwareAddr) func(*Server) error { return func(s *Server) error { s.ignoreHardwareAddress = h return nil } }
[ "func", "IgnoreHardwareAddresses", "(", "h", "[", "]", "net", ".", "HardwareAddr", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "ignoreHardwareAddress", "=", "h", "\n", "ret...
// Set Ignore Hardware Addresses
[ "Set", "Ignore", "Hardware", "Addresses" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L125-L130
154,113
d2g/dhcp4server
server.go
SetLocalAddr
func SetLocalAddr(a net.UDPAddr) func(*Server) error { return func(s *Server) error { s.laddr = a return nil } }
go
func SetLocalAddr(a net.UDPAddr) func(*Server) error { return func(s *Server) error { s.laddr = a return nil } }
[ "func", "SetLocalAddr", "(", "a", "net", ".", "UDPAddr", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "laddr", "=", "a", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Set The Local Address
[ "Set", "The", "Local", "Address" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L141-L146
154,114
d2g/dhcp4server
server.go
SetRemoteAddr
func SetRemoteAddr(a net.UDPAddr) func(*Server) error { return func(s *Server) error { s.raddr = a return nil } }
go
func SetRemoteAddr(a net.UDPAddr) func(*Server) error { return func(s *Server) error { s.raddr = a return nil } }
[ "func", "SetRemoteAddr", "(", "a", "net", ".", "UDPAddr", ")", "func", "(", "*", "Server", ")", "error", "{", "return", "func", "(", "s", "*", "Server", ")", "error", "{", "s", ".", "raddr", "=", "a", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Set The Remote Address
[ "Set", "The", "Remote", "Address" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/server.go#L149-L154
154,115
monzo/phosphor-go
client.go
New
func New(configProvider ConfigProvider) (*Phosphor, error) { configProvider.Config().assertInitialized() // // TODO validate config // c := configProvider.Config() p := &Phosphor{ configProvider: configProvider, // initialise traceChan with default length, we'll replace this // asynchronously with one of the correct length on first use traceChan: make(chan []byte, defaultTraceBufferSize), exitChan: make(chan struct{}), } return p, nil }
go
func New(configProvider ConfigProvider) (*Phosphor, error) { configProvider.Config().assertInitialized() // // TODO validate config // c := configProvider.Config() p := &Phosphor{ configProvider: configProvider, // initialise traceChan with default length, we'll replace this // asynchronously with one of the correct length on first use traceChan: make(chan []byte, defaultTraceBufferSize), exitChan: make(chan struct{}), } return p, nil }
[ "func", "New", "(", "configProvider", "ConfigProvider", ")", "(", "*", "Phosphor", ",", "error", ")", "{", "configProvider", ".", "Config", "(", ")", ".", "assertInitialized", "(", ")", "\n\n", "// // TODO validate config", "// c := configProvider.Config()", "p", ...
// New initialises and returns a Phosphor client // This takes a config provider which can be a simple static config, // or a more dynamic configuration loader which watches a remote config source
[ "New", "initialises", "and", "returns", "a", "Phosphor", "client", "This", "takes", "a", "config", "provider", "which", "can", "be", "a", "simple", "static", "config", "or", "a", "more", "dynamic", "configuration", "loader", "which", "watches", "a", "remote", ...
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/client.go#L59-L74
154,116
monzo/phosphor-go
client.go
Send
func (p *Phosphor) Send(a *phos.Annotation) error { // Initialise the tracer on first use p.initOnce.Do(p.init) // Marshal to bytes to be sent on the wire // // We're marshaling this here so that the marshalling can be executed // concurrently by any number of clients before pushing this to a single // worker goroutine for transport // // TODO future versions of this may use a more feature rich wire format b, err := proto.Marshal(a) if err != nil { return err } c := p.configProvider.Config() select { case p.traceChan <- b: case <-time.After(c.SendTimeout): log.Tracef("Timeout after %v attempting to queue trace annotation: %+v", c.SendTimeout, a) return ErrTimeout } return nil }
go
func (p *Phosphor) Send(a *phos.Annotation) error { // Initialise the tracer on first use p.initOnce.Do(p.init) // Marshal to bytes to be sent on the wire // // We're marshaling this here so that the marshalling can be executed // concurrently by any number of clients before pushing this to a single // worker goroutine for transport // // TODO future versions of this may use a more feature rich wire format b, err := proto.Marshal(a) if err != nil { return err } c := p.configProvider.Config() select { case p.traceChan <- b: case <-time.After(c.SendTimeout): log.Tracef("Timeout after %v attempting to queue trace annotation: %+v", c.SendTimeout, a) return ErrTimeout } return nil }
[ "func", "(", "p", "*", "Phosphor", ")", "Send", "(", "a", "*", "phos", ".", "Annotation", ")", "error", "{", "// Initialise the tracer on first use", "p", ".", "initOnce", ".", "Do", "(", "p", ".", "init", ")", "\n\n", "// Marshal to bytes to be sent on the wi...
// Send an annotation to Phosphor
[ "Send", "an", "annotation", "to", "Phosphor" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/client.go#L77-L103
154,117
monzo/phosphor-go
client.go
monitorConfig
func (p *Phosphor) monitorConfig() { configChange := p.configProvider.Notify() configTimer := time.NewTicker(configForceReloadTime) immediate := make(chan struct{}, 1) immediate <- struct{}{} for { select { case <-p.exitChan: configTimer.Stop() return case <-immediate: case <-configChange: case <-configTimer.C: } if err := p.reloadConfig(); err != nil { log.Warnf("[Phosphor] Failed to reload configuration: %v", err) } } }
go
func (p *Phosphor) monitorConfig() { configChange := p.configProvider.Notify() configTimer := time.NewTicker(configForceReloadTime) immediate := make(chan struct{}, 1) immediate <- struct{}{} for { select { case <-p.exitChan: configTimer.Stop() return case <-immediate: case <-configChange: case <-configTimer.C: } if err := p.reloadConfig(); err != nil { log.Warnf("[Phosphor] Failed to reload configuration: %v", err) } } }
[ "func", "(", "p", "*", "Phosphor", ")", "monitorConfig", "(", ")", "{", "configChange", ":=", "p", ".", "configProvider", ".", "Notify", "(", ")", "\n", "configTimer", ":=", "time", ".", "NewTicker", "(", "configForceReloadTime", ")", "\n", "immediate", ":...
// monitorConfig observes the config provider and triggers a reload of the // configuration both when notified of a change and when a minimum time period // has elapsed
[ "monitorConfig", "observes", "the", "config", "provider", "and", "triggers", "a", "reload", "of", "the", "configuration", "both", "when", "notified", "of", "a", "change", "and", "when", "a", "minimum", "time", "period", "has", "elapsed" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/client.go#L115-L134
154,118
monzo/phosphor-go
client.go
reloadConfig
func (p *Phosphor) reloadConfig() error { c := p.configProvider.Config() // Skip reloading if the config is the same h := fmt.Sprintf("%x", deephash.Hash(c)) if p.compareConfigHash(h) { return nil } // keep reference to the old channel so we can drain this in parallel with // new traces the transport receives oldChan := p.traceChan // init new channel for traces, ensure this *isn't* zero bufLen := c.BufferSize if bufLen == 0 { bufLen = defaultTraceBufferSize } newChan := make(chan []byte, bufLen) // Get a new transport and keep a reference to the old one p.trMtx.Lock() defer p.trMtx.Unlock() oldTr := p.tr endpoint := fmt.Sprintf("%s:%v", c.Host, c.Port) newTr := newUDPTransport(endpoint) // start new transport by passing both channels to this // therefore it starts consuming from the new one (with nothing) // and also the old one (still current) in parallel to the previous transport // If this somehow fails, abort until next attempt if err := newTr.Consume(oldChan, newChan); err != nil { newTr.Stop() return err } // swap the client reference of the trace channel from old to new, so // new clients start using the new resized channel // TODO atomically swap this p.traceChan = newChan // gracefully shut down old transport, so just the new one is running if oldTr != nil { if err := oldTr.Stop(); err != nil { return err } } // set the config hash & swap the transport as we're finished p.updateConfigHash(h) p.tr = newTr return nil }
go
func (p *Phosphor) reloadConfig() error { c := p.configProvider.Config() // Skip reloading if the config is the same h := fmt.Sprintf("%x", deephash.Hash(c)) if p.compareConfigHash(h) { return nil } // keep reference to the old channel so we can drain this in parallel with // new traces the transport receives oldChan := p.traceChan // init new channel for traces, ensure this *isn't* zero bufLen := c.BufferSize if bufLen == 0 { bufLen = defaultTraceBufferSize } newChan := make(chan []byte, bufLen) // Get a new transport and keep a reference to the old one p.trMtx.Lock() defer p.trMtx.Unlock() oldTr := p.tr endpoint := fmt.Sprintf("%s:%v", c.Host, c.Port) newTr := newUDPTransport(endpoint) // start new transport by passing both channels to this // therefore it starts consuming from the new one (with nothing) // and also the old one (still current) in parallel to the previous transport // If this somehow fails, abort until next attempt if err := newTr.Consume(oldChan, newChan); err != nil { newTr.Stop() return err } // swap the client reference of the trace channel from old to new, so // new clients start using the new resized channel // TODO atomically swap this p.traceChan = newChan // gracefully shut down old transport, so just the new one is running if oldTr != nil { if err := oldTr.Stop(); err != nil { return err } } // set the config hash & swap the transport as we're finished p.updateConfigHash(h) p.tr = newTr return nil }
[ "func", "(", "p", "*", "Phosphor", ")", "reloadConfig", "(", ")", "error", "{", "c", ":=", "p", ".", "configProvider", ".", "Config", "(", ")", "\n\n", "// Skip reloading if the config is the same", "h", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", ...
// reloadConfig and reinitialise phosphor client if necessary // // Get Config // Test hash of config to determine if changed // If so, update config & reinit
[ "reloadConfig", "and", "reinitialise", "phosphor", "client", "if", "necessary", "Get", "Config", "Test", "hash", "of", "config", "to", "determine", "if", "changed", "If", "so", "update", "config", "&", "reinit" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/client.go#L154-L207
154,119
jbooth/flotilla
env.go
readTxn
func (e *env) readTxn() (*mdb.Txn, error) { e.l.Lock() defer e.l.Unlock() if e.shouldClose { // should never happen return nil, fmt.Errorf("Environment is marked as closing, no new txns allowed!") } t, err := e.e.BeginTxn(nil, mdb.RDONLY) if err != nil { return nil, err } e.numOpen++ return t, nil }
go
func (e *env) readTxn() (*mdb.Txn, error) { e.l.Lock() defer e.l.Unlock() if e.shouldClose { // should never happen return nil, fmt.Errorf("Environment is marked as closing, no new txns allowed!") } t, err := e.e.BeginTxn(nil, mdb.RDONLY) if err != nil { return nil, err } e.numOpen++ return t, nil }
[ "func", "(", "e", "*", "env", ")", "readTxn", "(", ")", "(", "*", "mdb", ".", "Txn", ",", "error", ")", "{", "e", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "l", ".", "Unlock", "(", ")", "\n", "if", "e", ".", "shouldClose", ...
// opens a read transaction,
[ "opens", "a", "read", "transaction" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/env.go#L39-L52
154,120
jbooth/flotilla
env.go
writeTxn
func (e *env) writeTxn() (*mdb.Txn, error) { e.l.Lock() defer e.l.Unlock() if e.shouldClose { // should never happen return nil, fmt.Errorf("Environment is marked as closing, no new txns allowed!") } t, err := e.e.BeginTxn(nil, 0) if err != nil { return nil, err } return t, nil }
go
func (e *env) writeTxn() (*mdb.Txn, error) { e.l.Lock() defer e.l.Unlock() if e.shouldClose { // should never happen return nil, fmt.Errorf("Environment is marked as closing, no new txns allowed!") } t, err := e.e.BeginTxn(nil, 0) if err != nil { return nil, err } return t, nil }
[ "func", "(", "e", "*", "env", ")", "writeTxn", "(", ")", "(", "*", "mdb", ".", "Txn", ",", "error", ")", "{", "e", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "l", ".", "Unlock", "(", ")", "\n", "if", "e", ".", "shouldClose", ...
// opens a write transaction, we don't track numOpen with these because // it shouldn't be called at the same time as a snapshot
[ "opens", "a", "write", "transaction", "we", "don", "t", "track", "numOpen", "with", "these", "because", "it", "shouldn", "t", "be", "called", "at", "the", "same", "time", "as", "a", "snapshot" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/env.go#L56-L68
154,121
jbooth/flotilla
env.go
CloseTransaction
func (e *env) CloseTransaction(t *mdb.Txn) error { t.Abort() // ignore error e.l.Lock() defer e.l.Unlock() e.numOpen-- if e.shouldClose && e.numOpen == 0 && !e.closed { e.e.Close() e.closed = true } e.e.Close() return nil }
go
func (e *env) CloseTransaction(t *mdb.Txn) error { t.Abort() // ignore error e.l.Lock() defer e.l.Unlock() e.numOpen-- if e.shouldClose && e.numOpen == 0 && !e.closed { e.e.Close() e.closed = true } e.e.Close() return nil }
[ "func", "(", "e", "*", "env", ")", "CloseTransaction", "(", "t", "*", "mdb", ".", "Txn", ")", "error", "{", "t", ".", "Abort", "(", ")", "// ignore error", "\n", "e", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "l", ".", "Unlock",...
// aborts transactionsuppressing any errors, and frees
[ "aborts", "transactionsuppressing", "any", "errors", "and", "frees" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/env.go#L71-L82
154,122
jbooth/flotilla
env.go
Close
func (e *env) Close() error { e.l.Lock() defer e.l.Unlock() e.shouldClose = true e.e.Sync(1) e.e.Close() return nil }
go
func (e *env) Close() error { e.l.Lock() defer e.l.Unlock() e.shouldClose = true e.e.Sync(1) e.e.Close() return nil }
[ "func", "(", "e", "*", "env", ")", "Close", "(", ")", "error", "{", "e", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "l", ".", "Unlock", "(", ")", "\n", "e", ".", "shouldClose", "=", "true", "\n", "e", ".", "e", ".", "Sync", ...
// marks this env as pending-closed. closing the last open transaction will close // env handle
[ "marks", "this", "env", "as", "pending", "-", "closed", ".", "closing", "the", "last", "open", "transaction", "will", "close", "env", "handle" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/env.go#L86-L93
154,123
nuagenetworks/libvrsdk
ovsdb/NuageTable.go
InsertRow
func (nuageTable *NuageTable) InsertRow(ovs *libovsdb.OvsdbClient, row NuageTableRow) error { glog.V(2).Infof("Trying to insert (%+v) into the Nuage Table (%s)", row, nuageTable.TableName) ovsdbRow := make(map[string]interface{}) err := row.CreateOVSDBRow(ovsdbRow) if err != nil { glog.Errorf("Unable to create the OVSDB row %v", err) return err } insertOp := libovsdb.Operation{ Op: "insert", Table: nuageTable.TableName, Row: ovsdbRow, UUIDName: "gopher", } operations := []libovsdb.Operation{insertOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { errStr := fmt.Errorf("Problem inserting row in the Nuage table row = "+ " (%+v) ovsdbrow (%+v) err (%+v) reply (%+v)", row, ovsdbRow, err, reply) glog.Error(errStr) return (errStr) } glog.V(2).Info("Insertion into Nuage VM Table succeeded with UUID %s", reply[0].UUID) return nil }
go
func (nuageTable *NuageTable) InsertRow(ovs *libovsdb.OvsdbClient, row NuageTableRow) error { glog.V(2).Infof("Trying to insert (%+v) into the Nuage Table (%s)", row, nuageTable.TableName) ovsdbRow := make(map[string]interface{}) err := row.CreateOVSDBRow(ovsdbRow) if err != nil { glog.Errorf("Unable to create the OVSDB row %v", err) return err } insertOp := libovsdb.Operation{ Op: "insert", Table: nuageTable.TableName, Row: ovsdbRow, UUIDName: "gopher", } operations := []libovsdb.Operation{insertOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { errStr := fmt.Errorf("Problem inserting row in the Nuage table row = "+ " (%+v) ovsdbrow (%+v) err (%+v) reply (%+v)", row, ovsdbRow, err, reply) glog.Error(errStr) return (errStr) } glog.V(2).Info("Insertion into Nuage VM Table succeeded with UUID %s", reply[0].UUID) return nil }
[ "func", "(", "nuageTable", "*", "NuageTable", ")", "InsertRow", "(", "ovs", "*", "libovsdb", ".", "OvsdbClient", ",", "row", "NuageTableRow", ")", "error", "{", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\"", ",", "row", ",", "nuageTa...
// InsertRow enables insertion of a row into the Nuage OVSDB table
[ "InsertRow", "enables", "insertion", "of", "a", "row", "into", "the", "Nuage", "OVSDB", "table" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageTable.go#L18-L51
154,124
nuagenetworks/libvrsdk
ovsdb/NuageTable.go
ReadRows
func (nuageTable *NuageTable) ReadRows(ovs *libovsdb.OvsdbClient, readRowArgs ReadRowArgs) ([]map[string]interface{}, error) { condition := readRowArgs.Condition columns := readRowArgs.Columns glog.V(2).Infof("Reading rows from table %s with condition (%+v)", nuageTable.TableName, condition) var selectOp libovsdb.Operation if len(condition) == 3 { ovsdbCondition := libovsdb.NewCondition(condition[0], condition[1], condition[2]) if columns == nil { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Where: []interface{}{ovsdbCondition}, } } else { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Where: []interface{}{ovsdbCondition}, Columns: columns, } } } else { if columns == nil { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Where: []interface{}{}, } } else { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Columns: columns, Where: []interface{}{}, } } } operations := []libovsdb.Operation{selectOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { glog.Errorf("Problem reading row from the Nuage table %s %v %+v", nuageTable.TableName, err, reply) return nil, fmt.Errorf("Problem reading row from the Nuage table %s %v", nuageTable.TableName, err) } return reply[0].Rows, nil }
go
func (nuageTable *NuageTable) ReadRows(ovs *libovsdb.OvsdbClient, readRowArgs ReadRowArgs) ([]map[string]interface{}, error) { condition := readRowArgs.Condition columns := readRowArgs.Columns glog.V(2).Infof("Reading rows from table %s with condition (%+v)", nuageTable.TableName, condition) var selectOp libovsdb.Operation if len(condition) == 3 { ovsdbCondition := libovsdb.NewCondition(condition[0], condition[1], condition[2]) if columns == nil { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Where: []interface{}{ovsdbCondition}, } } else { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Where: []interface{}{ovsdbCondition}, Columns: columns, } } } else { if columns == nil { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Where: []interface{}{}, } } else { selectOp = libovsdb.Operation{ Op: "select", Table: nuageTable.TableName, Columns: columns, Where: []interface{}{}, } } } operations := []libovsdb.Operation{selectOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { glog.Errorf("Problem reading row from the Nuage table %s %v %+v", nuageTable.TableName, err, reply) return nil, fmt.Errorf("Problem reading row from the Nuage table %s %v", nuageTable.TableName, err) } return reply[0].Rows, nil }
[ "func", "(", "nuageTable", "*", "NuageTable", ")", "ReadRows", "(", "ovs", "*", "libovsdb", ".", "OvsdbClient", ",", "readRowArgs", "ReadRowArgs", ")", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "condition", ...
// ReadRows enables reading of multiple rows from a Nuage OVSDB table.
[ "ReadRows", "enables", "reading", "of", "multiple", "rows", "from", "a", "Nuage", "OVSDB", "table", "." ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageTable.go#L60-L116
154,125
nuagenetworks/libvrsdk
ovsdb/NuageTable.go
DeleteRow
func (nuageTable *NuageTable) DeleteRow(ovs *libovsdb.OvsdbClient, condition []string) error { glog.V(2).Infof("Delete from table %s with condition (%+v)", nuageTable.TableName, condition) if len(condition) != 3 { glog.Errorf("Invalid condition %v", condition) return fmt.Errorf("Invalid condition") } ovsdbCondition := libovsdb.NewCondition(condition[0], condition[1], condition[2]) deleteOp := libovsdb.Operation{ Op: "delete", Table: nuageTable.TableName, Where: []interface{}{ovsdbCondition}, } operations := []libovsdb.Operation{deleteOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { errStr := fmt.Sprintf("Problem deleting row from the Nuage table %s (%+v) (%+v) (%+v)", nuageTable.TableName, ovsdbCondition, err, reply) glog.Errorf(errStr) return fmt.Errorf(errStr) } if reply[0].Count != 1 { glog.Errorf("Did not delete a Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) return fmt.Errorf("Did not delete a Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) } return nil }
go
func (nuageTable *NuageTable) DeleteRow(ovs *libovsdb.OvsdbClient, condition []string) error { glog.V(2).Infof("Delete from table %s with condition (%+v)", nuageTable.TableName, condition) if len(condition) != 3 { glog.Errorf("Invalid condition %v", condition) return fmt.Errorf("Invalid condition") } ovsdbCondition := libovsdb.NewCondition(condition[0], condition[1], condition[2]) deleteOp := libovsdb.Operation{ Op: "delete", Table: nuageTable.TableName, Where: []interface{}{ovsdbCondition}, } operations := []libovsdb.Operation{deleteOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { errStr := fmt.Sprintf("Problem deleting row from the Nuage table %s (%+v) (%+v) (%+v)", nuageTable.TableName, ovsdbCondition, err, reply) glog.Errorf(errStr) return fmt.Errorf(errStr) } if reply[0].Count != 1 { glog.Errorf("Did not delete a Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) return fmt.Errorf("Did not delete a Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) } return nil }
[ "func", "(", "nuageTable", "*", "NuageTable", ")", "DeleteRow", "(", "ovs", "*", "libovsdb", ".", "OvsdbClient", ",", "condition", "[", "]", "string", ")", "error", "{", "glog", ".", "V", "(", "2", ")", ".", "Infof", "(", "\"", "\"", ",", "nuageTable...
// DeleteRow is use to delete a row from the Nuage OVSDB table
[ "DeleteRow", "is", "use", "to", "delete", "a", "row", "from", "the", "Nuage", "OVSDB", "table" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageTable.go#L172-L207
154,126
nuagenetworks/libvrsdk
ovsdb/NuageTable.go
UpdateRow
func (nuageTable *NuageTable) UpdateRow(ovs *libovsdb.OvsdbClient, ovsdbRow map[string]interface{}, condition []string) error { glog.V(2).Infof("Trying to update the row (%+v) the Nuage Table (%s)", ovsdbRow, nuageTable.TableName) ovsdbCondition := libovsdb.NewCondition(condition[0], condition[1], condition[2]) updateOp := libovsdb.Operation{ Op: "update", Table: nuageTable.TableName, Row: ovsdbRow, Where: []interface{}{ovsdbCondition}, } operations := []libovsdb.Operation{updateOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { glog.Errorf("Failed to update row in the Nuage table %s %v", nuageTable.TableName, err) return fmt.Errorf("Failed to update row in the Nuage table %s %v", nuageTable.TableName, err) } if reply[0].Count != 1 { glog.Errorf("Failed to update the Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) return fmt.Errorf("Failed to update the Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) } return nil }
go
func (nuageTable *NuageTable) UpdateRow(ovs *libovsdb.OvsdbClient, ovsdbRow map[string]interface{}, condition []string) error { glog.V(2).Infof("Trying to update the row (%+v) the Nuage Table (%s)", ovsdbRow, nuageTable.TableName) ovsdbCondition := libovsdb.NewCondition(condition[0], condition[1], condition[2]) updateOp := libovsdb.Operation{ Op: "update", Table: nuageTable.TableName, Row: ovsdbRow, Where: []interface{}{ovsdbCondition}, } operations := []libovsdb.Operation{updateOp} reply, err := ovs.Transact(OvsDBName, operations...) glog.V(2).Infof("reply : (%+v) err : (%+v)", reply, err) if err != nil || len(reply) != 1 || reply[0].Error != "" { glog.Errorf("Failed to update row in the Nuage table %s %v", nuageTable.TableName, err) return fmt.Errorf("Failed to update row in the Nuage table %s %v", nuageTable.TableName, err) } if reply[0].Count != 1 { glog.Errorf("Failed to update the Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) return fmt.Errorf("Failed to update the Nuage Table entry for table %s condition %v", nuageTable.TableName, condition) } return nil }
[ "func", "(", "nuageTable", "*", "NuageTable", ")", "UpdateRow", "(", "ovs", "*", "libovsdb", ".", "OvsdbClient", ",", "ovsdbRow", "map", "[", "string", "]", "interface", "{", "}", ",", "condition", "[", "]", "string", ")", "error", "{", "glog", ".", "V...
// UpdateRow updates the OVSDB table row
[ "UpdateRow", "updates", "the", "OVSDB", "table", "row" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageTable.go#L210-L239
154,127
nuagenetworks/libvrsdk
api/VRSConnection.go
Update
func (vrsConnection VRSConnection) Update(context interface{}, tableUpdates libovsdb.TableUpdates) { vrsConnection.updatesChan <- &tableUpdates }
go
func (vrsConnection VRSConnection) Update(context interface{}, tableUpdates libovsdb.TableUpdates) { vrsConnection.updatesChan <- &tableUpdates }
[ "func", "(", "vrsConnection", "VRSConnection", ")", "Update", "(", "context", "interface", "{", "}", ",", "tableUpdates", "libovsdb", ".", "TableUpdates", ")", "{", "vrsConnection", ".", "updatesChan", "<-", "&", "tableUpdates", "\n", "}" ]
// Update will provide updates on OVSDB table updates
[ "Update", "will", "provide", "updates", "on", "OVSDB", "table", "updates" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/VRSConnection.go#L51-L53
154,128
nuagenetworks/libvrsdk
api/VRSConnection.go
NewUnixSocketConnection
func NewUnixSocketConnection(socketfile string) (VRSConnection, error) { var vrsConnection VRSConnection var err error if vrsConnection.ovsdbClient, err = libovsdb.ConnectWithUnixSocket(socketfile); err != nil { return vrsConnection, err } vrsConnection.vmTable.TableName = ovsdb.NuageVMTable vrsConnection.portTable.TableName = ovsdb.NuagePortTable vrsConnection.pncTable = make(portNameChannelMap) vrsConnection.pnpTable = make(portNamePortInfoMap) vrsConnection.registrationChannel = make(chan *Registration) vrsConnection.updatesChan = make(chan *libovsdb.TableUpdates) vrsConnection.stopChannel = make(chan bool) err = vrsConnection.monitorTable() return vrsConnection, err }
go
func NewUnixSocketConnection(socketfile string) (VRSConnection, error) { var vrsConnection VRSConnection var err error if vrsConnection.ovsdbClient, err = libovsdb.ConnectWithUnixSocket(socketfile); err != nil { return vrsConnection, err } vrsConnection.vmTable.TableName = ovsdb.NuageVMTable vrsConnection.portTable.TableName = ovsdb.NuagePortTable vrsConnection.pncTable = make(portNameChannelMap) vrsConnection.pnpTable = make(portNamePortInfoMap) vrsConnection.registrationChannel = make(chan *Registration) vrsConnection.updatesChan = make(chan *libovsdb.TableUpdates) vrsConnection.stopChannel = make(chan bool) err = vrsConnection.monitorTable() return vrsConnection, err }
[ "func", "NewUnixSocketConnection", "(", "socketfile", "string", ")", "(", "VRSConnection", ",", "error", ")", "{", "var", "vrsConnection", "VRSConnection", "\n", "var", "err", "error", "\n\n", "if", "vrsConnection", ".", "ovsdbClient", ",", "err", "=", "libovsdb...
// NewUnixSocketConnection creates a connection to the VRS Server using Unix sockets
[ "NewUnixSocketConnection", "creates", "a", "connection", "to", "the", "VRS", "Server", "using", "Unix", "sockets" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/VRSConnection.go#L56-L74
154,129
jbooth/flotilla
server.go
NewDefaultDB
func NewDefaultDB(peers []string, dataDir string, bindAddr string, ops map[string]Command) (DefaultOpsDB, error) { laddr, err := net.ResolveTCPAddr("tcp", bindAddr) if err != nil { return nil, err } listen, err := net.ListenTCP("tcp", laddr) if err != nil { return nil, err } db, err := NewDB( peers, dataDir, listen, defaultDialer, ops, log.New(os.Stderr, "flotilla", log.LstdFlags), ) if err != nil { return nil, err } // wrap with standard ops return dbOps{db}, nil }
go
func NewDefaultDB(peers []string, dataDir string, bindAddr string, ops map[string]Command) (DefaultOpsDB, error) { laddr, err := net.ResolveTCPAddr("tcp", bindAddr) if err != nil { return nil, err } listen, err := net.ListenTCP("tcp", laddr) if err != nil { return nil, err } db, err := NewDB( peers, dataDir, listen, defaultDialer, ops, log.New(os.Stderr, "flotilla", log.LstdFlags), ) if err != nil { return nil, err } // wrap with standard ops return dbOps{db}, nil }
[ "func", "NewDefaultDB", "(", "peers", "[", "]", "string", ",", "dataDir", "string", ",", "bindAddr", "string", ",", "ops", "map", "[", "string", "]", "Command", ")", "(", "DefaultOpsDB", ",", "error", ")", "{", "laddr", ",", "err", ":=", "net", ".", ...
// launches a new DB serving out of dataDir
[ "launches", "a", "new", "DB", "serving", "out", "of", "dataDir" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/server.go#L21-L44
154,130
jbooth/flotilla
server.go
NewDB
func NewDB( peers []string, dataDir string, listen net.Listener, dialer func(string, time.Duration) (net.Conn, error), commands map[string]Command, lg *log.Logger) (DB, error) { raftDir := dataDir + "/raft" mdbDir := dataDir + "/mdb" // make sure dirs exist if err := os.MkdirAll(raftDir, 0755); err != nil { return nil, err } if err := os.MkdirAll(dataDir, 0755); err != nil { return nil, err } commandsForStateMachine := defaultCommands() for cmd, cmdExec := range commands { _, ok := commandsForStateMachine[cmd] if ok { lg.Printf("WARNING overriding command %s with user-defined command", cmd) } commandsForStateMachine[cmd] = cmdExec } state, err := newFlotillaState( mdbDir, commandsForStateMachine, listen.Addr().String(), lg, ) if err != nil { return nil, err } streamLayers, err := NewMultiStream(listen, dialer, listen.Addr(), lg, dialCodeRaft, dialCodeFlot) if err != nil { return nil, err } // start raft server raft, err := newRaft(peers, raftDir, streamLayers[dialCodeRaft], state, lg) if err != nil { return nil, err } s := &server{ raft: raft, state: state, peers: peers, rpcLayer: streamLayers[dialCodeFlot], leaderLock: new(sync.Mutex), leaderConn: nil, lg: lg, } // serve followers go s.serveFollowers() return s, nil }
go
func NewDB( peers []string, dataDir string, listen net.Listener, dialer func(string, time.Duration) (net.Conn, error), commands map[string]Command, lg *log.Logger) (DB, error) { raftDir := dataDir + "/raft" mdbDir := dataDir + "/mdb" // make sure dirs exist if err := os.MkdirAll(raftDir, 0755); err != nil { return nil, err } if err := os.MkdirAll(dataDir, 0755); err != nil { return nil, err } commandsForStateMachine := defaultCommands() for cmd, cmdExec := range commands { _, ok := commandsForStateMachine[cmd] if ok { lg.Printf("WARNING overriding command %s with user-defined command", cmd) } commandsForStateMachine[cmd] = cmdExec } state, err := newFlotillaState( mdbDir, commandsForStateMachine, listen.Addr().String(), lg, ) if err != nil { return nil, err } streamLayers, err := NewMultiStream(listen, dialer, listen.Addr(), lg, dialCodeRaft, dialCodeFlot) if err != nil { return nil, err } // start raft server raft, err := newRaft(peers, raftDir, streamLayers[dialCodeRaft], state, lg) if err != nil { return nil, err } s := &server{ raft: raft, state: state, peers: peers, rpcLayer: streamLayers[dialCodeFlot], leaderLock: new(sync.Mutex), leaderConn: nil, lg: lg, } // serve followers go s.serveFollowers() return s, nil }
[ "func", "NewDB", "(", "peers", "[", "]", "string", ",", "dataDir", "string", ",", "listen", "net", ".", "Listener", ",", "dialer", "func", "(", "string", ",", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", ",", "commands", ...
// Instantiates a new DB serving the ops provided, using the provided dataDir and listener // If Peers is empty, we start as the sole leader. Otherwise, connect to the existing leader.
[ "Instantiates", "a", "new", "DB", "serving", "the", "ops", "provided", "using", "the", "provided", "dataDir", "and", "listener", "If", "Peers", "is", "empty", "we", "start", "as", "the", "sole", "leader", ".", "Otherwise", "connect", "to", "the", "existing",...
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/server.go#L48-L102
154,131
jbooth/flotilla
server.go
RemovePeer
func (s *server) RemovePeer(deadPeer net.Addr) error { if s.IsLeader() { return s.raft.RemovePeer(deadPeer).Error() } else { return nil } }
go
func (s *server) RemovePeer(deadPeer net.Addr) error { if s.IsLeader() { return s.raft.RemovePeer(deadPeer).Error() } else { return nil } }
[ "func", "(", "s", "*", "server", ")", "RemovePeer", "(", "deadPeer", "net", ".", "Addr", ")", "error", "{", "if", "s", ".", "IsLeader", "(", ")", "{", "return", "s", ".", "raft", ".", "RemovePeer", "(", "deadPeer", ")", ".", "Error", "(", ")", "\...
// only removes if leader, otherwise returns nil
[ "only", "removes", "if", "leader", "otherwise", "returns", "nil" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/server.go#L194-L200
154,132
jbooth/flotilla
server.go
Command
func (s *server) Command(cmd string, args [][]byte) <-chan Result { if s.IsLeader() { cb := s.state.newCommand() cmdBytes := bytesForCommand(cb.originAddr, cb.reqNo, cmd, args) s.raft.Apply(cmdBytes, commandTimeout) return cb.result } // couldn't exec as leader, fallback to forwarding cb, err := s.dispatchToLeader(cmd, args) if err != nil { if cb != nil { cb.cancel() } ret := make(chan Result, 1) ret <- Result{nil, err} return ret } return cb.result }
go
func (s *server) Command(cmd string, args [][]byte) <-chan Result { if s.IsLeader() { cb := s.state.newCommand() cmdBytes := bytesForCommand(cb.originAddr, cb.reqNo, cmd, args) s.raft.Apply(cmdBytes, commandTimeout) return cb.result } // couldn't exec as leader, fallback to forwarding cb, err := s.dispatchToLeader(cmd, args) if err != nil { if cb != nil { cb.cancel() } ret := make(chan Result, 1) ret <- Result{nil, err} return ret } return cb.result }
[ "func", "(", "s", "*", "server", ")", "Command", "(", "cmd", "string", ",", "args", "[", "]", "[", "]", "byte", ")", "<-", "chan", "Result", "{", "if", "s", ".", "IsLeader", "(", ")", "{", "cb", ":=", "s", ".", "state", ".", "newCommand", "(", ...
// public API, executes a command on leader, returns chan which will // block until command has been replicated to our local replica
[ "public", "API", "executes", "a", "command", "on", "leader", "returns", "chan", "which", "will", "block", "until", "command", "has", "been", "replicated", "to", "our", "local", "replica" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/server.go#L216-L235
154,133
jbooth/flotilla
server.go
dispatchToLeader
func (s *server) dispatchToLeader(cmd string, args [][]byte) (*commandCallback, error) { s.leaderLock.Lock() defer s.leaderLock.Unlock() var err error if s.leaderConn == nil || s.Leader() == nil || s.Leader().String() != s.leaderConn.remoteAddr().String() { if s.leaderConn != nil { s.lg.Printf("Leader changed, reconnecting, was: %s, now %s", s.leaderConn.remoteAddr(), s.Leader()) } // reconnect if s.leaderConn != nil { s.leaderConn.c.Close() } newConn, err := s.rpcLayer.Dial(s.Leader().String(), 1*time.Minute) if err != nil { return nil, fmt.Errorf("Couldn't connect to leader at %s", s.Leader().String()) } s.leaderConn, err = newConnToLeader(newConn, s.rpcLayer.Addr().String(), s.lg) if err != nil { s.lg.Printf("Got error connecting to leader %s from follower %s : %s", s.Leader().String(), s.rpcLayer.Addr().String(), err) return nil, err } } cb := s.state.newCommand() err = s.leaderConn.forwardCommand(cb, cmd, args) if err != nil { cb.cancel() return nil, err } return cb, nil }
go
func (s *server) dispatchToLeader(cmd string, args [][]byte) (*commandCallback, error) { s.leaderLock.Lock() defer s.leaderLock.Unlock() var err error if s.leaderConn == nil || s.Leader() == nil || s.Leader().String() != s.leaderConn.remoteAddr().String() { if s.leaderConn != nil { s.lg.Printf("Leader changed, reconnecting, was: %s, now %s", s.leaderConn.remoteAddr(), s.Leader()) } // reconnect if s.leaderConn != nil { s.leaderConn.c.Close() } newConn, err := s.rpcLayer.Dial(s.Leader().String(), 1*time.Minute) if err != nil { return nil, fmt.Errorf("Couldn't connect to leader at %s", s.Leader().String()) } s.leaderConn, err = newConnToLeader(newConn, s.rpcLayer.Addr().String(), s.lg) if err != nil { s.lg.Printf("Got error connecting to leader %s from follower %s : %s", s.Leader().String(), s.rpcLayer.Addr().String(), err) return nil, err } } cb := s.state.newCommand() err = s.leaderConn.forwardCommand(cb, cmd, args) if err != nil { cb.cancel() return nil, err } return cb, nil }
[ "func", "(", "s", "*", "server", ")", "dispatchToLeader", "(", "cmd", "string", ",", "args", "[", "]", "[", "]", "byte", ")", "(", "*", "commandCallback", ",", "error", ")", "{", "s", ".", "leaderLock", ".", "Lock", "(", ")", "\n", "defer", "s", ...
// checks connection state and dispatches the task to leader // returns a callback registered with our state machine
[ "checks", "connection", "state", "and", "dispatches", "the", "task", "to", "leader", "returns", "a", "callback", "registered", "with", "our", "state", "machine" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/server.go#L239-L269
154,134
pdf/golifx
golifx.go
NewClient
func NewClient(p common.Protocol) (*Client, error) { c := &Client{ protocol: p, timeout: common.DefaultTimeout, retryInterval: common.DefaultRetryInterval, internalRetryInterval: 10 * time.Millisecond, quitChan: make(chan struct{}, 2), } c.protocol.SetTimeout(&c.timeout) c.protocol.SetRetryInterval(&c.retryInterval) if err := c.subscribe(); err != nil { return nil, err } err := c.discover() return c, err }
go
func NewClient(p common.Protocol) (*Client, error) { c := &Client{ protocol: p, timeout: common.DefaultTimeout, retryInterval: common.DefaultRetryInterval, internalRetryInterval: 10 * time.Millisecond, quitChan: make(chan struct{}, 2), } c.protocol.SetTimeout(&c.timeout) c.protocol.SetRetryInterval(&c.retryInterval) if err := c.subscribe(); err != nil { return nil, err } err := c.discover() return c, err }
[ "func", "NewClient", "(", "p", "common", ".", "Protocol", ")", "(", "*", "Client", ",", "error", ")", "{", "c", ":=", "&", "Client", "{", "protocol", ":", "p", ",", "timeout", ":", "common", ".", "DefaultTimeout", ",", "retryInterval", ":", "common", ...
// NewClient returns a pointer to a new Client and any error that occurred // initializing the client, using the protocol p. It also kicks off a discovery // run.
[ "NewClient", "returns", "a", "pointer", "to", "a", "new", "Client", "and", "any", "error", "that", "occurred", "initializing", "the", "client", "using", "the", "protocol", "p", ".", "It", "also", "kicks", "off", "a", "discovery", "run", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/golifx.go#L34-L49
154,135
goraz/cast
uint.go
Uint
func Uint(input interface{}) (output uint64, err error) { switch castValue := input.(type) { case Uinter: output = castValue.Uint() return case string: output, err = strconv.ParseUint(castValue, 10, 64) return case []byte: output, err = strconv.ParseUint(string(castValue), 10, 64) return case int: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int8: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int16: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int32: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int64: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case uint: output = uint64(castValue) return case uint8: output = uint64(castValue) return case uint16: output = uint64(castValue) return case uint32: output = uint64(castValue) return case uint64: output = uint64(castValue) return case float32: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case float64: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case bool: output = uint64(0) if castValue { output = uint64(1) } return case nil: output = uint64(0) return default: err = NewCastError("Could not convert to uint") } return }
go
func Uint(input interface{}) (output uint64, err error) { switch castValue := input.(type) { case Uinter: output = castValue.Uint() return case string: output, err = strconv.ParseUint(castValue, 10, 64) return case []byte: output, err = strconv.ParseUint(string(castValue), 10, 64) return case int: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int8: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int16: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int32: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case int64: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case uint: output = uint64(castValue) return case uint8: output = uint64(castValue) return case uint16: output = uint64(castValue) return case uint32: output = uint64(castValue) return case uint64: output = uint64(castValue) return case float32: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case float64: if castValue < 0 { err = NewCastError("Could not convert negative value to uint") return } output = uint64(castValue) return case bool: output = uint64(0) if castValue { output = uint64(1) } return case nil: output = uint64(0) return default: err = NewCastError("Could not convert to uint") } return }
[ "func", "Uint", "(", "input", "interface", "{", "}", ")", "(", "output", "uint64", ",", "err", "error", ")", "{", "switch", "castValue", ":=", "input", ".", "(", "type", ")", "{", "case", "Uinter", ":", "output", "=", "castValue", ".", "Uint", "(", ...
//Uint Cast input to uint64
[ "Uint", "Cast", "input", "to", "uint64" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/uint.go#L14-L103
154,136
goraz/cast
uint.go
MustUint
func MustUint(input interface{}) uint64 { output, err := Uint(input) if err != nil { panic(err) } return output }
go
func MustUint(input interface{}) uint64 { output, err := Uint(input) if err != nil { panic(err) } return output }
[ "func", "MustUint", "(", "input", "interface", "{", "}", ")", "uint64", "{", "output", ",", "err", ":=", "Uint", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "output", "\n", "}" ]
//MustUint cast input to uint64 and panic if error
[ "MustUint", "cast", "input", "to", "uint64", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/uint.go#L106-L112
154,137
goraz/cast
float.go
Float
func Float(input interface{}) (output float64, err error) { switch castValue := input.(type) { case Floater: output = castValue.Float() return case string: output, err = strconv.ParseFloat(castValue, 64) case []byte: output, err = strconv.ParseFloat(string(castValue), 64) return case int: output = float64(castValue) return case int8: output = float64(castValue) return case int16: output = float64(castValue) return case int32: output = float64(castValue) return case int64: output = float64(castValue) return case uint: output = float64(castValue) return case uint8: output = float64(castValue) return case uint16: output = float64(castValue) return case uint32: output = float64(castValue) return case uint64: output = float64(castValue) return case float32: output = float64(castValue) return case float64: output = float64(castValue) return case bool: output = float64(0) if castValue { output = float64(1) } return case nil: output = float64(0) return default: err = NewCastError("Could not convert to float64") } return }
go
func Float(input interface{}) (output float64, err error) { switch castValue := input.(type) { case Floater: output = castValue.Float() return case string: output, err = strconv.ParseFloat(castValue, 64) case []byte: output, err = strconv.ParseFloat(string(castValue), 64) return case int: output = float64(castValue) return case int8: output = float64(castValue) return case int16: output = float64(castValue) return case int32: output = float64(castValue) return case int64: output = float64(castValue) return case uint: output = float64(castValue) return case uint8: output = float64(castValue) return case uint16: output = float64(castValue) return case uint32: output = float64(castValue) return case uint64: output = float64(castValue) return case float32: output = float64(castValue) return case float64: output = float64(castValue) return case bool: output = float64(0) if castValue { output = float64(1) } return case nil: output = float64(0) return default: err = NewCastError("Could not convert to float64") } return }
[ "func", "Float", "(", "input", "interface", "{", "}", ")", "(", "output", "float64", ",", "err", "error", ")", "{", "switch", "castValue", ":=", "input", ".", "(", "type", ")", "{", "case", "Floater", ":", "output", "=", "castValue", ".", "Float", "(...
//Float cast input to int64
[ "Float", "cast", "input", "to", "int64" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/float.go#L14-L74
154,138
goraz/cast
float.go
MustFloat
func MustFloat(input interface{}) float64 { output, err := Float(input) if err != nil { panic(err) } return output }
go
func MustFloat(input interface{}) float64 { output, err := Float(input) if err != nil { panic(err) } return output }
[ "func", "MustFloat", "(", "input", "interface", "{", "}", ")", "float64", "{", "output", ",", "err", ":=", "Float", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "output", "\n", "}" ]
//MustFloat cast input to int64 and panic if error
[ "MustFloat", "cast", "input", "to", "int64", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/float.go#L77-L83
154,139
goraz/cast
int_slice.go
MustIntSlice
func MustIntSlice(input interface{}) []int64 { output, err := IntSlice(input) if err != nil { panic(err) } return output }
go
func MustIntSlice(input interface{}) []int64 { output, err := IntSlice(input) if err != nil { panic(err) } return output }
[ "func", "MustIntSlice", "(", "input", "interface", "{", "}", ")", "[", "]", "int64", "{", "output", ",", "err", ":=", "IntSlice", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "output",...
//MustIntSlice cast input slice to int64 slice and panic if error
[ "MustIntSlice", "cast", "input", "slice", "to", "int64", "slice", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/int_slice.go#L119-L125
154,140
goraz/cast
float_slice.go
MustFloatSlice
func MustFloatSlice(input interface{}) []float64 { output, err := FloatSlice(input) if err != nil { panic(err) } return output }
go
func MustFloatSlice(input interface{}) []float64 { output, err := FloatSlice(input) if err != nil { panic(err) } return output }
[ "func", "MustFloatSlice", "(", "input", "interface", "{", "}", ")", "[", "]", "float64", "{", "output", ",", "err", ":=", "FloatSlice", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "ou...
//MustFloatSlice cast input slice to float64 slice and panic if error
[ "MustFloatSlice", "cast", "input", "slice", "to", "float64", "slice", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/float_slice.go#L116-L122
154,141
goraz/cast
string_slice.go
MustStringSlice
func MustStringSlice(input interface{}) []string { output, err := StringSlice(input) if err != nil { panic(err) } return output }
go
func MustStringSlice(input interface{}) []string { output, err := StringSlice(input) if err != nil { panic(err) } return output }
[ "func", "MustStringSlice", "(", "input", "interface", "{", "}", ")", "[", "]", "string", "{", "output", ",", "err", ":=", "StringSlice", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "o...
//MustStringSlice cast input slice to string slice and panic if error
[ "MustStringSlice", "cast", "input", "slice", "to", "string", "slice", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/string_slice.go#L114-L120
154,142
goraz/cast
int.go
Int
func Int(input interface{}) (output int64, err error) { switch castValue := input.(type) { case Inter: output = castValue.Int() return case string: output, err = strconv.ParseInt(castValue, 10, 64) return case []byte: output, err = strconv.ParseInt(string(castValue), 10, 64) return case int: output = int64(castValue) return case int8: output = int64(castValue) return case int16: output = int64(castValue) return case int32: output = int64(castValue) return case int64: output = int64(castValue) return case uint: output = int64(castValue) return case uint8: output = int64(castValue) return case uint16: output = int64(castValue) return case uint32: output = int64(castValue) return case uint64: output = int64(castValue) return case float32: output = int64(castValue) return case float64: output = int64(castValue) return case bool: output = int64(0) if castValue { output = int64(1) } return case nil: output = int64(0) return default: err = NewCastError("Could not convert to int") } return }
go
func Int(input interface{}) (output int64, err error) { switch castValue := input.(type) { case Inter: output = castValue.Int() return case string: output, err = strconv.ParseInt(castValue, 10, 64) return case []byte: output, err = strconv.ParseInt(string(castValue), 10, 64) return case int: output = int64(castValue) return case int8: output = int64(castValue) return case int16: output = int64(castValue) return case int32: output = int64(castValue) return case int64: output = int64(castValue) return case uint: output = int64(castValue) return case uint8: output = int64(castValue) return case uint16: output = int64(castValue) return case uint32: output = int64(castValue) return case uint64: output = int64(castValue) return case float32: output = int64(castValue) return case float64: output = int64(castValue) return case bool: output = int64(0) if castValue { output = int64(1) } return case nil: output = int64(0) return default: err = NewCastError("Could not convert to int") } return }
[ "func", "Int", "(", "input", "interface", "{", "}", ")", "(", "output", "int64", ",", "err", "error", ")", "{", "switch", "castValue", ":=", "input", ".", "(", "type", ")", "{", "case", "Inter", ":", "output", "=", "castValue", ".", "Int", "(", ")"...
//Int cast input to int64
[ "Int", "cast", "input", "to", "int64" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/int.go#L14-L75
154,143
goraz/cast
int.go
MustInt
func MustInt(input interface{}) int64 { output, err := Int(input) if err != nil { panic(err) } return output }
go
func MustInt(input interface{}) int64 { output, err := Int(input) if err != nil { panic(err) } return output }
[ "func", "MustInt", "(", "input", "interface", "{", "}", ")", "int64", "{", "output", ",", "err", ":=", "Int", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "output", "\n", "}" ]
//MustInt cast input to int64 and panic if error
[ "MustInt", "cast", "input", "to", "int64", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/int.go#L78-L84
154,144
goraz/cast
bool.go
Bool
func Bool(input interface{}) (output bool, err error) { switch castValue := input.(type) { case Booler: output = castValue.Bool() return case string: var errParse error output, errParse = strconv.ParseBool(castValue) if errParse != nil && len(castValue) > 0 { output = true } return case int: if castValue != 0 { output = true } return case int8: if castValue != 0 { output = true } return case int16: if castValue != 0 { output = true } return case int32: if castValue != 0 { output = true } return case int64: if castValue != 0 { output = true } return case uint: if castValue != 0 { output = true } return case uint8: if castValue != 0 { output = true } return case uint16: if castValue != 0 { output = true } return case uint32: if castValue != 0 { output = true } return case uint64: if castValue != 0 { output = true } return case float32: if castValue != 0 { output = true } return case float64: if castValue != 0 { output = true } return case bool: output = castValue return case nil: output = false return default: err = NewCastError("Could not convert to bool") } return }
go
func Bool(input interface{}) (output bool, err error) { switch castValue := input.(type) { case Booler: output = castValue.Bool() return case string: var errParse error output, errParse = strconv.ParseBool(castValue) if errParse != nil && len(castValue) > 0 { output = true } return case int: if castValue != 0 { output = true } return case int8: if castValue != 0 { output = true } return case int16: if castValue != 0 { output = true } return case int32: if castValue != 0 { output = true } return case int64: if castValue != 0 { output = true } return case uint: if castValue != 0 { output = true } return case uint8: if castValue != 0 { output = true } return case uint16: if castValue != 0 { output = true } return case uint32: if castValue != 0 { output = true } return case uint64: if castValue != 0 { output = true } return case float32: if castValue != 0 { output = true } return case float64: if castValue != 0 { output = true } return case bool: output = castValue return case nil: output = false return default: err = NewCastError("Could not convert to bool") } return }
[ "func", "Bool", "(", "input", "interface", "{", "}", ")", "(", "output", "bool", ",", "err", "error", ")", "{", "switch", "castValue", ":=", "input", ".", "(", "type", ")", "{", "case", "Booler", ":", "output", "=", "castValue", ".", "Bool", "(", "...
//Bool cast input to bool
[ "Bool", "cast", "input", "to", "bool" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/bool.go#L14-L96
154,145
goraz/cast
bool.go
MustBool
func MustBool(input interface{}) bool { output, err := Bool(input) if err != nil { panic(err) } return output }
go
func MustBool(input interface{}) bool { output, err := Bool(input) if err != nil { panic(err) } return output }
[ "func", "MustBool", "(", "input", "interface", "{", "}", ")", "bool", "{", "output", ",", "err", ":=", "Bool", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "output", "\n", "}" ]
//MustBool cast input to bool and panic if error
[ "MustBool", "cast", "input", "to", "bool", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/bool.go#L99-L105
154,146
goraz/cast
string.go
String
func String(input interface{}) (output string, err error) { switch castValue := input.(type) { case Stringer: output = castValue.String() return case string: output = string(castValue) return case []byte: output = string(castValue) return case int: output = strconv.Itoa(castValue) return case int8: output = strconv.Itoa(int(castValue)) return case int16: output = strconv.Itoa(int(castValue)) return case int32: output = strconv.Itoa(int(castValue)) return case int64: output = strconv.FormatInt(castValue, 10) return case uint: output = strconv.FormatUint(uint64(castValue), 10) return case uint8: output = strconv.FormatUint(uint64(castValue), 10) return case uint16: output = strconv.FormatUint(uint64(castValue), 10) return case uint32: output = strconv.FormatUint(uint64(castValue), 10) return case uint64: output = strconv.FormatUint(uint64(castValue), 10) return case float32: // What exact value for perc value output = strconv.FormatFloat(float64(castValue), 'g', -1, 64) return case float64: // What exact value for perc value output = strconv.FormatFloat(castValue, 'g', -1, 64) return case nil: output = "" return case bool: output = strconv.FormatBool(castValue) return default: err = NewCastError("Could not convert to string") } return }
go
func String(input interface{}) (output string, err error) { switch castValue := input.(type) { case Stringer: output = castValue.String() return case string: output = string(castValue) return case []byte: output = string(castValue) return case int: output = strconv.Itoa(castValue) return case int8: output = strconv.Itoa(int(castValue)) return case int16: output = strconv.Itoa(int(castValue)) return case int32: output = strconv.Itoa(int(castValue)) return case int64: output = strconv.FormatInt(castValue, 10) return case uint: output = strconv.FormatUint(uint64(castValue), 10) return case uint8: output = strconv.FormatUint(uint64(castValue), 10) return case uint16: output = strconv.FormatUint(uint64(castValue), 10) return case uint32: output = strconv.FormatUint(uint64(castValue), 10) return case uint64: output = strconv.FormatUint(uint64(castValue), 10) return case float32: // What exact value for perc value output = strconv.FormatFloat(float64(castValue), 'g', -1, 64) return case float64: // What exact value for perc value output = strconv.FormatFloat(castValue, 'g', -1, 64) return case nil: output = "" return case bool: output = strconv.FormatBool(castValue) return default: err = NewCastError("Could not convert to string") } return }
[ "func", "String", "(", "input", "interface", "{", "}", ")", "(", "output", "string", ",", "err", "error", ")", "{", "switch", "castValue", ":=", "input", ".", "(", "type", ")", "{", "case", "Stringer", ":", "output", "=", "castValue", ".", "String", ...
//String cast input to string
[ "String", "cast", "input", "to", "string" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/string.go#L14-L74
154,147
goraz/cast
string.go
MustString
func MustString(input interface{}) string { output, err := String(input) if err != nil { panic(err) } return output }
go
func MustString(input interface{}) string { output, err := String(input) if err != nil { panic(err) } return output }
[ "func", "MustString", "(", "input", "interface", "{", "}", ")", "string", "{", "output", ",", "err", ":=", "String", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "output", "\n", "}" ]
//MustString cast input to string and panic if error
[ "MustString", "cast", "input", "to", "string", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/string.go#L77-L83
154,148
goraz/cast
duration.go
Duration
func Duration(input interface{}) (output time.Duration, err error) { switch castValue := input.(type) { case string: output, err = time.ParseDuration(castValue) if err != nil { outputInt, errCast := Int(castValue) if errCast != nil { err = NewCastError("Could not convert to time.Duration") return } output = time.Duration(int(outputInt)) } return case time.Duration: output = castValue return default: outputInt, errCast := Int(castValue) if errCast == nil { output = time.Duration(int(outputInt)) return } err = NewCastError("Could not convert to time.Duration") } return }
go
func Duration(input interface{}) (output time.Duration, err error) { switch castValue := input.(type) { case string: output, err = time.ParseDuration(castValue) if err != nil { outputInt, errCast := Int(castValue) if errCast != nil { err = NewCastError("Could not convert to time.Duration") return } output = time.Duration(int(outputInt)) } return case time.Duration: output = castValue return default: outputInt, errCast := Int(castValue) if errCast == nil { output = time.Duration(int(outputInt)) return } err = NewCastError("Could not convert to time.Duration") } return }
[ "func", "Duration", "(", "input", "interface", "{", "}", ")", "(", "output", "time", ".", "Duration", ",", "err", "error", ")", "{", "switch", "castValue", ":=", "input", ".", "(", "type", ")", "{", "case", "string", ":", "output", ",", "err", "=", ...
//Duration cast input to time.Duration
[ "Duration", "cast", "input", "to", "time", ".", "Duration" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/duration.go#L6-L31
154,149
goraz/cast
duration.go
MustDuration
func MustDuration(input interface{}) time.Duration { output, err := Duration(input) if err != nil { panic(err) } return output }
go
func MustDuration(input interface{}) time.Duration { output, err := Duration(input) if err != nil { panic(err) } return output }
[ "func", "MustDuration", "(", "input", "interface", "{", "}", ")", "time", ".", "Duration", "{", "output", ",", "err", ":=", "Duration", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "ou...
//MustDuration cast input to time.Duration and panic if error
[ "MustDuration", "cast", "input", "to", "time", ".", "Duration", "and", "panic", "if", "error" ]
a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa
https://github.com/goraz/cast/blob/a1918f6ea079f56d6a8c87d07ec8a950c2fbeafa/duration.go#L34-L40
154,150
crackcomm/cloudflare
client_zones.go
Create
func (zones *Zones) Create(ctx context.Context, domain string) (zone *Zone, err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(struct { Name string `json:"name"` }{ Name: domain, }) if err != nil { return } response, err := httpDo(ctx, zones.Options, "POST", apiURL("/zones"), buffer) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } zone = new(Zone) err = json.Unmarshal(result.Result, &zone) return }
go
func (zones *Zones) Create(ctx context.Context, domain string) (zone *Zone, err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(struct { Name string `json:"name"` }{ Name: domain, }) if err != nil { return } response, err := httpDo(ctx, zones.Options, "POST", apiURL("/zones"), buffer) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } zone = new(Zone) err = json.Unmarshal(result.Result, &zone) return }
[ "func", "(", "zones", "*", "Zones", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "domain", "string", ")", "(", "zone", "*", "Zone", ",", "err", "error", ")", "{", "buffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", ...
// Create - Creates a zone.
[ "Create", "-", "Creates", "a", "zone", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_zones.go#L17-L39
154,151
crackcomm/cloudflare
client_zones.go
List
func (zones *Zones) List(ctx context.Context) ([]*Zone, error) { return zones.listPages(ctx, 1) }
go
func (zones *Zones) List(ctx context.Context) ([]*Zone, error) { return zones.listPages(ctx, 1) }
[ "func", "(", "zones", "*", "Zones", ")", "List", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "*", "Zone", ",", "error", ")", "{", "return", "zones", ".", "listPages", "(", "ctx", ",", "1", ")", "\n", "}" ]
// List - Lists all zones.
[ "List", "-", "Lists", "all", "zones", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_zones.go#L42-L44
154,152
crackcomm/cloudflare
client_zones.go
Details
func (zones *Zones) Details(ctx context.Context, id string) (zone *Zone, err error) { response, err := httpDo(ctx, zones.Options, "GET", apiURL("/zones/%s", id), nil) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } zone = new(Zone) err = json.Unmarshal(result.Result, &zone) return }
go
func (zones *Zones) Details(ctx context.Context, id string) (zone *Zone, err error) { response, err := httpDo(ctx, zones.Options, "GET", apiURL("/zones/%s", id), nil) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } zone = new(Zone) err = json.Unmarshal(result.Result, &zone) return }
[ "func", "(", "zones", "*", "Zones", ")", "Details", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "zone", "*", "Zone", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "httpDo", "(", "ctx", ",", "zones", ".", "...
// Details - Requests Zone details by ID.
[ "Details", "-", "Requests", "Zone", "details", "by", "ID", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_zones.go#L47-L60
154,153
crackcomm/cloudflare
client_zones.go
Patch
func (zones *Zones) Patch(ctx context.Context, id string, patch *ZonePatch) (err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(patch) if err != nil { return } response, err := httpDo(ctx, zones.Options, "POST", apiURL("/zones/%s", id), buffer) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
go
func (zones *Zones) Patch(ctx context.Context, id string, patch *ZonePatch) (err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(patch) if err != nil { return } response, err := httpDo(ctx, zones.Options, "POST", apiURL("/zones/%s", id), buffer) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
[ "func", "(", "zones", "*", "Zones", ")", "Patch", "(", "ctx", "context", ".", "Context", ",", "id", "string", ",", "patch", "*", "ZonePatch", ")", "(", "err", "error", ")", "{", "buffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", ...
// Patch - Patches a zone. It has a limited possibilities.
[ "Patch", "-", "Patches", "a", "zone", ".", "It", "has", "a", "limited", "possibilities", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_zones.go#L63-L76
154,154
crackcomm/cloudflare
client_zones.go
Delete
func (zones *Zones) Delete(ctx context.Context, id string) (err error) { response, err := httpDo(ctx, zones.Options, "DELETE", apiURL("/zones/%s", id), nil) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
go
func (zones *Zones) Delete(ctx context.Context, id string) (err error) { response, err := httpDo(ctx, zones.Options, "DELETE", apiURL("/zones/%s", id), nil) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
[ "func", "(", "zones", "*", "Zones", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "err", "error", ")", "{", "response", ",", "err", ":=", "httpDo", "(", "ctx", ",", "zones", ".", "Options", ",", "\"", "\"", ...
// Delete - Deletes zone by id.
[ "Delete", "-", "Deletes", "zone", "by", "id", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_zones.go#L79-L87
154,155
captncraig/easyauth
providers/token/json.go
NewJsonStore
func NewJsonStore(fname string) (TokenDataAccess, error) { j := &jsonStore{ path: fname, tokens: map[string]*Token{}, } if err := j.read(); err != nil { return nil, err } return j, nil }
go
func NewJsonStore(fname string) (TokenDataAccess, error) { j := &jsonStore{ path: fname, tokens: map[string]*Token{}, } if err := j.read(); err != nil { return nil, err } return j, nil }
[ "func", "NewJsonStore", "(", "fname", "string", ")", "(", "TokenDataAccess", ",", "error", ")", "{", "j", ":=", "&", "jsonStore", "{", "path", ":", "fname", ",", "tokens", ":", "map", "[", "string", "]", "*", "Token", "{", "}", ",", "}", "\n", "if"...
//NewJsonStore makes a simple token store that keeps tokens in-memory, //backed up to a local json file. //Not suitable for high volume or high reliability. //if you specify an empty string for file name, nothing will be backed up to disk, and you will have a solely in-memory store
[ "NewJsonStore", "makes", "a", "simple", "token", "store", "that", "keeps", "tokens", "in", "-", "memory", "backed", "up", "to", "a", "local", "json", "file", ".", "Not", "suitable", "for", "high", "volume", "or", "high", "reliability", ".", "if", "you", ...
c6de284138cfb3c428a4870ceec7391fddcec2ef
https://github.com/captncraig/easyauth/blob/c6de284138cfb3c428a4870ceec7391fddcec2ef/providers/token/json.go#L23-L32
154,156
apid/apidApigeeSync
listener.go
postInitPlugins
func (l *listenerManager) postInitPlugins(event apid.Event) { var plinfoDetails []pluginDetail if pie, ok := event.(apid.PluginsInitializedEvent); ok { /* * Store the plugin details in the heap. Needed during * Bearer token generation request. */ for _, plugin := range pie.Plugins { name := plugin.Name version := plugin.Version if schemaVersion, ok := plugin.ExtraData["schemaVersion"].(string); ok { inf := pluginDetail{ Name: name, SchemaVersion: schemaVersion} plinfoDetails = append(plinfoDetails, inf) log.Debugf("plugin %s is version %s, schemaVersion: %s", name, version, schemaVersion) } } if plinfoDetails == nil { log.Panic("No Plugins registered!") } pgInfo, err := json.Marshal(plinfoDetails) if err != nil { log.Panicf("Unable to marshal plugin data: %v", err) } apidPluginDetails = string(pgInfo[:]) log.Debug("start post plugin init") l.tokenMan.start() go l.bootstrap(apidInfo.LastSnapshot) log.Debug("Done post plugin init") } }
go
func (l *listenerManager) postInitPlugins(event apid.Event) { var plinfoDetails []pluginDetail if pie, ok := event.(apid.PluginsInitializedEvent); ok { /* * Store the plugin details in the heap. Needed during * Bearer token generation request. */ for _, plugin := range pie.Plugins { name := plugin.Name version := plugin.Version if schemaVersion, ok := plugin.ExtraData["schemaVersion"].(string); ok { inf := pluginDetail{ Name: name, SchemaVersion: schemaVersion} plinfoDetails = append(plinfoDetails, inf) log.Debugf("plugin %s is version %s, schemaVersion: %s", name, version, schemaVersion) } } if plinfoDetails == nil { log.Panic("No Plugins registered!") } pgInfo, err := json.Marshal(plinfoDetails) if err != nil { log.Panicf("Unable to marshal plugin data: %v", err) } apidPluginDetails = string(pgInfo[:]) log.Debug("start post plugin init") l.tokenMan.start() go l.bootstrap(apidInfo.LastSnapshot) log.Debug("Done post plugin init") } }
[ "func", "(", "l", "*", "listenerManager", ")", "postInitPlugins", "(", "event", "apid", ".", "Event", ")", "{", "var", "plinfoDetails", "[", "]", "pluginDetail", "\n", "if", "pie", ",", "ok", ":=", "event", ".", "(", "apid", ".", "PluginsInitializedEvent",...
// Plugins have all initialized, gather their info and start the ApigeeSync downloads
[ "Plugins", "have", "all", "initialized", "gather", "their", "info", "and", "start", "the", "ApigeeSync", "downloads" ]
655b66d3ded76155c155649c401cc9ac0fbf3969
https://github.com/apid/apidApigeeSync/blob/655b66d3ded76155c155649c401cc9ac0fbf3969/listener.go#L44-L79
154,157
cjgdev/goryman
transport.go
NewTcpTransport
func NewTcpTransport(conn net.Conn) *TcpTransport { t := &TcpTransport{ conn: conn, requestQueue: make(chan request), } go t.runRequestQueue() return t }
go
func NewTcpTransport(conn net.Conn) *TcpTransport { t := &TcpTransport{ conn: conn, requestQueue: make(chan request), } go t.runRequestQueue() return t }
[ "func", "NewTcpTransport", "(", "conn", "net", ".", "Conn", ")", "*", "TcpTransport", "{", "t", ":=", "&", "TcpTransport", "{", "conn", ":", "conn", ",", "requestQueue", ":", "make", "(", "chan", "request", ")", ",", "}", "\n", "go", "t", ".", "runRe...
// NewTcpTransport - Factory
[ "NewTcpTransport", "-", "Factory" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L49-L56
154,158
cjgdev/goryman
transport.go
NewUdpTransport
func NewUdpTransport(conn net.Conn) *UdpTransport { t := &UdpTransport{ conn: conn, requestQueue: make(chan request), } go t.runRequestQueue() return t }
go
func NewUdpTransport(conn net.Conn) *UdpTransport { t := &UdpTransport{ conn: conn, requestQueue: make(chan request), } go t.runRequestQueue() return t }
[ "func", "NewUdpTransport", "(", "conn", "net", ".", "Conn", ")", "*", "UdpTransport", "{", "t", ":=", "&", "UdpTransport", "{", "conn", ":", "conn", ",", "requestQueue", ":", "make", "(", "chan", "request", ")", ",", "}", "\n", "go", "t", ".", "runRe...
// NewUdpTransport - Factory
[ "NewUdpTransport", "-", "Factory" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L59-L66
154,159
cjgdev/goryman
transport.go
SendRecv
func (t *TcpTransport) SendRecv(message *proto.Msg) (*proto.Msg, error) { response_ch := make(chan response) t.requestQueue <- request{message, response_ch} r := <-response_ch return r.message, r.err }
go
func (t *TcpTransport) SendRecv(message *proto.Msg) (*proto.Msg, error) { response_ch := make(chan response) t.requestQueue <- request{message, response_ch} r := <-response_ch return r.message, r.err }
[ "func", "(", "t", "*", "TcpTransport", ")", "SendRecv", "(", "message", "*", "proto", ".", "Msg", ")", "(", "*", "proto", ".", "Msg", ",", "error", ")", "{", "response_ch", ":=", "make", "(", "chan", "response", ")", "\n", "t", ".", "requestQueue", ...
// TcpTransport implementation of SendRecv, queues a request to send a message to the server
[ "TcpTransport", "implementation", "of", "SendRecv", "queues", "a", "request", "to", "send", "a", "message", "to", "the", "server" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L69-L74
154,160
cjgdev/goryman
transport.go
SendMaybeRecv
func (t *TcpTransport) SendMaybeRecv(message *proto.Msg) (*proto.Msg, error) { return t.SendRecv(message) }
go
func (t *TcpTransport) SendMaybeRecv(message *proto.Msg) (*proto.Msg, error) { return t.SendRecv(message) }
[ "func", "(", "t", "*", "TcpTransport", ")", "SendMaybeRecv", "(", "message", "*", "proto", ".", "Msg", ")", "(", "*", "proto", ".", "Msg", ",", "error", ")", "{", "return", "t", ".", "SendRecv", "(", "message", ")", "\n", "}" ]
// TcpTransport implementation of SendMaybeRecv, queues a request to send a message to the server
[ "TcpTransport", "implementation", "of", "SendMaybeRecv", "queues", "a", "request", "to", "send", "a", "message", "to", "the", "server" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L77-L79
154,161
cjgdev/goryman
transport.go
SendRecv
func (t *UdpTransport) SendRecv(message *proto.Msg) (*proto.Msg, error) { return nil, fmt.Errorf("udp doesn't support receiving acknowledgements") }
go
func (t *UdpTransport) SendRecv(message *proto.Msg) (*proto.Msg, error) { return nil, fmt.Errorf("udp doesn't support receiving acknowledgements") }
[ "func", "(", "t", "*", "UdpTransport", ")", "SendRecv", "(", "message", "*", "proto", ".", "Msg", ")", "(", "*", "proto", ".", "Msg", ",", "error", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// UdpTransport implementation of SendRecv, will automatically fail if called
[ "UdpTransport", "implementation", "of", "SendRecv", "will", "automatically", "fail", "if", "called" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L138-L140
154,162
cjgdev/goryman
transport.go
SendMaybeRecv
func (t *UdpTransport) SendMaybeRecv(message *proto.Msg) (*proto.Msg, error) { response_ch := make(chan response) t.requestQueue <- request{message, response_ch} r := <-response_ch return r.message, r.err }
go
func (t *UdpTransport) SendMaybeRecv(message *proto.Msg) (*proto.Msg, error) { response_ch := make(chan response) t.requestQueue <- request{message, response_ch} r := <-response_ch return r.message, r.err }
[ "func", "(", "t", "*", "UdpTransport", ")", "SendMaybeRecv", "(", "message", "*", "proto", ".", "Msg", ")", "(", "*", "proto", ".", "Msg", ",", "error", ")", "{", "response_ch", ":=", "make", "(", "chan", "response", ")", "\n", "t", ".", "requestQueu...
// UdpTransport implementation of SendMaybeRecv, queues a request to send a message to the server
[ "UdpTransport", "implementation", "of", "SendMaybeRecv", "queues", "a", "request", "to", "send", "a", "message", "to", "the", "server" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L143-L148
154,163
cjgdev/goryman
transport.go
Close
func (t *UdpTransport) Close() error { close(t.requestQueue) err := t.conn.Close() if err != nil { return err } return nil }
go
func (t *UdpTransport) Close() error { close(t.requestQueue) err := t.conn.Close() if err != nil { return err } return nil }
[ "func", "(", "t", "*", "UdpTransport", ")", "Close", "(", ")", "error", "{", "close", "(", "t", ".", "requestQueue", ")", "\n", "err", ":=", "t", ".", "conn", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "...
// Close will close the UdpTransport
[ "Close", "will", "close", "the", "UdpTransport" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L151-L158
154,164
cjgdev/goryman
transport.go
runRequestQueue
func (t *UdpTransport) runRequestQueue() { for req := range t.requestQueue { message := req.message response_ch := req.response_ch msg, err := t.execRequest(message) response_ch <- response{msg, err} } }
go
func (t *UdpTransport) runRequestQueue() { for req := range t.requestQueue { message := req.message response_ch := req.response_ch msg, err := t.execRequest(message) response_ch <- response{msg, err} } }
[ "func", "(", "t", "*", "UdpTransport", ")", "runRequestQueue", "(", ")", "{", "for", "req", ":=", "range", "t", ".", "requestQueue", "{", "message", ":=", "req", ".", "message", "\n", "response_ch", ":=", "req", ".", "response_ch", "\n\n", "msg", ",", ...
// runRequestQueue services the UdpTransport request queue
[ "runRequestQueue", "services", "the", "UdpTransport", "request", "queue" ]
55c3cbc3df542201b3c140e72a758d0adae4bc05
https://github.com/cjgdev/goryman/blob/55c3cbc3df542201b3c140e72a758d0adae4bc05/transport.go#L161-L170
154,165
apid/apidApigeeSync
token.go
invalidateToken
func (t *apidTokenManager) invalidateToken() { log.Debug("invalidating token") t.invalidateTokenChan <- true <-t.invalidateDone }
go
func (t *apidTokenManager) invalidateToken() { log.Debug("invalidating token") t.invalidateTokenChan <- true <-t.invalidateDone }
[ "func", "(", "t", "*", "apidTokenManager", ")", "invalidateToken", "(", ")", "{", "log", ".", "Debug", "(", "\"", "\"", ")", "\n", "t", ".", "invalidateTokenChan", "<-", "true", "\n", "<-", "t", ".", "invalidateDone", "\n", "}" ]
// will block until valid
[ "will", "block", "until", "valid" ]
655b66d3ded76155c155649c401cc9ac0fbf3969
https://github.com/apid/apidApigeeSync/blob/655b66d3ded76155c155649c401cc9ac0fbf3969/token.go#L102-L106
154,166
apid/apidApigeeSync
token.go
retrieveNewToken
func (t *apidTokenManager) retrieveNewToken() { log.Debug("Getting OAuth token...") uriString := config.GetString(configProxyServerBaseURI) uri, err := url.Parse(uriString) if err != nil { log.Panicf("unable to parse uri config '%s' value: '%s': %v", configProxyServerBaseURI, uriString, err) } uri.Path = path.Join(uri.Path, "/accesstoken") pollWithBackoff(t.quitPollingForToken, t.getRetrieveNewTokenClosure(uri), func(err error) { log.Errorf("Error getting new token : %v", err) }) }
go
func (t *apidTokenManager) retrieveNewToken() { log.Debug("Getting OAuth token...") uriString := config.GetString(configProxyServerBaseURI) uri, err := url.Parse(uriString) if err != nil { log.Panicf("unable to parse uri config '%s' value: '%s': %v", configProxyServerBaseURI, uriString, err) } uri.Path = path.Join(uri.Path, "/accesstoken") pollWithBackoff(t.quitPollingForToken, t.getRetrieveNewTokenClosure(uri), func(err error) { log.Errorf("Error getting new token : %v", err) }) }
[ "func", "(", "t", "*", "apidTokenManager", ")", "retrieveNewToken", "(", ")", "{", "log", ".", "Debug", "(", "\"", "\"", ")", "\n", "uriString", ":=", "config", ".", "GetString", "(", "configProxyServerBaseURI", ")", "\n", "uri", ",", "err", ":=", "url",...
// don't call externally. will block until success.
[ "don", "t", "call", "externally", ".", "will", "block", "until", "success", "." ]
655b66d3ded76155c155649c401cc9ac0fbf3969
https://github.com/apid/apidApigeeSync/blob/655b66d3ded76155c155649c401cc9ac0fbf3969/token.go#L137-L148
154,167
jsccast/tinygraph
repl.go
Scan
func (e *Env) Scan(g *Graph, s []byte, limit int64) [][]string { alloc := limit if 10000 < alloc { alloc = 10000 } acc := make([][]string, 0, alloc) g.Do(SPO, &Triple{[]byte(s), nil, nil, nil}, nil, func(t *Triple) bool { acc = append(acc, t.Strings()) limit-- if limit == 0 { return false } return true }) return acc }
go
func (e *Env) Scan(g *Graph, s []byte, limit int64) [][]string { alloc := limit if 10000 < alloc { alloc = 10000 } acc := make([][]string, 0, alloc) g.Do(SPO, &Triple{[]byte(s), nil, nil, nil}, nil, func(t *Triple) bool { acc = append(acc, t.Strings()) limit-- if limit == 0 { return false } return true }) return acc }
[ "func", "(", "e", "*", "Env", ")", "Scan", "(", "g", "*", "Graph", ",", "s", "[", "]", "byte", ",", "limit", "int64", ")", "[", "]", "[", "]", "string", "{", "alloc", ":=", "limit", "\n", "if", "10000", "<", "alloc", "{", "alloc", "=", "10000...
// Scan returns up to 'limit' triples starting with the given vertex.
[ "Scan", "returns", "up", "to", "limit", "triples", "starting", "with", "the", "given", "vertex", "." ]
72b309a39878d5618ba15fa102a6b5e906ddb43e
https://github.com/jsccast/tinygraph/blob/72b309a39878d5618ba15fa102a6b5e906ddb43e/repl.go#L142-L158
154,168
crackcomm/cloudflare
messages.go
Err
func (response *Response) Err() error { if len(response.Errors) > 0 { return response.Errors[0] } return nil }
go
func (response *Response) Err() error { if len(response.Errors) > 0 { return response.Errors[0] } return nil }
[ "func", "(", "response", "*", "Response", ")", "Err", "(", ")", "error", "{", "if", "len", "(", "response", ".", "Errors", ")", ">", "0", "{", "return", "response", ".", "Errors", "[", "0", "]", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Err - Gets response error if any.
[ "Err", "-", "Gets", "response", "error", "if", "any", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/messages.go#L30-L35
154,169
apid/apidApigeeSync
snapshot.go
downloadDataSnapshot
func (s *apidSnapshotManager) downloadDataSnapshot() error { if atomic.SwapInt32(s.isDownloading, 1) == int32(1) { log.Panic("downloadDataSnapshot: only 1 thread can download snapshot at the same time!") } defer atomic.StoreInt32(s.isDownloading, int32(0)) log.Debug("download Snapshot for data scopes") scopes, err := s.dbMan.findScopesForId(apidInfo.ClusterID) if err != nil { return err } scopes = append(scopes, apidInfo.ClusterID) snapshot := &common.Snapshot{} s.downloadSnapshot(false, scopes, snapshot) return s.startOnDataSnapshot(snapshot.SnapshotInfo) }
go
func (s *apidSnapshotManager) downloadDataSnapshot() error { if atomic.SwapInt32(s.isDownloading, 1) == int32(1) { log.Panic("downloadDataSnapshot: only 1 thread can download snapshot at the same time!") } defer atomic.StoreInt32(s.isDownloading, int32(0)) log.Debug("download Snapshot for data scopes") scopes, err := s.dbMan.findScopesForId(apidInfo.ClusterID) if err != nil { return err } scopes = append(scopes, apidInfo.ClusterID) snapshot := &common.Snapshot{} s.downloadSnapshot(false, scopes, snapshot) return s.startOnDataSnapshot(snapshot.SnapshotInfo) }
[ "func", "(", "s", "*", "apidSnapshotManager", ")", "downloadDataSnapshot", "(", ")", "error", "{", "if", "atomic", ".", "SwapInt32", "(", "s", ".", "isDownloading", ",", "1", ")", "==", "int32", "(", "1", ")", "{", "log", ".", "Panic", "(", "\"", "\"...
// use the scope IDs from the boot snapshot to get all the data associated with the scopes
[ "use", "the", "scope", "IDs", "from", "the", "boot", "snapshot", "to", "get", "all", "the", "data", "associated", "with", "the", "scopes" ]
655b66d3ded76155c155649c401cc9ac0fbf3969
https://github.com/apid/apidApigeeSync/blob/655b66d3ded76155c155649c401cc9ac0fbf3969/snapshot.go#L119-L135
154,170
apid/apidApigeeSync
snapshot.go
downloadSnapshot
func (s *apidSnapshotManager) downloadSnapshot(isBoot bool, scopes []string, snapshot *common.Snapshot) { log.Debug("downloadSnapshot") snapshotUri, err := url.Parse(config.GetString(configSnapServerBaseURI)) if err != nil { log.Panicf("bad url value for config %s: %s", snapshotUri, err) } snapshotUri.Path = path.Join(snapshotUri.Path, "snapshots") v := url.Values{} for _, scope := range scopes { v.Add("scope", scope) } snapshotUri.RawQuery = v.Encode() uri := snapshotUri.String() log.Infof("Snapshot Download: %s", uri) //pollWithBackoff only accepts function that accept a single quit channel //to accommodate functions which need more parameters, wrap them in closures attemptDownload := s.getAttemptDownloadClosure(isBoot, snapshot, uri) pollWithBackoff(s.quitChan, attemptDownload, handleSnapshotServerError) }
go
func (s *apidSnapshotManager) downloadSnapshot(isBoot bool, scopes []string, snapshot *common.Snapshot) { log.Debug("downloadSnapshot") snapshotUri, err := url.Parse(config.GetString(configSnapServerBaseURI)) if err != nil { log.Panicf("bad url value for config %s: %s", snapshotUri, err) } snapshotUri.Path = path.Join(snapshotUri.Path, "snapshots") v := url.Values{} for _, scope := range scopes { v.Add("scope", scope) } snapshotUri.RawQuery = v.Encode() uri := snapshotUri.String() log.Infof("Snapshot Download: %s", uri) //pollWithBackoff only accepts function that accept a single quit channel //to accommodate functions which need more parameters, wrap them in closures attemptDownload := s.getAttemptDownloadClosure(isBoot, snapshot, uri) pollWithBackoff(s.quitChan, attemptDownload, handleSnapshotServerError) }
[ "func", "(", "s", "*", "apidSnapshotManager", ")", "downloadSnapshot", "(", "isBoot", "bool", ",", "scopes", "[", "]", "string", ",", "snapshot", "*", "common", ".", "Snapshot", ")", "{", "log", ".", "Debug", "(", "\"", "\"", ")", "\n\n", "snapshotUri", ...
// a blocking method // will keep retrying with backoff until success
[ "a", "blocking", "method", "will", "keep", "retrying", "with", "backoff", "until", "success" ]
655b66d3ded76155c155649c401cc9ac0fbf3969
https://github.com/apid/apidApigeeSync/blob/655b66d3ded76155c155649c401cc9ac0fbf3969/snapshot.go#L140-L163
154,171
jsccast/tinygraph
triples.go
Permute
func (t *Triple) Permute(index Index) *Triple { switch index { case SPO: case OPS: s := t.S t.S = t.O t.O = s case PSO: s := t.S t.S = t.P t.P = s } return t }
go
func (t *Triple) Permute(index Index) *Triple { switch index { case SPO: case OPS: s := t.S t.S = t.O t.O = s case PSO: s := t.S t.S = t.P t.P = s } return t }
[ "func", "(", "t", "*", "Triple", ")", "Permute", "(", "index", "Index", ")", "*", "Triple", "{", "switch", "index", "{", "case", "SPO", ":", "case", "OPS", ":", "s", ":=", "t", ".", "S", "\n", "t", ".", "S", "=", "t", ".", "O", "\n", "t", "...
// Does not copy!
[ "Does", "not", "copy!" ]
72b309a39878d5618ba15fa102a6b5e906ddb43e
https://github.com/jsccast/tinygraph/blob/72b309a39878d5618ba15fa102a6b5e906ddb43e/triples.go#L153-L167
154,172
spiegel-im-spiegel/logf
logf.go
SetOutput
func (l *Logger) SetOutput(w io.Writer) { l.mu.Lock() defer l.mu.Unlock() l.lg.SetOutput(w) }
go
func (l *Logger) SetOutput(w io.Writer) { l.mu.Lock() defer l.mu.Unlock() l.lg.SetOutput(w) }
[ "func", "(", "l", "*", "Logger", ")", "SetOutput", "(", "w", "io", ".", "Writer", ")", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "Unlock", "(", ")", "\n", "l", ".", "lg", ".", "SetOutput", "(", "w", ")"...
// SetOutput sets the output destination for the logger.
[ "SetOutput", "sets", "the", "output", "destination", "for", "the", "logger", "." ]
3c2fa3581e9ec1f66d3c6b2f7f4d142af68b9dec
https://github.com/spiegel-im-spiegel/logf/blob/3c2fa3581e9ec1f66d3c6b2f7f4d142af68b9dec/logf.go#L76-L80
154,173
spiegel-im-spiegel/logf
logf.go
SetMinLevel
func (l *Logger) SetMinLevel(lv Level) { l.mu.Lock() defer l.mu.Unlock() l.min = lv }
go
func (l *Logger) SetMinLevel(lv Level) { l.mu.Lock() defer l.mu.Unlock() l.min = lv }
[ "func", "(", "l", "*", "Logger", ")", "SetMinLevel", "(", "lv", "Level", ")", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "Unlock", "(", ")", "\n", "l", ".", "min", "=", "lv", "\n", "}" ]
// SetMinLevel sets the minimum level for the logger.
[ "SetMinLevel", "sets", "the", "minimum", "level", "for", "the", "logger", "." ]
3c2fa3581e9ec1f66d3c6b2f7f4d142af68b9dec
https://github.com/spiegel-im-spiegel/logf/blob/3c2fa3581e9ec1f66d3c6b2f7f4d142af68b9dec/logf.go#L96-L100
154,174
rdwilliamson/aws
glacier/archive.go
UploadArchive
func (c *Connection) UploadArchive(vault string, archive io.ReadSeeker, description string) (string, error) { // Build reuest. request, err := http.NewRequest("POST", c.vault(vault)+"/archives", archive) if err != nil { return "", err } request.Header.Add("x-amz-glacier-version", "2012-06-01") th := NewTreeHash() request.ContentLength, err = io.Copy(th, archive) if err != nil { return "", err } th.Close() _, err = archive.Seek(0, 0) if err != nil { return "", err } hash := th.Hash() request.Header.Add("x-amz-archive-description", description) request.Header.Add("x-amz-sha256-tree-hash", toHex(th.TreeHash())) request.Header.Add("x-amz-content-sha256", toHex(hash)) c.Signature.Sign(request, aws.HashedPayload(hash)) // Perform request. response, err := c.client().Do(request) if err != nil { return "", err } defer response.Body.Close() if response.StatusCode != http.StatusCreated { return "", aws.ParseError(response) } io.Copy(ioutil.Discard, response.Body) // Parse success response. _, location := path.Split(response.Header.Get("Location")) return location, nil }
go
func (c *Connection) UploadArchive(vault string, archive io.ReadSeeker, description string) (string, error) { // Build reuest. request, err := http.NewRequest("POST", c.vault(vault)+"/archives", archive) if err != nil { return "", err } request.Header.Add("x-amz-glacier-version", "2012-06-01") th := NewTreeHash() request.ContentLength, err = io.Copy(th, archive) if err != nil { return "", err } th.Close() _, err = archive.Seek(0, 0) if err != nil { return "", err } hash := th.Hash() request.Header.Add("x-amz-archive-description", description) request.Header.Add("x-amz-sha256-tree-hash", toHex(th.TreeHash())) request.Header.Add("x-amz-content-sha256", toHex(hash)) c.Signature.Sign(request, aws.HashedPayload(hash)) // Perform request. response, err := c.client().Do(request) if err != nil { return "", err } defer response.Body.Close() if response.StatusCode != http.StatusCreated { return "", aws.ParseError(response) } io.Copy(ioutil.Discard, response.Body) // Parse success response. _, location := path.Split(response.Header.Get("Location")) return location, nil }
[ "func", "(", "c", "*", "Connection", ")", "UploadArchive", "(", "vault", "string", ",", "archive", "io", ".", "ReadSeeker", ",", "description", "string", ")", "(", "string", ",", "error", ")", "{", "// Build reuest.", "request", ",", "err", ":=", "http", ...
// Upload archive to vault with optional description. The entire archive will // be read in order to create its tree hash before uploading. // // Returns the archive ID or the first error encountered.
[ "Upload", "archive", "to", "vault", "with", "optional", "description", ".", "The", "entire", "archive", "will", "be", "read", "in", "order", "to", "create", "its", "tree", "hash", "before", "uploading", ".", "Returns", "the", "archive", "ID", "or", "the", ...
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/archive.go#L16-L61
154,175
rdwilliamson/aws
glacier/treehash.go
Add
func (t *MultiTreeHasher) Add(hash string) { var b [sha256.Size]byte hex.Decode(b[:], []byte(hash)) t.nodes = append(t.nodes, b) }
go
func (t *MultiTreeHasher) Add(hash string) { var b [sha256.Size]byte hex.Decode(b[:], []byte(hash)) t.nodes = append(t.nodes, b) }
[ "func", "(", "t", "*", "MultiTreeHasher", ")", "Add", "(", "hash", "string", ")", "{", "var", "b", "[", "sha256", ".", "Size", "]", "byte", "\n", "hex", ".", "Decode", "(", "b", "[", ":", "]", ",", "[", "]", "byte", "(", "hash", ")", ")", "\n...
// Add appends the hex-encoded hash to the treehash as a new node // Add must be called sequentially on parts.
[ "Add", "appends", "the", "hex", "-", "encoded", "hash", "to", "the", "treehash", "as", "a", "new", "node", "Add", "must", "be", "called", "sequentially", "on", "parts", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L19-L23
154,176
rdwilliamson/aws
glacier/treehash.go
CreateHash
func (t *MultiTreeHasher) CreateHash() string { if len(t.nodes) == 0 { return "" } rootHash := treeHash(t.nodes) return hex.EncodeToString(rootHash[:]) }
go
func (t *MultiTreeHasher) CreateHash() string { if len(t.nodes) == 0 { return "" } rootHash := treeHash(t.nodes) return hex.EncodeToString(rootHash[:]) }
[ "func", "(", "t", "*", "MultiTreeHasher", ")", "CreateHash", "(", ")", "string", "{", "if", "len", "(", "t", ".", "nodes", ")", "==", "0", "{", "return", "\"", "\"", "\n", "}", "\n", "rootHash", ":=", "treeHash", "(", "t", ".", "nodes", ")", "\n"...
// CreateHash returns the root-level hex-encoded hash to send in the // CompleteMultipart request.
[ "CreateHash", "returns", "the", "root", "-", "level", "hex", "-", "encoded", "hash", "to", "send", "in", "the", "CompleteMultipart", "request", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L27-L33
154,177
rdwilliamson/aws
glacier/treehash.go
treeHash
func treeHash(nodes [][sha256.Size]byte) [sha256.Size]byte { var combine [sha256.Size * 2]byte for len(nodes) > 1 { for i := 0; i < len(nodes)/2; i++ { copy(combine[:sha256.Size], nodes[i*2][:]) copy(combine[sha256.Size:], nodes[i*2+1][:]) nodes[i] = sha256.Sum256(combine[:]) } if len(nodes)%2 == 0 { nodes = nodes[:len(nodes)/2] } else { nodes[len(nodes)/2] = nodes[len(nodes)-1] nodes = nodes[:len(nodes)/2+1] } } return nodes[0] }
go
func treeHash(nodes [][sha256.Size]byte) [sha256.Size]byte { var combine [sha256.Size * 2]byte for len(nodes) > 1 { for i := 0; i < len(nodes)/2; i++ { copy(combine[:sha256.Size], nodes[i*2][:]) copy(combine[sha256.Size:], nodes[i*2+1][:]) nodes[i] = sha256.Sum256(combine[:]) } if len(nodes)%2 == 0 { nodes = nodes[:len(nodes)/2] } else { nodes[len(nodes)/2] = nodes[len(nodes)-1] nodes = nodes[:len(nodes)/2+1] } } return nodes[0] }
[ "func", "treeHash", "(", "nodes", "[", "]", "[", "sha256", ".", "Size", "]", "byte", ")", "[", "sha256", ".", "Size", "]", "byte", "{", "var", "combine", "[", "sha256", ".", "Size", "*", "2", "]", "byte", "\n", "for", "len", "(", "nodes", ")", ...
// treeHash calculates the root-level treeHash given sequential // leaf nodes.
[ "treeHash", "calculates", "the", "root", "-", "level", "treeHash", "given", "sequential", "leaf", "nodes", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L37-L53
154,178
rdwilliamson/aws
glacier/treehash.go
NewTreeHash
func NewTreeHash() *TreeHash { result := &TreeHash{ runningHash: sha256.New(), remaining: make([]byte, 0, 1<<20), } result.Reset() return result }
go
func NewTreeHash() *TreeHash { result := &TreeHash{ runningHash: sha256.New(), remaining: make([]byte, 0, 1<<20), } result.Reset() return result }
[ "func", "NewTreeHash", "(", ")", "*", "TreeHash", "{", "result", ":=", "&", "TreeHash", "{", "runningHash", ":", "sha256", ".", "New", "(", ")", ",", "remaining", ":", "make", "(", "[", "]", "byte", ",", "0", ",", "1", "<<", "20", ")", ",", "}", ...
// NewTreeHash returns an new, initialized tree hasher.
[ "NewTreeHash", "returns", "an", "new", "initialized", "tree", "hasher", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L71-L78
154,179
rdwilliamson/aws
glacier/treehash.go
Reset
func (th *TreeHash) Reset() { th.runningHash.Reset() th.remaining = th.remaining[:0] th.nodes = th.nodes[:0] th.treeHash = [sha256.Size]byte{} th.linearHash = [sha256.Size]byte{} }
go
func (th *TreeHash) Reset() { th.runningHash.Reset() th.remaining = th.remaining[:0] th.nodes = th.nodes[:0] th.treeHash = [sha256.Size]byte{} th.linearHash = [sha256.Size]byte{} }
[ "func", "(", "th", "*", "TreeHash", ")", "Reset", "(", ")", "{", "th", ".", "runningHash", ".", "Reset", "(", ")", "\n", "th", ".", "remaining", "=", "th", ".", "remaining", "[", ":", "0", "]", "\n", "th", ".", "nodes", "=", "th", ".", "nodes",...
// Reset the tree hash's state allowing it to be reused.
[ "Reset", "the", "tree", "hash", "s", "state", "allowing", "it", "to", "be", "reused", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L81-L87
154,180
rdwilliamson/aws
glacier/treehash.go
Write
func (th *TreeHash) Write(p []byte) (int, error) { n := len(p) // Not enough data to fill a 1 MB chunk. if len(th.remaining)+len(p) < 1<<20 { th.remaining = append(th.remaining, p...) return n, nil } // Move enough to fill th.remaining to 1 MB. fill := 1<<20 - len(th.remaining) th.remaining = append(th.remaining, p[:fill]...) p = p[fill:] // Append the 1 MB in th.remaining. th.nodes = append(th.nodes, sha256.Sum256(th.remaining)) th.runningHash.Write(th.remaining) th.remaining = th.remaining[:0] // Append all 1M chunks remaining in p. for len(p) >= 1<<20 { th.nodes = append(th.nodes, sha256.Sum256(p[:1<<20])) th.runningHash.Write(p[:1<<20]) p = p[1<<20:] } // Copy what remains in p to th.remaining. th.remaining = append(th.remaining, p...) return n, nil }
go
func (th *TreeHash) Write(p []byte) (int, error) { n := len(p) // Not enough data to fill a 1 MB chunk. if len(th.remaining)+len(p) < 1<<20 { th.remaining = append(th.remaining, p...) return n, nil } // Move enough to fill th.remaining to 1 MB. fill := 1<<20 - len(th.remaining) th.remaining = append(th.remaining, p[:fill]...) p = p[fill:] // Append the 1 MB in th.remaining. th.nodes = append(th.nodes, sha256.Sum256(th.remaining)) th.runningHash.Write(th.remaining) th.remaining = th.remaining[:0] // Append all 1M chunks remaining in p. for len(p) >= 1<<20 { th.nodes = append(th.nodes, sha256.Sum256(p[:1<<20])) th.runningHash.Write(p[:1<<20]) p = p[1<<20:] } // Copy what remains in p to th.remaining. th.remaining = append(th.remaining, p...) return n, nil }
[ "func", "(", "th", "*", "TreeHash", ")", "Write", "(", "p", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "n", ":=", "len", "(", "p", ")", "\n\n", "// Not enough data to fill a 1 MB chunk.", "if", "len", "(", "th", ".", "remaining", ")",...
// Write writes all of p, storing every 1 MiB of data's hash.
[ "Write", "writes", "all", "of", "p", "storing", "every", "1", "MiB", "of", "data", "s", "hash", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L90-L120
154,181
rdwilliamson/aws
glacier/treehash.go
Close
func (th *TreeHash) Close() error { // create last node; it is impossible that it has a size > 1 MB if len(th.remaining) > 0 { th.nodes = append(th.nodes, sha256.Sum256(th.remaining)) th.runningHash.Write(th.remaining) } // Calculate the tree and linear hashes if len(th.nodes) > 0 { th.treeHash = treeHash(th.nodes) } th.runningHash.Sum(th.linearHash[:0]) return nil }
go
func (th *TreeHash) Close() error { // create last node; it is impossible that it has a size > 1 MB if len(th.remaining) > 0 { th.nodes = append(th.nodes, sha256.Sum256(th.remaining)) th.runningHash.Write(th.remaining) } // Calculate the tree and linear hashes if len(th.nodes) > 0 { th.treeHash = treeHash(th.nodes) } th.runningHash.Sum(th.linearHash[:0]) return nil }
[ "func", "(", "th", "*", "TreeHash", ")", "Close", "(", ")", "error", "{", "// create last node; it is impossible that it has a size > 1 MB", "if", "len", "(", "th", ".", "remaining", ")", ">", "0", "{", "th", ".", "nodes", "=", "append", "(", "th", ".", "n...
// Close closes the the remaing chunks of data and then calculates the tree hash.
[ "Close", "closes", "the", "the", "remaing", "chunks", "of", "data", "and", "then", "calculates", "the", "tree", "hash", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/glacier/treehash.go#L123-L135
154,182
garfunkel/go-tvdb
tvdb.go
UnmarshalXML
func (pipeList *PipeList) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) (err error) { content := "" if err = decoder.DecodeElement(&content, &start); err != nil { return err } *pipeList = strings.Split(strings.Trim(content, "|"), "|") return }
go
func (pipeList *PipeList) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) (err error) { content := "" if err = decoder.DecodeElement(&content, &start); err != nil { return err } *pipeList = strings.Split(strings.Trim(content, "|"), "|") return }
[ "func", "(", "pipeList", "*", "PipeList", ")", "UnmarshalXML", "(", "decoder", "*", "xml", ".", "Decoder", ",", "start", "xml", ".", "StartElement", ")", "(", "err", "error", ")", "{", "content", ":=", "\"", "\"", "\n\n", "if", "err", "=", "decoder", ...
// UnmarshalXML unmarshals an XML element with string value into a pip-separated list of strings.
[ "UnmarshalXML", "unmarshals", "an", "XML", "element", "with", "string", "value", "into", "a", "pip", "-", "separated", "list", "of", "strings", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L46-L56
154,183
garfunkel/go-tvdb
tvdb.go
GetDetail
func (seriesList *SeriesList) GetDetail() (err error) { for seriesIndex := range seriesList.Series { if err = seriesList.Series[seriesIndex].GetDetail(); err != nil { return } } return }
go
func (seriesList *SeriesList) GetDetail() (err error) { for seriesIndex := range seriesList.Series { if err = seriesList.Series[seriesIndex].GetDetail(); err != nil { return } } return }
[ "func", "(", "seriesList", "*", "SeriesList", ")", "GetDetail", "(", ")", "(", "err", "error", ")", "{", "for", "seriesIndex", ":=", "range", "seriesList", ".", "Series", "{", "if", "err", "=", "seriesList", ".", "Series", "[", "seriesIndex", "]", ".", ...
// GetDetail gets more detail for all TV shows in a list.
[ "GetDetail", "gets", "more", "detail", "for", "all", "TV", "shows", "in", "a", "list", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L132-L140
154,184
garfunkel/go-tvdb
tvdb.go
GetDetail
func (series *Series) GetDetail() (err error) { response, err := http.Get(fmt.Sprintf(GetDetailURL, APIKey, strconv.FormatUint(series.ID, 10))) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } // Unmarshal data into SeriesList object seriesList := SeriesList{} if err = xml.Unmarshal(data, &seriesList); err != nil { return } // Copy the first result into the series object *series = *seriesList.Series[0] episodeList := EpisodeList{} if err = xml.Unmarshal(data, &episodeList); err != nil { return } if series.Seasons == nil { series.Seasons = make(map[uint64][]*Episode) } for _, episode := range episodeList.Episodes { series.Seasons[episode.SeasonNumber] = append(series.Seasons[episode.SeasonNumber], episode) } return }
go
func (series *Series) GetDetail() (err error) { response, err := http.Get(fmt.Sprintf(GetDetailURL, APIKey, strconv.FormatUint(series.ID, 10))) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } // Unmarshal data into SeriesList object seriesList := SeriesList{} if err = xml.Unmarshal(data, &seriesList); err != nil { return } // Copy the first result into the series object *series = *seriesList.Series[0] episodeList := EpisodeList{} if err = xml.Unmarshal(data, &episodeList); err != nil { return } if series.Seasons == nil { series.Seasons = make(map[uint64][]*Episode) } for _, episode := range episodeList.Episodes { series.Seasons[episode.SeasonNumber] = append(series.Seasons[episode.SeasonNumber], episode) } return }
[ "func", "(", "series", "*", "Series", ")", "GetDetail", "(", ")", "(", "err", "error", ")", "{", "response", ",", "err", ":=", "http", ".", "Get", "(", "fmt", ".", "Sprintf", "(", "GetDetailURL", ",", "APIKey", ",", "strconv", ".", "FormatUint", "(",...
// GetDetail gets more detail for a TV show, including information on it's episodes.
[ "GetDetail", "gets", "more", "detail", "for", "a", "TV", "show", "including", "information", "on", "it", "s", "episodes", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L143-L180
154,185
garfunkel/go-tvdb
tvdb.go
GetSeries
func GetSeries(name string) (seriesList SeriesList, err error) { response, err := http.Get(fmt.Sprintf(GetSeriesURL, url.QueryEscape(name))) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } err = xml.Unmarshal(data, &seriesList) return }
go
func GetSeries(name string) (seriesList SeriesList, err error) { response, err := http.Get(fmt.Sprintf(GetSeriesURL, url.QueryEscape(name))) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } err = xml.Unmarshal(data, &seriesList) return }
[ "func", "GetSeries", "(", "name", "string", ")", "(", "seriesList", "SeriesList", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "http", ".", "Get", "(", "fmt", ".", "Sprintf", "(", "GetSeriesURL", ",", "url", ".", "QueryEscape", "(", "na...
// GetSeries gets a list of TV series by name, by performing a simple search.
[ "GetSeries", "gets", "a", "list", "of", "TV", "series", "by", "name", "by", "performing", "a", "simple", "search", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L183-L199
154,186
garfunkel/go-tvdb
tvdb.go
GetSeriesByID
func GetSeriesByID(id uint64) (series *Series, err error) { response, err := http.Get(fmt.Sprintf(GetSeriesByIDURL, APIKey, id)) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } seriesList := SeriesList{} if err = xml.Unmarshal(data, &seriesList); err != nil { return } if len(seriesList.Series) != 1 { err = errors.New("incorrect number of series") return } series = seriesList.Series[0] return }
go
func GetSeriesByID(id uint64) (series *Series, err error) { response, err := http.Get(fmt.Sprintf(GetSeriesByIDURL, APIKey, id)) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } seriesList := SeriesList{} if err = xml.Unmarshal(data, &seriesList); err != nil { return } if len(seriesList.Series) != 1 { err = errors.New("incorrect number of series") return } series = seriesList.Series[0] return }
[ "func", "GetSeriesByID", "(", "id", "uint64", ")", "(", "series", "*", "Series", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "http", ".", "Get", "(", "fmt", ".", "Sprintf", "(", "GetSeriesByIDURL", ",", "APIKey", ",", "id", ")", ")",...
// GetSeriesByID gets a TV series by ID.
[ "GetSeriesByID", "gets", "a", "TV", "series", "by", "ID", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L202-L230
154,187
garfunkel/go-tvdb
tvdb.go
GetSeriesByIMDBID
func GetSeriesByIMDBID(id string) (series *Series, err error) { response, err := http.Get(fmt.Sprintf(GetSeriesByIMDBIDURL, id)) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } seriesList := SeriesList{} if err = xml.Unmarshal(data, &seriesList); err != nil { return } if len(seriesList.Series) != 1 { err = errors.New("incorrect number of series") return } series = seriesList.Series[0] return }
go
func GetSeriesByIMDBID(id string) (series *Series, err error) { response, err := http.Get(fmt.Sprintf(GetSeriesByIMDBIDURL, id)) if err != nil { return } data, err := ioutil.ReadAll(response.Body) if err != nil { return } seriesList := SeriesList{} if err = xml.Unmarshal(data, &seriesList); err != nil { return } if len(seriesList.Series) != 1 { err = errors.New("incorrect number of series") return } series = seriesList.Series[0] return }
[ "func", "GetSeriesByIMDBID", "(", "id", "string", ")", "(", "series", "*", "Series", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "http", ".", "Get", "(", "fmt", ".", "Sprintf", "(", "GetSeriesByIMDBIDURL", ",", "id", ")", ")", "\n\n", ...
// GetSeriesByIMDBID gets series from IMDb's ID.
[ "GetSeriesByIMDBID", "gets", "series", "from", "IMDb", "s", "ID", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L233-L261
154,188
garfunkel/go-tvdb
tvdb.go
SearchSeries
func SearchSeries(name string, maxResults int) (seriesList SeriesList, err error) { response, err := http.Get(fmt.Sprintf(SearchSeriesURL, url.QueryEscape(name))) if err != nil { return } buf, err := ioutil.ReadAll(response.Body) if err != nil { return } groups := SearchSeriesRegex.FindAllSubmatch(buf, -1) doneSeriesIDs := make(map[uint64]struct{}) for _, group := range groups { seriesID := uint64(0) var series *Series seriesID, err = strconv.ParseUint(string(group[2]), 10, 64) if _, ok := doneSeriesIDs[seriesID]; ok { continue } if err != nil { return } series, err = GetSeriesByID(seriesID) if err != nil { // Some series can't be found, so we will ignore these. if _, ok := err.(*xml.SyntaxError); ok { err = nil continue } else { return } } seriesList.Series = append(seriesList.Series, series) doneSeriesIDs[seriesID] = struct{}{} if len(seriesList.Series) == maxResults { break } } return }
go
func SearchSeries(name string, maxResults int) (seriesList SeriesList, err error) { response, err := http.Get(fmt.Sprintf(SearchSeriesURL, url.QueryEscape(name))) if err != nil { return } buf, err := ioutil.ReadAll(response.Body) if err != nil { return } groups := SearchSeriesRegex.FindAllSubmatch(buf, -1) doneSeriesIDs := make(map[uint64]struct{}) for _, group := range groups { seriesID := uint64(0) var series *Series seriesID, err = strconv.ParseUint(string(group[2]), 10, 64) if _, ok := doneSeriesIDs[seriesID]; ok { continue } if err != nil { return } series, err = GetSeriesByID(seriesID) if err != nil { // Some series can't be found, so we will ignore these. if _, ok := err.(*xml.SyntaxError); ok { err = nil continue } else { return } } seriesList.Series = append(seriesList.Series, series) doneSeriesIDs[seriesID] = struct{}{} if len(seriesList.Series) == maxResults { break } } return }
[ "func", "SearchSeries", "(", "name", "string", ",", "maxResults", "int", ")", "(", "seriesList", "SeriesList", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "http", ".", "Get", "(", "fmt", ".", "Sprintf", "(", "SearchSeriesURL", ",", "url"...
// SearchSeries searches for TV shows by name, using the more sophisticated // search on TheTVDB's homepage. This is the recommended search method.
[ "SearchSeries", "searches", "for", "TV", "shows", "by", "name", "using", "the", "more", "sophisticated", "search", "on", "TheTVDB", "s", "homepage", ".", "This", "is", "the", "recommended", "search", "method", "." ]
59b4220a6dad5aa6d153d3b373a8020de417b9d7
https://github.com/garfunkel/go-tvdb/blob/59b4220a6dad5aa6d153d3b373a8020de417b9d7/tvdb.go#L265-L316
154,189
jsccast/tinygraph
options.go
LoadOptions
func LoadOptions(filename string) (*Options, error) { var bs []byte if strings.HasPrefix(filename, "{") { bs = []byte(filename) } else { var err error log.Printf("LoadOptions reading %s", filename) bs, err = ioutil.ReadFile(filename) if err != nil { log.Printf("LoadOptions error: %v (%s)", err, filename) return nil, err } } opts := make(Options) err := json.Unmarshal(bs, &opts) if err != nil { log.Printf("LoadOptions unmarshal error: %v on \"%s\"", err, bs) return nil, err } return &opts, nil }
go
func LoadOptions(filename string) (*Options, error) { var bs []byte if strings.HasPrefix(filename, "{") { bs = []byte(filename) } else { var err error log.Printf("LoadOptions reading %s", filename) bs, err = ioutil.ReadFile(filename) if err != nil { log.Printf("LoadOptions error: %v (%s)", err, filename) return nil, err } } opts := make(Options) err := json.Unmarshal(bs, &opts) if err != nil { log.Printf("LoadOptions unmarshal error: %v on \"%s\"", err, bs) return nil, err } return &opts, nil }
[ "func", "LoadOptions", "(", "filename", "string", ")", "(", "*", "Options", ",", "error", ")", "{", "var", "bs", "[", "]", "byte", "\n", "if", "strings", ".", "HasPrefix", "(", "filename", ",", "\"", "\"", ")", "{", "bs", "=", "[", "]", "byte", "...
// Filename can either be a file name or JSON. Surprise!
[ "Filename", "can", "either", "be", "a", "file", "name", "or", "JSON", ".", "Surprise!" ]
72b309a39878d5618ba15fa102a6b5e906ddb43e
https://github.com/jsccast/tinygraph/blob/72b309a39878d5618ba15fa102a6b5e906ddb43e/options.go#L40-L62
154,190
rdwilliamson/aws
aws.go
stringRequiresEncoding
func stringRequiresEncoding(s string) bool { for _, c := range []byte(s) { if charRequiresEncoding(c) { return true } } return false }
go
func stringRequiresEncoding(s string) bool { for _, c := range []byte(s) { if charRequiresEncoding(c) { return true } } return false }
[ "func", "stringRequiresEncoding", "(", "s", "string", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "[", "]", "byte", "(", "s", ")", "{", "if", "charRequiresEncoding", "(", "c", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "retu...
// Tests if a character requires encoding in a URI. //
[ "Tests", "if", "a", "character", "requires", "encoding", "in", "a", "URI", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/aws.go#L45-L52
154,191
rdwilliamson/aws
aws.go
toHex
func toHex(x []byte) []byte { z := make([]byte, 2*len(x)) hex.Encode(z, x) return z }
go
func toHex(x []byte) []byte { z := make([]byte, 2*len(x)) hex.Encode(z, x) return z }
[ "func", "toHex", "(", "x", "[", "]", "byte", ")", "[", "]", "byte", "{", "z", ":=", "make", "(", "[", "]", "byte", ",", "2", "*", "len", "(", "x", ")", ")", "\n", "hex", ".", "Encode", "(", "z", ",", "x", ")", "\n", "return", "z", "\n", ...
// Return a new copy of the input byte array that is // hex encoded. //
[ "Return", "a", "new", "copy", "of", "the", "input", "byte", "array", "that", "is", "hex", "encoded", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/aws.go#L97-L101
154,192
rdwilliamson/aws
aws.go
NewSignature
func NewSignature(secret, access string, r *Region, service string) *Signature { var s Signature s.AccessID = access s.Date = time.Now().UTC().Format(ISO8601BasicFormatShort) s.Region = r s.Service = service s.generateSigningKey(secret) return &s }
go
func NewSignature(secret, access string, r *Region, service string) *Signature { var s Signature s.AccessID = access s.Date = time.Now().UTC().Format(ISO8601BasicFormatShort) s.Region = r s.Service = service s.generateSigningKey(secret) return &s }
[ "func", "NewSignature", "(", "secret", ",", "access", "string", ",", "r", "*", "Region", ",", "service", "string", ")", "*", "Signature", "{", "var", "s", "Signature", "\n\n", "s", ".", "AccessID", "=", "access", "\n", "s", ".", "Date", "=", "time", ...
// NewSignature creates a new signature from the secret key, access key, // region, and service with the date set to UTC now.
[ "NewSignature", "creates", "a", "new", "signature", "from", "the", "secret", "key", "access", "key", "region", "and", "service", "with", "the", "date", "set", "to", "UTC", "now", "." ]
54608bb65939fc94439865d46598a57f7f15fb0e
https://github.com/rdwilliamson/aws/blob/54608bb65939fc94439865d46598a57f7f15fb0e/aws.go#L135-L145
154,193
karlseguin/expect
mock/conn.go
Conn
func Conn() *MockConn { return &MockConn{ first: true, Written: make([][]byte, 0, 4), readings: make([][]byte, 0, 4), } }
go
func Conn() *MockConn { return &MockConn{ first: true, Written: make([][]byte, 0, 4), readings: make([][]byte, 0, 4), } }
[ "func", "Conn", "(", ")", "*", "MockConn", "{", "return", "&", "MockConn", "{", "first", ":", "true", ",", "Written", ":", "make", "(", "[", "]", "[", "]", "byte", ",", "0", ",", "4", ")", ",", "readings", ":", "make", "(", "[", "]", "[", "]"...
// Creates a new mock object which satisfies the net.Conn interface
[ "Creates", "a", "new", "mock", "object", "which", "satisfies", "the", "net", ".", "Conn", "interface" ]
ecc6aa3406d03d381160d52b8a76268abdb14321
https://github.com/karlseguin/expect/blob/ecc6aa3406d03d381160d52b8a76268abdb14321/mock/conn.go#L20-L26
154,194
karlseguin/expect
mock/conn.go
Drain
func (c *MockConn) Drain() []byte { left := 0 for i := c.readIndex; i < len(c.readings); i++ { left += len(c.readings[i]) } data := make([]byte, 0, left) for i := c.readIndex; i < len(c.readings); i++ { data = append(data, c.readings[i]...) } return data }
go
func (c *MockConn) Drain() []byte { left := 0 for i := c.readIndex; i < len(c.readings); i++ { left += len(c.readings[i]) } data := make([]byte, 0, left) for i := c.readIndex; i < len(c.readings); i++ { data = append(data, c.readings[i]...) } return data }
[ "func", "(", "c", "*", "MockConn", ")", "Drain", "(", ")", "[", "]", "byte", "{", "left", ":=", "0", "\n", "for", "i", ":=", "c", ".", "readIndex", ";", "i", "<", "len", "(", "c", ".", "readings", ")", ";", "i", "++", "{", "left", "+=", "le...
// Returns whatever data hasn't been read yet
[ "Returns", "whatever", "data", "hasn", "t", "been", "read", "yet" ]
ecc6aa3406d03d381160d52b8a76268abdb14321
https://github.com/karlseguin/expect/blob/ecc6aa3406d03d381160d52b8a76268abdb14321/mock/conn.go#L113-L123
154,195
crackcomm/cloudflare
client_records.go
Create
func (records *Records) Create(ctx context.Context, record *Record) (err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(record) if err != nil { return } response, err := httpDo(ctx, records.Options, "POST", apiURL("/zones/%s/dns_records", record.ZoneID), buffer) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } res := new(Record) err = json.Unmarshal(result.Result, &res) if err != nil { return } record.ID = res.ID record.TTL = res.TTL record.Locked = res.Locked record.Proxied = res.Proxied record.Proxiable = res.Proxiable record.CreatedOn = res.CreatedOn record.ModifiedOn = res.ModifiedOn return }
go
func (records *Records) Create(ctx context.Context, record *Record) (err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(record) if err != nil { return } response, err := httpDo(ctx, records.Options, "POST", apiURL("/zones/%s/dns_records", record.ZoneID), buffer) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } res := new(Record) err = json.Unmarshal(result.Result, &res) if err != nil { return } record.ID = res.ID record.TTL = res.TTL record.Locked = res.Locked record.Proxied = res.Proxied record.Proxiable = res.Proxiable record.CreatedOn = res.CreatedOn record.ModifiedOn = res.ModifiedOn return }
[ "func", "(", "records", "*", "Records", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "record", "*", "Record", ")", "(", "err", "error", ")", "{", "buffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", "=", "json", ".", ...
// Create - Creates a zone DNS record. // Required parameters of a record are - `type`, `name` and `content`. // Optional parameters of a record are - `ttl`.
[ "Create", "-", "Creates", "a", "zone", "DNS", "record", ".", "Required", "parameters", "of", "a", "record", "are", "-", "type", "name", "and", "content", ".", "Optional", "parameters", "of", "a", "record", "are", "-", "ttl", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_records.go#L19-L47
154,196
crackcomm/cloudflare
client_records.go
List
func (records *Records) List(ctx context.Context, zoneID string) ([]*Record, error) { return records.listPages(ctx, zoneID, 1) }
go
func (records *Records) List(ctx context.Context, zoneID string) ([]*Record, error) { return records.listPages(ctx, zoneID, 1) }
[ "func", "(", "records", "*", "Records", ")", "List", "(", "ctx", "context", ".", "Context", ",", "zoneID", "string", ")", "(", "[", "]", "*", "Record", ",", "error", ")", "{", "return", "records", ".", "listPages", "(", "ctx", ",", "zoneID", ",", "...
// List - Lists all zone DNS records.
[ "List", "-", "Lists", "all", "zone", "DNS", "records", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_records.go#L50-L52
154,197
crackcomm/cloudflare
client_records.go
Details
func (records *Records) Details(ctx context.Context, zoneID, recordID string) (record *Record, err error) { response, err := httpDo(ctx, records.Options, "GET", apiURL("/zones/%s/dns_records/%s", zoneID, recordID), nil) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } record = new(Record) err = json.Unmarshal(result.Result, &record) return }
go
func (records *Records) Details(ctx context.Context, zoneID, recordID string) (record *Record, err error) { response, err := httpDo(ctx, records.Options, "GET", apiURL("/zones/%s/dns_records/%s", zoneID, recordID), nil) if err != nil { return } defer response.Body.Close() result, err := readResponse(response.Body) if err != nil { return } record = new(Record) err = json.Unmarshal(result.Result, &record) return }
[ "func", "(", "records", "*", "Records", ")", "Details", "(", "ctx", "context", ".", "Context", ",", "zoneID", ",", "recordID", "string", ")", "(", "record", "*", "Record", ",", "err", "error", ")", "{", "response", ",", "err", ":=", "httpDo", "(", "c...
// Details - Requests zone DNS record details by zone ID and record ID.
[ "Details", "-", "Requests", "zone", "DNS", "record", "details", "by", "zone", "ID", "and", "record", "ID", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_records.go#L55-L68
154,198
crackcomm/cloudflare
client_records.go
Patch
func (records *Records) Patch(ctx context.Context, record *Record) (err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(record) if err != nil { return } response, err := httpDo(ctx, records.Options, "PUT", apiURL("/zones/%s/dns_records/%s", record.ZoneID, record.ID), buffer) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
go
func (records *Records) Patch(ctx context.Context, record *Record) (err error) { buffer := new(bytes.Buffer) err = json.NewEncoder(buffer).Encode(record) if err != nil { return } response, err := httpDo(ctx, records.Options, "PUT", apiURL("/zones/%s/dns_records/%s", record.ZoneID, record.ID), buffer) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
[ "func", "(", "records", "*", "Records", ")", "Patch", "(", "ctx", "context", ".", "Context", ",", "record", "*", "Record", ")", "(", "err", "error", ")", "{", "buffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "err", "=", "json", ".", ...
// Patch - Patches a zone DNS record.
[ "Patch", "-", "Patches", "a", "zone", "DNS", "record", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_records.go#L71-L84
154,199
crackcomm/cloudflare
client_records.go
Delete
func (records *Records) Delete(ctx context.Context, zoneID, recordID string) (err error) { response, err := httpDo(ctx, records.Options, "DELETE", apiURL("/zones/%s/dns_records/%s", zoneID, recordID), nil) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
go
func (records *Records) Delete(ctx context.Context, zoneID, recordID string) (err error) { response, err := httpDo(ctx, records.Options, "DELETE", apiURL("/zones/%s/dns_records/%s", zoneID, recordID), nil) if err != nil { return } defer response.Body.Close() _, err = readResponse(response.Body) return }
[ "func", "(", "records", "*", "Records", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "zoneID", ",", "recordID", "string", ")", "(", "err", "error", ")", "{", "response", ",", "err", ":=", "httpDo", "(", "ctx", ",", "records", ".", "Opti...
// Delete - Deletes zone DNS record by zone ID and record ID.
[ "Delete", "-", "Deletes", "zone", "DNS", "record", "by", "zone", "ID", "and", "record", "ID", "." ]
dc358193164414054010e3fafdb6cc8def4eb864
https://github.com/crackcomm/cloudflare/blob/dc358193164414054010e3fafdb6cc8def4eb864/client_records.go#L87-L95