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
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
15,500
exoscale/egoscale
virtual_machines.go
NicByID
func (vm VirtualMachine) NicByID(nicID UUID) *Nic { for _, nic := range vm.Nic { if nic.ID.Equal(nicID) { n := nic n.VirtualMachineID = vm.ID return &n } } return nil }
go
func (vm VirtualMachine) NicByID(nicID UUID) *Nic { for _, nic := range vm.Nic { if nic.ID.Equal(nicID) { n := nic n.VirtualMachineID = vm.ID return &n } } return nil }
[ "func", "(", "vm", "VirtualMachine", ")", "NicByID", "(", "nicID", "UUID", ")", "*", "Nic", "{", "for", "_", ",", "nic", ":=", "range", "vm", ".", "Nic", "{", "if", "nic", ".", "ID", ".", "Equal", "(", "nicID", ")", "{", "n", ":=", "nic", "\n", "n", ".", "VirtualMachineID", "=", "vm", ".", "ID", "\n", "return", "&", "n", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// NicByID returns the corresponding interface base on its ID
[ "NicByID", "returns", "the", "corresponding", "interface", "base", "on", "its", "ID" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/virtual_machines.go#L196-L206
15,501
exoscale/egoscale
accounts.go
ListRequest
func (a Account) ListRequest() (ListCommand, error) { return &ListAccounts{ ID: a.ID, State: a.State, }, nil }
go
func (a Account) ListRequest() (ListCommand, error) { return &ListAccounts{ ID: a.ID, State: a.State, }, nil }
[ "func", "(", "a", "Account", ")", "ListRequest", "(", ")", "(", "ListCommand", ",", "error", ")", "{", "return", "&", "ListAccounts", "{", "ID", ":", "a", ".", "ID", ",", "State", ":", "a", ".", "State", ",", "}", ",", "nil", "\n", "}" ]
// ListRequest builds the ListAccountsGroups request
[ "ListRequest", "builds", "the", "ListAccountsGroups", "request" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/accounts.go#L55-L60
15,502
exoscale/egoscale
nics.go
ListRequest
func (nic Nic) ListRequest() (ListCommand, error) { req := &ListNics{ VirtualMachineID: nic.VirtualMachineID, NicID: nic.ID, NetworkID: nic.NetworkID, } return req, nil }
go
func (nic Nic) ListRequest() (ListCommand, error) { req := &ListNics{ VirtualMachineID: nic.VirtualMachineID, NicID: nic.ID, NetworkID: nic.NetworkID, } return req, nil }
[ "func", "(", "nic", "Nic", ")", "ListRequest", "(", ")", "(", "ListCommand", ",", "error", ")", "{", "req", ":=", "&", "ListNics", "{", "VirtualMachineID", ":", "nic", ".", "VirtualMachineID", ",", "NicID", ":", "nic", ".", "ID", ",", "NetworkID", ":", "nic", ".", "NetworkID", ",", "}", "\n\n", "return", "req", ",", "nil", "\n", "}" ]
// ListRequest build a ListNics request from the given Nic
[ "ListRequest", "build", "a", "ListNics", "request", "from", "the", "given", "Nic" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/nics.go#L33-L41
15,503
exoscale/egoscale
isos.go
ListRequest
func (iso ISO) ListRequest() (ListCommand, error) { req := &ListISOs{ ID: iso.ID, Name: iso.Name, ZoneID: iso.ZoneID, } if iso.Bootable { *req.Bootable = true } if iso.IsFeatured { req.IsoFilter = "featured" } if iso.IsPublic { *req.IsPublic = true } if iso.IsReady { *req.IsReady = true } for i := range iso.Tags { req.Tags = append(req.Tags, iso.Tags[i]) } return req, nil }
go
func (iso ISO) ListRequest() (ListCommand, error) { req := &ListISOs{ ID: iso.ID, Name: iso.Name, ZoneID: iso.ZoneID, } if iso.Bootable { *req.Bootable = true } if iso.IsFeatured { req.IsoFilter = "featured" } if iso.IsPublic { *req.IsPublic = true } if iso.IsReady { *req.IsReady = true } for i := range iso.Tags { req.Tags = append(req.Tags, iso.Tags[i]) } return req, nil }
[ "func", "(", "iso", "ISO", ")", "ListRequest", "(", ")", "(", "ListCommand", ",", "error", ")", "{", "req", ":=", "&", "ListISOs", "{", "ID", ":", "iso", ".", "ID", ",", "Name", ":", "iso", ".", "Name", ",", "ZoneID", ":", "iso", ".", "ZoneID", ",", "}", "\n", "if", "iso", ".", "Bootable", "{", "*", "req", ".", "Bootable", "=", "true", "\n", "}", "\n", "if", "iso", ".", "IsFeatured", "{", "req", ".", "IsoFilter", "=", "\"", "\"", "\n", "}", "\n", "if", "iso", ".", "IsPublic", "{", "*", "req", ".", "IsPublic", "=", "true", "\n", "}", "\n", "if", "iso", ".", "IsReady", "{", "*", "req", ".", "IsReady", "=", "true", "\n", "}", "\n\n", "for", "i", ":=", "range", "iso", ".", "Tags", "{", "req", ".", "Tags", "=", "append", "(", "req", ".", "Tags", ",", "iso", ".", "Tags", "[", "i", "]", ")", "\n", "}", "\n\n", "return", "req", ",", "nil", "\n", "}" ]
// ListRequest produces the ListIsos command.
[ "ListRequest", "produces", "the", "ListIsos", "command", "." ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/isos.go#L12-L36
15,504
exoscale/egoscale
affinity_groups.go
ListRequest
func (ag AffinityGroup) ListRequest() (ListCommand, error) { return &ListAffinityGroups{ ID: ag.ID, Name: ag.Name, }, nil }
go
func (ag AffinityGroup) ListRequest() (ListCommand, error) { return &ListAffinityGroups{ ID: ag.ID, Name: ag.Name, }, nil }
[ "func", "(", "ag", "AffinityGroup", ")", "ListRequest", "(", ")", "(", "ListCommand", ",", "error", ")", "{", "return", "&", "ListAffinityGroups", "{", "ID", ":", "ag", ".", "ID", ",", "Name", ":", "ag", ".", "Name", ",", "}", ",", "nil", "\n", "}" ]
// ListRequest builds the ListAffinityGroups request
[ "ListRequest", "builds", "the", "ListAffinityGroups", "request" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/affinity_groups.go#L23-L28
15,505
exoscale/egoscale
affinity_groups.go
Delete
func (ag AffinityGroup) Delete(ctx context.Context, client *Client) error { if ag.ID == nil && ag.Name == "" { return fmt.Errorf("an Affinity Group may only be deleted using ID or Name") } req := &DeleteAffinityGroup{} if ag.ID != nil { req.ID = ag.ID } else { req.Name = ag.Name } return client.BooleanRequestWithContext(ctx, req) }
go
func (ag AffinityGroup) Delete(ctx context.Context, client *Client) error { if ag.ID == nil && ag.Name == "" { return fmt.Errorf("an Affinity Group may only be deleted using ID or Name") } req := &DeleteAffinityGroup{} if ag.ID != nil { req.ID = ag.ID } else { req.Name = ag.Name } return client.BooleanRequestWithContext(ctx, req) }
[ "func", "(", "ag", "AffinityGroup", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "client", "*", "Client", ")", "error", "{", "if", "ag", ".", "ID", "==", "nil", "&&", "ag", ".", "Name", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "req", ":=", "&", "DeleteAffinityGroup", "{", "}", "\n\n", "if", "ag", ".", "ID", "!=", "nil", "{", "req", ".", "ID", "=", "ag", ".", "ID", "\n", "}", "else", "{", "req", ".", "Name", "=", "ag", ".", "Name", "\n", "}", "\n\n", "return", "client", ".", "BooleanRequestWithContext", "(", "ctx", ",", "req", ")", "\n", "}" ]
// Delete removes the given Affinity Group
[ "Delete", "removes", "the", "given", "Affinity", "Group" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/affinity_groups.go#L31-L45
15,506
exoscale/egoscale
macaddress.go
MAC48
func MAC48(a, b, c, d, e, f byte) MACAddress { m := make(MACAddress, 6) m[0] = a m[1] = b m[2] = c m[3] = d m[4] = e m[5] = f return m }
go
func MAC48(a, b, c, d, e, f byte) MACAddress { m := make(MACAddress, 6) m[0] = a m[1] = b m[2] = c m[3] = d m[4] = e m[5] = f return m }
[ "func", "MAC48", "(", "a", ",", "b", ",", "c", ",", "d", ",", "e", ",", "f", "byte", ")", "MACAddress", "{", "m", ":=", "make", "(", "MACAddress", ",", "6", ")", "\n", "m", "[", "0", "]", "=", "a", "\n", "m", "[", "1", "]", "=", "b", "\n", "m", "[", "2", "]", "=", "c", "\n", "m", "[", "3", "]", "=", "d", "\n", "m", "[", "4", "]", "=", "e", "\n", "m", "[", "5", "]", "=", "f", "\n", "return", "m", "\n", "}" ]
// MAC48 builds a MAC-48 MACAddress
[ "MAC48", "builds", "a", "MAC", "-", "48", "MACAddress" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/macaddress.go#L18-L27
15,507
exoscale/egoscale
macaddress.go
MarshalJSON
func (mac MACAddress) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%q", mac.String())), nil }
go
func (mac MACAddress) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf("%q", mac.String())), nil }
[ "func", "(", "mac", "MACAddress", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mac", ".", "String", "(", ")", ")", ")", ",", "nil", "\n", "}" ]
// MarshalJSON converts the MAC Address to a string representation
[ "MarshalJSON", "converts", "the", "MAC", "Address", "to", "a", "string", "representation" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/macaddress.go#L46-L48
15,508
exoscale/egoscale
macaddress.go
ParseMAC
func ParseMAC(s string) (MACAddress, error) { hw, err := net.ParseMAC(s) return (MACAddress)(hw), err }
go
func ParseMAC(s string) (MACAddress, error) { hw, err := net.ParseMAC(s) return (MACAddress)(hw), err }
[ "func", "ParseMAC", "(", "s", "string", ")", "(", "MACAddress", ",", "error", ")", "{", "hw", ",", "err", ":=", "net", ".", "ParseMAC", "(", "s", ")", "\n", "return", "(", "MACAddress", ")", "(", "hw", ")", ",", "err", "\n", "}" ]
// ParseMAC converts a string into a MACAddress
[ "ParseMAC", "converts", "a", "string", "into", "a", "MACAddress" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/macaddress.go#L51-L54
15,509
exoscale/egoscale
macaddress.go
MustParseMAC
func MustParseMAC(s string) MACAddress { mac, err := ParseMAC(s) if err != nil { panic(err) } return mac }
go
func MustParseMAC(s string) MACAddress { mac, err := ParseMAC(s) if err != nil { panic(err) } return mac }
[ "func", "MustParseMAC", "(", "s", "string", ")", "MACAddress", "{", "mac", ",", "err", ":=", "ParseMAC", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "mac", "\n", "}" ]
// MustParseMAC acts like ParseMAC but panics if in case of an error
[ "MustParseMAC", "acts", "like", "ParseMAC", "but", "panics", "if", "in", "case", "of", "an", "error" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/macaddress.go#L57-L63
15,510
exoscale/egoscale
runstatus_maintenance.go
Match
func (maintenance RunstatusMaintenance) Match(other RunstatusMaintenance) bool { if other.Title != "" && maintenance.Title == other.Title { return true } if other.ID > 0 && maintenance.ID == other.ID { return true } return false }
go
func (maintenance RunstatusMaintenance) Match(other RunstatusMaintenance) bool { if other.Title != "" && maintenance.Title == other.Title { return true } if other.ID > 0 && maintenance.ID == other.ID { return true } return false }
[ "func", "(", "maintenance", "RunstatusMaintenance", ")", "Match", "(", "other", "RunstatusMaintenance", ")", "bool", "{", "if", "other", ".", "Title", "!=", "\"", "\"", "&&", "maintenance", ".", "Title", "==", "other", ".", "Title", "{", "return", "true", "\n", "}", "\n\n", "if", "other", ".", "ID", ">", "0", "&&", "maintenance", ".", "ID", "==", "other", ".", "ID", "{", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// Match returns true if the other maintenance has got similarities with itself
[ "Match", "returns", "true", "if", "the", "other", "maintenance", "has", "got", "similarities", "with", "itself" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/runstatus_maintenance.go#L32-L42
15,511
exoscale/egoscale
runstatus_maintenance.go
GetRunstatusMaintenance
func (client *Client) GetRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) (*RunstatusMaintenance, error) { if maintenance.URL != "" { return client.getRunstatusMaintenance(ctx, maintenance.URL) } if maintenance.PageURL == "" { return nil, fmt.Errorf("empty Page URL for %#v", maintenance) } page, err := client.getRunstatusPage(ctx, maintenance.PageURL) if err != nil { return nil, err } for i := range page.Maintenances { m := &page.Maintenances[i] if m.Match(maintenance) { if err := m.FakeID(); err != nil { log.Printf("bad fake ID for %#v, %s", m, err) } return m, nil } } return nil, fmt.Errorf("%#v not found", maintenance) }
go
func (client *Client) GetRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) (*RunstatusMaintenance, error) { if maintenance.URL != "" { return client.getRunstatusMaintenance(ctx, maintenance.URL) } if maintenance.PageURL == "" { return nil, fmt.Errorf("empty Page URL for %#v", maintenance) } page, err := client.getRunstatusPage(ctx, maintenance.PageURL) if err != nil { return nil, err } for i := range page.Maintenances { m := &page.Maintenances[i] if m.Match(maintenance) { if err := m.FakeID(); err != nil { log.Printf("bad fake ID for %#v, %s", m, err) } return m, nil } } return nil, fmt.Errorf("%#v not found", maintenance) }
[ "func", "(", "client", "*", "Client", ")", "GetRunstatusMaintenance", "(", "ctx", "context", ".", "Context", ",", "maintenance", "RunstatusMaintenance", ")", "(", "*", "RunstatusMaintenance", ",", "error", ")", "{", "if", "maintenance", ".", "URL", "!=", "\"", "\"", "{", "return", "client", ".", "getRunstatusMaintenance", "(", "ctx", ",", "maintenance", ".", "URL", ")", "\n", "}", "\n\n", "if", "maintenance", ".", "PageURL", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "maintenance", ")", "\n", "}", "\n\n", "page", ",", "err", ":=", "client", ".", "getRunstatusPage", "(", "ctx", ",", "maintenance", ".", "PageURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "i", ":=", "range", "page", ".", "Maintenances", "{", "m", ":=", "&", "page", ".", "Maintenances", "[", "i", "]", "\n", "if", "m", ".", "Match", "(", "maintenance", ")", "{", "if", "err", ":=", "m", ".", "FakeID", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "m", ",", "err", ")", "\n", "}", "\n", "return", "m", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "maintenance", ")", "\n", "}" ]
// GetRunstatusMaintenance retrieves the details of a specific maintenance.
[ "GetRunstatusMaintenance", "retrieves", "the", "details", "of", "a", "specific", "maintenance", "." ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/runstatus_maintenance.go#L76-L101
15,512
exoscale/egoscale
runstatus_maintenance.go
ListRunstatusMaintenances
func (client *Client) ListRunstatusMaintenances(ctx context.Context, page RunstatusPage) ([]RunstatusMaintenance, error) { if page.MaintenancesURL == "" { return nil, fmt.Errorf("empty Maintenances URL for %#v", page) } results := make([]RunstatusMaintenance, 0) var err error client.PaginateRunstatusMaintenances(ctx, page, func(maintenance *RunstatusMaintenance, e error) bool { if e != nil { err = e return false } results = append(results, *maintenance) return true }) return results, err }
go
func (client *Client) ListRunstatusMaintenances(ctx context.Context, page RunstatusPage) ([]RunstatusMaintenance, error) { if page.MaintenancesURL == "" { return nil, fmt.Errorf("empty Maintenances URL for %#v", page) } results := make([]RunstatusMaintenance, 0) var err error client.PaginateRunstatusMaintenances(ctx, page, func(maintenance *RunstatusMaintenance, e error) bool { if e != nil { err = e return false } results = append(results, *maintenance) return true }) return results, err }
[ "func", "(", "client", "*", "Client", ")", "ListRunstatusMaintenances", "(", "ctx", "context", ".", "Context", ",", "page", "RunstatusPage", ")", "(", "[", "]", "RunstatusMaintenance", ",", "error", ")", "{", "if", "page", ".", "MaintenancesURL", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "page", ")", "\n", "}", "\n\n", "results", ":=", "make", "(", "[", "]", "RunstatusMaintenance", ",", "0", ")", "\n\n", "var", "err", "error", "\n", "client", ".", "PaginateRunstatusMaintenances", "(", "ctx", ",", "page", ",", "func", "(", "maintenance", "*", "RunstatusMaintenance", ",", "e", "error", ")", "bool", "{", "if", "e", "!=", "nil", "{", "err", "=", "e", "\n", "return", "false", "\n", "}", "\n\n", "results", "=", "append", "(", "results", ",", "*", "maintenance", ")", "\n", "return", "true", "\n", "}", ")", "\n\n", "return", "results", ",", "err", "\n", "}" ]
// ListRunstatusMaintenances returns the list of maintenances for the page.
[ "ListRunstatusMaintenances", "returns", "the", "list", "of", "maintenances", "for", "the", "page", "." ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/runstatus_maintenance.go#L117-L136
15,513
exoscale/egoscale
runstatus_maintenance.go
PaginateRunstatusMaintenances
func (client *Client) PaginateRunstatusMaintenances(ctx context.Context, page RunstatusPage, callback func(*RunstatusMaintenance, error) bool) { // nolint: dupl if page.MaintenancesURL == "" { callback(nil, fmt.Errorf("empty Maintenances URL for %#v", page)) return } maintenancesURL := page.MaintenancesURL for maintenancesURL != "" { resp, err := client.runstatusRequest(ctx, maintenancesURL, nil, "GET") if err != nil { callback(nil, err) return } var ms *RunstatusMaintenanceList if err := json.Unmarshal(resp, &ms); err != nil { callback(nil, err) return } for i := range ms.Maintenances { if err := ms.Maintenances[i].FakeID(); err != nil { log.Printf("bad fake ID for %#v, %s", ms.Maintenances[i], err) } if cont := callback(&ms.Maintenances[i], nil); !cont { return } } maintenancesURL = ms.Next } }
go
func (client *Client) PaginateRunstatusMaintenances(ctx context.Context, page RunstatusPage, callback func(*RunstatusMaintenance, error) bool) { // nolint: dupl if page.MaintenancesURL == "" { callback(nil, fmt.Errorf("empty Maintenances URL for %#v", page)) return } maintenancesURL := page.MaintenancesURL for maintenancesURL != "" { resp, err := client.runstatusRequest(ctx, maintenancesURL, nil, "GET") if err != nil { callback(nil, err) return } var ms *RunstatusMaintenanceList if err := json.Unmarshal(resp, &ms); err != nil { callback(nil, err) return } for i := range ms.Maintenances { if err := ms.Maintenances[i].FakeID(); err != nil { log.Printf("bad fake ID for %#v, %s", ms.Maintenances[i], err) } if cont := callback(&ms.Maintenances[i], nil); !cont { return } } maintenancesURL = ms.Next } }
[ "func", "(", "client", "*", "Client", ")", "PaginateRunstatusMaintenances", "(", "ctx", "context", ".", "Context", ",", "page", "RunstatusPage", ",", "callback", "func", "(", "*", "RunstatusMaintenance", ",", "error", ")", "bool", ")", "{", "// nolint: dupl", "if", "page", ".", "MaintenancesURL", "==", "\"", "\"", "{", "callback", "(", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "page", ")", ")", "\n", "return", "\n", "}", "\n\n", "maintenancesURL", ":=", "page", ".", "MaintenancesURL", "\n", "for", "maintenancesURL", "!=", "\"", "\"", "{", "resp", ",", "err", ":=", "client", ".", "runstatusRequest", "(", "ctx", ",", "maintenancesURL", ",", "nil", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "callback", "(", "nil", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "var", "ms", "*", "RunstatusMaintenanceList", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "&", "ms", ")", ";", "err", "!=", "nil", "{", "callback", "(", "nil", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "for", "i", ":=", "range", "ms", ".", "Maintenances", "{", "if", "err", ":=", "ms", ".", "Maintenances", "[", "i", "]", ".", "FakeID", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "ms", ".", "Maintenances", "[", "i", "]", ",", "err", ")", "\n", "}", "\n", "if", "cont", ":=", "callback", "(", "&", "ms", ".", "Maintenances", "[", "i", "]", ",", "nil", ")", ";", "!", "cont", "{", "return", "\n", "}", "\n", "}", "\n\n", "maintenancesURL", "=", "ms", ".", "Next", "\n", "}", "\n", "}" ]
// PaginateRunstatusMaintenances paginate Maintenances
[ "PaginateRunstatusMaintenances", "paginate", "Maintenances" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/runstatus_maintenance.go#L139-L170
15,514
exoscale/egoscale
runstatus_maintenance.go
CreateRunstatusMaintenance
func (client *Client) CreateRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) (*RunstatusMaintenance, error) { if maintenance.PageURL == "" { return nil, fmt.Errorf("empty Page URL for %#v", maintenance) } page, err := client.getRunstatusPage(ctx, maintenance.PageURL) if err != nil { return nil, err } resp, err := client.runstatusRequest(ctx, page.MaintenancesURL, maintenance, "POST") if err != nil { return nil, err } m := &RunstatusMaintenance{} if err := json.Unmarshal(resp, &m); err != nil { return nil, err } if err := m.FakeID(); err != nil { log.Printf("bad fake ID for %#v, %s", m, err) } return m, nil }
go
func (client *Client) CreateRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) (*RunstatusMaintenance, error) { if maintenance.PageURL == "" { return nil, fmt.Errorf("empty Page URL for %#v", maintenance) } page, err := client.getRunstatusPage(ctx, maintenance.PageURL) if err != nil { return nil, err } resp, err := client.runstatusRequest(ctx, page.MaintenancesURL, maintenance, "POST") if err != nil { return nil, err } m := &RunstatusMaintenance{} if err := json.Unmarshal(resp, &m); err != nil { return nil, err } if err := m.FakeID(); err != nil { log.Printf("bad fake ID for %#v, %s", m, err) } return m, nil }
[ "func", "(", "client", "*", "Client", ")", "CreateRunstatusMaintenance", "(", "ctx", "context", ".", "Context", ",", "maintenance", "RunstatusMaintenance", ")", "(", "*", "RunstatusMaintenance", ",", "error", ")", "{", "if", "maintenance", ".", "PageURL", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "maintenance", ")", "\n", "}", "\n\n", "page", ",", "err", ":=", "client", ".", "getRunstatusPage", "(", "ctx", ",", "maintenance", ".", "PageURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "resp", ",", "err", ":=", "client", ".", "runstatusRequest", "(", "ctx", ",", "page", ".", "MaintenancesURL", ",", "maintenance", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "m", ":=", "&", "RunstatusMaintenance", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "resp", ",", "&", "m", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "m", ".", "FakeID", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "m", ",", "err", ")", "\n", "}", "\n\n", "return", "m", ",", "nil", "\n", "}" ]
// CreateRunstatusMaintenance create runstatus Maintenance
[ "CreateRunstatusMaintenance", "create", "runstatus", "Maintenance" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/runstatus_maintenance.go#L173-L198
15,515
exoscale/egoscale
runstatus_maintenance.go
DeleteRunstatusMaintenance
func (client *Client) DeleteRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) error { if maintenance.URL == "" { return fmt.Errorf("empty URL for %#v", maintenance) } _, err := client.runstatusRequest(ctx, maintenance.URL, nil, "DELETE") return err }
go
func (client *Client) DeleteRunstatusMaintenance(ctx context.Context, maintenance RunstatusMaintenance) error { if maintenance.URL == "" { return fmt.Errorf("empty URL for %#v", maintenance) } _, err := client.runstatusRequest(ctx, maintenance.URL, nil, "DELETE") return err }
[ "func", "(", "client", "*", "Client", ")", "DeleteRunstatusMaintenance", "(", "ctx", "context", ".", "Context", ",", "maintenance", "RunstatusMaintenance", ")", "error", "{", "if", "maintenance", ".", "URL", "==", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "maintenance", ")", "\n", "}", "\n\n", "_", ",", "err", ":=", "client", ".", "runstatusRequest", "(", "ctx", ",", "maintenance", ".", "URL", ",", "nil", ",", "\"", "\"", ")", "\n", "return", "err", "\n", "}" ]
// DeleteRunstatusMaintenance delete runstatus Maintenance
[ "DeleteRunstatusMaintenance", "delete", "runstatus", "Maintenance" ]
4e527724b8225e8315d580accd1c4e860202d41b
https://github.com/exoscale/egoscale/blob/4e527724b8225e8315d580accd1c4e860202d41b/runstatus_maintenance.go#L201-L208
15,516
nemosupremo/vault-gatekeeper
tlsutil.go
ListenAndServeTLS
func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error { // From http.ListenAndServeTLS: // https://github.com/golang/go/blob/release-branch.go1.10/src/net/http/server.go#L3000-L3003 server := &http.Server{Addr: addr, Handler: handler} keypair, err := NewKeypairReloader(certFile, keyFile) if err != nil { return err } server.TLSConfig = &tls.Config{GetCertificate: keypair.GetCertificateFunc()} // The certFile and keyFile arguments below are ignored if the GetCertificate field is not nil. return server.ListenAndServeTLS("", "") }
go
func ListenAndServeTLS(addr, certFile, keyFile string, handler http.Handler) error { // From http.ListenAndServeTLS: // https://github.com/golang/go/blob/release-branch.go1.10/src/net/http/server.go#L3000-L3003 server := &http.Server{Addr: addr, Handler: handler} keypair, err := NewKeypairReloader(certFile, keyFile) if err != nil { return err } server.TLSConfig = &tls.Config{GetCertificate: keypair.GetCertificateFunc()} // The certFile and keyFile arguments below are ignored if the GetCertificate field is not nil. return server.ListenAndServeTLS("", "") }
[ "func", "ListenAndServeTLS", "(", "addr", ",", "certFile", ",", "keyFile", "string", ",", "handler", "http", ".", "Handler", ")", "error", "{", "// From http.ListenAndServeTLS:", "// https://github.com/golang/go/blob/release-branch.go1.10/src/net/http/server.go#L3000-L3003", "server", ":=", "&", "http", ".", "Server", "{", "Addr", ":", "addr", ",", "Handler", ":", "handler", "}", "\n\n", "keypair", ",", "err", ":=", "NewKeypairReloader", "(", "certFile", ",", "keyFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "server", ".", "TLSConfig", "=", "&", "tls", ".", "Config", "{", "GetCertificate", ":", "keypair", ".", "GetCertificateFunc", "(", ")", "}", "\n\n", "// The certFile and keyFile arguments below are ignored if the GetCertificate field is not nil.", "return", "server", ".", "ListenAndServeTLS", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}" ]
// This works just like http.ListenAndServeTLS but certificates are loaded into // a wrapper struct that reloads certificates from disk when a SIGHUP is // received.
[ "This", "works", "just", "like", "http", ".", "ListenAndServeTLS", "but", "certificates", "are", "loaded", "into", "a", "wrapper", "struct", "that", "reloads", "certificates", "from", "disk", "when", "a", "SIGHUP", "is", "received", "." ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/tlsutil.go#L77-L90
15,517
nemosupremo/vault-gatekeeper
usagestore/memory.go
NewInMemoryUsageStore
func NewInMemoryUsageStore() (UsageStore, error) { m := &memoryStore{} m.set = make(map[string]memEntry) m.quit = make(chan struct{}) go m.garbageCollector() return m, nil }
go
func NewInMemoryUsageStore() (UsageStore, error) { m := &memoryStore{} m.set = make(map[string]memEntry) m.quit = make(chan struct{}) go m.garbageCollector() return m, nil }
[ "func", "NewInMemoryUsageStore", "(", ")", "(", "UsageStore", ",", "error", ")", "{", "m", ":=", "&", "memoryStore", "{", "}", "\n", "m", ".", "set", "=", "make", "(", "map", "[", "string", "]", "memEntry", ")", "\n", "m", ".", "quit", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "go", "m", ".", "garbageCollector", "(", ")", "\n", "return", "m", ",", "nil", "\n", "}" ]
// NewInMemoryUsageStore creates a usage store backed by memory. This usage // store is only appropriate for single instance gatekeeper deployments // and should not be used for high availablility deployments.
[ "NewInMemoryUsageStore", "creates", "a", "usage", "store", "backed", "by", "memory", ".", "This", "usage", "store", "is", "only", "appropriate", "for", "single", "instance", "gatekeeper", "deployments", "and", "should", "not", "be", "used", "for", "high", "availablility", "deployments", "." ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/usagestore/memory.go#L24-L30
15,518
nemosupremo/vault-gatekeeper
gatekeeper/cert.go
LoadCACert
func LoadCACert(path string) (*x509.CertPool, error) { result := x509.NewCertPool() if err := appendPEMCertsFromPath(result, path); err != nil { return nil, err } return result, nil }
go
func LoadCACert(path string) (*x509.CertPool, error) { result := x509.NewCertPool() if err := appendPEMCertsFromPath(result, path); err != nil { return nil, err } return result, nil }
[ "func", "LoadCACert", "(", "path", "string", ")", "(", "*", "x509", ".", "CertPool", ",", "error", ")", "{", "result", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "if", "err", ":=", "appendPEMCertsFromPath", "(", "result", ",", "path", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// Loads the certificate from given path and creates a certificate pool from it.
[ "Loads", "the", "certificate", "from", "given", "path", "and", "creates", "a", "certificate", "pool", "from", "it", "." ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/gatekeeper/cert.go#L12-L19
15,519
nemosupremo/vault-gatekeeper
gatekeeper/cert.go
LoadCAPath
func LoadCAPath(path string) (*x509.CertPool, error) { result := x509.NewCertPool() // filepath.WalkFunc to traverse the directory structure, starting from input path // attempting to load certs into result in the process appendCerts := func(path string, info os.FileInfo, err error) error { // cascade errors to the end of the traversal, // we fail early if there are files other than certs under path if err != nil { return err } // ignore dirs if info.IsDir() { return nil } // try and append certs from files if err := appendPEMCertsFromPath(result, path); err != nil { // fail if we can't append PEM certs or get no PEM certs from a file return err } return nil } // if we error while walking with appendCerts, don't return any certs if err := filepath.Walk(path, appendCerts); err != nil { return nil, err } return result, nil }
go
func LoadCAPath(path string) (*x509.CertPool, error) { result := x509.NewCertPool() // filepath.WalkFunc to traverse the directory structure, starting from input path // attempting to load certs into result in the process appendCerts := func(path string, info os.FileInfo, err error) error { // cascade errors to the end of the traversal, // we fail early if there are files other than certs under path if err != nil { return err } // ignore dirs if info.IsDir() { return nil } // try and append certs from files if err := appendPEMCertsFromPath(result, path); err != nil { // fail if we can't append PEM certs or get no PEM certs from a file return err } return nil } // if we error while walking with appendCerts, don't return any certs if err := filepath.Walk(path, appendCerts); err != nil { return nil, err } return result, nil }
[ "func", "LoadCAPath", "(", "path", "string", ")", "(", "*", "x509", ".", "CertPool", ",", "error", ")", "{", "result", ":=", "x509", ".", "NewCertPool", "(", ")", "\n\n", "// filepath.WalkFunc to traverse the directory structure, starting from input path", "// attempting to load certs into result in the process", "appendCerts", ":=", "func", "(", "path", "string", ",", "info", "os", ".", "FileInfo", ",", "err", "error", ")", "error", "{", "// cascade errors to the end of the traversal,", "// we fail early if there are files other than certs under path", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// ignore dirs", "if", "info", ".", "IsDir", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "// try and append certs from files", "if", "err", ":=", "appendPEMCertsFromPath", "(", "result", ",", "path", ")", ";", "err", "!=", "nil", "{", "// fail if we can't append PEM certs or get no PEM certs from a file", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}", "\n\n", "// if we error while walking with appendCerts, don't return any certs", "if", "err", ":=", "filepath", ".", "Walk", "(", "path", ",", "appendCerts", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// Loads the certificates present in the given directory or file and creates a // certificate pool from it. Assumes that _only_ PEM formatted cert files // are present in the given directory. The presence of other files will // cause this to fail.
[ "Loads", "the", "certificates", "present", "in", "the", "given", "directory", "or", "file", "and", "creates", "a", "certificate", "pool", "from", "it", ".", "Assumes", "that", "_only_", "PEM", "formatted", "cert", "files", "are", "present", "in", "the", "given", "directory", ".", "The", "presence", "of", "other", "files", "will", "cause", "this", "to", "fail", "." ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/gatekeeper/cert.go#L25-L57
15,520
nemosupremo/vault-gatekeeper
scheduler/dcosee_mesos/mesos.go
NewMesosScheduler
func NewMesosScheduler(master string, uid string, privateKeyFile io.Reader) (scheduler.Scheduler, error) { //Create the object m := &mesosScheduler{ master: master, uid: uid, } //Parse and validate the private key if err := m.parsePrivateKey(privateKeyFile); err != nil { return nil, err } //Build the transport tr := &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, } //If requested ignore the TLS verify if viper.GetBool("mesos-skipverify") { if tr.TLSClientConfig == nil { tr.TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, } } else { tr.TLSClientConfig.InsecureSkipVerify = true } } client := http.DefaultClient client.Transport = tr m.client = client //Check to see if you can communicate with the Mesos Master if _, _, err := m.getMesosMaster(); err != nil { return nil, err } //Create initial authorization token if err := m.createAuthorizationToken(); err != nil { return nil, err } return m, nil }
go
func NewMesosScheduler(master string, uid string, privateKeyFile io.Reader) (scheduler.Scheduler, error) { //Create the object m := &mesosScheduler{ master: master, uid: uid, } //Parse and validate the private key if err := m.parsePrivateKey(privateKeyFile); err != nil { return nil, err } //Build the transport tr := &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, DualStack: true, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, } //If requested ignore the TLS verify if viper.GetBool("mesos-skipverify") { if tr.TLSClientConfig == nil { tr.TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, } } else { tr.TLSClientConfig.InsecureSkipVerify = true } } client := http.DefaultClient client.Transport = tr m.client = client //Check to see if you can communicate with the Mesos Master if _, _, err := m.getMesosMaster(); err != nil { return nil, err } //Create initial authorization token if err := m.createAuthorizationToken(); err != nil { return nil, err } return m, nil }
[ "func", "NewMesosScheduler", "(", "master", "string", ",", "uid", "string", ",", "privateKeyFile", "io", ".", "Reader", ")", "(", "scheduler", ".", "Scheduler", ",", "error", ")", "{", "//Create the object", "m", ":=", "&", "mesosScheduler", "{", "master", ":", "master", ",", "uid", ":", "uid", ",", "}", "\n\n", "//Parse and validate the private key", "if", "err", ":=", "m", ".", "parsePrivateKey", "(", "privateKeyFile", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "//Build the transport", "tr", ":=", "&", "http", ".", "Transport", "{", "Proxy", ":", "http", ".", "ProxyFromEnvironment", ",", "DialContext", ":", "(", "&", "net", ".", "Dialer", "{", "Timeout", ":", "30", "*", "time", ".", "Second", ",", "KeepAlive", ":", "30", "*", "time", ".", "Second", ",", "DualStack", ":", "true", ",", "}", ")", ".", "DialContext", ",", "MaxIdleConns", ":", "100", ",", "IdleConnTimeout", ":", "90", "*", "time", ".", "Second", ",", "TLSHandshakeTimeout", ":", "10", "*", "time", ".", "Second", ",", "ExpectContinueTimeout", ":", "1", "*", "time", ".", "Second", ",", "}", "\n\n", "//If requested ignore the TLS verify", "if", "viper", ".", "GetBool", "(", "\"", "\"", ")", "{", "if", "tr", ".", "TLSClientConfig", "==", "nil", "{", "tr", ".", "TLSClientConfig", "=", "&", "tls", ".", "Config", "{", "InsecureSkipVerify", ":", "true", ",", "}", "\n", "}", "else", "{", "tr", ".", "TLSClientConfig", ".", "InsecureSkipVerify", "=", "true", "\n", "}", "\n", "}", "\n", "client", ":=", "http", ".", "DefaultClient", "\n", "client", ".", "Transport", "=", "tr", "\n", "m", ".", "client", "=", "client", "\n\n", "//Check to see if you can communicate with the Mesos Master", "if", "_", ",", "_", ",", "err", ":=", "m", ".", "getMesosMaster", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "//Create initial authorization token", "if", "err", ":=", "m", ".", "createAuthorizationToken", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "m", ",", "nil", "\n", "}" ]
//NewMesosScheduler creates the object for talking to mesos. In this case it // will create the object to talk to DCOS EE Mesos which needs some authentication // pieces setup
[ "NewMesosScheduler", "creates", "the", "object", "for", "talking", "to", "mesos", ".", "In", "this", "case", "it", "will", "create", "the", "object", "to", "talk", "to", "DCOS", "EE", "Mesos", "which", "needs", "some", "authentication", "pieces", "setup" ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/scheduler/dcosee_mesos/mesos.go#L157-L208
15,521
nemosupremo/vault-gatekeeper
scheduler/dcosee_mesos/mesos.go
parsePrivateKey
func (m *mesosScheduler) parsePrivateKey(privateKeyFile io.Reader) error { //Read the Data from the private key file data, err := ioutil.ReadAll(privateKeyFile) if err != nil { return err } //Parse the data in to the Private Key object //If we need a password object for this we will have to use a different function pk, err := jwt.ParseRSAPrivateKeyFromPEM(data) if err != nil { return err } //Validate the private key if err := pk.Validate(); err != nil { return err } //Set the key in the scheduler object m.privateKey = pk return nil }
go
func (m *mesosScheduler) parsePrivateKey(privateKeyFile io.Reader) error { //Read the Data from the private key file data, err := ioutil.ReadAll(privateKeyFile) if err != nil { return err } //Parse the data in to the Private Key object //If we need a password object for this we will have to use a different function pk, err := jwt.ParseRSAPrivateKeyFromPEM(data) if err != nil { return err } //Validate the private key if err := pk.Validate(); err != nil { return err } //Set the key in the scheduler object m.privateKey = pk return nil }
[ "func", "(", "m", "*", "mesosScheduler", ")", "parsePrivateKey", "(", "privateKeyFile", "io", ".", "Reader", ")", "error", "{", "//Read the Data from the private key file", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "privateKeyFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "//Parse the data in to the Private Key object", "//If we need a password object for this we will have to use a different function", "pk", ",", "err", ":=", "jwt", ".", "ParseRSAPrivateKeyFromPEM", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "//Validate the private key", "if", "err", ":=", "pk", ".", "Validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "//Set the key in the scheduler object", "m", ".", "privateKey", "=", "pk", "\n", "return", "nil", "\n", "}" ]
//Parse the private Key for the JWT
[ "Parse", "the", "private", "Key", "for", "the", "JWT" ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/scheduler/dcosee_mesos/mesos.go#L211-L233
15,522
nemosupremo/vault-gatekeeper
scheduler/dcosee_mesos/mesos.go
createLoginToken
func (m *mesosScheduler) createLoginToken() ([]byte, error) { // create a signer for rsa 256 sm := jwt.GetSigningMethod("RS256") mc := jwt.MapClaims{} t := jwt.NewWithClaims(sm, mc) // set our claims mc["uid"] = m.uid // set the expire time // see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-20#section-4.1.4 mc["exp"] = time.Now().Add(defaultLoginExp).Unix() tokenString, err := t.SignedString(m.privateKey) if err != nil { log.Errorf("Token Signing error: %v\n", err) return nil, err } log.Debugf("Login Token: %s\n", tokenString) return []byte(tokenString), nil }
go
func (m *mesosScheduler) createLoginToken() ([]byte, error) { // create a signer for rsa 256 sm := jwt.GetSigningMethod("RS256") mc := jwt.MapClaims{} t := jwt.NewWithClaims(sm, mc) // set our claims mc["uid"] = m.uid // set the expire time // see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-20#section-4.1.4 mc["exp"] = time.Now().Add(defaultLoginExp).Unix() tokenString, err := t.SignedString(m.privateKey) if err != nil { log.Errorf("Token Signing error: %v\n", err) return nil, err } log.Debugf("Login Token: %s\n", tokenString) return []byte(tokenString), nil }
[ "func", "(", "m", "*", "mesosScheduler", ")", "createLoginToken", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "// create a signer for rsa 256", "sm", ":=", "jwt", ".", "GetSigningMethod", "(", "\"", "\"", ")", "\n", "mc", ":=", "jwt", ".", "MapClaims", "{", "}", "\n", "t", ":=", "jwt", ".", "NewWithClaims", "(", "sm", ",", "mc", ")", "\n\n", "// set our claims", "mc", "[", "\"", "\"", "]", "=", "m", ".", "uid", "\n\n", "// set the expire time", "// see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-20#section-4.1.4", "mc", "[", "\"", "\"", "]", "=", "time", ".", "Now", "(", ")", ".", "Add", "(", "defaultLoginExp", ")", ".", "Unix", "(", ")", "\n\n", "tokenString", ",", "err", ":=", "t", ".", "SignedString", "(", "m", ".", "privateKey", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "err", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "log", ".", "Debugf", "(", "\"", "\\n", "\"", ",", "tokenString", ")", "\n\n", "return", "[", "]", "byte", "(", "tokenString", ")", ",", "nil", "\n", "}" ]
//Create the DCOS login token based on the private key and uid
[ "Create", "the", "DCOS", "login", "token", "based", "on", "the", "private", "key", "and", "uid" ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/scheduler/dcosee_mesos/mesos.go#L236-L258
15,523
nemosupremo/vault-gatekeeper
vault/unsealer/unsealer.go
Token
func (t TokenUnsealer) Token() (string, error) { r, err := vault.Request{goreq.Request{ Uri: vault.Path("/v1/auth/token/lookup-self", ""), MaxRedirects: 10, RedirectHeaders: true, }.WithHeader("X-Vault-Token", t.AuthToken)}.Do() if err == nil { defer r.Body.Close() switch r.StatusCode { case 200: return t.AuthToken, nil default: var e vault.Error e.Code = r.StatusCode if err := r.Body.FromJsonTo(&e); err == nil { return "", e } else { e.Errors = []string{"communication error."} return "", e } } } else { return "", err } }
go
func (t TokenUnsealer) Token() (string, error) { r, err := vault.Request{goreq.Request{ Uri: vault.Path("/v1/auth/token/lookup-self", ""), MaxRedirects: 10, RedirectHeaders: true, }.WithHeader("X-Vault-Token", t.AuthToken)}.Do() if err == nil { defer r.Body.Close() switch r.StatusCode { case 200: return t.AuthToken, nil default: var e vault.Error e.Code = r.StatusCode if err := r.Body.FromJsonTo(&e); err == nil { return "", e } else { e.Errors = []string{"communication error."} return "", e } } } else { return "", err } }
[ "func", "(", "t", "TokenUnsealer", ")", "Token", "(", ")", "(", "string", ",", "error", ")", "{", "r", ",", "err", ":=", "vault", ".", "Request", "{", "goreq", ".", "Request", "{", "Uri", ":", "vault", ".", "Path", "(", "\"", "\"", ",", "\"", "\"", ")", ",", "MaxRedirects", ":", "10", ",", "RedirectHeaders", ":", "true", ",", "}", ".", "WithHeader", "(", "\"", "\"", ",", "t", ".", "AuthToken", ")", "}", ".", "Do", "(", ")", "\n", "if", "err", "==", "nil", "{", "defer", "r", ".", "Body", ".", "Close", "(", ")", "\n", "switch", "r", ".", "StatusCode", "{", "case", "200", ":", "return", "t", ".", "AuthToken", ",", "nil", "\n", "default", ":", "var", "e", "vault", ".", "Error", "\n", "e", ".", "Code", "=", "r", ".", "StatusCode", "\n", "if", "err", ":=", "r", ".", "Body", ".", "FromJsonTo", "(", "&", "e", ")", ";", "err", "==", "nil", "{", "return", "\"", "\"", ",", "e", "\n", "}", "else", "{", "e", ".", "Errors", "=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "return", "\"", "\"", ",", "e", "\n", "}", "\n", "}", "\n", "}", "else", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}" ]
// Retrieving a token with the TokenUnsealer checks that the token is still // valid first.
[ "Retrieving", "a", "token", "with", "the", "TokenUnsealer", "checks", "that", "the", "token", "is", "still", "valid", "first", "." ]
d47c5055802338e8bb6d668bd36d1c330064d16e
https://github.com/nemosupremo/vault-gatekeeper/blob/d47c5055802338e8bb6d668bd36d1c330064d16e/vault/unsealer/unsealer.go#L29-L53
15,524
docker/go-events
channel.go
NewChannel
func NewChannel(buffer int) *Channel { return &Channel{ C: make(chan Event, buffer), closed: make(chan struct{}), } }
go
func NewChannel(buffer int) *Channel { return &Channel{ C: make(chan Event, buffer), closed: make(chan struct{}), } }
[ "func", "NewChannel", "(", "buffer", "int", ")", "*", "Channel", "{", "return", "&", "Channel", "{", "C", ":", "make", "(", "chan", "Event", ",", "buffer", ")", ",", "closed", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "}" ]
// NewChannel returns a channel. If buffer is zero, the channel is // unbuffered.
[ "NewChannel", "returns", "a", "channel", ".", "If", "buffer", "is", "zero", "the", "channel", "is", "unbuffered", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/channel.go#L21-L26
15,525
docker/go-events
channel.go
Write
func (ch *Channel) Write(event Event) error { select { case ch.C <- event: return nil case <-ch.closed: return ErrSinkClosed } }
go
func (ch *Channel) Write(event Event) error { select { case ch.C <- event: return nil case <-ch.closed: return ErrSinkClosed } }
[ "func", "(", "ch", "*", "Channel", ")", "Write", "(", "event", "Event", ")", "error", "{", "select", "{", "case", "ch", ".", "C", "<-", "event", ":", "return", "nil", "\n", "case", "<-", "ch", ".", "closed", ":", "return", "ErrSinkClosed", "\n", "}", "\n", "}" ]
// Write the event to the channel. Must be called in a separate goroutine from // the listener.
[ "Write", "the", "event", "to", "the", "channel", ".", "Must", "be", "called", "in", "a", "separate", "goroutine", "from", "the", "listener", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/channel.go#L35-L42
15,526
docker/go-events
channel.go
Close
func (ch *Channel) Close() error { ch.once.Do(func() { close(ch.closed) }) return nil }
go
func (ch *Channel) Close() error { ch.once.Do(func() { close(ch.closed) }) return nil }
[ "func", "(", "ch", "*", "Channel", ")", "Close", "(", ")", "error", "{", "ch", ".", "once", ".", "Do", "(", "func", "(", ")", "{", "close", "(", "ch", ".", "closed", ")", "\n", "}", ")", "\n\n", "return", "nil", "\n", "}" ]
// Close the channel sink.
[ "Close", "the", "channel", "sink", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/channel.go#L45-L51
15,527
docker/go-events
broadcast.go
NewBroadcaster
func NewBroadcaster(sinks ...Sink) *Broadcaster { b := Broadcaster{ sinks: sinks, events: make(chan Event), adds: make(chan configureRequest), removes: make(chan configureRequest), shutdown: make(chan struct{}), closed: make(chan struct{}), } // Start the broadcaster go b.run() return &b }
go
func NewBroadcaster(sinks ...Sink) *Broadcaster { b := Broadcaster{ sinks: sinks, events: make(chan Event), adds: make(chan configureRequest), removes: make(chan configureRequest), shutdown: make(chan struct{}), closed: make(chan struct{}), } // Start the broadcaster go b.run() return &b }
[ "func", "NewBroadcaster", "(", "sinks", "...", "Sink", ")", "*", "Broadcaster", "{", "b", ":=", "Broadcaster", "{", "sinks", ":", "sinks", ",", "events", ":", "make", "(", "chan", "Event", ")", ",", "adds", ":", "make", "(", "chan", "configureRequest", ")", ",", "removes", ":", "make", "(", "chan", "configureRequest", ")", ",", "shutdown", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "closed", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n\n", "// Start the broadcaster", "go", "b", ".", "run", "(", ")", "\n\n", "return", "&", "b", "\n", "}" ]
// NewBroadcaster appends one or more sinks to the list of sinks. The // broadcaster behavior will be affected by the properties of the sink. // Generally, the sink should accept all messages and deal with reliability on // its own. Use of EventQueue and RetryingSink should be used here.
[ "NewBroadcaster", "appends", "one", "or", "more", "sinks", "to", "the", "list", "of", "sinks", ".", "The", "broadcaster", "behavior", "will", "be", "affected", "by", "the", "properties", "of", "the", "sink", ".", "Generally", "the", "sink", "should", "accept", "all", "messages", "and", "deal", "with", "reliability", "on", "its", "own", ".", "Use", "of", "EventQueue", "and", "RetryingSink", "should", "be", "used", "here", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/broadcast.go#L28-L42
15,528
docker/go-events
broadcast.go
Add
func (b *Broadcaster) Add(sink Sink) error { return b.configure(b.adds, sink) }
go
func (b *Broadcaster) Add(sink Sink) error { return b.configure(b.adds, sink) }
[ "func", "(", "b", "*", "Broadcaster", ")", "Add", "(", "sink", "Sink", ")", "error", "{", "return", "b", ".", "configure", "(", "b", ".", "adds", ",", "sink", ")", "\n", "}" ]
// Add the sink to the broadcaster. // // The provided sink must be comparable with equality. Typically, this just // works with a regular pointer type.
[ "Add", "the", "sink", "to", "the", "broadcaster", ".", "The", "provided", "sink", "must", "be", "comparable", "with", "equality", ".", "Typically", "this", "just", "works", "with", "a", "regular", "pointer", "type", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/broadcast.go#L60-L62
15,529
docker/go-events
broadcast.go
Remove
func (b *Broadcaster) Remove(sink Sink) error { return b.configure(b.removes, sink) }
go
func (b *Broadcaster) Remove(sink Sink) error { return b.configure(b.removes, sink) }
[ "func", "(", "b", "*", "Broadcaster", ")", "Remove", "(", "sink", "Sink", ")", "error", "{", "return", "b", ".", "configure", "(", "b", ".", "removes", ",", "sink", ")", "\n", "}" ]
// Remove the provided sink.
[ "Remove", "the", "provided", "sink", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/broadcast.go#L65-L67
15,530
docker/go-events
queue.go
NewQueue
func NewQueue(dst Sink) *Queue { eq := Queue{ dst: dst, events: list.New(), } eq.cond = sync.NewCond(&eq.mu) go eq.run() return &eq }
go
func NewQueue(dst Sink) *Queue { eq := Queue{ dst: dst, events: list.New(), } eq.cond = sync.NewCond(&eq.mu) go eq.run() return &eq }
[ "func", "NewQueue", "(", "dst", "Sink", ")", "*", "Queue", "{", "eq", ":=", "Queue", "{", "dst", ":", "dst", ",", "events", ":", "list", ".", "New", "(", ")", ",", "}", "\n\n", "eq", ".", "cond", "=", "sync", ".", "NewCond", "(", "&", "eq", ".", "mu", ")", "\n", "go", "eq", ".", "run", "(", ")", "\n", "return", "&", "eq", "\n", "}" ]
// NewQueue returns a queue to the provided Sink dst.
[ "NewQueue", "returns", "a", "queue", "to", "the", "provided", "Sink", "dst", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/queue.go#L22-L31
15,531
docker/go-events
queue.go
Write
func (eq *Queue) Write(event Event) error { eq.mu.Lock() defer eq.mu.Unlock() if eq.closed { return ErrSinkClosed } eq.events.PushBack(event) eq.cond.Signal() // signal waiters return nil }
go
func (eq *Queue) Write(event Event) error { eq.mu.Lock() defer eq.mu.Unlock() if eq.closed { return ErrSinkClosed } eq.events.PushBack(event) eq.cond.Signal() // signal waiters return nil }
[ "func", "(", "eq", "*", "Queue", ")", "Write", "(", "event", "Event", ")", "error", "{", "eq", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "eq", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "eq", ".", "closed", "{", "return", "ErrSinkClosed", "\n", "}", "\n\n", "eq", ".", "events", ".", "PushBack", "(", "event", ")", "\n", "eq", ".", "cond", ".", "Signal", "(", ")", "// signal waiters", "\n\n", "return", "nil", "\n", "}" ]
// Write accepts the events into the queue, only failing if the queue has // been closed.
[ "Write", "accepts", "the", "events", "into", "the", "queue", "only", "failing", "if", "the", "queue", "has", "been", "closed", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/queue.go#L35-L47
15,532
docker/go-events
queue.go
Close
func (eq *Queue) Close() error { eq.mu.Lock() defer eq.mu.Unlock() if eq.closed { return nil } // set closed flag eq.closed = true eq.cond.Signal() // signal flushes queue eq.cond.Wait() // wait for signal from last flush return eq.dst.Close() }
go
func (eq *Queue) Close() error { eq.mu.Lock() defer eq.mu.Unlock() if eq.closed { return nil } // set closed flag eq.closed = true eq.cond.Signal() // signal flushes queue eq.cond.Wait() // wait for signal from last flush return eq.dst.Close() }
[ "func", "(", "eq", "*", "Queue", ")", "Close", "(", ")", "error", "{", "eq", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "eq", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "eq", ".", "closed", "{", "return", "nil", "\n", "}", "\n\n", "// set closed flag", "eq", ".", "closed", "=", "true", "\n", "eq", ".", "cond", ".", "Signal", "(", ")", "// signal flushes queue", "\n", "eq", ".", "cond", ".", "Wait", "(", ")", "// wait for signal from last flush", "\n", "return", "eq", ".", "dst", ".", "Close", "(", ")", "\n", "}" ]
// Close shutsdown the event queue, flushing
[ "Close", "shutsdown", "the", "event", "queue", "flushing" ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/queue.go#L50-L63
15,533
docker/go-events
retry.go
NewRetryingSink
func NewRetryingSink(sink Sink, strategy RetryStrategy) *RetryingSink { rs := &RetryingSink{ sink: sink, strategy: strategy, closed: make(chan struct{}), } return rs }
go
func NewRetryingSink(sink Sink, strategy RetryStrategy) *RetryingSink { rs := &RetryingSink{ sink: sink, strategy: strategy, closed: make(chan struct{}), } return rs }
[ "func", "NewRetryingSink", "(", "sink", "Sink", ",", "strategy", "RetryStrategy", ")", "*", "RetryingSink", "{", "rs", ":=", "&", "RetryingSink", "{", "sink", ":", "sink", ",", "strategy", ":", "strategy", ",", "closed", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n\n", "return", "rs", "\n", "}" ]
// NewRetryingSink returns a sink that will retry writes to a sink, backing // off on failure. Parameters threshold and backoff adjust the behavior of the // circuit breaker.
[ "NewRetryingSink", "returns", "a", "sink", "that", "will", "retry", "writes", "to", "a", "sink", "backing", "off", "on", "failure", ".", "Parameters", "threshold", "and", "backoff", "adjust", "the", "behavior", "of", "the", "circuit", "breaker", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L28-L36
15,534
docker/go-events
retry.go
NewBreaker
func NewBreaker(threshold int, backoff time.Duration) *Breaker { return &Breaker{ threshold: threshold, backoff: backoff, } }
go
func NewBreaker(threshold int, backoff time.Duration) *Breaker { return &Breaker{ threshold: threshold, backoff: backoff, } }
[ "func", "NewBreaker", "(", "threshold", "int", ",", "backoff", "time", ".", "Duration", ")", "*", "Breaker", "{", "return", "&", "Breaker", "{", "threshold", ":", "threshold", ",", "backoff", ":", "backoff", ",", "}", "\n", "}" ]
// NewBreaker returns a breaker that will backoff after the threshold has been // tripped. A Breaker is thread safe and may be shared by many goroutines.
[ "NewBreaker", "returns", "a", "breaker", "that", "will", "backoff", "after", "the", "threshold", "has", "been", "tripped", ".", "A", "Breaker", "is", "thread", "safe", "and", "may", "be", "shared", "by", "many", "goroutines", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L138-L143
15,535
docker/go-events
retry.go
Proceed
func (b *Breaker) Proceed(event Event) time.Duration { b.mu.Lock() defer b.mu.Unlock() if b.recent < b.threshold { return 0 } return b.last.Add(b.backoff).Sub(time.Now()) }
go
func (b *Breaker) Proceed(event Event) time.Duration { b.mu.Lock() defer b.mu.Unlock() if b.recent < b.threshold { return 0 } return b.last.Add(b.backoff).Sub(time.Now()) }
[ "func", "(", "b", "*", "Breaker", ")", "Proceed", "(", "event", "Event", ")", "time", ".", "Duration", "{", "b", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "b", ".", "recent", "<", "b", ".", "threshold", "{", "return", "0", "\n", "}", "\n\n", "return", "b", ".", "last", ".", "Add", "(", "b", ".", "backoff", ")", ".", "Sub", "(", "time", ".", "Now", "(", ")", ")", "\n", "}" ]
// Proceed checks the failures against the threshold.
[ "Proceed", "checks", "the", "failures", "against", "the", "threshold", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L146-L155
15,536
docker/go-events
retry.go
Success
func (b *Breaker) Success(event Event) { b.mu.Lock() defer b.mu.Unlock() b.recent = 0 b.last = time.Time{} }
go
func (b *Breaker) Success(event Event) { b.mu.Lock() defer b.mu.Unlock() b.recent = 0 b.last = time.Time{} }
[ "func", "(", "b", "*", "Breaker", ")", "Success", "(", "event", "Event", ")", "{", "b", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "b", ".", "recent", "=", "0", "\n", "b", ".", "last", "=", "time", ".", "Time", "{", "}", "\n", "}" ]
// Success resets the breaker.
[ "Success", "resets", "the", "breaker", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L158-L164
15,537
docker/go-events
retry.go
Failure
func (b *Breaker) Failure(event Event, err error) bool { b.mu.Lock() defer b.mu.Unlock() b.recent++ b.last = time.Now().UTC() return false // never drop events. }
go
func (b *Breaker) Failure(event Event, err error) bool { b.mu.Lock() defer b.mu.Unlock() b.recent++ b.last = time.Now().UTC() return false // never drop events. }
[ "func", "(", "b", "*", "Breaker", ")", "Failure", "(", "event", "Event", ",", "err", "error", ")", "bool", "{", "b", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "b", ".", "recent", "++", "\n", "b", ".", "last", "=", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", "\n", "return", "false", "// never drop events.", "\n", "}" ]
// Failure records the failure and latest failure time.
[ "Failure", "records", "the", "failure", "and", "latest", "failure", "time", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L167-L174
15,538
docker/go-events
retry.go
Proceed
func (b *ExponentialBackoff) Proceed(event Event) time.Duration { return b.backoff(atomic.LoadUint64(&b.failures)) }
go
func (b *ExponentialBackoff) Proceed(event Event) time.Duration { return b.backoff(atomic.LoadUint64(&b.failures)) }
[ "func", "(", "b", "*", "ExponentialBackoff", ")", "Proceed", "(", "event", "Event", ")", "time", ".", "Duration", "{", "return", "b", ".", "backoff", "(", "atomic", ".", "LoadUint64", "(", "&", "b", ".", "failures", ")", ")", "\n", "}" ]
// Proceed returns the next randomly bound exponential backoff time.
[ "Proceed", "returns", "the", "next", "randomly", "bound", "exponential", "backoff", "time", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L219-L221
15,539
docker/go-events
retry.go
Failure
func (b *ExponentialBackoff) Failure(event Event, err error) bool { atomic.AddUint64(&b.failures, 1) return false }
go
func (b *ExponentialBackoff) Failure(event Event, err error) bool { atomic.AddUint64(&b.failures, 1) return false }
[ "func", "(", "b", "*", "ExponentialBackoff", ")", "Failure", "(", "event", "Event", ",", "err", "error", ")", "bool", "{", "atomic", ".", "AddUint64", "(", "&", "b", ".", "failures", ",", "1", ")", "\n", "return", "false", "\n", "}" ]
// Failure increments the failure counter.
[ "Failure", "increments", "the", "failure", "counter", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L229-L232
15,540
docker/go-events
retry.go
backoff
func (b *ExponentialBackoff) backoff(failures uint64) time.Duration { if failures <= 0 { // proceed normally when there are no failures. return 0 } factor := b.config.Factor if factor <= 0 { factor = DefaultExponentialBackoffConfig.Factor } backoff := b.config.Base + factor*time.Duration(1<<(failures-1)) max := b.config.Max if max <= 0 { max = DefaultExponentialBackoffConfig.Max } if backoff > max || backoff < 0 { backoff = max } // Choose a uniformly distributed value from [0, backoff). return time.Duration(rand.Int63n(int64(backoff))) }
go
func (b *ExponentialBackoff) backoff(failures uint64) time.Duration { if failures <= 0 { // proceed normally when there are no failures. return 0 } factor := b.config.Factor if factor <= 0 { factor = DefaultExponentialBackoffConfig.Factor } backoff := b.config.Base + factor*time.Duration(1<<(failures-1)) max := b.config.Max if max <= 0 { max = DefaultExponentialBackoffConfig.Max } if backoff > max || backoff < 0 { backoff = max } // Choose a uniformly distributed value from [0, backoff). return time.Duration(rand.Int63n(int64(backoff))) }
[ "func", "(", "b", "*", "ExponentialBackoff", ")", "backoff", "(", "failures", "uint64", ")", "time", ".", "Duration", "{", "if", "failures", "<=", "0", "{", "// proceed normally when there are no failures.", "return", "0", "\n", "}", "\n\n", "factor", ":=", "b", ".", "config", ".", "Factor", "\n", "if", "factor", "<=", "0", "{", "factor", "=", "DefaultExponentialBackoffConfig", ".", "Factor", "\n", "}", "\n\n", "backoff", ":=", "b", ".", "config", ".", "Base", "+", "factor", "*", "time", ".", "Duration", "(", "1", "<<", "(", "failures", "-", "1", ")", ")", "\n\n", "max", ":=", "b", ".", "config", ".", "Max", "\n", "if", "max", "<=", "0", "{", "max", "=", "DefaultExponentialBackoffConfig", ".", "Max", "\n", "}", "\n\n", "if", "backoff", ">", "max", "||", "backoff", "<", "0", "{", "backoff", "=", "max", "\n", "}", "\n\n", "// Choose a uniformly distributed value from [0, backoff).", "return", "time", ".", "Duration", "(", "rand", ".", "Int63n", "(", "int64", "(", "backoff", ")", ")", ")", "\n", "}" ]
// backoff calculates the amount of time to wait based on the number of // consecutive failures.
[ "backoff", "calculates", "the", "amount", "of", "time", "to", "wait", "based", "on", "the", "number", "of", "consecutive", "failures", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/retry.go#L236-L260
15,541
docker/go-events
filter.go
NewFilter
func NewFilter(dst Sink, matcher Matcher) Sink { return &Filter{dst: dst, matcher: matcher} }
go
func NewFilter(dst Sink, matcher Matcher) Sink { return &Filter{dst: dst, matcher: matcher} }
[ "func", "NewFilter", "(", "dst", "Sink", ",", "matcher", "Matcher", ")", "Sink", "{", "return", "&", "Filter", "{", "dst", ":", "dst", ",", "matcher", ":", "matcher", "}", "\n", "}" ]
// NewFilter returns a new filter that will send to events to dst that return // true for Matcher.
[ "NewFilter", "returns", "a", "new", "filter", "that", "will", "send", "to", "events", "to", "dst", "that", "return", "true", "for", "Matcher", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/filter.go#L26-L28
15,542
docker/go-events
filter.go
Write
func (f *Filter) Write(event Event) error { if f.closed { return ErrSinkClosed } if f.matcher.Match(event) { return f.dst.Write(event) } return nil }
go
func (f *Filter) Write(event Event) error { if f.closed { return ErrSinkClosed } if f.matcher.Match(event) { return f.dst.Write(event) } return nil }
[ "func", "(", "f", "*", "Filter", ")", "Write", "(", "event", "Event", ")", "error", "{", "if", "f", ".", "closed", "{", "return", "ErrSinkClosed", "\n", "}", "\n\n", "if", "f", ".", "matcher", ".", "Match", "(", "event", ")", "{", "return", "f", ".", "dst", ".", "Write", "(", "event", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Write an event to the filter.
[ "Write", "an", "event", "to", "the", "filter", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/filter.go#L31-L41
15,543
docker/go-events
filter.go
Close
func (f *Filter) Close() error { // TODO(stevvooe): Not all sinks should have Close. if f.closed { return nil } f.closed = true return f.dst.Close() }
go
func (f *Filter) Close() error { // TODO(stevvooe): Not all sinks should have Close. if f.closed { return nil } f.closed = true return f.dst.Close() }
[ "func", "(", "f", "*", "Filter", ")", "Close", "(", ")", "error", "{", "// TODO(stevvooe): Not all sinks should have Close.", "if", "f", ".", "closed", "{", "return", "nil", "\n", "}", "\n\n", "f", ".", "closed", "=", "true", "\n", "return", "f", ".", "dst", ".", "Close", "(", ")", "\n", "}" ]
// Close the filter and allow no more events to pass through.
[ "Close", "the", "filter", "and", "allow", "no", "more", "events", "to", "pass", "through", "." ]
9461782956ad83b30282bf90e31fa6a70c255ba9
https://github.com/docker/go-events/blob/9461782956ad83b30282bf90e31fa6a70c255ba9/filter.go#L44-L52
15,544
pkg/math
uint8.go
MaxUint8N
func MaxUint8N(v ...uint8) uint8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint8(v[0], v[1]) default: l := len(v) / 2 return MaxUint8N(MaxUint8N(v[:l]...), MaxUint8N(v[l:]...)) } }
go
func MaxUint8N(v ...uint8) uint8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint8(v[0], v[1]) default: l := len(v) / 2 return MaxUint8N(MaxUint8N(v[:l]...), MaxUint8N(v[l:]...)) } }
[ "func", "MaxUint8N", "(", "v", "...", "uint8", ")", "uint8", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxUint8", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxUint8N", "(", "MaxUint8N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxUint8N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxUint8N returns the largest uint8 in the set provided. // If no values are provided, MaxUint8 returns 0.
[ "MaxUint8N", "returns", "the", "largest", "uint8", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxUint8", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint8.go#L21-L33
15,545
pkg/math
uint8.go
MinUint8N
func MinUint8N(v ...uint8) uint8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint8(v[0], v[1]) default: l := len(v) / 2 return MinUint8N(MinUint8N(v[:l]...), MinUint8N(v[l:]...)) } }
go
func MinUint8N(v ...uint8) uint8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint8(v[0], v[1]) default: l := len(v) / 2 return MinUint8N(MinUint8N(v[:l]...), MinUint8N(v[l:]...)) } }
[ "func", "MinUint8N", "(", "v", "...", "uint8", ")", "uint8", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinUint8", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinUint8N", "(", "MinUint8N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinUint8N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinUint8N returns the smallest uint8 in the set provided. // If no values are provided, MinUint8 returns 0.
[ "MinUint8N", "returns", "the", "smallest", "uint8", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinUint8", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint8.go#L37-L49
15,546
pkg/math
extra.go
MaxN
func MaxN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return Max(v[0], v[1]) default: l := len(v) / 2 return MaxN(MaxN(v[:l]...), MaxN(v[l:]...)) } }
go
func MaxN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return Max(v[0], v[1]) default: l := len(v) / 2 return MaxN(MaxN(v[:l]...), MaxN(v[l:]...)) } }
[ "func", "MaxN", "(", "v", "...", "int", ")", "int", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "Max", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxN", "(", "MaxN", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxN", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxN returns the largest int in the set provided. // If no values are provided, Max returns 0.
[ "MaxN", "returns", "the", "largest", "int", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "Max", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/extra.go#L21-L33
15,547
pkg/math
extra.go
MinN
func MinN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return Min(v[0], v[1]) default: l := len(v) / 2 return MinN(MinN(v[:l]...), MinN(v[l:]...)) } }
go
func MinN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return Min(v[0], v[1]) default: l := len(v) / 2 return MinN(MinN(v[:l]...), MinN(v[l:]...)) } }
[ "func", "MinN", "(", "v", "...", "int", ")", "int", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "Min", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinN", "(", "MinN", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinN", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinN returns the smallest int in the set provided. // If no values are provided, Min returns 0.
[ "MinN", "returns", "the", "smallest", "int", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "Min", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/extra.go#L37-L49
15,548
pkg/math
uint16.go
MaxUint16N
func MaxUint16N(v ...uint16) uint16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint16(v[0], v[1]) default: l := len(v) / 2 return MaxUint16N(MaxUint16N(v[:l]...), MaxUint16N(v[l:]...)) } }
go
func MaxUint16N(v ...uint16) uint16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint16(v[0], v[1]) default: l := len(v) / 2 return MaxUint16N(MaxUint16N(v[:l]...), MaxUint16N(v[l:]...)) } }
[ "func", "MaxUint16N", "(", "v", "...", "uint16", ")", "uint16", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxUint16", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxUint16N", "(", "MaxUint16N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxUint16N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxUint16N returns the largest uint16 in the set provided. // If no values are provided, MaxUint16 returns 0.
[ "MaxUint16N", "returns", "the", "largest", "uint16", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxUint16", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint16.go#L21-L33
15,549
pkg/math
uint16.go
MinUint16N
func MinUint16N(v ...uint16) uint16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint16(v[0], v[1]) default: l := len(v) / 2 return MinUint16N(MinUint16N(v[:l]...), MinUint16N(v[l:]...)) } }
go
func MinUint16N(v ...uint16) uint16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint16(v[0], v[1]) default: l := len(v) / 2 return MinUint16N(MinUint16N(v[:l]...), MinUint16N(v[l:]...)) } }
[ "func", "MinUint16N", "(", "v", "...", "uint16", ")", "uint16", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinUint16", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinUint16N", "(", "MinUint16N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinUint16N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinUint16N returns the smallest uint16 in the set provided. // If no values are provided, MinUint16 returns 0.
[ "MinUint16N", "returns", "the", "smallest", "uint16", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinUint16", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint16.go#L37-L49
15,550
pkg/math
int8.go
MaxInt8N
func MaxInt8N(v ...int8) int8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt8(v[0], v[1]) default: l := len(v) / 2 return MaxInt8N(MaxInt8N(v[:l]...), MaxInt8N(v[l:]...)) } }
go
func MaxInt8N(v ...int8) int8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt8(v[0], v[1]) default: l := len(v) / 2 return MaxInt8N(MaxInt8N(v[:l]...), MaxInt8N(v[l:]...)) } }
[ "func", "MaxInt8N", "(", "v", "...", "int8", ")", "int8", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxInt8", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxInt8N", "(", "MaxInt8N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxInt8N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxInt8N returns the largest int8 in the set provided. // If no values are provided, MaxInt8 returns 0.
[ "MaxInt8N", "returns", "the", "largest", "int8", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxInt8", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int8.go#L21-L33
15,551
pkg/math
int8.go
MinInt8N
func MinInt8N(v ...int8) int8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt8(v[0], v[1]) default: l := len(v) / 2 return MinInt8N(MinInt8N(v[:l]...), MinInt8N(v[l:]...)) } }
go
func MinInt8N(v ...int8) int8 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt8(v[0], v[1]) default: l := len(v) / 2 return MinInt8N(MinInt8N(v[:l]...), MinInt8N(v[l:]...)) } }
[ "func", "MinInt8N", "(", "v", "...", "int8", ")", "int8", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinInt8", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinInt8N", "(", "MinInt8N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinInt8N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinInt8N returns the smallest int8 in the set provided. // If no values are provided, MinInt8 returns 0.
[ "MinInt8N", "returns", "the", "smallest", "int8", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinInt8", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int8.go#L37-L49
15,552
pkg/math
int64.go
MaxInt64N
func MaxInt64N(v ...int64) int64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt64(v[0], v[1]) default: l := len(v) / 2 return MaxInt64N(MaxInt64N(v[:l]...), MaxInt64N(v[l:]...)) } }
go
func MaxInt64N(v ...int64) int64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt64(v[0], v[1]) default: l := len(v) / 2 return MaxInt64N(MaxInt64N(v[:l]...), MaxInt64N(v[l:]...)) } }
[ "func", "MaxInt64N", "(", "v", "...", "int64", ")", "int64", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxInt64", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxInt64N", "(", "MaxInt64N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxInt64N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxInt64N returns the largest int64 in the set provided. // If no values are provided, MaxInt64 returns 0.
[ "MaxInt64N", "returns", "the", "largest", "int64", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxInt64", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int64.go#L21-L33
15,553
pkg/math
int64.go
MinInt64N
func MinInt64N(v ...int64) int64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt64(v[0], v[1]) default: l := len(v) / 2 return MinInt64N(MinInt64N(v[:l]...), MinInt64N(v[l:]...)) } }
go
func MinInt64N(v ...int64) int64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt64(v[0], v[1]) default: l := len(v) / 2 return MinInt64N(MinInt64N(v[:l]...), MinInt64N(v[l:]...)) } }
[ "func", "MinInt64N", "(", "v", "...", "int64", ")", "int64", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinInt64", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinInt64N", "(", "MinInt64N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinInt64N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinInt64N returns the smallest int64 in the set provided. // If no values are provided, MinInt64 returns 0.
[ "MinInt64N", "returns", "the", "smallest", "int64", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinInt64", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int64.go#L37-L49
15,554
pkg/math
uint.go
MaxUintN
func MaxUintN(v ...uint) uint { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint(v[0], v[1]) default: l := len(v) / 2 return MaxUintN(MaxUintN(v[:l]...), MaxUintN(v[l:]...)) } }
go
func MaxUintN(v ...uint) uint { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint(v[0], v[1]) default: l := len(v) / 2 return MaxUintN(MaxUintN(v[:l]...), MaxUintN(v[l:]...)) } }
[ "func", "MaxUintN", "(", "v", "...", "uint", ")", "uint", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxUint", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxUintN", "(", "MaxUintN", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxUintN", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxUintN returns the largest uint in the set provided. // If no values are provided, MaxUint returns 0.
[ "MaxUintN", "returns", "the", "largest", "uint", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxUint", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint.go#L21-L33
15,555
pkg/math
uint.go
MinUintN
func MinUintN(v ...uint) uint { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint(v[0], v[1]) default: l := len(v) / 2 return MinUintN(MinUintN(v[:l]...), MinUintN(v[l:]...)) } }
go
func MinUintN(v ...uint) uint { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint(v[0], v[1]) default: l := len(v) / 2 return MinUintN(MinUintN(v[:l]...), MinUintN(v[l:]...)) } }
[ "func", "MinUintN", "(", "v", "...", "uint", ")", "uint", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinUint", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinUintN", "(", "MinUintN", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinUintN", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinUintN returns the smallest uint in the set provided. // If no values are provided, MinUint returns 0.
[ "MinUintN", "returns", "the", "smallest", "uint", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinUint", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint.go#L37-L49
15,556
pkg/math
int32.go
MaxInt32N
func MaxInt32N(v ...int32) int32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt32(v[0], v[1]) default: l := len(v) / 2 return MaxInt32N(MaxInt32N(v[:l]...), MaxInt32N(v[l:]...)) } }
go
func MaxInt32N(v ...int32) int32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt32(v[0], v[1]) default: l := len(v) / 2 return MaxInt32N(MaxInt32N(v[:l]...), MaxInt32N(v[l:]...)) } }
[ "func", "MaxInt32N", "(", "v", "...", "int32", ")", "int32", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxInt32", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxInt32N", "(", "MaxInt32N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxInt32N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxInt32N returns the largest int32 in the set provided. // If no values are provided, MaxInt32 returns 0.
[ "MaxInt32N", "returns", "the", "largest", "int32", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxInt32", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int32.go#L21-L33
15,557
pkg/math
int32.go
MinInt32N
func MinInt32N(v ...int32) int32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt32(v[0], v[1]) default: l := len(v) / 2 return MinInt32N(MinInt32N(v[:l]...), MinInt32N(v[l:]...)) } }
go
func MinInt32N(v ...int32) int32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt32(v[0], v[1]) default: l := len(v) / 2 return MinInt32N(MinInt32N(v[:l]...), MinInt32N(v[l:]...)) } }
[ "func", "MinInt32N", "(", "v", "...", "int32", ")", "int32", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinInt32", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinInt32N", "(", "MinInt32N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinInt32N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinInt32N returns the smallest int32 in the set provided. // If no values are provided, MinInt32 returns 0.
[ "MinInt32N", "returns", "the", "smallest", "int32", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinInt32", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int32.go#L37-L49
15,558
pkg/math
int.go
MaxIntN
func MaxIntN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt(v[0], v[1]) default: l := len(v) / 2 return MaxIntN(MaxIntN(v[:l]...), MaxIntN(v[l:]...)) } }
go
func MaxIntN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt(v[0], v[1]) default: l := len(v) / 2 return MaxIntN(MaxIntN(v[:l]...), MaxIntN(v[l:]...)) } }
[ "func", "MaxIntN", "(", "v", "...", "int", ")", "int", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxInt", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxIntN", "(", "MaxIntN", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxIntN", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxIntN returns the largest int in the set provided. // If no values are provided, MaxInt returns 0.
[ "MaxIntN", "returns", "the", "largest", "int", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxInt", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int.go#L21-L33
15,559
pkg/math
int.go
MinIntN
func MinIntN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt(v[0], v[1]) default: l := len(v) / 2 return MinIntN(MinIntN(v[:l]...), MinIntN(v[l:]...)) } }
go
func MinIntN(v ...int) int { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt(v[0], v[1]) default: l := len(v) / 2 return MinIntN(MinIntN(v[:l]...), MinIntN(v[l:]...)) } }
[ "func", "MinIntN", "(", "v", "...", "int", ")", "int", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinInt", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinIntN", "(", "MinIntN", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinIntN", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinIntN returns the smallest int in the set provided. // If no values are provided, MinInt returns 0.
[ "MinIntN", "returns", "the", "smallest", "int", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinInt", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int.go#L37-L49
15,560
pkg/math
uint64.go
MaxUint64N
func MaxUint64N(v ...uint64) uint64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint64(v[0], v[1]) default: l := len(v) / 2 return MaxUint64N(MaxUint64N(v[:l]...), MaxUint64N(v[l:]...)) } }
go
func MaxUint64N(v ...uint64) uint64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint64(v[0], v[1]) default: l := len(v) / 2 return MaxUint64N(MaxUint64N(v[:l]...), MaxUint64N(v[l:]...)) } }
[ "func", "MaxUint64N", "(", "v", "...", "uint64", ")", "uint64", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxUint64", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxUint64N", "(", "MaxUint64N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxUint64N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxUint64N returns the largest uint64 in the set provided. // If no values are provided, MaxUint64 returns 0.
[ "MaxUint64N", "returns", "the", "largest", "uint64", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxUint64", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint64.go#L21-L33
15,561
pkg/math
uint64.go
MinUint64N
func MinUint64N(v ...uint64) uint64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint64(v[0], v[1]) default: l := len(v) / 2 return MinUint64N(MinUint64N(v[:l]...), MinUint64N(v[l:]...)) } }
go
func MinUint64N(v ...uint64) uint64 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint64(v[0], v[1]) default: l := len(v) / 2 return MinUint64N(MinUint64N(v[:l]...), MinUint64N(v[l:]...)) } }
[ "func", "MinUint64N", "(", "v", "...", "uint64", ")", "uint64", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinUint64", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinUint64N", "(", "MinUint64N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinUint64N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinUint64N returns the smallest uint64 in the set provided. // If no values are provided, MinUint64 returns 0.
[ "MinUint64N", "returns", "the", "smallest", "uint64", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinUint64", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint64.go#L37-L49
15,562
pkg/math
uint32.go
MaxUint32N
func MaxUint32N(v ...uint32) uint32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint32(v[0], v[1]) default: l := len(v) / 2 return MaxUint32N(MaxUint32N(v[:l]...), MaxUint32N(v[l:]...)) } }
go
func MaxUint32N(v ...uint32) uint32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxUint32(v[0], v[1]) default: l := len(v) / 2 return MaxUint32N(MaxUint32N(v[:l]...), MaxUint32N(v[l:]...)) } }
[ "func", "MaxUint32N", "(", "v", "...", "uint32", ")", "uint32", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxUint32", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxUint32N", "(", "MaxUint32N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxUint32N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxUint32N returns the largest uint32 in the set provided. // If no values are provided, MaxUint32 returns 0.
[ "MaxUint32N", "returns", "the", "largest", "uint32", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxUint32", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint32.go#L21-L33
15,563
pkg/math
uint32.go
MinUint32N
func MinUint32N(v ...uint32) uint32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint32(v[0], v[1]) default: l := len(v) / 2 return MinUint32N(MinUint32N(v[:l]...), MinUint32N(v[l:]...)) } }
go
func MinUint32N(v ...uint32) uint32 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinUint32(v[0], v[1]) default: l := len(v) / 2 return MinUint32N(MinUint32N(v[:l]...), MinUint32N(v[l:]...)) } }
[ "func", "MinUint32N", "(", "v", "...", "uint32", ")", "uint32", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinUint32", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinUint32N", "(", "MinUint32N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinUint32N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinUint32N returns the smallest uint32 in the set provided. // If no values are provided, MinUint32 returns 0.
[ "MinUint32N", "returns", "the", "smallest", "uint32", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinUint32", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/uint32.go#L37-L49
15,564
pkg/math
int16.go
MaxInt16N
func MaxInt16N(v ...int16) int16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt16(v[0], v[1]) default: l := len(v) / 2 return MaxInt16N(MaxInt16N(v[:l]...), MaxInt16N(v[l:]...)) } }
go
func MaxInt16N(v ...int16) int16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MaxInt16(v[0], v[1]) default: l := len(v) / 2 return MaxInt16N(MaxInt16N(v[:l]...), MaxInt16N(v[l:]...)) } }
[ "func", "MaxInt16N", "(", "v", "...", "int16", ")", "int16", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MaxInt16", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MaxInt16N", "(", "MaxInt16N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MaxInt16N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MaxInt16N returns the largest int16 in the set provided. // If no values are provided, MaxInt16 returns 0.
[ "MaxInt16N", "returns", "the", "largest", "int16", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MaxInt16", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int16.go#L21-L33
15,565
pkg/math
int16.go
MinInt16N
func MinInt16N(v ...int16) int16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt16(v[0], v[1]) default: l := len(v) / 2 return MinInt16N(MinInt16N(v[:l]...), MinInt16N(v[l:]...)) } }
go
func MinInt16N(v ...int16) int16 { switch len(v) { case 0: return 0 case 1: return v[0] case 2: return MinInt16(v[0], v[1]) default: l := len(v) / 2 return MinInt16N(MinInt16N(v[:l]...), MinInt16N(v[l:]...)) } }
[ "func", "MinInt16N", "(", "v", "...", "int16", ")", "int16", "{", "switch", "len", "(", "v", ")", "{", "case", "0", ":", "return", "0", "\n", "case", "1", ":", "return", "v", "[", "0", "]", "\n", "case", "2", ":", "return", "MinInt16", "(", "v", "[", "0", "]", ",", "v", "[", "1", "]", ")", "\n", "default", ":", "l", ":=", "len", "(", "v", ")", "/", "2", "\n", "return", "MinInt16N", "(", "MinInt16N", "(", "v", "[", ":", "l", "]", "...", ")", ",", "MinInt16N", "(", "v", "[", "l", ":", "]", "...", ")", ")", "\n", "}", "\n", "}" ]
// MinInt16N returns the smallest int16 in the set provided. // If no values are provided, MinInt16 returns 0.
[ "MinInt16N", "returns", "the", "smallest", "int16", "in", "the", "set", "provided", ".", "If", "no", "values", "are", "provided", "MinInt16", "returns", "0", "." ]
f2ed9e40e245cdeec72c4b642d27ed4553f90667
https://github.com/pkg/math/blob/f2ed9e40e245cdeec72c4b642d27ed4553f90667/int16.go#L37-L49
15,566
martinlindhe/base36
base36.go
Encode
func Encode(value uint64) string { var res [16]byte var i int for i = len(res) - 1; value != 0; i-- { res[i] = base36[value%36] value /= 36 } return string(res[i+1:]) }
go
func Encode(value uint64) string { var res [16]byte var i int for i = len(res) - 1; value != 0; i-- { res[i] = base36[value%36] value /= 36 } return string(res[i+1:]) }
[ "func", "Encode", "(", "value", "uint64", ")", "string", "{", "var", "res", "[", "16", "]", "byte", "\n", "var", "i", "int", "\n", "for", "i", "=", "len", "(", "res", ")", "-", "1", ";", "value", "!=", "0", ";", "i", "--", "{", "res", "[", "i", "]", "=", "base36", "[", "value", "%", "36", "]", "\n", "value", "/=", "36", "\n", "}", "\n", "return", "string", "(", "res", "[", "i", "+", "1", ":", "]", ")", "\n", "}" ]
// Encode encodes a number to base36.
[ "Encode", "encodes", "a", "number", "to", "base36", "." ]
7c6542dfbb41505111dde1f321eb5d5002f5fb88
https://github.com/martinlindhe/base36/blob/7c6542dfbb41505111dde1f321eb5d5002f5fb88/base36.go#L35-L43
15,567
martinlindhe/base36
base36.go
Decode
func Decode(s string) uint64 { res := uint64(0) l := len(s) - 1 for idx := range s { c := s[l-idx] res += uint64(index[c]) * uint64(math.Pow(36, float64(idx))) } return res }
go
func Decode(s string) uint64 { res := uint64(0) l := len(s) - 1 for idx := range s { c := s[l-idx] res += uint64(index[c]) * uint64(math.Pow(36, float64(idx))) } return res }
[ "func", "Decode", "(", "s", "string", ")", "uint64", "{", "res", ":=", "uint64", "(", "0", ")", "\n", "l", ":=", "len", "(", "s", ")", "-", "1", "\n", "for", "idx", ":=", "range", "s", "{", "c", ":=", "s", "[", "l", "-", "idx", "]", "\n", "res", "+=", "uint64", "(", "index", "[", "c", "]", ")", "*", "uint64", "(", "math", ".", "Pow", "(", "36", ",", "float64", "(", "idx", ")", ")", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// Decode decodes a base36-encoded string.
[ "Decode", "decodes", "a", "base36", "-", "encoded", "string", "." ]
7c6542dfbb41505111dde1f321eb5d5002f5fb88
https://github.com/martinlindhe/base36/blob/7c6542dfbb41505111dde1f321eb5d5002f5fb88/base36.go#L46-L54
15,568
martinlindhe/base36
base36.go
DecodeToBytes
func DecodeToBytes(b string) []byte { alphabet := string(base36) answer := big.NewInt(0) j := big.NewInt(1) for i := len(b) - 1; i >= 0; i-- { tmp := strings.IndexAny(alphabet, string(b[i])) if tmp == -1 { return []byte("") } idx := big.NewInt(int64(tmp)) tmp1 := big.NewInt(0) tmp1.Mul(j, idx) answer.Add(answer, tmp1) j.Mul(j, bigRadix) } tmpval := answer.Bytes() var numZeros int for numZeros = 0; numZeros < len(b); numZeros++ { if b[numZeros] != alphabet[0] { break } } flen := numZeros + len(tmpval) val := make([]byte, flen, flen) copy(val[numZeros:], tmpval) return val }
go
func DecodeToBytes(b string) []byte { alphabet := string(base36) answer := big.NewInt(0) j := big.NewInt(1) for i := len(b) - 1; i >= 0; i-- { tmp := strings.IndexAny(alphabet, string(b[i])) if tmp == -1 { return []byte("") } idx := big.NewInt(int64(tmp)) tmp1 := big.NewInt(0) tmp1.Mul(j, idx) answer.Add(answer, tmp1) j.Mul(j, bigRadix) } tmpval := answer.Bytes() var numZeros int for numZeros = 0; numZeros < len(b); numZeros++ { if b[numZeros] != alphabet[0] { break } } flen := numZeros + len(tmpval) val := make([]byte, flen, flen) copy(val[numZeros:], tmpval) return val }
[ "func", "DecodeToBytes", "(", "b", "string", ")", "[", "]", "byte", "{", "alphabet", ":=", "string", "(", "base36", ")", "\n", "answer", ":=", "big", ".", "NewInt", "(", "0", ")", "\n", "j", ":=", "big", ".", "NewInt", "(", "1", ")", "\n\n", "for", "i", ":=", "len", "(", "b", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "tmp", ":=", "strings", ".", "IndexAny", "(", "alphabet", ",", "string", "(", "b", "[", "i", "]", ")", ")", "\n", "if", "tmp", "==", "-", "1", "{", "return", "[", "]", "byte", "(", "\"", "\"", ")", "\n", "}", "\n", "idx", ":=", "big", ".", "NewInt", "(", "int64", "(", "tmp", ")", ")", "\n", "tmp1", ":=", "big", ".", "NewInt", "(", "0", ")", "\n", "tmp1", ".", "Mul", "(", "j", ",", "idx", ")", "\n\n", "answer", ".", "Add", "(", "answer", ",", "tmp1", ")", "\n", "j", ".", "Mul", "(", "j", ",", "bigRadix", ")", "\n", "}", "\n\n", "tmpval", ":=", "answer", ".", "Bytes", "(", ")", "\n\n", "var", "numZeros", "int", "\n", "for", "numZeros", "=", "0", ";", "numZeros", "<", "len", "(", "b", ")", ";", "numZeros", "++", "{", "if", "b", "[", "numZeros", "]", "!=", "alphabet", "[", "0", "]", "{", "break", "\n", "}", "\n", "}", "\n", "flen", ":=", "numZeros", "+", "len", "(", "tmpval", ")", "\n", "val", ":=", "make", "(", "[", "]", "byte", ",", "flen", ",", "flen", ")", "\n", "copy", "(", "val", "[", "numZeros", ":", "]", ",", "tmpval", ")", "\n\n", "return", "val", "\n", "}" ]
// DecodeToBytes decodes a base36 string to a byte slice, using alphabet.
[ "DecodeToBytes", "decodes", "a", "base36", "string", "to", "a", "byte", "slice", "using", "alphabet", "." ]
7c6542dfbb41505111dde1f321eb5d5002f5fb88
https://github.com/martinlindhe/base36/blob/7c6542dfbb41505111dde1f321eb5d5002f5fb88/base36.go#L94-L125
15,569
wsxiaoys/terminal
color/color.go
Colorize
func Colorize(x string) string { attr := 0 fg := 39 bg := 49 for _, key := range x { c, ok := codeMap[int(key)] switch { case !ok: log.Printf("Wrong color syntax: %c", key) case 0 <= c && c <= 8: attr = c case 30 <= c && c <= 37: fg = c case 40 <= c && c <= 47: bg = c case c == 60: fg += c } } return fmt.Sprintf("\033[%d;%d;%dm", attr, fg, bg) }
go
func Colorize(x string) string { attr := 0 fg := 39 bg := 49 for _, key := range x { c, ok := codeMap[int(key)] switch { case !ok: log.Printf("Wrong color syntax: %c", key) case 0 <= c && c <= 8: attr = c case 30 <= c && c <= 37: fg = c case 40 <= c && c <= 47: bg = c case c == 60: fg += c } } return fmt.Sprintf("\033[%d;%d;%dm", attr, fg, bg) }
[ "func", "Colorize", "(", "x", "string", ")", "string", "{", "attr", ":=", "0", "\n", "fg", ":=", "39", "\n", "bg", ":=", "49", "\n\n", "for", "_", ",", "key", ":=", "range", "x", "{", "c", ",", "ok", ":=", "codeMap", "[", "int", "(", "key", ")", "]", "\n", "switch", "{", "case", "!", "ok", ":", "log", ".", "Printf", "(", "\"", "\"", ",", "key", ")", "\n", "case", "0", "<=", "c", "&&", "c", "<=", "8", ":", "attr", "=", "c", "\n", "case", "30", "<=", "c", "&&", "c", "<=", "37", ":", "fg", "=", "c", "\n", "case", "40", "<=", "c", "&&", "c", "<=", "47", ":", "bg", "=", "c", "\n", "case", "c", "==", "60", ":", "fg", "+=", "c", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\\033", "\"", ",", "attr", ",", "fg", ",", "bg", ")", "\n", "}" ]
// Compile color syntax string like "rG" to escape code.
[ "Compile", "color", "syntax", "string", "like", "rG", "to", "escape", "code", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L79-L100
15,570
wsxiaoys/terminal
color/color.go
compileColorSyntax
func compileColorSyntax(input, output *bytes.Buffer) { i, _, err := input.ReadRune() if err != nil { // EOF got log.Print("Parse failed on color syntax") return } switch i { default: output.WriteString(Colorize(string(i))) case '{': color := bytes.NewBufferString("") for { i, _, err := input.ReadRune() if err != nil { log.Print("Parse failed on color syntax") break } if i == '}' { break } color.WriteRune(i) } output.WriteString(Colorize(color.String())) case EscapeChar: output.WriteRune(EscapeChar) } }
go
func compileColorSyntax(input, output *bytes.Buffer) { i, _, err := input.ReadRune() if err != nil { // EOF got log.Print("Parse failed on color syntax") return } switch i { default: output.WriteString(Colorize(string(i))) case '{': color := bytes.NewBufferString("") for { i, _, err := input.ReadRune() if err != nil { log.Print("Parse failed on color syntax") break } if i == '}' { break } color.WriteRune(i) } output.WriteString(Colorize(color.String())) case EscapeChar: output.WriteRune(EscapeChar) } }
[ "func", "compileColorSyntax", "(", "input", ",", "output", "*", "bytes", ".", "Buffer", ")", "{", "i", ",", "_", ",", "err", ":=", "input", ".", "ReadRune", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// EOF got", "log", ".", "Print", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "switch", "i", "{", "default", ":", "output", ".", "WriteString", "(", "Colorize", "(", "string", "(", "i", ")", ")", ")", "\n", "case", "'{'", ":", "color", ":=", "bytes", ".", "NewBufferString", "(", "\"", "\"", ")", "\n", "for", "{", "i", ",", "_", ",", "err", ":=", "input", ".", "ReadRune", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Print", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "if", "i", "==", "'}'", "{", "break", "\n", "}", "\n", "color", ".", "WriteRune", "(", "i", ")", "\n", "}", "\n", "output", ".", "WriteString", "(", "Colorize", "(", "color", ".", "String", "(", ")", ")", ")", "\n", "case", "EscapeChar", ":", "output", ".", "WriteRune", "(", "EscapeChar", ")", "\n", "}", "\n", "}" ]
// Handle state after meeting one '@'
[ "Handle", "state", "after", "meeting", "one" ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L103-L131
15,571
wsxiaoys/terminal
color/color.go
compile
func compile(x string) string { if x == "" { return "" } input := bytes.NewBufferString(x) output := bytes.NewBufferString("") for { i, _, err := input.ReadRune() if err != nil { break } switch i { default: output.WriteRune(i) case EscapeChar: compileColorSyntax(input, output) } } return output.String() }
go
func compile(x string) string { if x == "" { return "" } input := bytes.NewBufferString(x) output := bytes.NewBufferString("") for { i, _, err := input.ReadRune() if err != nil { break } switch i { default: output.WriteRune(i) case EscapeChar: compileColorSyntax(input, output) } } return output.String() }
[ "func", "compile", "(", "x", "string", ")", "string", "{", "if", "x", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n\n", "input", ":=", "bytes", ".", "NewBufferString", "(", "x", ")", "\n", "output", ":=", "bytes", ".", "NewBufferString", "(", "\"", "\"", ")", "\n\n", "for", "{", "i", ",", "_", ",", "err", ":=", "input", ".", "ReadRune", "(", ")", "\n", "if", "err", "!=", "nil", "{", "break", "\n", "}", "\n", "switch", "i", "{", "default", ":", "output", ".", "WriteRune", "(", "i", ")", "\n", "case", "EscapeChar", ":", "compileColorSyntax", "(", "input", ",", "output", ")", "\n", "}", "\n", "}", "\n", "return", "output", ".", "String", "(", ")", "\n", "}" ]
// Compile the string and replace color syntax with concrete escape code.
[ "Compile", "the", "string", "and", "replace", "color", "syntax", "with", "concrete", "escape", "code", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L134-L155
15,572
wsxiaoys/terminal
color/color.go
compileValues
func compileValues(a *[]interface{}) { for i, x := range *a { if str, ok := x.(string); ok { (*a)[i] = compile(str) } } }
go
func compileValues(a *[]interface{}) { for i, x := range *a { if str, ok := x.(string); ok { (*a)[i] = compile(str) } } }
[ "func", "compileValues", "(", "a", "*", "[", "]", "interface", "{", "}", ")", "{", "for", "i", ",", "x", ":=", "range", "*", "a", "{", "if", "str", ",", "ok", ":=", "x", ".", "(", "string", ")", ";", "ok", "{", "(", "*", "a", ")", "[", "i", "]", "=", "compile", "(", "str", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Compile multiple values, only do compiling on string type.
[ "Compile", "multiple", "values", "only", "do", "compiling", "on", "string", "type", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L158-L164
15,573
wsxiaoys/terminal
color/color.go
Print
func Print(a ...interface{}) (int, error) { a = append(a, ResetCode) compileValues(&a) return fmt.Print(a...) }
go
func Print(a ...interface{}) (int, error) { a = append(a, ResetCode) compileValues(&a) return fmt.Print(a...) }
[ "func", "Print", "(", "a", "...", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "a", "=", "append", "(", "a", ",", "ResetCode", ")", "\n", "compileValues", "(", "&", "a", ")", "\n", "return", "fmt", ".", "Print", "(", "a", "...", ")", "\n", "}" ]
// Similar to fmt.Print, will reset the color at the end.
[ "Similar", "to", "fmt", ".", "Print", "will", "reset", "the", "color", "at", "the", "end", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L167-L171
15,574
wsxiaoys/terminal
color/color.go
Println
func Println(a ...interface{}) (int, error) { a = append(a, ResetCode) compileValues(&a) return fmt.Println(a...) }
go
func Println(a ...interface{}) (int, error) { a = append(a, ResetCode) compileValues(&a) return fmt.Println(a...) }
[ "func", "Println", "(", "a", "...", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "a", "=", "append", "(", "a", ",", "ResetCode", ")", "\n", "compileValues", "(", "&", "a", ")", "\n", "return", "fmt", ".", "Println", "(", "a", "...", ")", "\n", "}" ]
// Similar to fmt.Println, will reset the color at the end.
[ "Similar", "to", "fmt", ".", "Println", "will", "reset", "the", "color", "at", "the", "end", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L174-L178
15,575
wsxiaoys/terminal
color/color.go
Printf
func Printf(format string, a ...interface{}) (int, error) { format += ResetCode format = compile(format) return fmt.Printf(format, a...) }
go
func Printf(format string, a ...interface{}) (int, error) { format += ResetCode format = compile(format) return fmt.Printf(format, a...) }
[ "func", "Printf", "(", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "format", "+=", "ResetCode", "\n", "format", "=", "compile", "(", "format", ")", "\n", "return", "fmt", ".", "Printf", "(", "format", ",", "a", "...", ")", "\n", "}" ]
// Similar to fmt.Printf, will reset the color at the end.
[ "Similar", "to", "fmt", ".", "Printf", "will", "reset", "the", "color", "at", "the", "end", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L181-L185
15,576
wsxiaoys/terminal
color/color.go
Fprint
func Fprint(w io.Writer, a ...interface{}) (int, error) { a = append(a, ResetCode) compileValues(&a) return fmt.Fprint(w, a...) }
go
func Fprint(w io.Writer, a ...interface{}) (int, error) { a = append(a, ResetCode) compileValues(&a) return fmt.Fprint(w, a...) }
[ "func", "Fprint", "(", "w", "io", ".", "Writer", ",", "a", "...", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "a", "=", "append", "(", "a", ",", "ResetCode", ")", "\n", "compileValues", "(", "&", "a", ")", "\n", "return", "fmt", ".", "Fprint", "(", "w", ",", "a", "...", ")", "\n", "}" ]
// Similar to fmt.Fprint, will reset the color at the end.
[ "Similar", "to", "fmt", ".", "Fprint", "will", "reset", "the", "color", "at", "the", "end", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L188-L192
15,577
wsxiaoys/terminal
color/color.go
Fprintf
func Fprintf(w io.Writer, format string, a ...interface{}) (int, error) { format += ResetCode format = compile(format) return fmt.Fprintf(w, format, a...) }
go
func Fprintf(w io.Writer, format string, a ...interface{}) (int, error) { format += ResetCode format = compile(format) return fmt.Fprintf(w, format, a...) }
[ "func", "Fprintf", "(", "w", "io", ".", "Writer", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "format", "+=", "ResetCode", "\n", "format", "=", "compile", "(", "format", ")", "\n", "return", "fmt", ".", "Fprintf", "(", "w", ",", "format", ",", "a", "...", ")", "\n", "}" ]
// Similar to fmt.Fprintf, will reset the color at the end.
[ "Similar", "to", "fmt", ".", "Fprintf", "will", "reset", "the", "color", "at", "the", "end", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L202-L206
15,578
wsxiaoys/terminal
color/color.go
Sprint
func Sprint(a ...interface{}) string { a = append(a, ResetCode) compileValues(&a) return fmt.Sprint(a...) }
go
func Sprint(a ...interface{}) string { a = append(a, ResetCode) compileValues(&a) return fmt.Sprint(a...) }
[ "func", "Sprint", "(", "a", "...", "interface", "{", "}", ")", "string", "{", "a", "=", "append", "(", "a", ",", "ResetCode", ")", "\n", "compileValues", "(", "&", "a", ")", "\n", "return", "fmt", ".", "Sprint", "(", "a", "...", ")", "\n", "}" ]
// Similar to fmt.Sprint, will reset the color at the end.
[ "Similar", "to", "fmt", ".", "Sprint", "will", "reset", "the", "color", "at", "the", "end", "." ]
0940f3fc43a0ed42d04916b1c04578462c650b09
https://github.com/wsxiaoys/terminal/blob/0940f3fc43a0ed42d04916b1c04578462c650b09/color/color.go#L209-L213
15,579
guelfey/go.dbus
conn.go
SystemBusPrivate
func SystemBusPrivate() (*Conn, error) { address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS") if address != "" { return Dial(address) } return Dial(defaultSystemBusAddress) }
go
func SystemBusPrivate() (*Conn, error) { address := os.Getenv("DBUS_SYSTEM_BUS_ADDRESS") if address != "" { return Dial(address) } return Dial(defaultSystemBusAddress) }
[ "func", "SystemBusPrivate", "(", ")", "(", "*", "Conn", ",", "error", ")", "{", "address", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "address", "!=", "\"", "\"", "{", "return", "Dial", "(", "address", ")", "\n", "}", "\n", "return", "Dial", "(", "defaultSystemBusAddress", ")", "\n", "}" ]
// SystemBusPrivate returns a new private connection to the system bus.
[ "SystemBusPrivate", "returns", "a", "new", "private", "connection", "to", "the", "system", "bus", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L132-L138
15,580
guelfey/go.dbus
conn.go
Dial
func Dial(address string) (*Conn, error) { tr, err := getTransport(address) if err != nil { return nil, err } return newConn(tr) }
go
func Dial(address string) (*Conn, error) { tr, err := getTransport(address) if err != nil { return nil, err } return newConn(tr) }
[ "func", "Dial", "(", "address", "string", ")", "(", "*", "Conn", ",", "error", ")", "{", "tr", ",", "err", ":=", "getTransport", "(", "address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "newConn", "(", "tr", ")", "\n", "}" ]
// Dial establishes a new private connection to the message bus specified by address.
[ "Dial", "establishes", "a", "new", "private", "connection", "to", "the", "message", "bus", "specified", "by", "address", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L141-L147
15,581
guelfey/go.dbus
conn.go
getSerial
func (conn *Conn) getSerial() uint32 { conn.serialLck.Lock() defer conn.serialLck.Unlock() n := conn.nextSerial for conn.serialUsed[n] { n++ } conn.serialUsed[n] = true conn.nextSerial = n + 1 return n }
go
func (conn *Conn) getSerial() uint32 { conn.serialLck.Lock() defer conn.serialLck.Unlock() n := conn.nextSerial for conn.serialUsed[n] { n++ } conn.serialUsed[n] = true conn.nextSerial = n + 1 return n }
[ "func", "(", "conn", "*", "Conn", ")", "getSerial", "(", ")", "uint32", "{", "conn", ".", "serialLck", ".", "Lock", "(", ")", "\n", "defer", "conn", ".", "serialLck", ".", "Unlock", "(", ")", "\n", "n", ":=", "conn", ".", "nextSerial", "\n", "for", "conn", ".", "serialUsed", "[", "n", "]", "{", "n", "++", "\n", "}", "\n", "conn", ".", "serialUsed", "[", "n", "]", "=", "true", "\n", "conn", ".", "nextSerial", "=", "n", "+", "1", "\n", "return", "n", "\n", "}" ]
// getSerial returns an unused serial.
[ "getSerial", "returns", "an", "unused", "serial", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L209-L219
15,582
guelfey/go.dbus
conn.go
Names
func (conn *Conn) Names() []string { conn.namesLck.RLock() // copy the slice so it can't be modified s := make([]string, len(conn.names)) copy(s, conn.names) conn.namesLck.RUnlock() return s }
go
func (conn *Conn) Names() []string { conn.namesLck.RLock() // copy the slice so it can't be modified s := make([]string, len(conn.names)) copy(s, conn.names) conn.namesLck.RUnlock() return s }
[ "func", "(", "conn", "*", "Conn", ")", "Names", "(", ")", "[", "]", "string", "{", "conn", ".", "namesLck", ".", "RLock", "(", ")", "\n", "// copy the slice so it can't be modified", "s", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "conn", ".", "names", ")", ")", "\n", "copy", "(", "s", ",", "conn", ".", "names", ")", "\n", "conn", ".", "namesLck", ".", "RUnlock", "(", ")", "\n", "return", "s", "\n", "}" ]
// Names returns the list of all names that are currently owned by this // connection. The slice is always at least one element long, the first element // being the unique name of the connection.
[ "Names", "returns", "the", "list", "of", "all", "names", "that", "are", "currently", "owned", "by", "this", "connection", ".", "The", "slice", "is", "always", "at", "least", "one", "element", "long", "the", "first", "element", "being", "the", "unique", "name", "of", "the", "connection", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L350-L357
15,583
guelfey/go.dbus
conn.go
Object
func (conn *Conn) Object(dest string, path ObjectPath) *Object { return &Object{conn, dest, path} }
go
func (conn *Conn) Object(dest string, path ObjectPath) *Object { return &Object{conn, dest, path} }
[ "func", "(", "conn", "*", "Conn", ")", "Object", "(", "dest", "string", ",", "path", "ObjectPath", ")", "*", "Object", "{", "return", "&", "Object", "{", "conn", ",", "dest", ",", "path", "}", "\n", "}" ]
// Object returns the object identified by the given destination name and path.
[ "Object", "returns", "the", "object", "identified", "by", "the", "given", "destination", "name", "and", "path", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L360-L362
15,584
guelfey/go.dbus
conn.go
outWorker
func (conn *Conn) outWorker() { for msg := range conn.out { err := conn.SendMessage(msg) conn.callsLck.RLock() if err != nil { if c := conn.calls[msg.serial]; c != nil { c.Err = err c.Done <- c } conn.serialLck.Lock() delete(conn.serialUsed, msg.serial) conn.serialLck.Unlock() } else if msg.Type != TypeMethodCall { conn.serialLck.Lock() delete(conn.serialUsed, msg.serial) conn.serialLck.Unlock() } conn.callsLck.RUnlock() } }
go
func (conn *Conn) outWorker() { for msg := range conn.out { err := conn.SendMessage(msg) conn.callsLck.RLock() if err != nil { if c := conn.calls[msg.serial]; c != nil { c.Err = err c.Done <- c } conn.serialLck.Lock() delete(conn.serialUsed, msg.serial) conn.serialLck.Unlock() } else if msg.Type != TypeMethodCall { conn.serialLck.Lock() delete(conn.serialUsed, msg.serial) conn.serialLck.Unlock() } conn.callsLck.RUnlock() } }
[ "func", "(", "conn", "*", "Conn", ")", "outWorker", "(", ")", "{", "for", "msg", ":=", "range", "conn", ".", "out", "{", "err", ":=", "conn", ".", "SendMessage", "(", "msg", ")", "\n", "conn", ".", "callsLck", ".", "RLock", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "c", ":=", "conn", ".", "calls", "[", "msg", ".", "serial", "]", ";", "c", "!=", "nil", "{", "c", ".", "Err", "=", "err", "\n", "c", ".", "Done", "<-", "c", "\n", "}", "\n", "conn", ".", "serialLck", ".", "Lock", "(", ")", "\n", "delete", "(", "conn", ".", "serialUsed", ",", "msg", ".", "serial", ")", "\n", "conn", ".", "serialLck", ".", "Unlock", "(", ")", "\n", "}", "else", "if", "msg", ".", "Type", "!=", "TypeMethodCall", "{", "conn", ".", "serialLck", ".", "Lock", "(", ")", "\n", "delete", "(", "conn", ".", "serialUsed", ",", "msg", ".", "serial", ")", "\n", "conn", ".", "serialLck", ".", "Unlock", "(", ")", "\n", "}", "\n", "conn", ".", "callsLck", ".", "RUnlock", "(", ")", "\n", "}", "\n", "}" ]
// outWorker runs in an own goroutine, encoding and sending messages that are // sent to conn.out.
[ "outWorker", "runs", "in", "an", "own", "goroutine", "encoding", "and", "sending", "messages", "that", "are", "sent", "to", "conn", ".", "out", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L366-L385
15,585
guelfey/go.dbus
conn.go
Signal
func (conn *Conn) Signal(ch chan<- *Signal) { conn.signalsLck.Lock() conn.signals = append(conn.signals, ch) conn.signalsLck.Unlock() }
go
func (conn *Conn) Signal(ch chan<- *Signal) { conn.signalsLck.Lock() conn.signals = append(conn.signals, ch) conn.signalsLck.Unlock() }
[ "func", "(", "conn", "*", "Conn", ")", "Signal", "(", "ch", "chan", "<-", "*", "Signal", ")", "{", "conn", ".", "signalsLck", ".", "Lock", "(", ")", "\n", "conn", ".", "signals", "=", "append", "(", "conn", ".", "signals", ",", "ch", ")", "\n", "conn", ".", "signalsLck", ".", "Unlock", "(", ")", "\n", "}" ]
// Signal registers the given channel to be passed all received signal messages. // The caller has to make sure that ch is sufficiently buffered; if a message // arrives when a write to c is not possible, it is discarded. // // Multiple of these channels can be registered at the same time. Passing a // channel that already is registered will remove it from the list of the // registered channels. // // These channels are "overwritten" by Eavesdrop; i.e., if there currently is a // channel for eavesdropped messages, this channel receives all signals, and // none of the channels passed to Signal will receive any signals.
[ "Signal", "registers", "the", "given", "channel", "to", "be", "passed", "all", "received", "signal", "messages", ".", "The", "caller", "has", "to", "make", "sure", "that", "ch", "is", "sufficiently", "buffered", ";", "if", "a", "message", "arrives", "when", "a", "write", "to", "c", "is", "not", "possible", "it", "is", "discarded", ".", "Multiple", "of", "these", "channels", "can", "be", "registered", "at", "the", "same", "time", ".", "Passing", "a", "channel", "that", "already", "is", "registered", "will", "remove", "it", "from", "the", "list", "of", "the", "registered", "channels", ".", "These", "channels", "are", "overwritten", "by", "Eavesdrop", ";", "i", ".", "e", ".", "if", "there", "currently", "is", "a", "channel", "for", "eavesdropped", "messages", "this", "channel", "receives", "all", "signals", "and", "none", "of", "the", "channels", "passed", "to", "Signal", "will", "receive", "any", "signals", "." ]
f6a3a2366cc39b8479cadc499d3c735fb10fbdda
https://github.com/guelfey/go.dbus/blob/f6a3a2366cc39b8479cadc499d3c735fb10fbdda/conn.go#L487-L491
15,586
sethgrid/curse
curse.go
GetScreenDimensions
func GetScreenDimensions() (cols int, lines int, err error) { ws, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ) if err != nil { return -1, -1, err } return int(ws.Col), int(ws.Row), nil }
go
func GetScreenDimensions() (cols int, lines int, err error) { ws, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ) if err != nil { return -1, -1, err } return int(ws.Col), int(ws.Row), nil }
[ "func", "GetScreenDimensions", "(", ")", "(", "cols", "int", ",", "lines", "int", ",", "err", "error", ")", "{", "ws", ",", "err", ":=", "unix", ".", "IoctlGetWinsize", "(", "0", ",", "unix", ".", "TIOCGWINSZ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "-", "1", ",", "err", "\n", "}", "\n", "return", "int", "(", "ws", ".", "Col", ")", ",", "int", "(", "ws", ".", "Row", ")", ",", "nil", "\n", "}" ]
// using named returns to help when using the method to know what is what
[ "using", "named", "returns", "to", "help", "when", "using", "the", "method", "to", "know", "what", "is", "what" ]
d4ee583ebf0f588f3594a262c5e2726ddebda2cc
https://github.com/sethgrid/curse/blob/d4ee583ebf0f588f3594a262c5e2726ddebda2cc/curse.go#L146-L152
15,587
patrickmn/sortutil
getter.go
SimpleGetter
func SimpleGetter() Getter { return func(s reflect.Value) []reflect.Value { vals := valueSlice(s.Len()) for i := range vals { vals[i] = reflect.Indirect(reflect.Indirect(s.Index(i))) } return vals } }
go
func SimpleGetter() Getter { return func(s reflect.Value) []reflect.Value { vals := valueSlice(s.Len()) for i := range vals { vals[i] = reflect.Indirect(reflect.Indirect(s.Index(i))) } return vals } }
[ "func", "SimpleGetter", "(", ")", "Getter", "{", "return", "func", "(", "s", "reflect", ".", "Value", ")", "[", "]", "reflect", ".", "Value", "{", "vals", ":=", "valueSlice", "(", "s", ".", "Len", "(", ")", ")", "\n", "for", "i", ":=", "range", "vals", "{", "vals", "[", "i", "]", "=", "reflect", ".", "Indirect", "(", "reflect", ".", "Indirect", "(", "s", ".", "Index", "(", "i", ")", ")", ")", "\n", "}", "\n", "return", "vals", "\n", "}", "\n", "}" ]
// Returns a Getter which returns the values from a reflect.Value for a // slice. This is the default Getter used if none is passed to Sort.
[ "Returns", "a", "Getter", "which", "returns", "the", "values", "from", "a", "reflect", ".", "Value", "for", "a", "slice", ".", "This", "is", "the", "default", "Getter", "used", "if", "none", "is", "passed", "to", "Sort", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/getter.go#L20-L28
15,588
patrickmn/sortutil
sortutil.go
Swap
func (s *Sorter) Swap(i, j int) { x := s.Slice.Index(i) y := s.Slice.Index(j) tmp := reflect.New(s.itemType).Elem() tmp.Set(x) x.Set(y) y.Set(tmp) }
go
func (s *Sorter) Swap(i, j int) { x := s.Slice.Index(i) y := s.Slice.Index(j) tmp := reflect.New(s.itemType).Elem() tmp.Set(x) x.Set(y) y.Set(tmp) }
[ "func", "(", "s", "*", "Sorter", ")", "Swap", "(", "i", ",", "j", "int", ")", "{", "x", ":=", "s", ".", "Slice", ".", "Index", "(", "i", ")", "\n", "y", ":=", "s", ".", "Slice", ".", "Index", "(", "j", ")", "\n", "tmp", ":=", "reflect", ".", "New", "(", "s", ".", "itemType", ")", ".", "Elem", "(", ")", "\n", "tmp", ".", "Set", "(", "x", ")", "\n", "x", ".", "Set", "(", "y", ")", "\n", "y", ".", "Set", "(", "tmp", ")", "\n", "}" ]
// Swaps two indices in the slice being sorted.
[ "Swaps", "two", "indices", "in", "the", "slice", "being", "sorted", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L147-L154
15,589
patrickmn/sortutil
sortutil.go
New
func New(slice interface{}, getter Getter, ordering Ordering) *Sorter { v := reflect.ValueOf(slice) return &Sorter{ Slice: v, Getter: getter, Ordering: ordering, } }
go
func New(slice interface{}, getter Getter, ordering Ordering) *Sorter { v := reflect.ValueOf(slice) return &Sorter{ Slice: v, Getter: getter, Ordering: ordering, } }
[ "func", "New", "(", "slice", "interface", "{", "}", ",", "getter", "Getter", ",", "ordering", "Ordering", ")", "*", "Sorter", "{", "v", ":=", "reflect", ".", "ValueOf", "(", "slice", ")", "\n", "return", "&", "Sorter", "{", "Slice", ":", "v", ",", "Getter", ":", "getter", ",", "Ordering", ":", "ordering", ",", "}", "\n", "}" ]
// Returns a Sorter for a slice which will sort according to the // items retrieved by getter, in the given ordering.
[ "Returns", "a", "Sorter", "for", "a", "slice", "which", "will", "sort", "according", "to", "the", "items", "retrieved", "by", "getter", "in", "the", "given", "ordering", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L232-L239
15,590
patrickmn/sortutil
sortutil.go
AscByField
func AscByField(slice interface{}, name string) { New(slice, FieldGetter(name), Ascending).Sort() }
go
func AscByField(slice interface{}, name string) { New(slice, FieldGetter(name), Ascending).Sort() }
[ "func", "AscByField", "(", "slice", "interface", "{", "}", ",", "name", "string", ")", "{", "New", "(", "slice", ",", "FieldGetter", "(", "name", ")", ",", "Ascending", ")", ".", "Sort", "(", ")", "\n", "}" ]
// Sort a slice in ascending order by a field name.
[ "Sort", "a", "slice", "in", "ascending", "order", "by", "a", "field", "name", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L272-L274
15,591
patrickmn/sortutil
sortutil.go
DescByField
func DescByField(slice interface{}, name string) { New(slice, FieldGetter(name), Descending).Sort() }
go
func DescByField(slice interface{}, name string) { New(slice, FieldGetter(name), Descending).Sort() }
[ "func", "DescByField", "(", "slice", "interface", "{", "}", ",", "name", "string", ")", "{", "New", "(", "slice", ",", "FieldGetter", "(", "name", ")", ",", "Descending", ")", ".", "Sort", "(", ")", "\n", "}" ]
// Sort a slice in descending order by a field name.
[ "Sort", "a", "slice", "in", "descending", "order", "by", "a", "field", "name", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L277-L279
15,592
patrickmn/sortutil
sortutil.go
AscByIndex
func AscByIndex(slice interface{}, index int) { New(slice, IndexGetter(index), Ascending).Sort() }
go
func AscByIndex(slice interface{}, index int) { New(slice, IndexGetter(index), Ascending).Sort() }
[ "func", "AscByIndex", "(", "slice", "interface", "{", "}", ",", "index", "int", ")", "{", "New", "(", "slice", ",", "IndexGetter", "(", "index", ")", ",", "Ascending", ")", ".", "Sort", "(", ")", "\n", "}" ]
// Sort a slice in ascending order by an index in a child slice.
[ "Sort", "a", "slice", "in", "ascending", "order", "by", "an", "index", "in", "a", "child", "slice", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L324-L326
15,593
patrickmn/sortutil
sortutil.go
DescByIndex
func DescByIndex(slice interface{}, index int) { New(slice, IndexGetter(index), Descending).Sort() }
go
func DescByIndex(slice interface{}, index int) { New(slice, IndexGetter(index), Descending).Sort() }
[ "func", "DescByIndex", "(", "slice", "interface", "{", "}", ",", "index", "int", ")", "{", "New", "(", "slice", ",", "IndexGetter", "(", "index", ")", ",", "Descending", ")", ".", "Sort", "(", ")", "\n", "}" ]
// Sort a slice in descending order by an index in a child slice.
[ "Sort", "a", "slice", "in", "descending", "order", "by", "an", "index", "in", "a", "child", "slice", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L329-L331
15,594
patrickmn/sortutil
sortutil.go
Reverse
func Reverse(slice interface{}) { s := reverser{New(slice, nil, 0)} if s.Len() < 2 { return } s.itemType = s.Slice.Index(0).Type() ReverseInterface(s) }
go
func Reverse(slice interface{}) { s := reverser{New(slice, nil, 0)} if s.Len() < 2 { return } s.itemType = s.Slice.Index(0).Type() ReverseInterface(s) }
[ "func", "Reverse", "(", "slice", "interface", "{", "}", ")", "{", "s", ":=", "reverser", "{", "New", "(", "slice", ",", "nil", ",", "0", ")", "}", "\n", "if", "s", ".", "Len", "(", ")", "<", "2", "{", "return", "\n", "}", "\n", "s", ".", "itemType", "=", "s", ".", "Slice", ".", "Index", "(", "0", ")", ".", "Type", "(", ")", "\n", "ReverseInterface", "(", "s", ")", "\n", "}" ]
// Reverse a slice.
[ "Reverse", "a", "slice", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L346-L353
15,595
patrickmn/sortutil
sortutil.go
ReverseInterface
func ReverseInterface(s sort.Interface) { for i, j := 0, s.Len()-1; i < j; i, j = i+1, j-1 { s.Swap(i, j) } }
go
func ReverseInterface(s sort.Interface) { for i, j := 0, s.Len()-1; i < j; i, j = i+1, j-1 { s.Swap(i, j) } }
[ "func", "ReverseInterface", "(", "s", "sort", ".", "Interface", ")", "{", "for", "i", ",", "j", ":=", "0", ",", "s", ".", "Len", "(", ")", "-", "1", ";", "i", "<", "j", ";", "i", ",", "j", "=", "i", "+", "1", ",", "j", "-", "1", "{", "s", ".", "Swap", "(", "i", ",", "j", ")", "\n", "}", "\n", "}" ]
// Reverse a type which implements sort.Interface.
[ "Reverse", "a", "type", "which", "implements", "sort", ".", "Interface", "." ]
abeda66eb583fac2d8d98d3d2e6fbd5c67af7947
https://github.com/patrickmn/sortutil/blob/abeda66eb583fac2d8d98d3d2e6fbd5c67af7947/sortutil.go#L356-L360
15,596
LindsayBradford/go-dbf
godbf/dbftable.go
New
func New(encoding string) (table *DbfTable) { // Create and populate DbaseTable struct dt := new(DbfTable) dt.fileEncoding = encoding dt.encoder = mahonia.NewEncoder(encoding) dt.decoder = mahonia.NewDecoder(encoding) // set whether or not this table has been created from scratch dt.createdFromScratch = true // read dbase table header information dt.fileSignature = 0x03 dt.updateYear = byte(time.Now().Year() - 1900) dt.updateMonth = byte(time.Now().Month()) dt.updateDay = byte(time.Now().Day()) dt.numberOfRecords = 0 dt.numberOfBytesInHeader = 32 dt.lengthOfEachRecord = 0 // create fieldMap to translate field name to index dt.fieldMap = make(map[string]int) // Number of fields in dbase table dt.numberOfFields = int((dt.numberOfBytesInHeader - 1 - 32) / 32) s := make([]byte, dt.numberOfBytesInHeader) //fmt.Printf("number of fields:\n%#v\n", numberOfFields) //fmt.Printf("DbfReader:\n%#v\n", int(dt.Fields[2].fixedFieldLength)) //fmt.Printf("num records in table:%v\n", (dt.numberOfRecords)) //fmt.Printf("fixedFieldLength of each record:%v\n", (dt.lengthOfEachRecord)) // Since we are reading dbase file from the disk at least at this // phase changing schema of dbase file is not allowed. dt.dataEntryStarted = false // set DbfTable dataStore slice that will store the complete file in memory dt.dataStore = s dt.dataStore[0] = dt.fileSignature dt.dataStore[1] = dt.updateYear dt.dataStore[2] = dt.updateMonth dt.dataStore[3] = dt.updateDay // no MDX file (index upon demand) dt.dataStore[28] = 0x00 // set dbase language driver // Huston we have problem! // There is no easy way to deal with encoding issues. At least at the moment // I will try to find archaic encoding code defined by dbase standard (if there is any) // for given encoding. If none match I will go with default ANSI. // // Despite this flag in set in dbase file, I will continue to use provide encoding for // the everything except this file encoding flag. // // Why? To make sure at least if you know the real encoding you can process text accordingly. if code, ok := encodingTable[lookup[encoding]]; ok { dt.dataStore[29] = code } else { dt.dataStore[29] = 0x57 // ANSI } return dt }
go
func New(encoding string) (table *DbfTable) { // Create and populate DbaseTable struct dt := new(DbfTable) dt.fileEncoding = encoding dt.encoder = mahonia.NewEncoder(encoding) dt.decoder = mahonia.NewDecoder(encoding) // set whether or not this table has been created from scratch dt.createdFromScratch = true // read dbase table header information dt.fileSignature = 0x03 dt.updateYear = byte(time.Now().Year() - 1900) dt.updateMonth = byte(time.Now().Month()) dt.updateDay = byte(time.Now().Day()) dt.numberOfRecords = 0 dt.numberOfBytesInHeader = 32 dt.lengthOfEachRecord = 0 // create fieldMap to translate field name to index dt.fieldMap = make(map[string]int) // Number of fields in dbase table dt.numberOfFields = int((dt.numberOfBytesInHeader - 1 - 32) / 32) s := make([]byte, dt.numberOfBytesInHeader) //fmt.Printf("number of fields:\n%#v\n", numberOfFields) //fmt.Printf("DbfReader:\n%#v\n", int(dt.Fields[2].fixedFieldLength)) //fmt.Printf("num records in table:%v\n", (dt.numberOfRecords)) //fmt.Printf("fixedFieldLength of each record:%v\n", (dt.lengthOfEachRecord)) // Since we are reading dbase file from the disk at least at this // phase changing schema of dbase file is not allowed. dt.dataEntryStarted = false // set DbfTable dataStore slice that will store the complete file in memory dt.dataStore = s dt.dataStore[0] = dt.fileSignature dt.dataStore[1] = dt.updateYear dt.dataStore[2] = dt.updateMonth dt.dataStore[3] = dt.updateDay // no MDX file (index upon demand) dt.dataStore[28] = 0x00 // set dbase language driver // Huston we have problem! // There is no easy way to deal with encoding issues. At least at the moment // I will try to find archaic encoding code defined by dbase standard (if there is any) // for given encoding. If none match I will go with default ANSI. // // Despite this flag in set in dbase file, I will continue to use provide encoding for // the everything except this file encoding flag. // // Why? To make sure at least if you know the real encoding you can process text accordingly. if code, ok := encodingTable[lookup[encoding]]; ok { dt.dataStore[29] = code } else { dt.dataStore[29] = 0x57 // ANSI } return dt }
[ "func", "New", "(", "encoding", "string", ")", "(", "table", "*", "DbfTable", ")", "{", "// Create and populate DbaseTable struct", "dt", ":=", "new", "(", "DbfTable", ")", "\n\n", "dt", ".", "fileEncoding", "=", "encoding", "\n", "dt", ".", "encoder", "=", "mahonia", ".", "NewEncoder", "(", "encoding", ")", "\n", "dt", ".", "decoder", "=", "mahonia", ".", "NewDecoder", "(", "encoding", ")", "\n\n", "// set whether or not this table has been created from scratch", "dt", ".", "createdFromScratch", "=", "true", "\n\n", "// read dbase table header information", "dt", ".", "fileSignature", "=", "0x03", "\n", "dt", ".", "updateYear", "=", "byte", "(", "time", ".", "Now", "(", ")", ".", "Year", "(", ")", "-", "1900", ")", "\n", "dt", ".", "updateMonth", "=", "byte", "(", "time", ".", "Now", "(", ")", ".", "Month", "(", ")", ")", "\n", "dt", ".", "updateDay", "=", "byte", "(", "time", ".", "Now", "(", ")", ".", "Day", "(", ")", ")", "\n", "dt", ".", "numberOfRecords", "=", "0", "\n", "dt", ".", "numberOfBytesInHeader", "=", "32", "\n", "dt", ".", "lengthOfEachRecord", "=", "0", "\n\n", "// create fieldMap to translate field name to index", "dt", ".", "fieldMap", "=", "make", "(", "map", "[", "string", "]", "int", ")", "\n\n", "// Number of fields in dbase table", "dt", ".", "numberOfFields", "=", "int", "(", "(", "dt", ".", "numberOfBytesInHeader", "-", "1", "-", "32", ")", "/", "32", ")", "\n\n", "s", ":=", "make", "(", "[", "]", "byte", ",", "dt", ".", "numberOfBytesInHeader", ")", "\n\n", "//fmt.Printf(\"number of fields:\\n%#v\\n\", numberOfFields)", "//fmt.Printf(\"DbfReader:\\n%#v\\n\", int(dt.Fields[2].fixedFieldLength))", "//fmt.Printf(\"num records in table:%v\\n\", (dt.numberOfRecords))", "//fmt.Printf(\"fixedFieldLength of each record:%v\\n\", (dt.lengthOfEachRecord))", "// Since we are reading dbase file from the disk at least at this", "// phase changing schema of dbase file is not allowed.", "dt", ".", "dataEntryStarted", "=", "false", "\n\n", "// set DbfTable dataStore slice that will store the complete file in memory", "dt", ".", "dataStore", "=", "s", "\n\n", "dt", ".", "dataStore", "[", "0", "]", "=", "dt", ".", "fileSignature", "\n", "dt", ".", "dataStore", "[", "1", "]", "=", "dt", ".", "updateYear", "\n", "dt", ".", "dataStore", "[", "2", "]", "=", "dt", ".", "updateMonth", "\n", "dt", ".", "dataStore", "[", "3", "]", "=", "dt", ".", "updateDay", "\n\n", "// no MDX file (index upon demand)", "dt", ".", "dataStore", "[", "28", "]", "=", "0x00", "\n\n", "// set dbase language driver", "// Huston we have problem!", "// There is no easy way to deal with encoding issues. At least at the moment", "// I will try to find archaic encoding code defined by dbase standard (if there is any)", "// for given encoding. If none match I will go with default ANSI.", "//", "// Despite this flag in set in dbase file, I will continue to use provide encoding for", "// the everything except this file encoding flag.", "//", "// Why? To make sure at least if you know the real encoding you can process text accordingly.", "if", "code", ",", "ok", ":=", "encodingTable", "[", "lookup", "[", "encoding", "]", "]", ";", "ok", "{", "dt", ".", "dataStore", "[", "29", "]", "=", "code", "\n", "}", "else", "{", "dt", ".", "dataStore", "[", "29", "]", "=", "0x57", "// ANSI", "\n", "}", "\n\n", "return", "dt", "\n", "}" ]
// New creates a new dbase table from scratch for the given character encoding
[ "New", "creates", "a", "new", "dbase", "table", "from", "scratch", "for", "the", "given", "character", "encoding" ]
5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f
https://github.com/LindsayBradford/go-dbf/blob/5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f/godbf/dbftable.go#L59-L127
15,597
LindsayBradford/go-dbf
godbf/dbftable.go
FieldNames
func (dt *DbfTable) FieldNames() []string { names := make([]string, 0) for _, field := range dt.Fields() { names = append(names, field.name) } return names }
go
func (dt *DbfTable) FieldNames() []string { names := make([]string, 0) for _, field := range dt.Fields() { names = append(names, field.name) } return names }
[ "func", "(", "dt", "*", "DbfTable", ")", "FieldNames", "(", ")", "[", "]", "string", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n\n", "for", "_", ",", "field", ":=", "range", "dt", ".", "Fields", "(", ")", "{", "names", "=", "append", "(", "names", ",", "field", ".", "name", ")", "\n", "}", "\n\n", "return", "names", "\n", "}" ]
// FieldNames return the names of fields in the table as a slice
[ "FieldNames", "return", "the", "names", "of", "fields", "in", "the", "table", "as", "a", "slice" ]
5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f
https://github.com/LindsayBradford/go-dbf/blob/5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f/godbf/dbftable.go#L284-L292
15,598
LindsayBradford/go-dbf
godbf/dbftable.go
HasField
func (dt *DbfTable) HasField(fieldName string) bool { for i := 0; i < len(dt.fields); i++ { if dt.fields[i].name == fieldName { return true } } return false }
go
func (dt *DbfTable) HasField(fieldName string) bool { for i := 0; i < len(dt.fields); i++ { if dt.fields[i].name == fieldName { return true } } return false }
[ "func", "(", "dt", "*", "DbfTable", ")", "HasField", "(", "fieldName", "string", ")", "bool", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "dt", ".", "fields", ")", ";", "i", "++", "{", "if", "dt", ".", "fields", "[", "i", "]", ".", "name", "==", "fieldName", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// HasField returns true if the table has a field with the given name // If the field does not exist an error is returned.
[ "HasField", "returns", "true", "if", "the", "table", "has", "a", "field", "with", "the", "given", "name", "If", "the", "field", "does", "not", "exist", "an", "error", "is", "returned", "." ]
5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f
https://github.com/LindsayBradford/go-dbf/blob/5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f/godbf/dbftable.go#L296-L305
15,599
LindsayBradford/go-dbf
godbf/dbftable.go
DecimalPlacesInField
func (dt *DbfTable) DecimalPlacesInField(fieldName string) (uint8, error) { if !dt.HasField(fieldName) { return 0, errors.New("Field name \"" + fieldName + "\" does not exist. ") } for i := 0; i < len(dt.fields); i++ { if dt.fields[i].name == fieldName && dt.fields[i].usesDecimalPlaces() { return dt.fields[i].decimalPlaces, nil } } return 0, errors.New("Type of field \"" + fieldName + "\" is not Numeric or Float.") }
go
func (dt *DbfTable) DecimalPlacesInField(fieldName string) (uint8, error) { if !dt.HasField(fieldName) { return 0, errors.New("Field name \"" + fieldName + "\" does not exist. ") } for i := 0; i < len(dt.fields); i++ { if dt.fields[i].name == fieldName && dt.fields[i].usesDecimalPlaces() { return dt.fields[i].decimalPlaces, nil } } return 0, errors.New("Type of field \"" + fieldName + "\" is not Numeric or Float.") }
[ "func", "(", "dt", "*", "DbfTable", ")", "DecimalPlacesInField", "(", "fieldName", "string", ")", "(", "uint8", ",", "error", ")", "{", "if", "!", "dt", ".", "HasField", "(", "fieldName", ")", "{", "return", "0", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "fieldName", "+", "\"", "\\\"", "\"", ")", "\n", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "dt", ".", "fields", ")", ";", "i", "++", "{", "if", "dt", ".", "fields", "[", "i", "]", ".", "name", "==", "fieldName", "&&", "dt", ".", "fields", "[", "i", "]", ".", "usesDecimalPlaces", "(", ")", "{", "return", "dt", ".", "fields", "[", "i", "]", ".", "decimalPlaces", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "0", ",", "errors", ".", "New", "(", "\"", "\\\"", "\"", "+", "fieldName", "+", "\"", "\\\"", "\"", ")", "\n", "}" ]
// DecimalPlacesInField returns the number of decimal places for the field with the given name. // If the field does not exist, or does not use decimal places, an error is returned.
[ "DecimalPlacesInField", "returns", "the", "number", "of", "decimal", "places", "for", "the", "field", "with", "the", "given", "name", ".", "If", "the", "field", "does", "not", "exist", "or", "does", "not", "use", "decimal", "places", "an", "error", "is", "returned", "." ]
5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f
https://github.com/LindsayBradford/go-dbf/blob/5f7a16f88561c4d09bd4e74d6c3d1f95e074de3f/godbf/dbftable.go#L309-L321