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,000
nickvanw/ircx
bot.go
Handle
func (b *Bot) Handle(cmd string, handler Handler) { b.handlers[cmd] = append(b.handlers[cmd], handler) }
go
func (b *Bot) Handle(cmd string, handler Handler) { b.handlers[cmd] = append(b.handlers[cmd], handler) }
[ "func", "(", "b", "*", "Bot", ")", "Handle", "(", "cmd", "string", ",", "handler", "Handler", ")", "{", "b", ".", "handlers", "[", "cmd", "]", "=", "append", "(", "b", ".", "handlers", "[", "cmd", "]", ",", "handler", ")", "\n", "}" ]
// Handle registers the handler for the given command
[ "Handle", "registers", "the", "handler", "for", "the", "given", "command" ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/bot.go#L165-L167
154,001
nickvanw/ircx
bot.go
HandleFunc
func (b *Bot) HandleFunc(cmd string, handler func(s Sender, m *irc.Message)) { b.handlers[cmd] = append(b.handlers[cmd], HandlerFunc(handler)) }
go
func (b *Bot) HandleFunc(cmd string, handler func(s Sender, m *irc.Message)) { b.handlers[cmd] = append(b.handlers[cmd], HandlerFunc(handler)) }
[ "func", "(", "b", "*", "Bot", ")", "HandleFunc", "(", "cmd", "string", ",", "handler", "func", "(", "s", "Sender", ",", "m", "*", "irc", ".", "Message", ")", ")", "{", "b", ".", "handlers", "[", "cmd", "]", "=", "append", "(", "b", ".", "handle...
// HandleFunc registers the handler function for the given command
[ "HandleFunc", "registers", "the", "handler", "function", "for", "the", "given", "command" ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/bot.go#L170-L172
154,002
nickvanw/ircx
bot.go
Handle
func (f HandlerFunc) Handle(s Sender, m *irc.Message) { f(s, m) }
go
func (f HandlerFunc) Handle(s Sender, m *irc.Message) { f(s, m) }
[ "func", "(", "f", "HandlerFunc", ")", "Handle", "(", "s", "Sender", ",", "m", "*", "irc", ".", "Message", ")", "{", "f", "(", "s", ",", "m", ")", "\n", "}" ]
// Handle calls the HandlerFunc with the sender and irc message
[ "Handle", "calls", "the", "HandlerFunc", "with", "the", "sender", "and", "irc", "message" ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/bot.go#L191-L193
154,003
pdf/golifx
common/color.go
AverageColor
func AverageColor(colors ...Color) (color Color) { var ( x, y float64 hue, sat, bri, kel int ) // Sum sind/cosd for hues for _, c := range colors { // Convert hue to degrees h := float64(c.Hue) / float64(math.MaxUint16) * 360.0 x += math.Cos(h / 180.0 * math.Pi) y += math.Sin(h / 180.0 * math.Pi) sat += int(c.Saturation) bri += int(c.Brightness) kel += int(c.Kelvin) } // Average sind/cosd x /= float64(len(colors)) y /= float64(len(colors)) // Take atan2 of averaged hue and convert to uint16 scale hue = int((math.Atan2(y, x) * 180.0 / math.Pi) / 360.0 * float64(math.MaxUint16)) sat /= len(colors) bri /= len(colors) kel /= len(colors) color.Hue = uint16(hue) color.Saturation = uint16(sat) color.Brightness = uint16(bri) color.Kelvin = uint16(kel) return color }
go
func AverageColor(colors ...Color) (color Color) { var ( x, y float64 hue, sat, bri, kel int ) // Sum sind/cosd for hues for _, c := range colors { // Convert hue to degrees h := float64(c.Hue) / float64(math.MaxUint16) * 360.0 x += math.Cos(h / 180.0 * math.Pi) y += math.Sin(h / 180.0 * math.Pi) sat += int(c.Saturation) bri += int(c.Brightness) kel += int(c.Kelvin) } // Average sind/cosd x /= float64(len(colors)) y /= float64(len(colors)) // Take atan2 of averaged hue and convert to uint16 scale hue = int((math.Atan2(y, x) * 180.0 / math.Pi) / 360.0 * float64(math.MaxUint16)) sat /= len(colors) bri /= len(colors) kel /= len(colors) color.Hue = uint16(hue) color.Saturation = uint16(sat) color.Brightness = uint16(bri) color.Kelvin = uint16(kel) return color }
[ "func", "AverageColor", "(", "colors", "...", "Color", ")", "(", "color", "Color", ")", "{", "var", "(", "x", ",", "y", "float64", "\n", "hue", ",", "sat", ",", "bri", ",", "kel", "int", "\n", ")", "\n\n", "// Sum sind/cosd for hues", "for", "_", ","...
// AverageColor returns the average of the provided colors
[ "AverageColor", "returns", "the", "average", "of", "the", "provided", "colors" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/color.go#L18-L52
154,004
pdf/golifx
common/color.go
ColorEqual
func ColorEqual(a, b Color) bool { return a.Hue == b.Hue && a.Saturation == b.Saturation && a.Brightness == b.Brightness && a.Kelvin == b.Kelvin }
go
func ColorEqual(a, b Color) bool { return a.Hue == b.Hue && a.Saturation == b.Saturation && a.Brightness == b.Brightness && a.Kelvin == b.Kelvin }
[ "func", "ColorEqual", "(", "a", ",", "b", "Color", ")", "bool", "{", "return", "a", ".", "Hue", "==", "b", ".", "Hue", "&&", "a", ".", "Saturation", "==", "b", ".", "Saturation", "&&", "a", ".", "Brightness", "==", "b", ".", "Brightness", "&&", "...
// ColorEqual tests whether two Colors are equal
[ "ColorEqual", "tests", "whether", "two", "Colors", "are", "equal" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/color.go#L55-L60
154,005
pdf/golifx
common/subscription.go
notify
func (s *Subscription) notify(event interface{}) error { timeout := time.After(DefaultTimeout) select { case <-s.quitChan: Log.Debugf("Subscription %s already closed", s.id) return ErrClosed case s.events <- event: return nil case <-timeout: Log.Debugf("Timeout on subscription %s", s.id) return ErrTimeout } }
go
func (s *Subscription) notify(event interface{}) error { timeout := time.After(DefaultTimeout) select { case <-s.quitChan: Log.Debugf("Subscription %s already closed", s.id) return ErrClosed case s.events <- event: return nil case <-timeout: Log.Debugf("Timeout on subscription %s", s.id) return ErrTimeout } }
[ "func", "(", "s", "*", "Subscription", ")", "notify", "(", "event", "interface", "{", "}", ")", "error", "{", "timeout", ":=", "time", ".", "After", "(", "DefaultTimeout", ")", "\n", "select", "{", "case", "<-", "s", ".", "quitChan", ":", "Log", ".",...
// notify pushes an event onto the events channel
[ "notify", "pushes", "an", "event", "onto", "the", "events", "channel" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/subscription.go#L35-L47
154,006
pdf/golifx
common/subscription.go
Close
func (s *Subscription) Close() error { s.Lock() defer s.Unlock() select { case <-s.quitChan: Log.Debugf("Subscription %s already closed", s.id) return ErrClosed default: close(s.quitChan) close(s.events) } return s.provider.unsubscribe(s) }
go
func (s *Subscription) Close() error { s.Lock() defer s.Unlock() select { case <-s.quitChan: Log.Debugf("Subscription %s already closed", s.id) return ErrClosed default: close(s.quitChan) close(s.events) } return s.provider.unsubscribe(s) }
[ "func", "(", "s", "*", "Subscription", ")", "Close", "(", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "select", "{", "case", "<-", "s", ".", "quitChan", ":", "Log", ".", "Debugf", "(", "\"",...
// Close cleans up resources and notifies the provider that the subscription // should no longer be used. It is important to close subscriptions when you // are done with them to avoid blocking operations.
[ "Close", "cleans", "up", "resources", "and", "notifies", "the", "provider", "that", "the", "subscription", "should", "no", "longer", "be", "used", ".", "It", "is", "important", "to", "close", "subscriptions", "when", "you", "are", "done", "with", "them", "to...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/subscription.go#L52-L64
154,007
pdf/golifx
common/subscription.go
newSubscription
func newSubscription(provider *SubscriptionProvider) *Subscription { return &Subscription{ id: uuid.NewV4(), events: make(chan interface{}, subscriptionChanSize), quitChan: make(chan struct{}), provider: provider, } }
go
func newSubscription(provider *SubscriptionProvider) *Subscription { return &Subscription{ id: uuid.NewV4(), events: make(chan interface{}, subscriptionChanSize), quitChan: make(chan struct{}), provider: provider, } }
[ "func", "newSubscription", "(", "provider", "*", "SubscriptionProvider", ")", "*", "Subscription", "{", "return", "&", "Subscription", "{", "id", ":", "uuid", ".", "NewV4", "(", ")", ",", "events", ":", "make", "(", "chan", "interface", "{", "}", ",", "s...
// newSubscription instantiates a new Subscription
[ "newSubscription", "instantiates", "a", "new", "Subscription" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/subscription.go#L67-L74
154,008
pdf/golifx
common/logger.go
Panicf
func (l *StubLogger) Panicf(format string, args ...interface{}) { panic(fmt.Sprintf(format, args...)) }
go
func (l *StubLogger) Panicf(format string, args ...interface{}) { panic(fmt.Sprintf(format, args...)) }
[ "func", "(", "l", "*", "StubLogger", ")", "Panicf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "format", ",", "args", "...", ")", ")", "\n", "}" ]
// Panicf handles debug level messages, and panics the application
[ "Panicf", "handles", "debug", "level", "messages", "and", "panics", "the", "application" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/logger.go#L47-L49
154,009
pdf/golifx
common/logger.go
Debugf
func (l *logPrefixer) Debugf(format string, args ...interface{}) { l.Lock() l.log.Debugf(l.prefix(format), args...) l.Unlock() }
go
func (l *logPrefixer) Debugf(format string, args ...interface{}) { l.Lock() l.log.Debugf(l.prefix(format), args...) l.Unlock() }
[ "func", "(", "l", "*", "logPrefixer", ")", "Debugf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "l", ".", "Lock", "(", ")", "\n", "l", ".", "log", ".", "Debugf", "(", "l", ".", "prefix", "(", "format", ")", ",...
// Debugf handles debug level messages, prefixing them for golifx
[ "Debugf", "handles", "debug", "level", "messages", "prefixing", "them", "for", "golifx" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/logger.go#L57-L61
154,010
nuagenetworks/libvrsdk
ovsdb/NuagePortTableRow.go
Equals
func (row *NuagePortTableRow) Equals(otherRow interface{}) bool { nuagePortTableRow, ok := otherRow.(NuagePortTableRow) if !ok { return false } if strings.Compare(row.Name, nuagePortTableRow.Name) != 0 { return false } if strings.Compare(row.Mac, nuagePortTableRow.Mac) != 0 { return false } if strings.Compare(row.IPAddr, nuagePortTableRow.IPAddr) != 0 { return false } if strings.Compare(row.SubnetMask, nuagePortTableRow.SubnetMask) != 0 { return false } if strings.Compare(row.Gateway, nuagePortTableRow.Gateway) != 0 { return false } if strings.Compare(row.Bridge, nuagePortTableRow.Bridge) != 0 { return false } if strings.Compare(row.Alias, nuagePortTableRow.Alias) != 0 { return false } if strings.Compare(row.NuageDomain, nuagePortTableRow.NuageDomain) != 0 { return false } if strings.Compare(row.NuageNetwork, nuagePortTableRow.NuageNetwork) != 0 { return false } if strings.Compare(row.NuageNetworkType, nuagePortTableRow.NuageNetworkType) != 0 { return false } if strings.Compare(row.NuageZone, nuagePortTableRow.NuageZone) != 0 { return false } if row.EVPNId != nuagePortTableRow.EVPNId { return false } if row.VRFId != nuagePortTableRow.VRFId { return false } if row.VMDomain != nuagePortTableRow.VMDomain { return false } if !reflect.DeepEqual(row.Metadata, nuagePortTableRow.Metadata) { return false } if row.Dirty != nuagePortTableRow.Dirty { return false } return true }
go
func (row *NuagePortTableRow) Equals(otherRow interface{}) bool { nuagePortTableRow, ok := otherRow.(NuagePortTableRow) if !ok { return false } if strings.Compare(row.Name, nuagePortTableRow.Name) != 0 { return false } if strings.Compare(row.Mac, nuagePortTableRow.Mac) != 0 { return false } if strings.Compare(row.IPAddr, nuagePortTableRow.IPAddr) != 0 { return false } if strings.Compare(row.SubnetMask, nuagePortTableRow.SubnetMask) != 0 { return false } if strings.Compare(row.Gateway, nuagePortTableRow.Gateway) != 0 { return false } if strings.Compare(row.Bridge, nuagePortTableRow.Bridge) != 0 { return false } if strings.Compare(row.Alias, nuagePortTableRow.Alias) != 0 { return false } if strings.Compare(row.NuageDomain, nuagePortTableRow.NuageDomain) != 0 { return false } if strings.Compare(row.NuageNetwork, nuagePortTableRow.NuageNetwork) != 0 { return false } if strings.Compare(row.NuageNetworkType, nuagePortTableRow.NuageNetworkType) != 0 { return false } if strings.Compare(row.NuageZone, nuagePortTableRow.NuageZone) != 0 { return false } if row.EVPNId != nuagePortTableRow.EVPNId { return false } if row.VRFId != nuagePortTableRow.VRFId { return false } if row.VMDomain != nuagePortTableRow.VMDomain { return false } if !reflect.DeepEqual(row.Metadata, nuagePortTableRow.Metadata) { return false } if row.Dirty != nuagePortTableRow.Dirty { return false } return true }
[ "func", "(", "row", "*", "NuagePortTableRow", ")", "Equals", "(", "otherRow", "interface", "{", "}", ")", "bool", "{", "nuagePortTableRow", ",", "ok", ":=", "otherRow", ".", "(", "NuagePortTableRow", ")", "\n\n", "if", "!", "ok", "{", "return", "false", ...
// Equals checks for equality of two Nuage_Port_Table rows
[ "Equals", "checks", "for", "equality", "of", "two", "Nuage_Port_Table", "rows" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuagePortTableRow.go#L55-L128
154,011
nuagenetworks/libvrsdk
ovsdb/NuagePortTableRow.go
CreateOVSDBRow
func (row *NuagePortTableRow) CreateOVSDBRow(ovsdbRow map[string]interface{}) error { metadataMap, err := libovsdb.NewOvsMap(row.Metadata) if err != nil { glog.Errorf("error while creating metadataMap (%+v)", ovsdbRow) return err } ovsdbRow["name"] = row.Name ovsdbRow["mac"] = row.Mac ovsdbRow["ip_addr"] = row.IPAddr ovsdbRow["subnet_mask"] = row.SubnetMask ovsdbRow["gateway"] = row.Gateway ovsdbRow["bridge"] = row.Bridge ovsdbRow["alias"] = row.Alias ovsdbRow["nuage_domain"] = row.NuageDomain ovsdbRow["nuage_network"] = row.NuageNetwork ovsdbRow["nuage_zone"] = row.NuageZone ovsdbRow["nuage_network_type"] = row.NuageNetworkType ovsdbRow["evpn_id"] = row.EVPNId ovsdbRow["vrf_id"] = row.VRFId ovsdbRow["vm_domain"] = row.VMDomain ovsdbRow["metadata"] = metadataMap ovsdbRow["dirty"] = row.Dirty return nil }
go
func (row *NuagePortTableRow) CreateOVSDBRow(ovsdbRow map[string]interface{}) error { metadataMap, err := libovsdb.NewOvsMap(row.Metadata) if err != nil { glog.Errorf("error while creating metadataMap (%+v)", ovsdbRow) return err } ovsdbRow["name"] = row.Name ovsdbRow["mac"] = row.Mac ovsdbRow["ip_addr"] = row.IPAddr ovsdbRow["subnet_mask"] = row.SubnetMask ovsdbRow["gateway"] = row.Gateway ovsdbRow["bridge"] = row.Bridge ovsdbRow["alias"] = row.Alias ovsdbRow["nuage_domain"] = row.NuageDomain ovsdbRow["nuage_network"] = row.NuageNetwork ovsdbRow["nuage_zone"] = row.NuageZone ovsdbRow["nuage_network_type"] = row.NuageNetworkType ovsdbRow["evpn_id"] = row.EVPNId ovsdbRow["vrf_id"] = row.VRFId ovsdbRow["vm_domain"] = row.VMDomain ovsdbRow["metadata"] = metadataMap ovsdbRow["dirty"] = row.Dirty return nil }
[ "func", "(", "row", "*", "NuagePortTableRow", ")", "CreateOVSDBRow", "(", "ovsdbRow", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "metadataMap", ",", "err", ":=", "libovsdb", ".", "NewOvsMap", "(", "row", ".", "Metadata", ")", "\...
// CreateOVSDBRow creates a new row in Nuage_Port_Table using the data provided by the user
[ "CreateOVSDBRow", "creates", "a", "new", "row", "in", "Nuage_Port_Table", "using", "the", "data", "provided", "by", "the", "user" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuagePortTableRow.go#L131-L156
154,012
nickvanw/ircx
legacy.go
Classic
func Classic(server string, name string) *Bot { cfg := Config{ User: name, } return New(server, name, cfg) }
go
func Classic(server string, name string) *Bot { cfg := Config{ User: name, } return New(server, name, cfg) }
[ "func", "Classic", "(", "server", "string", ",", "name", "string", ")", "*", "Bot", "{", "cfg", ":=", "Config", "{", "User", ":", "name", ",", "}", "\n", "return", "New", "(", "server", ",", "name", ",", "cfg", ")", "\n", "}" ]
// Classic creates an instance of ircx poised to connect to the given server // with the given IRC name.
[ "Classic", "creates", "an", "instance", "of", "ircx", "poised", "to", "connect", "to", "the", "given", "server", "with", "the", "given", "IRC", "name", "." ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/legacy.go#L9-L14
154,013
nickvanw/ircx
legacy.go
WithLogin
func WithLogin(server string, name string, user string, password string) *Bot { cfg := Config{ User: user, Password: password, } return New(server, name, cfg) }
go
func WithLogin(server string, name string, user string, password string) *Bot { cfg := Config{ User: user, Password: password, } return New(server, name, cfg) }
[ "func", "WithLogin", "(", "server", "string", ",", "name", "string", ",", "user", "string", ",", "password", "string", ")", "*", "Bot", "{", "cfg", ":=", "Config", "{", "User", ":", "user", ",", "Password", ":", "password", ",", "}", "\n\n", "return", ...
// WithLogin creates an instance with the specified server, name user and password // for the IRC server
[ "WithLogin", "creates", "an", "instance", "with", "the", "specified", "server", "name", "user", "and", "password", "for", "the", "IRC", "server" ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/legacy.go#L18-L25
154,014
nickvanw/ircx
legacy.go
WithTLS
func WithTLS(server string, name string, tlsConfig *tls.Config) *Bot { if tlsConfig == nil { tlsConfig = &tls.Config{} } cfg := Config{ TLSConfig: tlsConfig, User: name, } return New(server, name, cfg) }
go
func WithTLS(server string, name string, tlsConfig *tls.Config) *Bot { if tlsConfig == nil { tlsConfig = &tls.Config{} } cfg := Config{ TLSConfig: tlsConfig, User: name, } return New(server, name, cfg) }
[ "func", "WithTLS", "(", "server", "string", ",", "name", "string", ",", "tlsConfig", "*", "tls", ".", "Config", ")", "*", "Bot", "{", "if", "tlsConfig", "==", "nil", "{", "tlsConfig", "=", "&", "tls", ".", "Config", "{", "}", "\n", "}", "\n", "cfg"...
// WithTLS creates an instance of ircx poised to connect to the given server // using TLS with the given IRC name.
[ "WithTLS", "creates", "an", "instance", "of", "ircx", "poised", "to", "connect", "to", "the", "given", "server", "using", "TLS", "with", "the", "given", "IRC", "name", "." ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/legacy.go#L29-L38
154,015
nickvanw/ircx
legacy.go
WithLoginTLS
func WithLoginTLS(server string, name string, user string, password string, tlsConfig *tls.Config) *Bot { if tlsConfig == nil { tlsConfig = &tls.Config{} } cfg := Config{ TLSConfig: tlsConfig, User: user, Password: password, } return New(server, name, cfg) }
go
func WithLoginTLS(server string, name string, user string, password string, tlsConfig *tls.Config) *Bot { if tlsConfig == nil { tlsConfig = &tls.Config{} } cfg := Config{ TLSConfig: tlsConfig, User: user, Password: password, } return New(server, name, cfg) }
[ "func", "WithLoginTLS", "(", "server", "string", ",", "name", "string", ",", "user", "string", ",", "password", "string", ",", "tlsConfig", "*", "tls", ".", "Config", ")", "*", "Bot", "{", "if", "tlsConfig", "==", "nil", "{", "tlsConfig", "=", "&", "tl...
// WithLoginTLS creates an instance with the specified information + TLS config
[ "WithLoginTLS", "creates", "an", "instance", "with", "the", "specified", "information", "+", "TLS", "config" ]
49cff0c1f801176c4cdf774252a5803f25cdb815
https://github.com/nickvanw/ircx/blob/49cff0c1f801176c4cdf774252a5803f25cdb815/legacy.go#L41-L51
154,016
nuagenetworks/libvrsdk
api/Port.go
GetAllPorts
func (vrsConnection *VRSConnection) GetAllPorts() ([]string, error) { readRowArgs := ovsdb.ReadRowArgs{ Condition: []string{ovsdb.NuagePortTableColumnName, "!=", "xxxx"}, Columns: []string{ovsdb.NuagePortTableColumnName}, } var nameRows []map[string]interface{} var err error if nameRows, err = vrsConnection.portTable.ReadRows(vrsConnection.ovsdbClient, readRowArgs); err != nil { return nil, fmt.Errorf("Unable to obtain the entity names %v", err) } var names []string for _, name := range nameRows { names = append(names, name[ovsdb.NuagePortTableColumnName].(string)) } return names, nil }
go
func (vrsConnection *VRSConnection) GetAllPorts() ([]string, error) { readRowArgs := ovsdb.ReadRowArgs{ Condition: []string{ovsdb.NuagePortTableColumnName, "!=", "xxxx"}, Columns: []string{ovsdb.NuagePortTableColumnName}, } var nameRows []map[string]interface{} var err error if nameRows, err = vrsConnection.portTable.ReadRows(vrsConnection.ovsdbClient, readRowArgs); err != nil { return nil, fmt.Errorf("Unable to obtain the entity names %v", err) } var names []string for _, name := range nameRows { names = append(names, name[ovsdb.NuagePortTableColumnName].(string)) } return names, nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "GetAllPorts", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "readRowArgs", ":=", "ovsdb", ".", "ReadRowArgs", "{", "Condition", ":", "[", "]", "string", "{", "ovsdb", ".", "NuagePortT...
// GetAllPorts returns the slice of all the vport names attached to the VRS
[ "GetAllPorts", "returns", "the", "slice", "of", "all", "the", "vport", "names", "attached", "to", "the", "VRS" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L35-L54
154,017
nuagenetworks/libvrsdk
api/Port.go
CreatePort
func (vrsConnection *VRSConnection) CreatePort(name string, attributes port.Attributes, metadata map[port.MetadataKey]string) error { portMetadata := make(map[string]string) for k, v := range metadata { portMetadata[string(k)] = v } nuagePortRow := ovsdb.NuagePortTableRow{ Name: name, Mac: attributes.MAC, Bridge: attributes.Bridge, NuageDomain: metadata[port.MetadataKeyDomain], NuageNetwork: metadata[port.MetadataKeyNetwork], NuageNetworkType: metadata[port.MetadataKeyNetworkType], NuageZone: metadata[port.MetadataKeyZone], VMDomain: attributes.Platform, Metadata: portMetadata, } if err := vrsConnection.portTable.InsertRow(vrsConnection.ovsdbClient, &nuagePortRow); err != nil { return fmt.Errorf("Problem adding port info to VRS %v", err) } return nil }
go
func (vrsConnection *VRSConnection) CreatePort(name string, attributes port.Attributes, metadata map[port.MetadataKey]string) error { portMetadata := make(map[string]string) for k, v := range metadata { portMetadata[string(k)] = v } nuagePortRow := ovsdb.NuagePortTableRow{ Name: name, Mac: attributes.MAC, Bridge: attributes.Bridge, NuageDomain: metadata[port.MetadataKeyDomain], NuageNetwork: metadata[port.MetadataKeyNetwork], NuageNetworkType: metadata[port.MetadataKeyNetworkType], NuageZone: metadata[port.MetadataKeyZone], VMDomain: attributes.Platform, Metadata: portMetadata, } if err := vrsConnection.portTable.InsertRow(vrsConnection.ovsdbClient, &nuagePortRow); err != nil { return fmt.Errorf("Problem adding port info to VRS %v", err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "CreatePort", "(", "name", "string", ",", "attributes", "port", ".", "Attributes", ",", "metadata", "map", "[", "port", ".", "MetadataKey", "]", "string", ")", "error", "{", "portMetadata", ":=", "make...
// CreatePort creates a new vPort in the Nuage VRS. The only mandatory inputs required to create // a port are it's name and MAC address
[ "CreatePort", "creates", "a", "new", "vPort", "in", "the", "Nuage", "VRS", ".", "The", "only", "mandatory", "inputs", "required", "to", "create", "a", "port", "are", "it", "s", "name", "and", "MAC", "address" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L58-L84
154,018
nuagenetworks/libvrsdk
api/Port.go
DestroyPort
func (vrsConnection *VRSConnection) DestroyPort(name string) error { condition := []string{ovsdb.NuagePortTableColumnName, "==", name} if err := vrsConnection.portTable.DeleteRow(vrsConnection.ovsdbClient, condition); err != nil { return fmt.Errorf("Unable to remove the port from VRS %v", err) } return nil }
go
func (vrsConnection *VRSConnection) DestroyPort(name string) error { condition := []string{ovsdb.NuagePortTableColumnName, "==", name} if err := vrsConnection.portTable.DeleteRow(vrsConnection.ovsdbClient, condition); err != nil { return fmt.Errorf("Unable to remove the port from VRS %v", err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "DestroyPort", "(", "name", "string", ")", "error", "{", "condition", ":=", "[", "]", "string", "{", "ovsdb", ".", "NuagePortTableColumnName", ",", "\"", "\"", ",", "name", "}", "\n", "if", "err", ...
// DestroyPort purges a port from the Nuage VRS
[ "DestroyPort", "purges", "a", "port", "from", "the", "Nuage", "VRS" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L87-L95
154,019
nuagenetworks/libvrsdk
api/Port.go
GetPortState
func (vrsConnection VRSConnection) GetPortState(name string) (map[port.StateKey]interface{}, error) { readRowArgs := ovsdb.ReadRowArgs{ Columns: []string{ovsdb.NuagePortTableColumnIPAddress, ovsdb.NuagePortTableColumnSubnetMask, ovsdb.NuagePortTableColumnGateway, ovsdb.NuagePortTableColumnEVPNID, ovsdb.NuagePortTableColumnVRFId}, Condition: []string{ovsdb.NuagePortTableColumnName, "==", name}, } var row map[string]interface{} var err error if row, err = vrsConnection.portTable.ReadRow(vrsConnection.ovsdbClient, readRowArgs); err != nil { return make(map[port.StateKey]interface{}), fmt.Errorf("Unable to obtain the port row %v", err) } portState := make(map[port.StateKey]interface{}) portState[port.StateKeyIPAddress] = row[ovsdb.NuagePortTableColumnIPAddress] portState[port.StateKeySubnetMask] = row[ovsdb.NuagePortTableColumnSubnetMask] portState[port.StateKeyGateway] = row[ovsdb.NuagePortTableColumnGateway] portState[port.StateKeyVrfID] = row[ovsdb.NuagePortTableColumnVRFId] portState[port.StateKeyEvpnID] = row[ovsdb.NuagePortTableColumnEVPNID] return portState, nil }
go
func (vrsConnection VRSConnection) GetPortState(name string) (map[port.StateKey]interface{}, error) { readRowArgs := ovsdb.ReadRowArgs{ Columns: []string{ovsdb.NuagePortTableColumnIPAddress, ovsdb.NuagePortTableColumnSubnetMask, ovsdb.NuagePortTableColumnGateway, ovsdb.NuagePortTableColumnEVPNID, ovsdb.NuagePortTableColumnVRFId}, Condition: []string{ovsdb.NuagePortTableColumnName, "==", name}, } var row map[string]interface{} var err error if row, err = vrsConnection.portTable.ReadRow(vrsConnection.ovsdbClient, readRowArgs); err != nil { return make(map[port.StateKey]interface{}), fmt.Errorf("Unable to obtain the port row %v", err) } portState := make(map[port.StateKey]interface{}) portState[port.StateKeyIPAddress] = row[ovsdb.NuagePortTableColumnIPAddress] portState[port.StateKeySubnetMask] = row[ovsdb.NuagePortTableColumnSubnetMask] portState[port.StateKeyGateway] = row[ovsdb.NuagePortTableColumnGateway] portState[port.StateKeyVrfID] = row[ovsdb.NuagePortTableColumnVRFId] portState[port.StateKeyEvpnID] = row[ovsdb.NuagePortTableColumnEVPNID] return portState, nil }
[ "func", "(", "vrsConnection", "VRSConnection", ")", "GetPortState", "(", "name", "string", ")", "(", "map", "[", "port", ".", "StateKey", "]", "interface", "{", "}", ",", "error", ")", "{", "readRowArgs", ":=", "ovsdb", ".", "ReadRowArgs", "{", "Columns", ...
// GetPortState gets the current resolution state of the port namely the IP address, Subnet Mask, Gateway, // EVPN ID and VRF ID
[ "GetPortState", "gets", "the", "current", "resolution", "state", "of", "the", "port", "namely", "the", "IP", "address", "Subnet", "Mask", "Gateway", "EVPN", "ID", "and", "VRF", "ID" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L99-L122
154,020
nuagenetworks/libvrsdk
api/Port.go
UpdatePortAttributes
func (vrsConnection *VRSConnection) UpdatePortAttributes(name string, attrs port.Attributes) error { row := make(map[string]interface{}) row[ovsdb.NuagePortTableColumnBridge] = attrs.Bridge row[ovsdb.NuagePortTableColumnMAC] = attrs.MAC row[ovsdb.NuagePortTableColumnVMDomain] = attrs.Platform condition := []string{ovsdb.NuagePortTableColumnName, "==", name} if err := vrsConnection.portTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the port attributes %s %v %v", name, attrs, err) } return nil }
go
func (vrsConnection *VRSConnection) UpdatePortAttributes(name string, attrs port.Attributes) error { row := make(map[string]interface{}) row[ovsdb.NuagePortTableColumnBridge] = attrs.Bridge row[ovsdb.NuagePortTableColumnMAC] = attrs.MAC row[ovsdb.NuagePortTableColumnVMDomain] = attrs.Platform condition := []string{ovsdb.NuagePortTableColumnName, "==", name} if err := vrsConnection.portTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the port attributes %s %v %v", name, attrs, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "UpdatePortAttributes", "(", "name", "string", ",", "attrs", "port", ".", "Attributes", ")", "error", "{", "row", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "...
// UpdatePortAttributes updates the attributes of the vPort
[ "UpdatePortAttributes", "updates", "the", "attributes", "of", "the", "vPort" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L125-L139
154,021
nuagenetworks/libvrsdk
api/Port.go
UpdatePortMetadata
func (vrsConnection *VRSConnection) UpdatePortMetadata(name string, metadata map[string]string) error { row := make(map[string]interface{}) metadataOVSDB, err := libovsdb.NewOvsMap(metadata) if err != nil { return fmt.Errorf("Unable to create OVSDB map %v", err) } row[ovsdb.NuagePortTableColumnMetadata] = metadataOVSDB key := string(port.MetadataKeyDomain) if len(metadata[key]) != 0 { row[ovsdb.NuagePortTableColumnNuageDomain] = metadata[key] delete(metadata, key) } key = string(port.MetadataKeyNetwork) if len(metadata[key]) != 0 { row[ovsdb.NuagePortTableColumnNuageNetwork] = metadata[key] delete(metadata, key) } key = string(port.MetadataKeyZone) if len(metadata[key]) != 0 { row[ovsdb.NuagePortTableColumnNuageZone] = metadata[key] delete(metadata, key) } condition := []string{ovsdb.NuagePortTableColumnName, "==", name} if err := vrsConnection.portTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the port metadata %s %v %v", name, metadata, err) } return nil }
go
func (vrsConnection *VRSConnection) UpdatePortMetadata(name string, metadata map[string]string) error { row := make(map[string]interface{}) metadataOVSDB, err := libovsdb.NewOvsMap(metadata) if err != nil { return fmt.Errorf("Unable to create OVSDB map %v", err) } row[ovsdb.NuagePortTableColumnMetadata] = metadataOVSDB key := string(port.MetadataKeyDomain) if len(metadata[key]) != 0 { row[ovsdb.NuagePortTableColumnNuageDomain] = metadata[key] delete(metadata, key) } key = string(port.MetadataKeyNetwork) if len(metadata[key]) != 0 { row[ovsdb.NuagePortTableColumnNuageNetwork] = metadata[key] delete(metadata, key) } key = string(port.MetadataKeyZone) if len(metadata[key]) != 0 { row[ovsdb.NuagePortTableColumnNuageZone] = metadata[key] delete(metadata, key) } condition := []string{ovsdb.NuagePortTableColumnName, "==", name} if err := vrsConnection.portTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the port metadata %s %v %v", name, metadata, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "UpdatePortMetadata", "(", "name", "string", ",", "metadata", "map", "[", "string", "]", "string", ")", "error", "{", "row", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")"...
// UpdatePortMetadata updates the metadata for the vPort
[ "UpdatePortMetadata", "updates", "the", "metadata", "for", "the", "vPort" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L142-L177
154,022
nuagenetworks/libvrsdk
api/Port.go
RegisterForPortUpdates
func (vrsConnection *VRSConnection) RegisterForPortUpdates(brport string, pnc chan *PortIPv4Info) error { vrsConnection.registrationChannel <- &Registration{Brport: brport, Channel: pnc, Register: true} return nil }
go
func (vrsConnection *VRSConnection) RegisterForPortUpdates(brport string, pnc chan *PortIPv4Info) error { vrsConnection.registrationChannel <- &Registration{Brport: brport, Channel: pnc, Register: true} return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "RegisterForPortUpdates", "(", "brport", "string", ",", "pnc", "chan", "*", "PortIPv4Info", ")", "error", "{", "vrsConnection", ".", "registrationChannel", "<-", "&", "Registration", "{", "Brport", ":", "b...
// RegisterForPortUpdates will help register via channel // for VRS port table updates
[ "RegisterForPortUpdates", "will", "help", "register", "via", "channel", "for", "VRS", "port", "table", "updates" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L181-L184
154,023
nuagenetworks/libvrsdk
api/Port.go
DeregisterForPortUpdates
func (vrsConnection *VRSConnection) DeregisterForPortUpdates(brport string) error { vrsConnection.registrationChannel <- &Registration{Brport: brport, Channel: nil, Register: false} return nil }
go
func (vrsConnection *VRSConnection) DeregisterForPortUpdates(brport string) error { vrsConnection.registrationChannel <- &Registration{Brport: brport, Channel: nil, Register: false} return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "DeregisterForPortUpdates", "(", "brport", "string", ")", "error", "{", "vrsConnection", ".", "registrationChannel", "<-", "&", "Registration", "{", "Brport", ":", "brport", ",", "Channel", ":", "nil", ","...
// DeregisterForPortUpdates will help de-register for VRS port table updates
[ "DeregisterForPortUpdates", "will", "help", "de", "-", "register", "for", "VRS", "port", "table", "updates" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L187-L190
154,024
nuagenetworks/libvrsdk
api/Port.go
AddPortToAlubr0
func (vrsConnection *VRSConnection) AddPortToAlubr0(intfName string, entityInfo EntityInfo) error { namedPortUUID := "port" namedIntfUUID := "intf" var err error // 1) Insert a row for Nuage port in OVSDB Interface table extIDMap := make(map[string]string) intfOp := libovsdb.Operation{} intf := make(map[string]interface{}) intf["name"] = intfName extIDMap["vm-name"] = entityInfo.Name extIDMap["vm-uuid"] = entityInfo.UUID intf["external_ids"], err = libovsdb.NewOvsMap(extIDMap) if err != nil { return err } // interface table ops intfOp = libovsdb.Operation{ Op: "insert", Table: interfaceTable, Row: intf, UUIDName: namedIntfUUID, } // 2) Insert a row for Nuage port in OVSDB Port table portOp := libovsdb.Operation{} port := make(map[string]interface{}) port["name"] = intfName port["interfaces"] = libovsdb.UUID{namedIntfUUID} port["external_ids"], err = libovsdb.NewOvsMap(extIDMap) if err != nil { return err } portOp = libovsdb.Operation{ Op: "insert", Table: portTable, Row: port, UUIDName: namedPortUUID, } // 3) Mutate the Ports column of the row in the Bridge table with new Nuage port mutateUUID := []libovsdb.UUID{libovsdb.UUID{namedPortUUID}} mutateSet, _ := libovsdb.NewOvsSet(mutateUUID) mutation := libovsdb.NewMutation("ports", "insert", mutateSet) condition := libovsdb.NewCondition("name", "==", bridgeName) mutateOp := libovsdb.Operation{ Op: "mutate", Table: bridgeTable, Mutations: []interface{}{mutation}, Where: []interface{}{condition}, } operations := []libovsdb.Operation{intfOp, portOp, mutateOp} reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, operations...) if err != nil || len(reply) < len(operations) { return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0") } return nil }
go
func (vrsConnection *VRSConnection) AddPortToAlubr0(intfName string, entityInfo EntityInfo) error { namedPortUUID := "port" namedIntfUUID := "intf" var err error // 1) Insert a row for Nuage port in OVSDB Interface table extIDMap := make(map[string]string) intfOp := libovsdb.Operation{} intf := make(map[string]interface{}) intf["name"] = intfName extIDMap["vm-name"] = entityInfo.Name extIDMap["vm-uuid"] = entityInfo.UUID intf["external_ids"], err = libovsdb.NewOvsMap(extIDMap) if err != nil { return err } // interface table ops intfOp = libovsdb.Operation{ Op: "insert", Table: interfaceTable, Row: intf, UUIDName: namedIntfUUID, } // 2) Insert a row for Nuage port in OVSDB Port table portOp := libovsdb.Operation{} port := make(map[string]interface{}) port["name"] = intfName port["interfaces"] = libovsdb.UUID{namedIntfUUID} port["external_ids"], err = libovsdb.NewOvsMap(extIDMap) if err != nil { return err } portOp = libovsdb.Operation{ Op: "insert", Table: portTable, Row: port, UUIDName: namedPortUUID, } // 3) Mutate the Ports column of the row in the Bridge table with new Nuage port mutateUUID := []libovsdb.UUID{libovsdb.UUID{namedPortUUID}} mutateSet, _ := libovsdb.NewOvsSet(mutateUUID) mutation := libovsdb.NewMutation("ports", "insert", mutateSet) condition := libovsdb.NewCondition("name", "==", bridgeName) mutateOp := libovsdb.Operation{ Op: "mutate", Table: bridgeTable, Mutations: []interface{}{mutation}, Where: []interface{}{condition}, } operations := []libovsdb.Operation{intfOp, portOp, mutateOp} reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, operations...) if err != nil || len(reply) < len(operations) { return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0") } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "AddPortToAlubr0", "(", "intfName", "string", ",", "entityInfo", "EntityInfo", ")", "error", "{", "namedPortUUID", ":=", "\"", "\"", "\n", "namedIntfUUID", ":=", "\"", "\"", "\n", "var", "err", "error", ...
// AddPortToAlubr0 adds Nuage port to alubr0 bridge
[ "AddPortToAlubr0", "adds", "Nuage", "port", "to", "alubr0", "bridge" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L291-L351
154,025
nuagenetworks/libvrsdk
api/Port.go
RemovePortFromAlubr0
func (vrsConnection *VRSConnection) RemovePortFromAlubr0(portName string) error { condition := libovsdb.NewCondition("name", "==", portName) selectOp := libovsdb.Operation{ Op: "select", Table: "Port", Where: []interface{}{condition}, } selectOperation := []libovsdb.Operation{selectOp} reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, selectOperation...) if err != nil || len(reply) != 1 || len(reply[0].Rows) != 1 { return fmt.Errorf("Problem selecting row in the OVSDB Port table for alubr0") } // Obtain Port table OVSDB row corresponding to the port name ovsdbRow := reply[0].Rows[0] portUUID := ovsdbRow["_uuid"] portUUIDStr := fmt.Sprintf("%v", portUUID) portUUIDNew := util.SplitUUIDString(portUUIDStr) condition = libovsdb.NewCondition("name", "==", portName) deleteOp := libovsdb.Operation{ Op: "delete", Table: "Port", Where: []interface{}{condition}, } // Deleting a Bridge row in Bridge table requires mutating the open_vswitch table. mutateUUID := []libovsdb.UUID{libovsdb.UUID{portUUIDNew}} mutateSet, _ := libovsdb.NewOvsSet(mutateUUID) mutation := libovsdb.NewMutation("ports", "delete", mutateSet) condition = libovsdb.NewCondition("name", "==", bridgeName) // simple mutate operation mutateOp := libovsdb.Operation{ Op: "mutate", Table: "Bridge", Mutations: []interface{}{mutation}, Where: []interface{}{condition}, } operations := []libovsdb.Operation{deleteOp, mutateOp} reply, err = vrsConnection.ovsdbClient.Transact(OvsDBName, operations...) if err != nil || len(reply) < len(operations) { return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0") } return nil }
go
func (vrsConnection *VRSConnection) RemovePortFromAlubr0(portName string) error { condition := libovsdb.NewCondition("name", "==", portName) selectOp := libovsdb.Operation{ Op: "select", Table: "Port", Where: []interface{}{condition}, } selectOperation := []libovsdb.Operation{selectOp} reply, err := vrsConnection.ovsdbClient.Transact(OvsDBName, selectOperation...) if err != nil || len(reply) != 1 || len(reply[0].Rows) != 1 { return fmt.Errorf("Problem selecting row in the OVSDB Port table for alubr0") } // Obtain Port table OVSDB row corresponding to the port name ovsdbRow := reply[0].Rows[0] portUUID := ovsdbRow["_uuid"] portUUIDStr := fmt.Sprintf("%v", portUUID) portUUIDNew := util.SplitUUIDString(portUUIDStr) condition = libovsdb.NewCondition("name", "==", portName) deleteOp := libovsdb.Operation{ Op: "delete", Table: "Port", Where: []interface{}{condition}, } // Deleting a Bridge row in Bridge table requires mutating the open_vswitch table. mutateUUID := []libovsdb.UUID{libovsdb.UUID{portUUIDNew}} mutateSet, _ := libovsdb.NewOvsSet(mutateUUID) mutation := libovsdb.NewMutation("ports", "delete", mutateSet) condition = libovsdb.NewCondition("name", "==", bridgeName) // simple mutate operation mutateOp := libovsdb.Operation{ Op: "mutate", Table: "Bridge", Mutations: []interface{}{mutation}, Where: []interface{}{condition}, } operations := []libovsdb.Operation{deleteOp, mutateOp} reply, err = vrsConnection.ovsdbClient.Transact(OvsDBName, operations...) if err != nil || len(reply) < len(operations) { return fmt.Errorf("Problem mutating row in the OVSDB Bridge table for alubr0") } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "RemovePortFromAlubr0", "(", "portName", "string", ")", "error", "{", "condition", ":=", "libovsdb", ".", "NewCondition", "(", "\"", "\"", ",", "\"", "\"", ",", "portName", ")", "\n", "selectOp", ":=",...
// RemovePortFromAlubr0 will remove a port from alubr0 bridge
[ "RemovePortFromAlubr0", "will", "remove", "a", "port", "from", "alubr0", "bridge" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Port.go#L354-L403
154,026
pdf/golifx
cmd/golifx-import-products/golifx-import-products.go
Printf
func (g *Generator) Printf(format string, a ...interface{}) { if _, err := fmt.Fprintf(&g.buf, format, a...); err != nil { log.Fatalln(err) } }
go
func (g *Generator) Printf(format string, a ...interface{}) { if _, err := fmt.Fprintf(&g.buf, format, a...); err != nil { log.Fatalln(err) } }
[ "func", "(", "g", "*", "Generator", ")", "Printf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "{", "if", "_", ",", "err", ":=", "fmt", ".", "Fprintf", "(", "&", "g", ".", "buf", ",", "format", ",", "a", "...", ")", ...
// Printf prints formatted strings to the buffer
[ "Printf", "prints", "formatted", "strings", "to", "the", "buffer" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/cmd/golifx-import-products/golifx-import-products.go#L101-L105
154,027
pdf/golifx
cmd/golifx-import-products/golifx-import-products.go
Write
func (g *Generator) Write(output string) { if err := ioutil.WriteFile(output, g.buf.Bytes(), 0644); err != nil { log.Fatalln(err) } }
go
func (g *Generator) Write(output string) { if err := ioutil.WriteFile(output, g.buf.Bytes(), 0644); err != nil { log.Fatalln(err) } }
[ "func", "(", "g", "*", "Generator", ")", "Write", "(", "output", "string", ")", "{", "if", "err", ":=", "ioutil", ".", "WriteFile", "(", "output", ",", "g", ".", "buf", ".", "Bytes", "(", ")", ",", "0644", ")", ";", "err", "!=", "nil", "{", "lo...
// Write outputs the buffer to the specified file path
[ "Write", "outputs", "the", "buffer", "to", "the", "specified", "file", "path" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/cmd/golifx-import-products/golifx-import-products.go#L108-L112
154,028
nuagenetworks/libvrsdk
ovsdb/NuageTableRow.go
UnMarshallOVSStringSet
func UnMarshallOVSStringSet(data interface{}) ([]string, error) { var values []string var err error if datum, ok := data.(string); ok { values = append(values, datum) } else { var set []interface{} set, ok := data.([]interface{}) if !ok { return values, fmt.Errorf("Invalid data") } if len(set) == 1 { values = append(values, (set[0]).(string)) } else { var key string var ok bool if key, ok = set[0].(string); !ok { return nil, fmt.Errorf("Invalid type %+v", set) } if strings.Compare(key, "set") != 0 { return nil, fmt.Errorf("Invalid keyword %s", key) } valArr := (set[1]).([]interface{}) for _, val := range valArr { values = append(values, val.(string)) } } } return values, err }
go
func UnMarshallOVSStringSet(data interface{}) ([]string, error) { var values []string var err error if datum, ok := data.(string); ok { values = append(values, datum) } else { var set []interface{} set, ok := data.([]interface{}) if !ok { return values, fmt.Errorf("Invalid data") } if len(set) == 1 { values = append(values, (set[0]).(string)) } else { var key string var ok bool if key, ok = set[0].(string); !ok { return nil, fmt.Errorf("Invalid type %+v", set) } if strings.Compare(key, "set") != 0 { return nil, fmt.Errorf("Invalid keyword %s", key) } valArr := (set[1]).([]interface{}) for _, val := range valArr { values = append(values, val.(string)) } } } return values, err }
[ "func", "UnMarshallOVSStringSet", "(", "data", "interface", "{", "}", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "values", "[", "]", "string", "\n", "var", "err", "error", "\n\n", "if", "datum", ",", "ok", ":=", "data", ".", "(", ...
// UnMarshallOVSStringSet unmarshals a ovsdb column which is an array of strings
[ "UnMarshallOVSStringSet", "unmarshals", "a", "ovsdb", "column", "which", "is", "an", "array", "of", "strings" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageTableRow.go#L15-L49
154,029
monzo/phosphor-go
config.go
NewConfig
func NewConfig() *Config { return &Config{ initialized: true, Host: "localhost", Port: 7760, SendTimeout: 5 * time.Millisecond, BufferSize: 250, // 64KB each, max 16MB mem usage MaxPacketSize: 65536 - 8 - 20, // 8-byte UDP header, 20-byte IP header } }
go
func NewConfig() *Config { return &Config{ initialized: true, Host: "localhost", Port: 7760, SendTimeout: 5 * time.Millisecond, BufferSize: 250, // 64KB each, max 16MB mem usage MaxPacketSize: 65536 - 8 - 20, // 8-byte UDP header, 20-byte IP header } }
[ "func", "NewConfig", "(", ")", "*", "Config", "{", "return", "&", "Config", "{", "initialized", ":", "true", ",", "Host", ":", "\"", "\"", ",", "Port", ":", "7760", ",", "SendTimeout", ":", "5", "*", "time", ".", "Millisecond", ",", "BufferSize", ":"...
// NewConfig returns a Config with default settings initialized
[ "NewConfig", "returns", "a", "Config", "with", "default", "settings", "initialized" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/config.go#L32-L41
154,030
pdf/golifx
common/subscription_provider.go
Subscribe
func (s *SubscriptionProvider) Subscribe() *Subscription { s.Lock() defer s.Unlock() if s.subscriptions == nil { s.subscriptions = make(map[string]*Subscription) } sub := newSubscription(s) s.subscriptions[sub.id.String()] = sub return sub }
go
func (s *SubscriptionProvider) Subscribe() *Subscription { s.Lock() defer s.Unlock() if s.subscriptions == nil { s.subscriptions = make(map[string]*Subscription) } sub := newSubscription(s) s.subscriptions[sub.id.String()] = sub return sub }
[ "func", "(", "s", "*", "SubscriptionProvider", ")", "Subscribe", "(", ")", "*", "Subscription", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "subscriptions", "==", "nil", "{", "s", ".", "subscr...
// Subscribe returns a new Subscription for this provider
[ "Subscribe", "returns", "a", "new", "Subscription", "for", "this", "provider" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/subscription_provider.go#L14-L24
154,031
pdf/golifx
common/subscription_provider.go
Notify
func (s *SubscriptionProvider) Notify(event interface{}) { s.RLock() defer s.RUnlock() for _, sub := range s.subscriptions { if err := sub.notify(event); err != nil { Log.Warnf("Failed notifying subscription (%s): %s", sub.id, err) } } }
go
func (s *SubscriptionProvider) Notify(event interface{}) { s.RLock() defer s.RUnlock() for _, sub := range s.subscriptions { if err := sub.notify(event); err != nil { Log.Warnf("Failed notifying subscription (%s): %s", sub.id, err) } } }
[ "func", "(", "s", "*", "SubscriptionProvider", ")", "Notify", "(", "event", "interface", "{", "}", ")", "{", "s", ".", "RLock", "(", ")", "\n", "defer", "s", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "sub", ":=", "range", "s", ".", "subscr...
// Notify sends the provided event to all subscribers
[ "Notify", "sends", "the", "provided", "event", "to", "all", "subscribers" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/subscription_provider.go#L27-L35
154,032
pdf/golifx
common/subscription_provider.go
Close
func (s *SubscriptionProvider) Close() (err error) { for _, sub := range s.subscriptions { serr := sub.Close() if serr != nil { err = serr } } return err }
go
func (s *SubscriptionProvider) Close() (err error) { for _, sub := range s.subscriptions { serr := sub.Close() if serr != nil { err = serr } } return err }
[ "func", "(", "s", "*", "SubscriptionProvider", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "for", "_", ",", "sub", ":=", "range", "s", ".", "subscriptions", "{", "serr", ":=", "sub", ".", "Close", "(", ")", "\n", "if", "serr", "!=", "n...
// Close all subscriptions
[ "Close", "all", "subscriptions" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/common/subscription_provider.go#L38-L47
154,033
jbooth/flotilla
multi_streamlayer.go
NewMultiStream
func NewMultiStream( listen net.Listener, dial func(string, time.Duration) (net.Conn, error), advertise net.Addr, lg *log.Logger, serviceCodes ...byte, ) (map[byte]raft.StreamLayer, error) { // sanity checks for listener and advertised address if advertise == nil { advertise = listen.Addr() } tcpAdvertise, ok := advertise.(*net.TCPAddr) if !ok { lg.Printf("NewMultiStream Warning: advertising non TCP address %s", advertise) } else if tcpAdvertise.IP.IsUnspecified() { lg.Printf("NewMultiStream Warning: advertising unspecified IP: %s for address %s", tcpAdvertise.IP, tcpAdvertise.String()) } // set up router r := &router{listen, make(chan net.Conn, 16), make(chan closeReq, 16), make(map[byte]*serviceStreams), lg} // set up a channel of conns for each unique serviceCode for _, b := range serviceCodes { _, exists := r.chans[b] if exists { lg.Printf("Warning, serviceCode %d was present more than once in NewMultiStream -- allocating a single service") continue } r.chans[b] = &serviceStreams{ r: r, addr: advertise, conns: make(chan net.Conn, 16), closed: false, myCode: b, dial: dial, } } // type hack, force to map[byte]raft.StreamLayer for return type retMap := make(map[byte]raft.StreamLayer) for k, v := range r.chans { retMap[k] = v } go r.serve() return retMap, nil }
go
func NewMultiStream( listen net.Listener, dial func(string, time.Duration) (net.Conn, error), advertise net.Addr, lg *log.Logger, serviceCodes ...byte, ) (map[byte]raft.StreamLayer, error) { // sanity checks for listener and advertised address if advertise == nil { advertise = listen.Addr() } tcpAdvertise, ok := advertise.(*net.TCPAddr) if !ok { lg.Printf("NewMultiStream Warning: advertising non TCP address %s", advertise) } else if tcpAdvertise.IP.IsUnspecified() { lg.Printf("NewMultiStream Warning: advertising unspecified IP: %s for address %s", tcpAdvertise.IP, tcpAdvertise.String()) } // set up router r := &router{listen, make(chan net.Conn, 16), make(chan closeReq, 16), make(map[byte]*serviceStreams), lg} // set up a channel of conns for each unique serviceCode for _, b := range serviceCodes { _, exists := r.chans[b] if exists { lg.Printf("Warning, serviceCode %d was present more than once in NewMultiStream -- allocating a single service") continue } r.chans[b] = &serviceStreams{ r: r, addr: advertise, conns: make(chan net.Conn, 16), closed: false, myCode: b, dial: dial, } } // type hack, force to map[byte]raft.StreamLayer for return type retMap := make(map[byte]raft.StreamLayer) for k, v := range r.chans { retMap[k] = v } go r.serve() return retMap, nil }
[ "func", "NewMultiStream", "(", "listen", "net", ".", "Listener", ",", "dial", "func", "(", "string", ",", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", ",", "advertise", "net", ".", "Addr", ",", "lg", "*", "log", ".", "L...
// Uses the provided list and dial functions, can be used to allow flotilla // to share a bound port with another binary service.
[ "Uses", "the", "provided", "list", "and", "dial", "functions", "can", "be", "used", "to", "allow", "flotilla", "to", "share", "a", "bound", "port", "with", "another", "binary", "service", "." ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/multi_streamlayer.go#L44-L86
154,034
jbooth/flotilla
multi_streamlayer.go
Dial
func (c *serviceStreams) Dial(address string, timeout time.Duration) (net.Conn, error) { return dialWithCode(c.dial, c.myCode, address, timeout) }
go
func (c *serviceStreams) Dial(address string, timeout time.Duration) (net.Conn, error) { return dialWithCode(c.dial, c.myCode, address, timeout) }
[ "func", "(", "c", "*", "serviceStreams", ")", "Dial", "(", "address", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "dialWithCode", "(", "c", ".", "dial", ",", "c", ".", "myCode", ...
// connects to the service listening on
[ "connects", "to", "the", "service", "listening", "on" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/multi_streamlayer.go#L190-L192
154,035
jbooth/flotilla
multi_streamlayer.go
Dial
func (t *TCPStreamLayer) Dial(address string, timeout time.Duration) (net.Conn, error) { return t.dialer(address, timeout) }
go
func (t *TCPStreamLayer) Dial(address string, timeout time.Duration) (net.Conn, error) { return t.dialer(address, timeout) }
[ "func", "(", "t", "*", "TCPStreamLayer", ")", "Dial", "(", "address", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "return", "t", ".", "dialer", "(", "address", ",", "timeout", ")", "\n", ...
// Dial implements the StreamLayer interface.
[ "Dial", "implements", "the", "StreamLayer", "interface", "." ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/multi_streamlayer.go#L202-L204
154,036
monzo/phosphor-go
transport.go
Consume
func (u *udpTransport) Consume(oldChan, newChan chan []byte) error { u.oldChan = oldChan u.newChan = newChan if err := u.connect(); err != nil { return err } u.t.Go(u.consume) return nil }
go
func (u *udpTransport) Consume(oldChan, newChan chan []byte) error { u.oldChan = oldChan u.newChan = newChan if err := u.connect(); err != nil { return err } u.t.Go(u.consume) return nil }
[ "func", "(", "u", "*", "udpTransport", ")", "Consume", "(", "oldChan", ",", "newChan", "chan", "[", "]", "byte", ")", "error", "{", "u", ".", "oldChan", "=", "oldChan", "\n", "u", ".", "newChan", "=", "newChan", "\n\n", "if", "err", ":=", "u", ".",...
// Consume causes the transport to connect, and start consuming traces // from the provided channels
[ "Consume", "causes", "the", "transport", "to", "connect", "and", "start", "consuming", "traces", "from", "the", "provided", "channels" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/transport.go#L41-L51
154,037
monzo/phosphor-go
transport.go
Stop
func (u *udpTransport) Stop() error { u.t.Kill(nil) return u.t.Wait() }
go
func (u *udpTransport) Stop() error { u.t.Kill(nil) return u.t.Wait() }
[ "func", "(", "u", "*", "udpTransport", ")", "Stop", "(", ")", "error", "{", "u", ".", "t", ".", "Kill", "(", "nil", ")", "\n", "return", "u", ".", "t", ".", "Wait", "(", ")", "\n", "}" ]
// Stop our transport, this can only be stopped once, and requires a new // transport to be created to resume sending
[ "Stop", "our", "transport", "this", "can", "only", "be", "stopped", "once", "and", "requires", "a", "new", "transport", "to", "be", "created", "to", "resume", "sending" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/transport.go#L55-L58
154,038
monzo/phosphor-go
transport.go
connect
func (u *udpTransport) connect() error { c, err := net.DialTimeout("udp", u.endpoint, 1*time.Second) if err != nil { return err } u.conn = c return nil }
go
func (u *udpTransport) connect() error { c, err := net.DialTimeout("udp", u.endpoint, 1*time.Second) if err != nil { return err } u.conn = c return nil }
[ "func", "(", "u", "*", "udpTransport", ")", "connect", "(", ")", "error", "{", "c", ",", "err", ":=", "net", ".", "DialTimeout", "(", "\"", "\"", ",", "u", ".", "endpoint", ",", "1", "*", "time", ".", "Second", ")", "\n", "if", "err", "!=", "ni...
// connect our transport
[ "connect", "our", "transport" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/transport.go#L61-L70
154,039
monzo/phosphor-go
transport.go
consume
func (u *udpTransport) consume() error { var b []byte for { select { case <-u.t.Dying(): return nil case b = <-u.oldChan: case b = <-u.newChan: } u.send(b) } }
go
func (u *udpTransport) consume() error { var b []byte for { select { case <-u.t.Dying(): return nil case b = <-u.oldChan: case b = <-u.newChan: } u.send(b) } }
[ "func", "(", "u", "*", "udpTransport", ")", "consume", "(", ")", "error", "{", "var", "b", "[", "]", "byte", "\n", "for", "{", "select", "{", "case", "<-", "u", ".", "t", ".", "Dying", "(", ")", ":", "return", "nil", "\n", "case", "b", "=", "...
// consume from our internal trace channels until we exit
[ "consume", "from", "our", "internal", "trace", "channels", "until", "we", "exit" ]
2833852a47b69a97851ef1f876e0aa0d7bd07f38
https://github.com/monzo/phosphor-go/blob/2833852a47b69a97851ef1f876e0aa0d7bd07f38/transport.go#L73-L85
154,040
nuagenetworks/libvrsdk
ovsdb/NuageVMTableRow.go
Equals
func (row *NuageVMTableRow) Equals(otherRow interface{}) bool { nuageVMTableRow, ok := otherRow.(NuageVMTableRow) if !ok { return false } if row.Type != nuageVMTableRow.Type { return false } if row.Event != nuageVMTableRow.Event { return false } if row.EventType != nuageVMTableRow.EventType { return false } if row.State != nuageVMTableRow.State { return false } if row.Reason != nuageVMTableRow.Reason { return false } if strings.Compare(row.VMUuid, nuageVMTableRow.VMUuid) != 0 { return false } if row.Domain != nuageVMTableRow.Domain { return false } if strings.Compare(row.VMName, nuageVMTableRow.VMName) != 0 { return false } if strings.Compare(row.NuageUser, nuageVMTableRow.NuageUser) != 0 { return false } if strings.Compare(row.NuageEnterprise, nuageVMTableRow.NuageEnterprise) != 0 { return false } if !reflect.DeepEqual(row.Metadata, nuageVMTableRow.Metadata) { return false } if !reflect.DeepEqual(row.Ports, nuageVMTableRow.Ports) { return false } if row.Dirty != nuageVMTableRow.Dirty { return false } return true }
go
func (row *NuageVMTableRow) Equals(otherRow interface{}) bool { nuageVMTableRow, ok := otherRow.(NuageVMTableRow) if !ok { return false } if row.Type != nuageVMTableRow.Type { return false } if row.Event != nuageVMTableRow.Event { return false } if row.EventType != nuageVMTableRow.EventType { return false } if row.State != nuageVMTableRow.State { return false } if row.Reason != nuageVMTableRow.Reason { return false } if strings.Compare(row.VMUuid, nuageVMTableRow.VMUuid) != 0 { return false } if row.Domain != nuageVMTableRow.Domain { return false } if strings.Compare(row.VMName, nuageVMTableRow.VMName) != 0 { return false } if strings.Compare(row.NuageUser, nuageVMTableRow.NuageUser) != 0 { return false } if strings.Compare(row.NuageEnterprise, nuageVMTableRow.NuageEnterprise) != 0 { return false } if !reflect.DeepEqual(row.Metadata, nuageVMTableRow.Metadata) { return false } if !reflect.DeepEqual(row.Ports, nuageVMTableRow.Ports) { return false } if row.Dirty != nuageVMTableRow.Dirty { return false } return true }
[ "func", "(", "row", "*", "NuageVMTableRow", ")", "Equals", "(", "otherRow", "interface", "{", "}", ")", "bool", "{", "nuageVMTableRow", ",", "ok", ":=", "otherRow", ".", "(", "NuageVMTableRow", ")", "\n\n", "if", "!", "ok", "{", "return", "false", "\n", ...
// Equals checks for equality of two rows in the Nuage_VM_Table
[ "Equals", "checks", "for", "equality", "of", "two", "rows", "in", "the", "Nuage_VM_Table" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageVMTableRow.go#L42-L103
154,041
nuagenetworks/libvrsdk
ovsdb/NuageVMTableRow.go
CreateOVSDBRow
func (row *NuageVMTableRow) CreateOVSDBRow(ovsdbRow map[string]interface{}) error { metadataMap, err := libovsdb.NewOvsMap(row.Metadata) if err != nil { return err } portSet, err := libovsdb.NewOvsSet(row.Ports) if err != nil { return err } ovsdbRow["type"] = row.Type ovsdbRow["event"] = row.Event ovsdbRow["event_type"] = row.EventType ovsdbRow["state"] = row.State ovsdbRow["reason"] = row.Reason ovsdbRow["vm_uuid"] = row.VMUuid ovsdbRow["domain"] = row.Domain ovsdbRow["vm_name"] = row.VMName ovsdbRow["nuage_user"] = row.NuageUser ovsdbRow["nuage_enterprise"] = row.NuageEnterprise ovsdbRow["metadata"] = metadataMap ovsdbRow["ports"] = portSet ovsdbRow["dirty"] = row.Dirty return nil }
go
func (row *NuageVMTableRow) CreateOVSDBRow(ovsdbRow map[string]interface{}) error { metadataMap, err := libovsdb.NewOvsMap(row.Metadata) if err != nil { return err } portSet, err := libovsdb.NewOvsSet(row.Ports) if err != nil { return err } ovsdbRow["type"] = row.Type ovsdbRow["event"] = row.Event ovsdbRow["event_type"] = row.EventType ovsdbRow["state"] = row.State ovsdbRow["reason"] = row.Reason ovsdbRow["vm_uuid"] = row.VMUuid ovsdbRow["domain"] = row.Domain ovsdbRow["vm_name"] = row.VMName ovsdbRow["nuage_user"] = row.NuageUser ovsdbRow["nuage_enterprise"] = row.NuageEnterprise ovsdbRow["metadata"] = metadataMap ovsdbRow["ports"] = portSet ovsdbRow["dirty"] = row.Dirty return nil }
[ "func", "(", "row", "*", "NuageVMTableRow", ")", "CreateOVSDBRow", "(", "ovsdbRow", "map", "[", "string", "]", "interface", "{", "}", ")", "error", "{", "metadataMap", ",", "err", ":=", "libovsdb", ".", "NewOvsMap", "(", "row", ".", "Metadata", ")", "\n"...
// CreateOVSDBRow creates a OVSDB row for Nuage_VM_Table
[ "CreateOVSDBRow", "creates", "a", "OVSDB", "row", "for", "Nuage_VM_Table" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/ovsdb/NuageVMTableRow.go#L106-L133
154,042
cupcake/gokiq
worker.go
denormalizeQueues
func (w *WorkerConfig) denormalizeQueues() { for queue, x := range w.Queues { for i := 0; i < x; i++ { w.randomQueues = append(w.randomQueues, w.nsKey("queue:"+queue)) } } }
go
func (w *WorkerConfig) denormalizeQueues() { for queue, x := range w.Queues { for i := 0; i < x; i++ { w.randomQueues = append(w.randomQueues, w.nsKey("queue:"+queue)) } } }
[ "func", "(", "w", "*", "WorkerConfig", ")", "denormalizeQueues", "(", ")", "{", "for", "queue", ",", "x", ":=", "range", "w", ".", "Queues", "{", "for", "i", ":=", "0", ";", "i", "<", "x", ";", "i", "++", "{", "w", ".", "randomQueues", "=", "ap...
// create a slice of queues with duplicates using the assigned frequencies
[ "create", "a", "slice", "of", "queues", "with", "duplicates", "using", "the", "assigned", "frequencies" ]
ebbb02812f6826798d779fbda06921d45b2c4446
https://github.com/cupcake/gokiq/blob/ebbb02812f6826798d779fbda06921d45b2c4446/worker.go#L192-L198
154,043
cupcake/gokiq
worker.go
queueList
func (w *WorkerConfig) queueList() []interface{} { size := len(w.Queues) res := make([]interface{}, 0, size) queues := make(map[string]struct{}, size) indices := rand.Perm(len(w.randomQueues))[:size] for _, i := range indices { queue := w.randomQueues[i] if _, ok := queues[queue]; !ok { queues[queue] = struct{}{} res = append(res, queue) } } return res }
go
func (w *WorkerConfig) queueList() []interface{} { size := len(w.Queues) res := make([]interface{}, 0, size) queues := make(map[string]struct{}, size) indices := rand.Perm(len(w.randomQueues))[:size] for _, i := range indices { queue := w.randomQueues[i] if _, ok := queues[queue]; !ok { queues[queue] = struct{}{} res = append(res, queue) } } return res }
[ "func", "(", "w", "*", "WorkerConfig", ")", "queueList", "(", ")", "[", "]", "interface", "{", "}", "{", "size", ":=", "len", "(", "w", ".", "Queues", ")", "\n", "res", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "0", ",", "size", ...
// get a random slice of unique queues from the slice of denormalized queues
[ "get", "a", "random", "slice", "of", "unique", "queues", "from", "the", "slice", "of", "denormalized", "queues" ]
ebbb02812f6826798d779fbda06921d45b2c4446
https://github.com/cupcake/gokiq/blob/ebbb02812f6826798d779fbda06921d45b2c4446/worker.go#L201-L216
154,044
cupcake/gokiq
worker.go
quitHandler
func (w *WorkerConfig) quitHandler() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) sig := <-c signal.Stop(c) log.Printf("state=stopping signal=%s pid=%d", sig, pid) w.Lock() // wait for the current run loop and scheduler iterations to finish close(w.workQueue) // tell worker goroutines to stop after they finish their current job w.clearWorkerSet() done := make(chan struct{}) go func() { w.done.Wait() done <- struct{}{} }() select { case <-done: case <-time.After(w.StopTimeout): log.Printf("state=stop_timeout timeout=%s pid=%d", w.StopTimeout, pid) w.requeueJobs() } log.Printf("state=stopped pid=%d", pid) os.Exit(0) }
go
func (w *WorkerConfig) quitHandler() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) sig := <-c signal.Stop(c) log.Printf("state=stopping signal=%s pid=%d", sig, pid) w.Lock() // wait for the current run loop and scheduler iterations to finish close(w.workQueue) // tell worker goroutines to stop after they finish their current job w.clearWorkerSet() done := make(chan struct{}) go func() { w.done.Wait() done <- struct{}{} }() select { case <-done: case <-time.After(w.StopTimeout): log.Printf("state=stop_timeout timeout=%s pid=%d", w.StopTimeout, pid) w.requeueJobs() } log.Printf("state=stopped pid=%d", pid) os.Exit(0) }
[ "func", "(", "w", "*", "WorkerConfig", ")", "quitHandler", "(", ")", "{", "c", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "1", ")", "\n", "signal", ".", "Notify", "(", "c", ",", "os", ".", "Interrupt", ",", "syscall", ".", "SIGTERM", ",...
// listens for SIGINT, SIGTERM, and SIGQUIT to perform a clean shutdown
[ "listens", "for", "SIGINT", "SIGTERM", "and", "SIGQUIT", "to", "perform", "a", "clean", "shutdown" ]
ebbb02812f6826798d779fbda06921d45b2c4446
https://github.com/cupcake/gokiq/blob/ebbb02812f6826798d779fbda06921d45b2c4446/worker.go#L263-L286
154,045
gocontrib/auth
oauth/oauth.go
Hostname
func Hostname() string { hostname := os.Getenv("HOSTNAME") if len(hostname) > 0 { return hostname } hostname, err := os.Hostname() if err == nil { return hostname } return "localhost" }
go
func Hostname() string { hostname := os.Getenv("HOSTNAME") if len(hostname) > 0 { return hostname } hostname, err := os.Hostname() if err == nil { return hostname } return "localhost" }
[ "func", "Hostname", "(", ")", "string", "{", "hostname", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "len", "(", "hostname", ")", ">", "0", "{", "return", "hostname", "\n", "}", "\n", "hostname", ",", "err", ":=", "os", ".", "Hos...
// Hostname reads HOSTNAME env var or os.Hostname used for your app
[ "Hostname", "reads", "HOSTNAME", "env", "var", "or", "os", ".", "Hostname", "used", "for", "your", "app" ]
71451935f159b63a80956018581919ef824fbd0e
https://github.com/gocontrib/auth/blob/71451935f159b63a80956018581919ef824fbd0e/oauth/oauth.go#L100-L110
154,046
gocontrib/auth
oauth/oauth.go
RegisterAPI
func RegisterAPI(r Router, config *auth.Config) { config = config.SetDefaults() userStore := config.UserStoreEx if userStore == nil { return } defaultGetProviderName := gothic.GetProviderName gothic.GetProviderName = func(r *http.Request) (string, error) { providerName := chi.URLParam(r, "provider") if len(providerName) > 0 { return providerName, nil } return defaultGetProviderName(r) } r.Get("/api/oauth/success", func(w http.ResponseWriter, r *http.Request) { // TODO print nice html page fmt.Fprintf(w, "<body>Hey, buddy!</body>") }) r.Get("/api/oauth/error", func(w http.ResponseWriter, r *http.Request) { // TODO print nice html error page fmt.Fprintf(w, "<body>Oops, your OAuth failed! Please try again later</body>") }) r.Get("/api/oauth/providers", func(w http.ResponseWriter, r *http.Request) { auth.SendJSON(w, providerNames) }) r.Get("/api/oauth/login/{provider}", func(w http.ResponseWriter, r *http.Request) { // try to get the user without re-authenticating if user, err := gothic.CompleteUserAuth(w, r); err == nil { completeOAuthFlow(w, r, config, user) } else { gothic.BeginAuthHandler(w, r) } }) r.Get("/api/oauth/logout/{provider}", func(w http.ResponseWriter, r *http.Request) { gothic.Logout(w, r) w.Header().Set("Location", "/") w.WriteHeader(http.StatusTemporaryRedirect) }) r.Get("/api/oauth/callback/{provider}", func(w http.ResponseWriter, r *http.Request) { user, err := gothic.CompleteUserAuth(w, r) if err != nil { oauthError(w, r, err) return } completeOAuthFlow(w, r, config, user) }) }
go
func RegisterAPI(r Router, config *auth.Config) { config = config.SetDefaults() userStore := config.UserStoreEx if userStore == nil { return } defaultGetProviderName := gothic.GetProviderName gothic.GetProviderName = func(r *http.Request) (string, error) { providerName := chi.URLParam(r, "provider") if len(providerName) > 0 { return providerName, nil } return defaultGetProviderName(r) } r.Get("/api/oauth/success", func(w http.ResponseWriter, r *http.Request) { // TODO print nice html page fmt.Fprintf(w, "<body>Hey, buddy!</body>") }) r.Get("/api/oauth/error", func(w http.ResponseWriter, r *http.Request) { // TODO print nice html error page fmt.Fprintf(w, "<body>Oops, your OAuth failed! Please try again later</body>") }) r.Get("/api/oauth/providers", func(w http.ResponseWriter, r *http.Request) { auth.SendJSON(w, providerNames) }) r.Get("/api/oauth/login/{provider}", func(w http.ResponseWriter, r *http.Request) { // try to get the user without re-authenticating if user, err := gothic.CompleteUserAuth(w, r); err == nil { completeOAuthFlow(w, r, config, user) } else { gothic.BeginAuthHandler(w, r) } }) r.Get("/api/oauth/logout/{provider}", func(w http.ResponseWriter, r *http.Request) { gothic.Logout(w, r) w.Header().Set("Location", "/") w.WriteHeader(http.StatusTemporaryRedirect) }) r.Get("/api/oauth/callback/{provider}", func(w http.ResponseWriter, r *http.Request) { user, err := gothic.CompleteUserAuth(w, r) if err != nil { oauthError(w, r, err) return } completeOAuthFlow(w, r, config, user) }) }
[ "func", "RegisterAPI", "(", "r", "Router", ",", "config", "*", "auth", ".", "Config", ")", "{", "config", "=", "config", ".", "SetDefaults", "(", ")", "\n\n", "userStore", ":=", "config", ".", "UserStoreEx", "\n", "if", "userStore", "==", "nil", "{", "...
// RegisterAPI registers OAuth HTTP handlers
[ "RegisterAPI", "registers", "OAuth", "HTTP", "handlers" ]
71451935f159b63a80956018581919ef824fbd0e
https://github.com/gocontrib/auth/blob/71451935f159b63a80956018581919ef824fbd0e/oauth/oauth.go#L118-L172
154,047
joyt/godate
godate.go
MustParse
func MustParse(s string) time.Time { d, err := Parse(s) if err != nil { panic(err) } return d }
go
func MustParse(s string) time.Time { d, err := Parse(s) if err != nil { panic(err) } return d }
[ "func", "MustParse", "(", "s", "string", ")", "time", ".", "Time", "{", "d", ",", "err", ":=", "Parse", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "d", "\n", "}" ]
// MustParse is like Parse except it panics if the string is not parseable.
[ "MustParse", "is", "like", "Parse", "except", "it", "panics", "if", "the", "string", "is", "not", "parseable", "." ]
7151572574a7c217932a48e0b23c111631e7181c
https://github.com/joyt/godate/blob/7151572574a7c217932a48e0b23c111631e7181c/godate.go#L168-L174
154,048
joyt/godate
godate.go
ParseInLocation
func ParseInLocation(s string, loc *time.Location) (time.Time, error) { _, l, err := ParseAndGetLayout(s) if err != nil { return time.Time{}, err } t, err := time.ParseInLocation(l, s, loc) return t, err }
go
func ParseInLocation(s string, loc *time.Location) (time.Time, error) { _, l, err := ParseAndGetLayout(s) if err != nil { return time.Time{}, err } t, err := time.ParseInLocation(l, s, loc) return t, err }
[ "func", "ParseInLocation", "(", "s", "string", ",", "loc", "*", "time", ".", "Location", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "_", ",", "l", ",", "err", ":=", "ParseAndGetLayout", "(", "s", ")", "\n", "if", "err", "!=", "nil", "...
// ParseInLocation is like Parse except it uses the given location when parsing the date.
[ "ParseInLocation", "is", "like", "Parse", "except", "it", "uses", "the", "given", "location", "when", "parsing", "the", "date", "." ]
7151572574a7c217932a48e0b23c111631e7181c
https://github.com/joyt/godate/blob/7151572574a7c217932a48e0b23c111631e7181c/godate.go#L177-L184
154,049
jbooth/flotilla
lib.go
defaultCommands
func defaultCommands() map[string]Command { return map[string]Command{ "Put": put, "PutIfAbsent": putIfAbsent, "CompareAndSwap": compareAndSwap, "CompareAndRemove": compareAndRemove, "Remove": remove, "Noop": noop, } }
go
func defaultCommands() map[string]Command { return map[string]Command{ "Put": put, "PutIfAbsent": putIfAbsent, "CompareAndSwap": compareAndSwap, "CompareAndRemove": compareAndRemove, "Remove": remove, "Noop": noop, } }
[ "func", "defaultCommands", "(", ")", "map", "[", "string", "]", "Command", "{", "return", "map", "[", "string", "]", "Command", "{", "\"", "\"", ":", "put", ",", "\"", "\"", ":", "putIfAbsent", ",", "\"", "\"", ":", "compareAndSwap", ",", "\"", "\"",...
// some default commands
[ "some", "default", "commands" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/lib.go#L9-L19
154,050
d2g/dhcp4server
leasepool/memorypool/memorypool.go
AddLease
func (t *MemoryPool) AddLease(newLease leasepool.Lease) error { t.poolLock.Lock() defer t.poolLock.Unlock() if t.pool == nil { t.pool = make([]leasepool.Lease, 0) } for i := range t.pool { if t.pool[i].IP.Equal(newLease.IP) { //Lease Already Exists In Pool return errors.New("Error: Lease IP \"" + newLease.IP.String() + "\" alreay exists in Pool") } } t.pool = append([]leasepool.Lease{newLease}, t.pool...) return nil }
go
func (t *MemoryPool) AddLease(newLease leasepool.Lease) error { t.poolLock.Lock() defer t.poolLock.Unlock() if t.pool == nil { t.pool = make([]leasepool.Lease, 0) } for i := range t.pool { if t.pool[i].IP.Equal(newLease.IP) { //Lease Already Exists In Pool return errors.New("Error: Lease IP \"" + newLease.IP.String() + "\" alreay exists in Pool") } } t.pool = append([]leasepool.Lease{newLease}, t.pool...) return nil }
[ "func", "(", "t", "*", "MemoryPool", ")", "AddLease", "(", "newLease", "leasepool", ".", "Lease", ")", "error", "{", "t", ".", "poolLock", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "poolLock", ".", "Unlock", "(", ")", "\n\n", "if", "t", ".", ...
//Add A Lease To The Pool
[ "Add", "A", "Lease", "To", "The", "Pool" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/leasepool/memorypool/memorypool.go#L17-L34
154,051
d2g/dhcp4server
leasepool/memorypool/memorypool.go
RemoveLease
func (t *MemoryPool) RemoveLease(leaseIP net.IP) error { t.poolLock.Lock() defer t.poolLock.Unlock() for i := range t.pool { if t.pool[i].IP.Equal(leaseIP) { //Move the Last Element to This Position. t.pool[i] = t.pool[len(t.pool)-1] //Shortern the Pool By One. t.pool = t.pool[0:(len(t.pool) - 1)] return nil } } return errors.New("Error: Lease IP \"" + leaseIP.String() + "\" Is Not In The Pool") }
go
func (t *MemoryPool) RemoveLease(leaseIP net.IP) error { t.poolLock.Lock() defer t.poolLock.Unlock() for i := range t.pool { if t.pool[i].IP.Equal(leaseIP) { //Move the Last Element to This Position. t.pool[i] = t.pool[len(t.pool)-1] //Shortern the Pool By One. t.pool = t.pool[0:(len(t.pool) - 1)] return nil } } return errors.New("Error: Lease IP \"" + leaseIP.String() + "\" Is Not In The Pool") }
[ "func", "(", "t", "*", "MemoryPool", ")", "RemoveLease", "(", "leaseIP", "net", ".", "IP", ")", "error", "{", "t", ".", "poolLock", ".", "Lock", "(", ")", "\n", "defer", "t", ".", "poolLock", ".", "Unlock", "(", ")", "\n\n", "for", "i", ":=", "ra...
//Remove a Lease From The Pool
[ "Remove", "a", "Lease", "From", "The", "Pool" ]
7d4a0a7f59a572d629ba5f49634b35c7fac7967e
https://github.com/d2g/dhcp4server/blob/7d4a0a7f59a572d629ba5f49634b35c7fac7967e/leasepool/memorypool/memorypool.go#L37-L54
154,052
osamingo/boolconv
boolconv.go
NewBoolByInterface
func NewBoolByInterface(i interface{}) (Bool, error) { t := reflect.TypeOf(i) val := reflect.ValueOf(i) if val.Kind() == reflect.Ptr { val = val.Elem() } if t.Name() == "Bool" { if b, ok := (val.Interface()).(Bool); ok { return b, nil } } switch val.Kind() { case reflect.Bool: return NewBool((val.Interface()).(bool)), nil case reflect.Uint8: return Bool((val.Interface()).(byte)), nil case reflect.String: if b, err := strconv.ParseBool((val.Interface()).(string)); err == nil { return NewBool(b), nil } case reflect.Slice: v := val.Index(0) if b, ok := (v.Interface()).(byte); ok { return Bool(b), nil } } return False, errors.New("unsupported type") }
go
func NewBoolByInterface(i interface{}) (Bool, error) { t := reflect.TypeOf(i) val := reflect.ValueOf(i) if val.Kind() == reflect.Ptr { val = val.Elem() } if t.Name() == "Bool" { if b, ok := (val.Interface()).(Bool); ok { return b, nil } } switch val.Kind() { case reflect.Bool: return NewBool((val.Interface()).(bool)), nil case reflect.Uint8: return Bool((val.Interface()).(byte)), nil case reflect.String: if b, err := strconv.ParseBool((val.Interface()).(string)); err == nil { return NewBool(b), nil } case reflect.Slice: v := val.Index(0) if b, ok := (v.Interface()).(byte); ok { return Bool(b), nil } } return False, errors.New("unsupported type") }
[ "func", "NewBoolByInterface", "(", "i", "interface", "{", "}", ")", "(", "Bool", ",", "error", ")", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "i", ")", "\n", "val", ":=", "reflect", ".", "ValueOf", "(", "i", ")", "\n", "if", "val", ".", "Kin...
// NewBoolByInterface converts interface into Bool.
[ "NewBoolByInterface", "converts", "interface", "into", "Bool", "." ]
9ef56333404fa41888f86478782acfe2e9c4012a
https://github.com/osamingo/boolconv/blob/9ef56333404fa41888f86478782acfe2e9c4012a/boolconv.go#L33-L68
154,053
gocontrib/auth
context.go
GetContextUser
func GetContextUser(c context.Context) User { var i = c.Value(userKey) if i == nil { return nil } return i.(User) }
go
func GetContextUser(c context.Context) User { var i = c.Value(userKey) if i == nil { return nil } return i.(User) }
[ "func", "GetContextUser", "(", "c", "context", ".", "Context", ")", "User", "{", "var", "i", "=", "c", ".", "Value", "(", "userKey", ")", "\n", "if", "i", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "i", ".", "(", "User", ")", ...
// GetContextUser returns authenticated user if it presents in given context
[ "GetContextUser", "returns", "authenticated", "user", "if", "it", "presents", "in", "given", "context" ]
71451935f159b63a80956018581919ef824fbd0e
https://github.com/gocontrib/auth/blob/71451935f159b63a80956018581919ef824fbd0e/context.go#L16-L22
154,054
gocontrib/auth
context.go
WithUser
func WithUser(parent context.Context, user User) context.Context { return context.WithValue(parent, userKey, user) }
go
func WithUser(parent context.Context, user User) context.Context { return context.WithValue(parent, userKey, user) }
[ "func", "WithUser", "(", "parent", "context", ".", "Context", ",", "user", "User", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "parent", ",", "userKey", ",", "user", ")", "\n", "}" ]
// WithUser returns new context with given user
[ "WithUser", "returns", "new", "context", "with", "given", "user" ]
71451935f159b63a80956018581919ef824fbd0e
https://github.com/gocontrib/auth/blob/71451935f159b63a80956018581919ef824fbd0e/context.go#L25-L27
154,055
pdf/golifx
client.go
GetLocations
func (c *Client) GetLocations() (locations []common.Location, err error) { return c.protocol.GetLocations() }
go
func (c *Client) GetLocations() (locations []common.Location, err error) { return c.protocol.GetLocations() }
[ "func", "(", "c", "*", "Client", ")", "GetLocations", "(", ")", "(", "locations", "[", "]", "common", ".", "Location", ",", "err", "error", ")", "{", "return", "c", ".", "protocol", ".", "GetLocations", "(", ")", "\n", "}" ]
// GetLocations returns a slice of all locations known to the client, or // common.ErrNotFound if no locations are currently known.
[ "GetLocations", "returns", "a", "slice", "of", "all", "locations", "known", "to", "the", "client", "or", "common", ".", "ErrNotFound", "if", "no", "locations", "are", "currently", "known", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L26-L28
154,056
pdf/golifx
client.go
GetLocationByID
func (c *Client) GetLocationByID(id string) (common.Location, error) { location, err := c.protocol.GetLocation(id) if err == nil { return location, nil } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err = sub.Close(); err != nil { common.Log.Warnf("Failed closing location subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewLocation: if id == event.Location.ID() { return event.Location, nil } } case <-timeout: return nil, common.ErrNotFound } } }
go
func (c *Client) GetLocationByID(id string) (common.Location, error) { location, err := c.protocol.GetLocation(id) if err == nil { return location, nil } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err = sub.Close(); err != nil { common.Log.Warnf("Failed closing location subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewLocation: if id == event.Location.ID() { return event.Location, nil } } case <-timeout: return nil, common.ErrNotFound } } }
[ "func", "(", "c", "*", "Client", ")", "GetLocationByID", "(", "id", "string", ")", "(", "common", ".", "Location", ",", "error", ")", "{", "location", ",", "err", ":=", "c", ".", "protocol", ".", "GetLocation", "(", "id", ")", "\n", "if", "err", "=...
// GetLocationByID looks up a location by its `id` and returns a common.Location. // May return a common.ErrNotFound error if the lookup times out without finding // the location.
[ "GetLocationByID", "looks", "up", "a", "location", "by", "its", "id", "and", "returns", "a", "common", ".", "Location", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "l...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L33-L70
154,057
pdf/golifx
client.go
GetLocationByLabel
func (c *Client) GetLocationByLabel(label string) (common.Location, error) { locations, _ := c.GetLocations() for _, location := range locations { if label == location.GetLabel() { return location, nil } } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err := sub.Close(); err != nil { common.Log.Warnf("Failed closing location subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewLocation: if label == event.Location.GetLabel() { return event.Location, nil } } case <-timeout: return nil, common.ErrNotFound } } }
go
func (c *Client) GetLocationByLabel(label string) (common.Location, error) { locations, _ := c.GetLocations() for _, location := range locations { if label == location.GetLabel() { return location, nil } } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err := sub.Close(); err != nil { common.Log.Warnf("Failed closing location subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewLocation: if label == event.Location.GetLabel() { return event.Location, nil } } case <-timeout: return nil, common.ErrNotFound } } }
[ "func", "(", "c", "*", "Client", ")", "GetLocationByLabel", "(", "label", "string", ")", "(", "common", ".", "Location", ",", "error", ")", "{", "locations", ",", "_", ":=", "c", ".", "GetLocations", "(", ")", "\n", "for", "_", ",", "location", ":=",...
// GetLocationByLabel looks up a location by its `label` and returns a // common.Location. May return a common.ErrNotFound error if the lookup times // out without finding the location.
[ "GetLocationByLabel", "looks", "up", "a", "location", "by", "its", "label", "and", "returns", "a", "common", ".", "Location", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the"...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L75-L114
154,058
pdf/golifx
client.go
GetGroupByID
func (c *Client) GetGroupByID(id string) (common.Group, error) { group, err := c.protocol.GetGroup(id) if err == nil { return group, nil } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err = sub.Close(); err != nil { common.Log.Warnf("Failed closing group subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewGroup: if id == event.Group.ID() { return event.Group, nil } } case <-timeout: return nil, common.ErrNotFound } } }
go
func (c *Client) GetGroupByID(id string) (common.Group, error) { group, err := c.protocol.GetGroup(id) if err == nil { return group, nil } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err = sub.Close(); err != nil { common.Log.Warnf("Failed closing group subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewGroup: if id == event.Group.ID() { return event.Group, nil } } case <-timeout: return nil, common.ErrNotFound } } }
[ "func", "(", "c", "*", "Client", ")", "GetGroupByID", "(", "id", "string", ")", "(", "common", ".", "Group", ",", "error", ")", "{", "group", ",", "err", ":=", "c", ".", "protocol", ".", "GetGroup", "(", "id", ")", "\n", "if", "err", "==", "nil",...
// GetGroupByID looks up a group by its `id` and returns a common.Group. // May return a common.ErrNotFound error if the lookup times out without finding // the group.
[ "GetGroupByID", "looks", "up", "a", "group", "by", "its", "id", "and", "returns", "a", "common", ".", "Group", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "group", ...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L125-L162
154,059
pdf/golifx
client.go
GetGroupByLabel
func (c *Client) GetGroupByLabel(label string) (common.Group, error) { groups, _ := c.GetGroups() for _, dev := range groups { if label == dev.GetLabel() { return dev, nil } } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err := sub.Close(); err != nil { common.Log.Warnf("Failed closing group subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewGroup: if label == event.Group.GetLabel() { return event.Group, nil } } case <-timeout: return nil, common.ErrNotFound } } }
go
func (c *Client) GetGroupByLabel(label string) (common.Group, error) { groups, _ := c.GetGroups() for _, dev := range groups { if label == dev.GetLabel() { return dev, nil } } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err := sub.Close(); err != nil { common.Log.Warnf("Failed closing group subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewGroup: if label == event.Group.GetLabel() { return event.Group, nil } } case <-timeout: return nil, common.ErrNotFound } } }
[ "func", "(", "c", "*", "Client", ")", "GetGroupByLabel", "(", "label", "string", ")", "(", "common", ".", "Group", ",", "error", ")", "{", "groups", ",", "_", ":=", "c", ".", "GetGroups", "(", ")", "\n", "for", "_", ",", "dev", ":=", "range", "gr...
// GetGroupByLabel looks up a group by its `label` and returns a common.Group. // May return a common.ErrNotFound error if the lookup times out without finding // the group.
[ "GetGroupByLabel", "looks", "up", "a", "group", "by", "its", "label", "and", "returns", "a", "common", ".", "Group", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "grou...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L167-L206
154,060
pdf/golifx
client.go
GetDevices
func (c *Client) GetDevices() (devices []common.Device, err error) { return c.protocol.GetDevices() }
go
func (c *Client) GetDevices() (devices []common.Device, err error) { return c.protocol.GetDevices() }
[ "func", "(", "c", "*", "Client", ")", "GetDevices", "(", ")", "(", "devices", "[", "]", "common", ".", "Device", ",", "err", "error", ")", "{", "return", "c", ".", "protocol", ".", "GetDevices", "(", ")", "\n", "}" ]
// GetDevices returns a slice of all devices known to the client, or // common.ErrNotFound if no devices are currently known.
[ "GetDevices", "returns", "a", "slice", "of", "all", "devices", "known", "to", "the", "client", "or", "common", ".", "ErrNotFound", "if", "no", "devices", "are", "currently", "known", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L210-L212
154,061
pdf/golifx
client.go
GetDeviceByID
func (c *Client) GetDeviceByID(id uint64) (common.Device, error) { dev, err := c.protocol.GetDevice(id) if err == nil { return dev, nil } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err = sub.Close(); err != nil { common.Log.Warnf("Failed closing device subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewDevice: if id == event.Device.ID() { return event.Device, nil } } case <-timeout: return nil, common.ErrNotFound } } }
go
func (c *Client) GetDeviceByID(id uint64) (common.Device, error) { dev, err := c.protocol.GetDevice(id) if err == nil { return dev, nil } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err = sub.Close(); err != nil { common.Log.Warnf("Failed closing device subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewDevice: if id == event.Device.ID() { return event.Device, nil } } case <-timeout: return nil, common.ErrNotFound } } }
[ "func", "(", "c", "*", "Client", ")", "GetDeviceByID", "(", "id", "uint64", ")", "(", "common", ".", "Device", ",", "error", ")", "{", "dev", ",", "err", ":=", "c", ".", "protocol", ".", "GetDevice", "(", "id", ")", "\n", "if", "err", "==", "nil"...
// GetDeviceByID looks up a device by its `id` and returns a common.Device. // May return a common.ErrNotFound error if the lookup times out without finding // the device.
[ "GetDeviceByID", "looks", "up", "a", "device", "by", "its", "id", "and", "returns", "a", "common", ".", "Device", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "device"...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L217-L254
154,062
pdf/golifx
client.go
GetDeviceByLabel
func (c *Client) GetDeviceByLabel(label string) (common.Device, error) { devices, _ := c.GetDevices() for _, dev := range devices { res, err := dev.GetLabel() if err == nil && res == label { return dev, nil } } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err := sub.Close(); err != nil { common.Log.Warnf("Failed closing device subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewDevice: l, err := event.Device.GetLabel() if err != nil { return nil, err } if l == label { return event.Device, nil } } case <-timeout: return nil, common.ErrNotFound } } }
go
func (c *Client) GetDeviceByLabel(label string) (common.Device, error) { devices, _ := c.GetDevices() for _, dev := range devices { res, err := dev.GetLabel() if err == nil && res == label { return dev, nil } } var timeout <-chan time.Time if c.timeout > 0 { timeout = time.After(c.timeout) } else { timeout = make(<-chan time.Time) } sub := c.protocol.Subscribe() defer func() { if err := sub.Close(); err != nil { common.Log.Warnf("Failed closing device subscription: %+v", err) } }() events := sub.Events() for { select { case event, ok := <-events: if !ok { return nil, common.ErrClosed } switch event := event.(type) { case common.EventNewDevice: l, err := event.Device.GetLabel() if err != nil { return nil, err } if l == label { return event.Device, nil } } case <-timeout: return nil, common.ErrNotFound } } }
[ "func", "(", "c", "*", "Client", ")", "GetDeviceByLabel", "(", "label", "string", ")", "(", "common", ".", "Device", ",", "error", ")", "{", "devices", ",", "_", ":=", "c", ".", "GetDevices", "(", ")", "\n", "for", "_", ",", "dev", ":=", "range", ...
// GetDeviceByLabel looks up a device by its `label` and returns a common.Device. // May return a common.ErrNotFound error if the lookup times out without finding // the device.
[ "GetDeviceByLabel", "looks", "up", "a", "device", "by", "its", "label", "and", "returns", "a", "common", ".", "Device", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "d...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L259-L303
154,063
pdf/golifx
client.go
GetLights
func (c *Client) GetLights() (lights []common.Light, err error) { devices, err := c.GetDevices() if err != nil { return lights, err } for _, dev := range devices { if light, ok := dev.(common.Light); ok { lights = append(lights, light) } } if len(lights) == 0 { return lights, common.ErrNotFound } return lights, nil }
go
func (c *Client) GetLights() (lights []common.Light, err error) { devices, err := c.GetDevices() if err != nil { return lights, err } for _, dev := range devices { if light, ok := dev.(common.Light); ok { lights = append(lights, light) } } if len(lights) == 0 { return lights, common.ErrNotFound } return lights, nil }
[ "func", "(", "c", "*", "Client", ")", "GetLights", "(", ")", "(", "lights", "[", "]", "common", ".", "Light", ",", "err", "error", ")", "{", "devices", ",", "err", ":=", "c", ".", "GetDevices", "(", ")", "\n", "if", "err", "!=", "nil", "{", "re...
// GetLights returns a slice of all lights known to the client, or // common.ErrNotFound if no lights are currently known.
[ "GetLights", "returns", "a", "slice", "of", "all", "lights", "known", "to", "the", "client", "or", "common", ".", "ErrNotFound", "if", "no", "lights", "are", "currently", "known", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L307-L324
154,064
pdf/golifx
client.go
GetLightByID
func (c *Client) GetLightByID(id uint64) (light common.Light, err error) { dev, err := c.GetDeviceByID(id) if err != nil { return nil, err } light, ok := dev.(common.Light) if !ok { return nil, common.ErrDeviceInvalidType } return light, nil }
go
func (c *Client) GetLightByID(id uint64) (light common.Light, err error) { dev, err := c.GetDeviceByID(id) if err != nil { return nil, err } light, ok := dev.(common.Light) if !ok { return nil, common.ErrDeviceInvalidType } return light, nil }
[ "func", "(", "c", "*", "Client", ")", "GetLightByID", "(", "id", "uint64", ")", "(", "light", "common", ".", "Light", ",", "err", "error", ")", "{", "dev", ",", "err", ":=", "c", ".", "GetDeviceByID", "(", "id", ")", "\n", "if", "err", "!=", "nil...
// GetLightByID looks up a light by its `id` and returns a common.Light. // May return a common.ErrNotFound error if the lookup times out without finding // the light, or common.ErrDeviceInvalidType if the device exists but is not a // light.
[ "GetLightByID", "looks", "up", "a", "light", "by", "its", "id", "and", "returns", "a", "common", ".", "Light", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "light", ...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L330-L342
154,065
pdf/golifx
client.go
GetLightByLabel
func (c *Client) GetLightByLabel(label string) (common.Light, error) { dev, err := c.GetDeviceByLabel(label) if err != nil { return nil, err } light, ok := dev.(common.Light) if !ok { return nil, common.ErrDeviceInvalidType } return light, nil }
go
func (c *Client) GetLightByLabel(label string) (common.Light, error) { dev, err := c.GetDeviceByLabel(label) if err != nil { return nil, err } light, ok := dev.(common.Light) if !ok { return nil, common.ErrDeviceInvalidType } return light, nil }
[ "func", "(", "c", "*", "Client", ")", "GetLightByLabel", "(", "label", "string", ")", "(", "common", ".", "Light", ",", "error", ")", "{", "dev", ",", "err", ":=", "c", ".", "GetDeviceByLabel", "(", "label", ")", "\n", "if", "err", "!=", "nil", "{"...
// GetLightByLabel looks up a light by its `label` and returns a common.Light. // May return a common.ErrNotFound error if the lookup times out without finding // the light, or common.ErrDeviceInvalidType if the device exists but is not a // light.
[ "GetLightByLabel", "looks", "up", "a", "light", "by", "its", "label", "and", "returns", "a", "common", ".", "Light", ".", "May", "return", "a", "common", ".", "ErrNotFound", "error", "if", "the", "lookup", "times", "out", "without", "finding", "the", "ligh...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L348-L360
154,066
pdf/golifx
client.go
SetPower
func (c *Client) SetPower(state bool) error { return c.protocol.SetPower(state) }
go
func (c *Client) SetPower(state bool) error { return c.protocol.SetPower(state) }
[ "func", "(", "c", "*", "Client", ")", "SetPower", "(", "state", "bool", ")", "error", "{", "return", "c", ".", "protocol", ".", "SetPower", "(", "state", ")", "\n", "}" ]
// SetPower broadcasts a request to change the power state of all devices on // the network. A state of true requests power on, and a state of false // requests power off.
[ "SetPower", "broadcasts", "a", "request", "to", "change", "the", "power", "state", "of", "all", "devices", "on", "the", "network", ".", "A", "state", "of", "true", "requests", "power", "on", "and", "a", "state", "of", "false", "requests", "power", "off", ...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L365-L367
154,067
pdf/golifx
client.go
SetPowerDuration
func (c *Client) SetPowerDuration(state bool, duration time.Duration) error { return c.protocol.SetPowerDuration(state, duration) }
go
func (c *Client) SetPowerDuration(state bool, duration time.Duration) error { return c.protocol.SetPowerDuration(state, duration) }
[ "func", "(", "c", "*", "Client", ")", "SetPowerDuration", "(", "state", "bool", ",", "duration", "time", ".", "Duration", ")", "error", "{", "return", "c", ".", "protocol", ".", "SetPowerDuration", "(", "state", ",", "duration", ")", "\n", "}" ]
// SetPowerDuration broadcasts a request to change the power state of all // devices on the network, transitioning over the specified duration. A state // of true requests power on, and a state of false requests power off. Not all // device types support transitioning, so if you wish to change the state of all // device types, you should use SetPower instead.
[ "SetPowerDuration", "broadcasts", "a", "request", "to", "change", "the", "power", "state", "of", "all", "devices", "on", "the", "network", "transitioning", "over", "the", "specified", "duration", ".", "A", "state", "of", "true", "requests", "power", "on", "and...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L374-L376
154,068
pdf/golifx
client.go
SetColor
func (c *Client) SetColor(color common.Color, duration time.Duration) error { return c.protocol.SetColor(color, duration) }
go
func (c *Client) SetColor(color common.Color, duration time.Duration) error { return c.protocol.SetColor(color, duration) }
[ "func", "(", "c", "*", "Client", ")", "SetColor", "(", "color", "common", ".", "Color", ",", "duration", "time", ".", "Duration", ")", "error", "{", "return", "c", ".", "protocol", ".", "SetColor", "(", "color", ",", "duration", ")", "\n", "}" ]
// SetColor broadcasts a request to change the color of all devices on the // network.
[ "SetColor", "broadcasts", "a", "request", "to", "change", "the", "color", "of", "all", "devices", "on", "the", "network", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L380-L382
154,069
pdf/golifx
client.go
SetDiscoveryInterval
func (c *Client) SetDiscoveryInterval(interval time.Duration) error { c.Lock() if c.discoveryInterval != 0 { for i := 0; i < cap(c.quitChan); i++ { c.quitChan <- struct{}{} } } c.discoveryInterval = interval c.Unlock() common.Log.Infof("Starting discovery with interval %v", interval) return c.discover() }
go
func (c *Client) SetDiscoveryInterval(interval time.Duration) error { c.Lock() if c.discoveryInterval != 0 { for i := 0; i < cap(c.quitChan); i++ { c.quitChan <- struct{}{} } } c.discoveryInterval = interval c.Unlock() common.Log.Infof("Starting discovery with interval %v", interval) return c.discover() }
[ "func", "(", "c", "*", "Client", ")", "SetDiscoveryInterval", "(", "interval", "time", ".", "Duration", ")", "error", "{", "c", ".", "Lock", "(", ")", "\n", "if", "c", ".", "discoveryInterval", "!=", "0", "{", "for", "i", ":=", "0", ";", "i", "<", ...
// SetDiscoveryInterval causes the client to discover devices and state every // interval. You should set this to a non-zero value for any long-running // process, otherwise devices will only be discovered once.
[ "SetDiscoveryInterval", "causes", "the", "client", "to", "discover", "devices", "and", "state", "every", "interval", ".", "You", "should", "set", "this", "to", "a", "non", "-", "zero", "value", "for", "any", "long", "-", "running", "process", "otherwise", "d...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L387-L398
154,070
pdf/golifx
client.go
SetRetryInterval
func (c *Client) SetRetryInterval(retryInterval time.Duration) { if c.timeout > 0 && retryInterval >= c.timeout { retryInterval = c.timeout / 2 } c.Lock() c.retryInterval = retryInterval c.Unlock() }
go
func (c *Client) SetRetryInterval(retryInterval time.Duration) { if c.timeout > 0 && retryInterval >= c.timeout { retryInterval = c.timeout / 2 } c.Lock() c.retryInterval = retryInterval c.Unlock() }
[ "func", "(", "c", "*", "Client", ")", "SetRetryInterval", "(", "retryInterval", "time", ".", "Duration", ")", "{", "if", "c", ".", "timeout", ">", "0", "&&", "retryInterval", ">=", "c", ".", "timeout", "{", "retryInterval", "=", "c", ".", "timeout", "/...
// SetRetryInterval sets the retry interval for operations on this client. If // a timeout has been set, and the retry interval exceeds the timeout, the retry // interval will be set to half the timeout
[ "SetRetryInterval", "sets", "the", "retry", "interval", "for", "operations", "on", "this", "client", ".", "If", "a", "timeout", "has", "been", "set", "and", "the", "retry", "interval", "exceeds", "the", "timeout", "the", "retry", "interval", "will", "be", "s...
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L416-L423
154,071
pdf/golifx
client.go
GetRetryInterval
func (c *Client) GetRetryInterval() *time.Duration { c.RLock() defer c.RUnlock() return &c.retryInterval }
go
func (c *Client) GetRetryInterval() *time.Duration { c.RLock() defer c.RUnlock() return &c.retryInterval }
[ "func", "(", "c", "*", "Client", ")", "GetRetryInterval", "(", ")", "*", "time", ".", "Duration", "{", "c", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "RUnlock", "(", ")", "\n", "return", "&", "c", ".", "retryInterval", "\n", "}" ]
// GetRetryInterval returns the currently configured retry interval for // operations on this client
[ "GetRetryInterval", "returns", "the", "currently", "configured", "retry", "interval", "for", "operations", "on", "this", "client" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L427-L431
154,072
pdf/golifx
client.go
Close
func (c *Client) Close() error { c.Lock() defer c.Unlock() select { case <-c.quitChan: common.Log.Warnf(`client already closed`) return common.ErrClosed default: close(c.quitChan) } if err := c.SubscriptionProvider.Close(); err != nil { common.Log.Warnf("closing subscriptions: %v", err) } return c.protocol.Close() }
go
func (c *Client) Close() error { c.Lock() defer c.Unlock() select { case <-c.quitChan: common.Log.Warnf(`client already closed`) return common.ErrClosed default: close(c.quitChan) } if err := c.SubscriptionProvider.Close(); err != nil { common.Log.Warnf("closing subscriptions: %v", err) } return c.protocol.Close() }
[ "func", "(", "c", "*", "Client", ")", "Close", "(", ")", "error", "{", "c", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "Unlock", "(", ")", "\n\n", "select", "{", "case", "<-", "c", ".", "quitChan", ":", "common", ".", "Log", ".", "Warnf", ...
// Close signals the termination of this client, and cleans up resources
[ "Close", "signals", "the", "termination", "of", "this", "client", "and", "cleans", "up", "resources" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L434-L450
154,073
pdf/golifx
client.go
subscribe
func (c *Client) subscribe() error { sub := c.protocol.Subscribe() events := sub.Events() go func() { for { select { case <-c.quitChan: return default: } select { case <-c.quitChan: return case event := <-events: switch event.(type) { case common.EventNewDevice, common.EventNewGroup, common.EventNewLocation, common.EventExpiredDevice, common.EventExpiredGroup, common.EventExpiredLocation: c.Notify(event) } } } }() return nil }
go
func (c *Client) subscribe() error { sub := c.protocol.Subscribe() events := sub.Events() go func() { for { select { case <-c.quitChan: return default: } select { case <-c.quitChan: return case event := <-events: switch event.(type) { case common.EventNewDevice, common.EventNewGroup, common.EventNewLocation, common.EventExpiredDevice, common.EventExpiredGroup, common.EventExpiredLocation: c.Notify(event) } } } }() return nil }
[ "func", "(", "c", "*", "Client", ")", "subscribe", "(", ")", "error", "{", "sub", ":=", "c", ".", "protocol", ".", "Subscribe", "(", ")", "\n", "events", ":=", "sub", ".", "Events", "(", ")", "\n\n", "go", "func", "(", ")", "{", "for", "{", "se...
// subscribe to protocol events and proxy to client subscriptions
[ "subscribe", "to", "protocol", "events", "and", "proxy", "to", "client", "subscriptions" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/client.go#L453-L482
154,074
jbooth/flotilla
statemachine.go
pipeCopy
func (s *flotillaSnapshot) pipeCopy() { defer s.pipeW.Close() s.copyErr <- s.env.CopyFd(int(s.pipeW.Fd())) // buffered chan here }
go
func (s *flotillaSnapshot) pipeCopy() { defer s.pipeW.Close() s.copyErr <- s.env.CopyFd(int(s.pipeW.Fd())) // buffered chan here }
[ "func", "(", "s", "*", "flotillaSnapshot", ")", "pipeCopy", "(", ")", "{", "defer", "s", ".", "pipeW", ".", "Close", "(", ")", "\n", "s", ".", "copyErr", "<-", "s", ".", "env", ".", "CopyFd", "(", "int", "(", "s", ".", "pipeW", ".", "Fd", "(", ...
// starts streaming snapshot into one end of pipe
[ "starts", "streaming", "snapshot", "into", "one", "end", "of", "pipe" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/statemachine.go#L166-L169
154,075
jbooth/flotilla
statemachine.go
Persist
func (s *flotillaSnapshot) Persist(sink raft.SnapshotSink) error { defer sink.Close() defer s.pipeR.Close() _, e1 := io.Copy(sink, s.pipeR) e2 := <-s.copyErr if e2 != nil { sink.Cancel() return fmt.Errorf("Error copying snapshot to pipe: %s", e2) } if e1 != nil { sink.Cancel() } else { sink.Close() } return e1 }
go
func (s *flotillaSnapshot) Persist(sink raft.SnapshotSink) error { defer sink.Close() defer s.pipeR.Close() _, e1 := io.Copy(sink, s.pipeR) e2 := <-s.copyErr if e2 != nil { sink.Cancel() return fmt.Errorf("Error copying snapshot to pipe: %s", e2) } if e1 != nil { sink.Cancel() } else { sink.Close() } return e1 }
[ "func", "(", "s", "*", "flotillaSnapshot", ")", "Persist", "(", "sink", "raft", ".", "SnapshotSink", ")", "error", "{", "defer", "sink", ".", "Close", "(", ")", "\n", "defer", "s", ".", "pipeR", ".", "Close", "(", ")", "\n", "_", ",", "e1", ":=", ...
// Persist should dump all necessary state to the WriteCloser, // and invoke close when finished or call Cancel on error.
[ "Persist", "should", "dump", "all", "necessary", "state", "to", "the", "WriteCloser", "and", "invoke", "close", "when", "finished", "or", "call", "Cancel", "on", "error", "." ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/statemachine.go#L173-L189
154,076
jbooth/flotilla
statemachine.go
Restore
func (f *flotillaState) Restore(in io.ReadCloser) error { // stream to filePath.tmp tempData := f.tempPath + "/data.mdb" _ = os.Remove(tempData) tempFile, err := os.Create(tempData) if err != nil { return err } defer tempFile.Close() if _, err = io.Copy(tempFile, in); err != nil { return err } // unlink existing DB and move new one into place // can't atomically rename directories so have to lock for this f.l.Lock() defer f.l.Unlock() if err = syscall.Unlink(f.dataPath + "/data.mdb"); err != nil { return err } if err = syscall.Unlink(f.dataPath + "/lock.mdb"); err != nil { return err } if err = os.Rename(tempData, f.dataPath+"/data.mdb"); err != nil { return err } // mark existing env as closeable when all outstanding txns finish // posix holds onto our data until we release FD f.env.Close() // re-initialize env f.env, err = newenv(f.dataPath) return err }
go
func (f *flotillaState) Restore(in io.ReadCloser) error { // stream to filePath.tmp tempData := f.tempPath + "/data.mdb" _ = os.Remove(tempData) tempFile, err := os.Create(tempData) if err != nil { return err } defer tempFile.Close() if _, err = io.Copy(tempFile, in); err != nil { return err } // unlink existing DB and move new one into place // can't atomically rename directories so have to lock for this f.l.Lock() defer f.l.Unlock() if err = syscall.Unlink(f.dataPath + "/data.mdb"); err != nil { return err } if err = syscall.Unlink(f.dataPath + "/lock.mdb"); err != nil { return err } if err = os.Rename(tempData, f.dataPath+"/data.mdb"); err != nil { return err } // mark existing env as closeable when all outstanding txns finish // posix holds onto our data until we release FD f.env.Close() // re-initialize env f.env, err = newenv(f.dataPath) return err }
[ "func", "(", "f", "*", "flotillaState", ")", "Restore", "(", "in", "io", ".", "ReadCloser", ")", "error", "{", "// stream to filePath.tmp", "tempData", ":=", "f", ".", "tempPath", "+", "\"", "\"", "\n", "_", "=", "os", ".", "Remove", "(", "tempData", "...
// Restore is used to restore an FSM from a snapshot. It is not called // concurrently with any other command. The FSM must discard all previous // state. // Note, this command is called concurrently with open read txns, so we handle that
[ "Restore", "is", "used", "to", "restore", "an", "FSM", "from", "a", "snapshot", ".", "It", "is", "not", "called", "concurrently", "with", "any", "other", "command", ".", "The", "FSM", "must", "discard", "all", "previous", "state", ".", "Note", "this", "c...
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/statemachine.go#L200-L231
154,077
pdf/golifx
protocol/v2/device/group.go
getColor
func (g *Group) getColor(cached bool) (common.Color, error) { var err error g.RLock() lastColor := g.color g.RUnlock() lights := g.Lights() if len(lights) == 0 { return lastColor, nil } colors := make([]common.Color, len(lights)) for i, light := range lights { var c common.Color if cached { c = light.CachedColor() } else { c, err = light.GetColor() if err != nil { return lastColor, err } } colors[i] = c } g.Lock() g.color = common.AverageColor(colors...) g.Unlock() g.RLock() defer g.RUnlock() if !common.ColorEqual(lastColor, g.color) { g.Notify(common.EventUpdateColor{Color: g.color}) } return g.color, nil }
go
func (g *Group) getColor(cached bool) (common.Color, error) { var err error g.RLock() lastColor := g.color g.RUnlock() lights := g.Lights() if len(lights) == 0 { return lastColor, nil } colors := make([]common.Color, len(lights)) for i, light := range lights { var c common.Color if cached { c = light.CachedColor() } else { c, err = light.GetColor() if err != nil { return lastColor, err } } colors[i] = c } g.Lock() g.color = common.AverageColor(colors...) g.Unlock() g.RLock() defer g.RUnlock() if !common.ColorEqual(lastColor, g.color) { g.Notify(common.EventUpdateColor{Color: g.color}) } return g.color, nil }
[ "func", "(", "g", "*", "Group", ")", "getColor", "(", "cached", "bool", ")", "(", "common", ".", "Color", ",", "error", ")", "{", "var", "err", "error", "\n\n", "g", ".", "RLock", "(", ")", "\n", "lastColor", ":=", "g", ".", "color", "\n", "g", ...
// getColor returns the average color for lights in the group, or error if any // light returns an error.
[ "getColor", "returns", "the", "average", "color", "for", "lights", "in", "the", "group", "or", "error", "if", "any", "light", "returns", "an", "error", "." ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2/device/group.go#L208-L246
154,078
pdf/golifx
protocol/v2/device/group.go
Close
func (g *Group) Close() error { g.Lock() defer g.Unlock() select { case <-g.quitChan: common.Log.Warnf(`group already closed`) return common.ErrClosed default: close(g.quitChan) } return g.SubscriptionProvider.Close() }
go
func (g *Group) Close() error { g.Lock() defer g.Unlock() select { case <-g.quitChan: common.Log.Warnf(`group already closed`) return common.ErrClosed default: close(g.quitChan) } return g.SubscriptionProvider.Close() }
[ "func", "(", "g", "*", "Group", ")", "Close", "(", ")", "error", "{", "g", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "Unlock", "(", ")", "\n\n", "select", "{", "case", "<-", "g", ".", "quitChan", ":", "common", ".", "Log", ".", "Warnf", ...
// Close cleans up Group resources
[ "Close", "cleans", "up", "Group", "resources" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2/device/group.go#L375-L388
154,079
nuagenetworks/libvrsdk
api/entity/Event.go
ValidateEvent
func ValidateEvent(eventCategory EventCategory, event Event) bool { valid := false switch eventCategory { case EventCategoryDefined: valid = int(event) >= 0 && event < EventDefinedLast case EventCategoryUndefined: valid = int(event) >= 0 && event < EventUndefinedLast case EventCategoryStarted: valid = int(event) >= 0 && event < EventStartedLast case EventCategorySuspended: valid = int(event) >= 0 && event < EventSuspendedLast case EventCategoryResumed: valid = int(event) >= 0 && event < EventResumedLast case EventCategoryStopped: valid = int(event) >= 0 && event < EventStoppedLast case EventCategoryShutdown: valid = int(event) >= 0 && event < EventShutdownLast case EventCategoryPmsuspended: valid = int(event) >= 0 && event < EventPMSuspendedLast } return valid }
go
func ValidateEvent(eventCategory EventCategory, event Event) bool { valid := false switch eventCategory { case EventCategoryDefined: valid = int(event) >= 0 && event < EventDefinedLast case EventCategoryUndefined: valid = int(event) >= 0 && event < EventUndefinedLast case EventCategoryStarted: valid = int(event) >= 0 && event < EventStartedLast case EventCategorySuspended: valid = int(event) >= 0 && event < EventSuspendedLast case EventCategoryResumed: valid = int(event) >= 0 && event < EventResumedLast case EventCategoryStopped: valid = int(event) >= 0 && event < EventStoppedLast case EventCategoryShutdown: valid = int(event) >= 0 && event < EventShutdownLast case EventCategoryPmsuspended: valid = int(event) >= 0 && event < EventPMSuspendedLast } return valid }
[ "func", "ValidateEvent", "(", "eventCategory", "EventCategory", ",", "event", "Event", ")", "bool", "{", "valid", ":=", "false", "\n", "switch", "eventCategory", "{", "case", "EventCategoryDefined", ":", "valid", "=", "int", "(", "event", ")", ">=", "0", "&&...
// ValidateEvent validates the event type given it's category
[ "ValidateEvent", "validates", "the", "event", "type", "given", "it", "s", "category" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/entity/Event.go#L91-L113
154,080
gocontrib/auth
config.go
SetDefaults
func (c *Config) SetDefaults() *Config { if len(c.TokenKey) == 0 { c.TokenKey = defaultTokenKey } if len(c.TokenCookie) == 0 { c.TokenCookie = defaultTokenCookie } if c.SingingMethod == nil { c.SingingMethod = defaultSingingMethod } if c.SecretKey == nil { s := os.Getenv("JWT_SECRET") if len(s) > 0 { c.SecretKey = []byte(s) } else { c.SecretKey = defaultSecretKey } } if c.TokenExpiration.Nanoseconds() == 0 { c.TokenExpiration = parse.MustDuration("7d") } return c }
go
func (c *Config) SetDefaults() *Config { if len(c.TokenKey) == 0 { c.TokenKey = defaultTokenKey } if len(c.TokenCookie) == 0 { c.TokenCookie = defaultTokenCookie } if c.SingingMethod == nil { c.SingingMethod = defaultSingingMethod } if c.SecretKey == nil { s := os.Getenv("JWT_SECRET") if len(s) > 0 { c.SecretKey = []byte(s) } else { c.SecretKey = defaultSecretKey } } if c.TokenExpiration.Nanoseconds() == 0 { c.TokenExpiration = parse.MustDuration("7d") } return c }
[ "func", "(", "c", "*", "Config", ")", "SetDefaults", "(", ")", "*", "Config", "{", "if", "len", "(", "c", ".", "TokenKey", ")", "==", "0", "{", "c", ".", "TokenKey", "=", "defaultTokenKey", "\n", "}", "\n", "if", "len", "(", "c", ".", "TokenCooki...
// Initializes default handlers if they omitted.
[ "Initializes", "default", "handlers", "if", "they", "omitted", "." ]
71451935f159b63a80956018581919ef824fbd0e
https://github.com/gocontrib/auth/blob/71451935f159b63a80956018581919ef824fbd0e/config.go#L44-L66
154,081
nuagenetworks/libvrsdk
api/Entity.go
CreateEntity
func (vrsConnection *VRSConnection) CreateEntity(info EntityInfo) error { if len(info.UUID) == 0 { return fmt.Errorf("Uuid absent") } if len(info.Name) == 0 { return fmt.Errorf("Name absent") } // The Nuage_VM_Table has separate columns for enterprise and user. // Hence make a copy of the metadata and delete these keys. var metadata map[string]string if info.Metadata != nil { metadata = make(map[string]string) for k, v := range info.Metadata { metadata[string(k)] = v } } //delete(metadata, string(entity.MetadataKeyEnterprise)) delete(metadata, string(entity.MetadataKeyUser)) nuageVMTableRow := ovsdb.NuageVMTableRow{ Type: int(info.Type), VMName: info.Name, VMUuid: info.UUID, Domain: info.Domain, NuageUser: info.Metadata[entity.MetadataKeyUser], NuageEnterprise: info.Metadata[entity.MetadataKeyEnterprise], Metadata: metadata, Ports: info.Ports, Event: int(entity.EventCategoryDefined), EventType: int(entity.EventDefinedAdded), State: int(entity.Running), Reason: int(entity.RunningUnknown), } if info.Events != nil { nuageVMTableRow.Event = int(info.Events.EntityEventCategory) nuageVMTableRow.EventType = int(info.Events.EntityEventType) nuageVMTableRow.State = int(info.Events.EntityState) nuageVMTableRow.Reason = int(info.Events.EntityReason) } if err := vrsConnection.vmTable.InsertRow(vrsConnection.ovsdbClient, &nuageVMTableRow); err != nil { return fmt.Errorf("Problem adding entity info to VRS %v", err) } return nil }
go
func (vrsConnection *VRSConnection) CreateEntity(info EntityInfo) error { if len(info.UUID) == 0 { return fmt.Errorf("Uuid absent") } if len(info.Name) == 0 { return fmt.Errorf("Name absent") } // The Nuage_VM_Table has separate columns for enterprise and user. // Hence make a copy of the metadata and delete these keys. var metadata map[string]string if info.Metadata != nil { metadata = make(map[string]string) for k, v := range info.Metadata { metadata[string(k)] = v } } //delete(metadata, string(entity.MetadataKeyEnterprise)) delete(metadata, string(entity.MetadataKeyUser)) nuageVMTableRow := ovsdb.NuageVMTableRow{ Type: int(info.Type), VMName: info.Name, VMUuid: info.UUID, Domain: info.Domain, NuageUser: info.Metadata[entity.MetadataKeyUser], NuageEnterprise: info.Metadata[entity.MetadataKeyEnterprise], Metadata: metadata, Ports: info.Ports, Event: int(entity.EventCategoryDefined), EventType: int(entity.EventDefinedAdded), State: int(entity.Running), Reason: int(entity.RunningUnknown), } if info.Events != nil { nuageVMTableRow.Event = int(info.Events.EntityEventCategory) nuageVMTableRow.EventType = int(info.Events.EntityEventType) nuageVMTableRow.State = int(info.Events.EntityState) nuageVMTableRow.Reason = int(info.Events.EntityReason) } if err := vrsConnection.vmTable.InsertRow(vrsConnection.ovsdbClient, &nuageVMTableRow); err != nil { return fmt.Errorf("Problem adding entity info to VRS %v", err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "CreateEntity", "(", "info", "EntityInfo", ")", "error", "{", "if", "len", "(", "info", ".", "UUID", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n"...
// CreateEntity adds an entity to the Nuage VRS
[ "CreateEntity", "adds", "an", "entity", "to", "the", "Nuage", "VRS" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L24-L73
154,082
nuagenetworks/libvrsdk
api/Entity.go
AddEntityPort
func (vrsConnection *VRSConnection) AddEntityPort(uuid string, portName string) error { var ports []string var err error if ports, err = vrsConnection.GetEntityPorts(uuid); err != nil { return fmt.Errorf("Unable to get existing ports %s %s", uuid, err) } ports = append(ports, portName) row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnPorts], err = libovsdb.NewOvsSet(ports) if err != nil { return err } condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err = vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to add port %s %s %s", uuid, portName, err) } return nil }
go
func (vrsConnection *VRSConnection) AddEntityPort(uuid string, portName string) error { var ports []string var err error if ports, err = vrsConnection.GetEntityPorts(uuid); err != nil { return fmt.Errorf("Unable to get existing ports %s %s", uuid, err) } ports = append(ports, portName) row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnPorts], err = libovsdb.NewOvsSet(ports) if err != nil { return err } condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err = vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to add port %s %s %s", uuid, portName, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "AddEntityPort", "(", "uuid", "string", ",", "portName", "string", ")", "error", "{", "var", "ports", "[", "]", "string", "\n", "var", "err", "error", "\n", "if", "ports", ",", "err", "=", "vrsConn...
// AddEntityPort adds a port to the Entity
[ "AddEntityPort", "adds", "a", "port", "to", "the", "Entity" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L98-L119
154,083
nuagenetworks/libvrsdk
api/Entity.go
RemoveEntityPort
func (vrsConnection *VRSConnection) RemoveEntityPort(uuid string, portName string) error { var ports []string var err error if ports, err = vrsConnection.GetEntityPorts(uuid); err != nil { return fmt.Errorf("Unable to get existing ports %s %s", uuid, err) } portIndex := -1 for i, port := range ports { if strings.Compare(port, portName) == 0 { portIndex = i break } } if portIndex == -1 { return fmt.Errorf("%s port %s not found", uuid, portName) } ports = append(ports[:portIndex], ports[(portIndex+1):]...) row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnPorts], err = libovsdb.NewOvsSet(ports) if err != nil { return err } condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err = vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to remove port %s %s %s", uuid, portName, err) } return nil }
go
func (vrsConnection *VRSConnection) RemoveEntityPort(uuid string, portName string) error { var ports []string var err error if ports, err = vrsConnection.GetEntityPorts(uuid); err != nil { return fmt.Errorf("Unable to get existing ports %s %s", uuid, err) } portIndex := -1 for i, port := range ports { if strings.Compare(port, portName) == 0 { portIndex = i break } } if portIndex == -1 { return fmt.Errorf("%s port %s not found", uuid, portName) } ports = append(ports[:portIndex], ports[(portIndex+1):]...) row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnPorts], err = libovsdb.NewOvsSet(ports) if err != nil { return err } condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err = vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to remove port %s %s %s", uuid, portName, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "RemoveEntityPort", "(", "uuid", "string", ",", "portName", "string", ")", "error", "{", "var", "ports", "[", "]", "string", "\n", "var", "err", "error", "\n", "if", "ports", ",", "err", "=", "vrsC...
// RemoveEntityPort removes port from the Entity
[ "RemoveEntityPort", "removes", "port", "from", "the", "Entity" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L122-L156
154,084
nuagenetworks/libvrsdk
api/Entity.go
GetEntityPorts
func (vrsConnection *VRSConnection) GetEntityPorts(uuid string) ([]string, error) { readRowArgs := ovsdb.ReadRowArgs{ Columns: []string{ovsdb.NuageVMTableColumnPorts}, Condition: []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid}, } row, err := vrsConnection.vmTable.ReadRow(vrsConnection.ovsdbClient, readRowArgs) if err != nil { return []string{}, fmt.Errorf("Unable to get port information for the VM") } return ovsdb.UnMarshallOVSStringSet(row[ovsdb.NuageVMTableColumnPorts]) }
go
func (vrsConnection *VRSConnection) GetEntityPorts(uuid string) ([]string, error) { readRowArgs := ovsdb.ReadRowArgs{ Columns: []string{ovsdb.NuageVMTableColumnPorts}, Condition: []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid}, } row, err := vrsConnection.vmTable.ReadRow(vrsConnection.ovsdbClient, readRowArgs) if err != nil { return []string{}, fmt.Errorf("Unable to get port information for the VM") } return ovsdb.UnMarshallOVSStringSet(row[ovsdb.NuageVMTableColumnPorts]) }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "GetEntityPorts", "(", "uuid", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "readRowArgs", ":=", "ovsdb", ".", "ReadRowArgs", "{", "Columns", ":", "[", "]", "string", "{", "ovsdb...
// GetEntityPorts retrives the list of all of the attached ports
[ "GetEntityPorts", "retrives", "the", "list", "of", "all", "of", "the", "attached", "ports" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L159-L172
154,085
nuagenetworks/libvrsdk
api/Entity.go
SetEntityState
func (vrsConnection *VRSConnection) SetEntityState(uuid string, state entity.State, subState entity.SubState) error { row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnState] = int(state) row[ovsdb.NuageVMTableColumnReason] = int(subState) condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err := vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the state %s %v %v %v", uuid, state, subState, err) } return nil }
go
func (vrsConnection *VRSConnection) SetEntityState(uuid string, state entity.State, subState entity.SubState) error { row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnState] = int(state) row[ovsdb.NuageVMTableColumnReason] = int(subState) condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err := vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the state %s %v %v %v", uuid, state, subState, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "SetEntityState", "(", "uuid", "string", ",", "state", "entity", ".", "State", ",", "subState", "entity", ".", "SubState", ")", "error", "{", "row", ":=", "make", "(", "map", "[", "string", "]", "i...
// SetEntityState sets the entity state
[ "SetEntityState", "sets", "the", "entity", "state" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L175-L188
154,086
nuagenetworks/libvrsdk
api/Entity.go
PostEntityEvent
func (vrsConnection *VRSConnection) PostEntityEvent(uuid string, evtCategory entity.EventCategory, evt entity.Event) error { if !entity.ValidateEvent(evtCategory, evt) { return fmt.Errorf("Invalid event %v for event category %v", evt, evtCategory) } row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnEventCategory] = int(evtCategory) row[ovsdb.NuageVMTableColumnEventType] = int(evt) condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err := vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to send the state %s %v %v %v", uuid, evtCategory, evt, err) } return nil }
go
func (vrsConnection *VRSConnection) PostEntityEvent(uuid string, evtCategory entity.EventCategory, evt entity.Event) error { if !entity.ValidateEvent(evtCategory, evt) { return fmt.Errorf("Invalid event %v for event category %v", evt, evtCategory) } row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnEventCategory] = int(evtCategory) row[ovsdb.NuageVMTableColumnEventType] = int(evt) condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err := vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to send the state %s %v %v %v", uuid, evtCategory, evt, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "PostEntityEvent", "(", "uuid", "string", ",", "evtCategory", "entity", ".", "EventCategory", ",", "evt", "entity", ".", "Event", ")", "error", "{", "if", "!", "entity", ".", "ValidateEvent", "(", "evt...
// PostEntityEvent posts a new event to entity
[ "PostEntityEvent", "posts", "a", "new", "event", "to", "entity" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L191-L208
154,087
nuagenetworks/libvrsdk
api/Entity.go
SetEntityMetadata
func (vrsConnection *VRSConnection) SetEntityMetadata(uuid string, metadata map[entity.MetadataKey]string) error { row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnMetadata] = metadata condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err := vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the metadata %s %v %v", uuid, metadata, err) } return nil }
go
func (vrsConnection *VRSConnection) SetEntityMetadata(uuid string, metadata map[entity.MetadataKey]string) error { row := make(map[string]interface{}) row[ovsdb.NuageVMTableColumnMetadata] = metadata condition := []string{ovsdb.NuageVMTableColumnVMUUID, "==", uuid} if err := vrsConnection.vmTable.UpdateRow(vrsConnection.ovsdbClient, row, condition); err != nil { return fmt.Errorf("Unable to update the metadata %s %v %v", uuid, metadata, err) } return nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "SetEntityMetadata", "(", "uuid", "string", ",", "metadata", "map", "[", "entity", ".", "MetadataKey", "]", "string", ")", "error", "{", "row", ":=", "make", "(", "map", "[", "string", "]", "interfac...
// SetEntityMetadata applies Nuage specific metadata to the Entity
[ "SetEntityMetadata", "applies", "Nuage", "specific", "metadata", "to", "the", "Entity" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L211-L222
154,088
nuagenetworks/libvrsdk
api/Entity.go
GetAllEntities
func (vrsConnection *VRSConnection) GetAllEntities() ([]string, error) { readRowArgs := ovsdb.ReadRowArgs{ Condition: []string{ovsdb.NuageVMTableColumnVMUUID, "!=", "xxxx"}, Columns: []string{ovsdb.NuageVMTableColumnVMUUID}, } var uuidRows []map[string]interface{} var err error if uuidRows, err = vrsConnection.vmTable.ReadRows(vrsConnection.ovsdbClient, readRowArgs); err != nil { return []string{}, fmt.Errorf("Unable to obtain the entity uuids %v", err) } var uuids []string for _, uuid := range uuidRows { uuids = append(uuids, uuid[ovsdb.NuageVMTableColumnVMUUID].(string)) } return uuids, nil }
go
func (vrsConnection *VRSConnection) GetAllEntities() ([]string, error) { readRowArgs := ovsdb.ReadRowArgs{ Condition: []string{ovsdb.NuageVMTableColumnVMUUID, "!=", "xxxx"}, Columns: []string{ovsdb.NuageVMTableColumnVMUUID}, } var uuidRows []map[string]interface{} var err error if uuidRows, err = vrsConnection.vmTable.ReadRows(vrsConnection.ovsdbClient, readRowArgs); err != nil { return []string{}, fmt.Errorf("Unable to obtain the entity uuids %v", err) } var uuids []string for _, uuid := range uuidRows { uuids = append(uuids, uuid[ovsdb.NuageVMTableColumnVMUUID].(string)) } return uuids, nil }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "GetAllEntities", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "readRowArgs", ":=", "ovsdb", ".", "ReadRowArgs", "{", "Condition", ":", "[", "]", "string", "{", "ovsdb", ".", "NuageVM...
// GetAllEntities retrives a slice of all the UUIDs of the entities associated with the VRS
[ "GetAllEntities", "retrives", "a", "slice", "of", "all", "the", "UUIDs", "of", "the", "entities", "associated", "with", "the", "VRS" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L225-L243
154,089
nuagenetworks/libvrsdk
api/Entity.go
CheckEntityExists
func (vrsConnection *VRSConnection) CheckEntityExists(id string) (bool, error) { readRowArgs := ovsdb.ReadRowArgs{ Condition: []string{ovsdb.NuageVMTableColumnVMUUID, "==", id}, Columns: []string{ovsdb.NuageVMTableColumnVMUUID}, } var idRows []map[string]interface{} var err error if idRows, err = vrsConnection.vmTable.ReadRows(vrsConnection.ovsdbClient, readRowArgs); err != nil { return false, fmt.Errorf("OVSDB read error %v", err) } var ids []string for _, row := range idRows { ids = append(ids, row[ovsdb.NuageVMTableColumnVMUUID].(string)) } if len(ids) == 1 && id == ids[0] { return true, err } return false, err }
go
func (vrsConnection *VRSConnection) CheckEntityExists(id string) (bool, error) { readRowArgs := ovsdb.ReadRowArgs{ Condition: []string{ovsdb.NuageVMTableColumnVMUUID, "==", id}, Columns: []string{ovsdb.NuageVMTableColumnVMUUID}, } var idRows []map[string]interface{} var err error if idRows, err = vrsConnection.vmTable.ReadRows(vrsConnection.ovsdbClient, readRowArgs); err != nil { return false, fmt.Errorf("OVSDB read error %v", err) } var ids []string for _, row := range idRows { ids = append(ids, row[ovsdb.NuageVMTableColumnVMUUID].(string)) } if len(ids) == 1 && id == ids[0] { return true, err } return false, err }
[ "func", "(", "vrsConnection", "*", "VRSConnection", ")", "CheckEntityExists", "(", "id", "string", ")", "(", "bool", ",", "error", ")", "{", "readRowArgs", ":=", "ovsdb", ".", "ReadRowArgs", "{", "Condition", ":", "[", "]", "string", "{", "ovsdb", ".", "...
// CheckEntityExists verifies if a specified entity exists in VRS
[ "CheckEntityExists", "verifies", "if", "a", "specified", "entity", "exists", "in", "VRS" ]
f17bbf11845f32f685251fc7e8689bddea28fe81
https://github.com/nuagenetworks/libvrsdk/blob/f17bbf11845f32f685251fc7e8689bddea28fe81/api/Entity.go#L246-L268
154,090
jbooth/flotilla
transport.go
newConnToLeader
func newConnToLeader(conn net.Conn, advertiseAddr string, lg *log.Logger) (*connToLeader, error) { // send join command h := &codec.MsgpackHandle{} ret := &connToLeader{ c: conn, e: codec.NewEncoder(conn, h), d: codec.NewDecoder(conn, h), l: new(sync.Mutex), lg: lg, pending: make(chan *commandCallback, 64), } join := &joinReq{ PeerAddr: advertiseAddr, } err := ret.e.Encode(join) if err != nil { ret.c.Close() return nil, err } joinResp := &joinResp{} err = ret.d.Decode(joinResp) if err != nil { ret.lg.Printf("Error connecting to leader at %s : %s", conn.RemoteAddr().String(), err) ret.c.Close() return nil, err } go ret.readResponses() return ret, nil }
go
func newConnToLeader(conn net.Conn, advertiseAddr string, lg *log.Logger) (*connToLeader, error) { // send join command h := &codec.MsgpackHandle{} ret := &connToLeader{ c: conn, e: codec.NewEncoder(conn, h), d: codec.NewDecoder(conn, h), l: new(sync.Mutex), lg: lg, pending: make(chan *commandCallback, 64), } join := &joinReq{ PeerAddr: advertiseAddr, } err := ret.e.Encode(join) if err != nil { ret.c.Close() return nil, err } joinResp := &joinResp{} err = ret.d.Decode(joinResp) if err != nil { ret.lg.Printf("Error connecting to leader at %s : %s", conn.RemoteAddr().String(), err) ret.c.Close() return nil, err } go ret.readResponses() return ret, nil }
[ "func", "newConnToLeader", "(", "conn", "net", ".", "Conn", ",", "advertiseAddr", "string", ",", "lg", "*", "log", ".", "Logger", ")", "(", "*", "connToLeader", ",", "error", ")", "{", "// send join command", "h", ":=", "&", "codec", ".", "MsgpackHandle", ...
// joins the raft leader and sets up infrastructure for // processing commands // can return ErrNotLeader
[ "joins", "the", "raft", "leader", "and", "sets", "up", "infrastructure", "for", "processing", "commands", "can", "return", "ErrNotLeader" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/transport.go#L26-L54
154,091
jbooth/flotilla
transport.go
forwardCommand
func (c *connToLeader) forwardCommand(cb *commandCallback, cmdName string, args [][]byte) error { c.l.Lock() defer c.l.Unlock() // marshal log object lg := logForCommand(cb.originAddr, cb.reqNo, cmdName, args) // put response chan in pending // send err := c.e.Encode(lg) if err != nil { cb.cancel() cb.result <- Result{nil, err} return err } else { // so our responseReader will forward appropriately c.pending <- cb } return nil }
go
func (c *connToLeader) forwardCommand(cb *commandCallback, cmdName string, args [][]byte) error { c.l.Lock() defer c.l.Unlock() // marshal log object lg := logForCommand(cb.originAddr, cb.reqNo, cmdName, args) // put response chan in pending // send err := c.e.Encode(lg) if err != nil { cb.cancel() cb.result <- Result{nil, err} return err } else { // so our responseReader will forward appropriately c.pending <- cb } return nil }
[ "func", "(", "c", "*", "connToLeader", ")", "forwardCommand", "(", "cb", "*", "commandCallback", ",", "cmdName", "string", ",", "args", "[", "]", "[", "]", "byte", ")", "error", "{", "c", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "c", ".", ...
// sends the command for remote execution. // returns error if we couldn't communicate with leader
[ "sends", "the", "command", "for", "remote", "execution", ".", "returns", "error", "if", "we", "couldn", "t", "communicate", "with", "leader" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/transport.go#L58-L75
154,092
jbooth/flotilla
transport.go
sendResponses
func sendResponses(futures chan raft.ApplyFuture, lg *log.Logger, e *codec.Encoder, conn net.Conn) { resp := &commandResp{} for f := range futures { err := f.Error() resp.Err = err err = e.Encode(resp) if err != nil { lg.Printf("Error writing response %s to host %s : %s", resp, conn.RemoteAddr().String(), err) conn.Close() return } } }
go
func sendResponses(futures chan raft.ApplyFuture, lg *log.Logger, e *codec.Encoder, conn net.Conn) { resp := &commandResp{} for f := range futures { err := f.Error() resp.Err = err err = e.Encode(resp) if err != nil { lg.Printf("Error writing response %s to host %s : %s", resp, conn.RemoteAddr().String(), err) conn.Close() return } } }
[ "func", "sendResponses", "(", "futures", "chan", "raft", ".", "ApplyFuture", ",", "lg", "*", "log", ".", "Logger", ",", "e", "*", "codec", ".", "Encoder", ",", "conn", "net", ".", "Conn", ")", "{", "resp", ":=", "&", "commandResp", "{", "}", "\n", ...
// runs alongside serveFollower to send actual responses
[ "runs", "alongside", "serveFollower", "to", "send", "actual", "responses" ]
da1c31d088be8a18adaa24f10abda6d2e9e30bae
https://github.com/jbooth/flotilla/blob/da1c31d088be8a18adaa24f10abda6d2e9e30bae/transport.go#L213-L225
154,093
pdf/golifx
protocol/v2.go
SetTimeout
func (p *V2) SetTimeout(timeout *time.Duration) { p.Lock() p.timeout = timeout p.Unlock() }
go
func (p *V2) SetTimeout(timeout *time.Duration) { p.Lock() p.timeout = timeout p.Unlock() }
[ "func", "(", "p", "*", "V2", ")", "SetTimeout", "(", "timeout", "*", "time", ".", "Duration", ")", "{", "p", ".", "Lock", "(", ")", "\n", "p", ".", "timeout", "=", "timeout", "\n", "p", ".", "Unlock", "(", ")", "\n", "}" ]
// SetTimeout attaches a timeout to the protocol
[ "SetTimeout", "attaches", "a", "timeout", "to", "the", "protocol" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L84-L88
154,094
pdf/golifx
protocol/v2.go
SetRetryInterval
func (p *V2) SetRetryInterval(retryInterval *time.Duration) { p.Lock() p.retryInterval = retryInterval p.Unlock() }
go
func (p *V2) SetRetryInterval(retryInterval *time.Duration) { p.Lock() p.retryInterval = retryInterval p.Unlock() }
[ "func", "(", "p", "*", "V2", ")", "SetRetryInterval", "(", "retryInterval", "*", "time", ".", "Duration", ")", "{", "p", ".", "Lock", "(", ")", "\n", "p", ".", "retryInterval", "=", "retryInterval", "\n", "p", ".", "Unlock", "(", ")", "\n", "}" ]
// SetRetryInterval attaches a retry interval to the protocol
[ "SetRetryInterval", "attaches", "a", "retry", "interval", "to", "the", "protocol" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L91-L95
154,095
pdf/golifx
protocol/v2.go
Discover
func (p *V2) Discover() error { if err := p.init(); err != nil { return err } if p.lastDiscovery.After(time.Time{}) { var extinct []device.GenericDevice p.RLock() for _, dev := range p.devices { // If the device has not been seen in twice the time since the last // discovery, mark it as extinct if dev.Seen().Before(time.Now().Add(time.Since(p.lastDiscovery) * -2)) { extinct = append(extinct, dev) } } p.RUnlock() // Remove extinct devices for _, dev := range extinct { p.removeDevice(dev.ID()) locationID := dev.CachedLocation() location, err := p.getLocation(locationID) if err == nil { if err = location.RemoveDevice(dev); err != nil { common.Log.Warnf("Failed removing extinct device '%d' from location (%s): %v", dev.ID(), locationID, err) } if len(location.Devices()) == 0 { p.removeLocation(location.ID()) p.Notify(common.EventExpiredLocation{Location: location}) } } groupID := dev.CachedGroup() group, err := p.getGroup(groupID) if err == nil { if err = group.RemoveDevice(dev); err != nil { common.Log.Warnf("Failed removing extinct device '%d' from group (%s): %v", dev.ID(), groupID, err) } if len(group.Devices()) == 0 { p.removeGroup(group.ID()) p.Notify(common.EventExpiredGroup{Group: group}) } } p.Notify(common.EventExpiredDevice{Device: dev}) } } if err := p.broadcast.Discover(); err != nil { return err } p.Lock() p.lastDiscovery = time.Now() p.Unlock() return nil }
go
func (p *V2) Discover() error { if err := p.init(); err != nil { return err } if p.lastDiscovery.After(time.Time{}) { var extinct []device.GenericDevice p.RLock() for _, dev := range p.devices { // If the device has not been seen in twice the time since the last // discovery, mark it as extinct if dev.Seen().Before(time.Now().Add(time.Since(p.lastDiscovery) * -2)) { extinct = append(extinct, dev) } } p.RUnlock() // Remove extinct devices for _, dev := range extinct { p.removeDevice(dev.ID()) locationID := dev.CachedLocation() location, err := p.getLocation(locationID) if err == nil { if err = location.RemoveDevice(dev); err != nil { common.Log.Warnf("Failed removing extinct device '%d' from location (%s): %v", dev.ID(), locationID, err) } if len(location.Devices()) == 0 { p.removeLocation(location.ID()) p.Notify(common.EventExpiredLocation{Location: location}) } } groupID := dev.CachedGroup() group, err := p.getGroup(groupID) if err == nil { if err = group.RemoveDevice(dev); err != nil { common.Log.Warnf("Failed removing extinct device '%d' from group (%s): %v", dev.ID(), groupID, err) } if len(group.Devices()) == 0 { p.removeGroup(group.ID()) p.Notify(common.EventExpiredGroup{Group: group}) } } p.Notify(common.EventExpiredDevice{Device: dev}) } } if err := p.broadcast.Discover(); err != nil { return err } p.Lock() p.lastDiscovery = time.Now() p.Unlock() return nil }
[ "func", "(", "p", "*", "V2", ")", "Discover", "(", ")", "error", "{", "if", "err", ":=", "p", ".", "init", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "p", ".", "lastDiscovery", ".", "After", "(", "time", "...
// Discover initiates device discovery, this may be a noop in some future // protocol versions. This is called immediately when the client connects to // the protocol
[ "Discover", "initiates", "device", "discovery", "this", "may", "be", "a", "noop", "in", "some", "future", "protocol", "versions", ".", "This", "is", "called", "immediately", "when", "the", "client", "connects", "to", "the", "protocol" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L100-L154
154,096
pdf/golifx
protocol/v2.go
SetPower
func (p *V2) SetPower(state bool) error { p.RLock() defer p.RUnlock() for _, dev := range p.devices { if err := dev.SetPower(state); err != nil { common.Log.Warnf("Failed setting power on %d: %+v", dev.ID(), err) continue } } return nil }
go
func (p *V2) SetPower(state bool) error { p.RLock() defer p.RUnlock() for _, dev := range p.devices { if err := dev.SetPower(state); err != nil { common.Log.Warnf("Failed setting power on %d: %+v", dev.ID(), err) continue } } return nil }
[ "func", "(", "p", "*", "V2", ")", "SetPower", "(", "state", "bool", ")", "error", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "dev", ":=", "range", "p", ".", "devices", "{", "if", "er...
// SetPower sets the power state globally, on all devices
[ "SetPower", "sets", "the", "power", "state", "globally", "on", "all", "devices" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L157-L167
154,097
pdf/golifx
protocol/v2.go
SetPowerDuration
func (p *V2) SetPowerDuration(state bool, duration time.Duration) error { p.RLock() defer p.RUnlock() for _, dev := range p.devices { l, ok := dev.(*device.Light) if !ok { continue } if err := l.SetPowerDuration(state, duration); err != nil { common.Log.Warnf("Failed setting power on %d: %+v", l.ID(), err) continue } } return nil }
go
func (p *V2) SetPowerDuration(state bool, duration time.Duration) error { p.RLock() defer p.RUnlock() for _, dev := range p.devices { l, ok := dev.(*device.Light) if !ok { continue } if err := l.SetPowerDuration(state, duration); err != nil { common.Log.Warnf("Failed setting power on %d: %+v", l.ID(), err) continue } } return nil }
[ "func", "(", "p", "*", "V2", ")", "SetPowerDuration", "(", "state", "bool", ",", "duration", "time", ".", "Duration", ")", "error", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "dev", ":="...
// SetPowerDuration sets the power state globally, on all devices, transitioning // over the specified duration
[ "SetPowerDuration", "sets", "the", "power", "state", "globally", "on", "all", "devices", "transitioning", "over", "the", "specified", "duration" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L171-L185
154,098
pdf/golifx
protocol/v2.go
SetColor
func (p *V2) SetColor(color common.Color, duration time.Duration) error { p.RLock() defer p.RUnlock() for _, dev := range p.devices { l, ok := dev.(*device.Light) if !ok { continue } if err := l.SetColor(color, duration); err != nil { common.Log.Warnf("Failed setting color on %d: %+v", l.ID(), err) continue } } return nil }
go
func (p *V2) SetColor(color common.Color, duration time.Duration) error { p.RLock() defer p.RUnlock() for _, dev := range p.devices { l, ok := dev.(*device.Light) if !ok { continue } if err := l.SetColor(color, duration); err != nil { common.Log.Warnf("Failed setting color on %d: %+v", l.ID(), err) continue } } return nil }
[ "func", "(", "p", "*", "V2", ")", "SetColor", "(", "color", "common", ".", "Color", ",", "duration", "time", ".", "Duration", ")", "error", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n", "for", "_", ",", "...
// SetColor changes the color globally, on all lights, transitioning over the // specified duration
[ "SetColor", "changes", "the", "color", "globally", "on", "all", "lights", "transitioning", "over", "the", "specified", "duration" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L189-L203
154,099
pdf/golifx
protocol/v2.go
Close
func (p *V2) Close() error { p.Lock() defer p.Unlock() for _, location := range p.locations { if err := location.Close(); err != nil { return err } } for _, group := range p.groups { if err := group.Close(); err != nil { return err } } for _, dev := range p.devices { if err := dev.Close(); err != nil { return err } } if err := p.broadcast.Close(); err != nil { return err } select { case <-p.quitChan: common.Log.Warnf(`protocol already closed`) return common.ErrClosed default: close(p.quitChan) p.wg.Wait() close(p.deviceQueue) } return p.SubscriptionProvider.Close() }
go
func (p *V2) Close() error { p.Lock() defer p.Unlock() for _, location := range p.locations { if err := location.Close(); err != nil { return err } } for _, group := range p.groups { if err := group.Close(); err != nil { return err } } for _, dev := range p.devices { if err := dev.Close(); err != nil { return err } } if err := p.broadcast.Close(); err != nil { return err } select { case <-p.quitChan: common.Log.Warnf(`protocol already closed`) return common.ErrClosed default: close(p.quitChan) p.wg.Wait() close(p.deviceQueue) } return p.SubscriptionProvider.Close() }
[ "func", "(", "p", "*", "V2", ")", "Close", "(", ")", "error", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "location", ":=", "range", "p", ".", "locations", "{", "if", "err", ":=", "lo...
// Close closes the protocol driver, no further communication with the protocol // is possible
[ "Close", "closes", "the", "protocol", "driver", "no", "further", "communication", "with", "the", "protocol", "is", "possible" ]
4a3b4e6351e362faf6af35ecc789ec69978ed905
https://github.com/pdf/golifx/blob/4a3b4e6351e362faf6af35ecc789ec69978ed905/protocol/v2.go#L207-L244