id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
17,200
rveen/ogdl
eval.go
evalBool
func (g *Graph) evalBool(e *Graph) bool { i, err := g.Eval(e) if err != nil { return false } b, _ := _boolf(i) return b }
go
func (g *Graph) evalBool(e *Graph) bool { i, err := g.Eval(e) if err != nil { return false } b, _ := _boolf(i) return b }
[ "func", "(", "g", "*", "Graph", ")", "evalBool", "(", "e", "*", "Graph", ")", "bool", "{", "i", ",", "err", ":=", "g", ".", "Eval", "(", "e", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "b", ",", "_", ":=",...
// EvalBool takes a parsed expression and evaluates it in the context of the // current graph, and converts the result to a boolean.
[ "EvalBool", "takes", "a", "parsed", "expression", "and", "evaluates", "it", "in", "the", "context", "of", "the", "current", "graph", "and", "converts", "the", "result", "to", "a", "boolean", "." ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/eval.go#L32-L39
17,201
rveen/ogdl
eval.go
assign
func (g *Graph) assign(p *Graph, v interface{}, op int) interface{} { if op == '=' { return g.set(p, v) } // if p doesn't exist, just set it to the value given left, _ := g.getPath(p) if left != nil { return g.set(p, calc(left.Out[0].This, v, op)) } switch op { case '+': return g.set(p, v) case '-': return g.set(p, calc(0, v, '-')) case '*': return g.set(p, 0) case '/': return g.set(p, "infinity") case '%': return g.set(p, "undefined") } return nil }
go
func (g *Graph) assign(p *Graph, v interface{}, op int) interface{} { if op == '=' { return g.set(p, v) } // if p doesn't exist, just set it to the value given left, _ := g.getPath(p) if left != nil { return g.set(p, calc(left.Out[0].This, v, op)) } switch op { case '+': return g.set(p, v) case '-': return g.set(p, calc(0, v, '-')) case '*': return g.set(p, 0) case '/': return g.set(p, "infinity") case '%': return g.set(p, "undefined") } return nil }
[ "func", "(", "g", "*", "Graph", ")", "assign", "(", "p", "*", "Graph", ",", "v", "interface", "{", "}", ",", "op", "int", ")", "interface", "{", "}", "{", "if", "op", "==", "'='", "{", "return", "g", ".", "set", "(", "p", ",", "v", ")", "\n...
// assign modifies the context graph
[ "assign", "modifies", "the", "context", "graph" ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/eval.go#L545-L571
17,202
rveen/ogdl
block.go
tree
func (p *Parser) tree(ns int, types bool) { for { b, err := p.line(ns, types) if !b || err != nil { break } } p.End() }
go
func (p *Parser) tree(ns int, types bool) { for { b, err := p.line(ns, types) if !b || err != nil { break } } p.End() }
[ "func", "(", "p", "*", "Parser", ")", "tree", "(", "ns", "int", ",", "types", "bool", ")", "{", "for", "{", "b", ",", "err", ":=", "p", ".", "line", "(", "ns", ",", "types", ")", "\n", "if", "!", "b", "||", "err", "!=", "nil", "{", "break",...
// tree reads all lines with indentation >= ns
[ "tree", "reads", "all", "lines", "with", "indentation", ">", "=", "ns" ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/block.go#L45-L53
17,203
rveen/ogdl
event.go
AddBytes
func (e *SimpleEventHandler) AddBytes(b []byte) { e.items = append(e.items, b) e.levels = append(e.levels, e.current) }
go
func (e *SimpleEventHandler) AddBytes(b []byte) { e.items = append(e.items, b) e.levels = append(e.levels, e.current) }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "AddBytes", "(", "b", "[", "]", "byte", ")", "{", "e", ".", "items", "=", "append", "(", "e", ".", "items", ",", "b", ")", "\n", "e", ".", "levels", "=", "append", "(", "e", ".", "levels", ",", ...
// AddBytes creates a byte array node at the current level
[ "AddBytes", "creates", "a", "byte", "array", "node", "at", "the", "current", "level" ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L16-L19
17,204
rveen/ogdl
event.go
Add
func (e *SimpleEventHandler) Add(s string) { e.items = append(e.items, s) e.levels = append(e.levels, e.current) }
go
func (e *SimpleEventHandler) Add(s string) { e.items = append(e.items, s) e.levels = append(e.levels, e.current) }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "Add", "(", "s", "string", ")", "{", "e", ".", "items", "=", "append", "(", "e", ".", "items", ",", "s", ")", "\n", "e", ".", "levels", "=", "append", "(", "e", ".", "levels", ",", "e", ".", "...
// Add creates a string node at the current level.
[ "Add", "creates", "a", "string", "node", "at", "the", "current", "level", "." ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L22-L25
17,205
rveen/ogdl
event.go
AddItf
func (e *SimpleEventHandler) AddItf(i interface{}) { e.items = append(e.items, i) e.levels = append(e.levels, e.current) }
go
func (e *SimpleEventHandler) AddItf(i interface{}) { e.items = append(e.items, i) e.levels = append(e.levels, e.current) }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "AddItf", "(", "i", "interface", "{", "}", ")", "{", "e", ".", "items", "=", "append", "(", "e", ".", "items", ",", "i", ")", "\n", "e", ".", "levels", "=", "append", "(", "e", ".", "levels", ",...
// AddItf creates a string node at the current level.
[ "AddItf", "creates", "a", "string", "node", "at", "the", "current", "level", "." ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L28-L31
17,206
rveen/ogdl
event.go
AddBytesAt
func (e *SimpleEventHandler) AddBytesAt(b []byte, lv int) { e.items = append(e.items, b) e.levels = append(e.levels, lv) if e.max < lv { e.max = lv } }
go
func (e *SimpleEventHandler) AddBytesAt(b []byte, lv int) { e.items = append(e.items, b) e.levels = append(e.levels, lv) if e.max < lv { e.max = lv } }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "AddBytesAt", "(", "b", "[", "]", "byte", ",", "lv", "int", ")", "{", "e", ".", "items", "=", "append", "(", "e", ".", "items", ",", "b", ")", "\n", "e", ".", "levels", "=", "append", "(", "e", ...
// AddBytesAt creates a byte array node at the specified level
[ "AddBytesAt", "creates", "a", "byte", "array", "node", "at", "the", "specified", "level" ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L34-L40
17,207
rveen/ogdl
event.go
AddAt
func (e *SimpleEventHandler) AddAt(s string, lv int) { e.items = append(e.items, s) e.levels = append(e.levels, lv) if e.max < lv { e.max = lv } }
go
func (e *SimpleEventHandler) AddAt(s string, lv int) { e.items = append(e.items, s) e.levels = append(e.levels, lv) if e.max < lv { e.max = lv } }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "AddAt", "(", "s", "string", ",", "lv", "int", ")", "{", "e", ".", "items", "=", "append", "(", "e", ".", "items", ",", "s", ")", "\n", "e", ".", "levels", "=", "append", "(", "e", ".", "levels"...
// AddAt creates a string node at the specified level.
[ "AddAt", "creates", "a", "string", "node", "at", "the", "specified", "level", "." ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L43-L49
17,208
rveen/ogdl
event.go
Delete
func (e *SimpleEventHandler) Delete() { e.items = e.items[0 : len(e.items)-1] e.levels = e.levels[0 : len(e.levels)-1] }
go
func (e *SimpleEventHandler) Delete() { e.items = e.items[0 : len(e.items)-1] e.levels = e.levels[0 : len(e.levels)-1] }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "Delete", "(", ")", "{", "e", ".", "items", "=", "e", ".", "items", "[", "0", ":", "len", "(", "e", ".", "items", ")", "-", "1", "]", "\n", "e", ".", "levels", "=", "e", ".", "levels", "[", ...
// Delete removes the last node added
[ "Delete", "removes", "the", "last", "node", "added" ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L52-L55
17,209
rveen/ogdl
event.go
SetLevel
func (e *SimpleEventHandler) SetLevel(l int) { e.current = l if e.max < l { e.max = l } }
go
func (e *SimpleEventHandler) SetLevel(l int) { e.current = l if e.max < l { e.max = l } }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "SetLevel", "(", "l", "int", ")", "{", "e", ".", "current", "=", "l", "\n", "if", "e", ".", "max", "<", "l", "{", "e", ".", "max", "=", "l", "\n", "}", "\n", "}" ]
// SetLevel sets the current level
[ "SetLevel", "sets", "the", "current", "level" ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L63-L68
17,210
rveen/ogdl
event.go
Inc
func (e *SimpleEventHandler) Inc() { e.current++ if e.max < e.current { e.max = e.current } }
go
func (e *SimpleEventHandler) Inc() { e.current++ if e.max < e.current { e.max = e.current } }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "Inc", "(", ")", "{", "e", ".", "current", "++", "\n", "if", "e", ".", "max", "<", "e", ".", "current", "{", "e", ".", "max", "=", "e", ".", "current", "\n", "}", "\n", "}" ]
// Inc increments the current level by 1.
[ "Inc", "increments", "the", "current", "level", "by", "1", "." ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L71-L76
17,211
rveen/ogdl
event.go
Tree
func (e *SimpleEventHandler) Tree() *Graph { g := make([]*Graph, e.max+2) g[0] = New("_") /* println("ev.Tree", len(e.items), len(e.levels), e.max) for i := 0; i < len(e.items); i++ { fmt.Printf(" - %d %v\n", e.levels[i], e.items[i]) } */ for i := 0; i < len(e.items); i++ { lv := e.levels[i] + 1 item := e.items[i] n := New(item) g[lv] = n g[lv-1].Add(n) } return g[0] }
go
func (e *SimpleEventHandler) Tree() *Graph { g := make([]*Graph, e.max+2) g[0] = New("_") /* println("ev.Tree", len(e.items), len(e.levels), e.max) for i := 0; i < len(e.items); i++ { fmt.Printf(" - %d %v\n", e.levels[i], e.items[i]) } */ for i := 0; i < len(e.items); i++ { lv := e.levels[i] + 1 item := e.items[i] n := New(item) g[lv] = n g[lv-1].Add(n) } return g[0] }
[ "func", "(", "e", "*", "SimpleEventHandler", ")", "Tree", "(", ")", "*", "Graph", "{", "g", ":=", "make", "(", "[", "]", "*", "Graph", ",", "e", ".", "max", "+", "2", ")", "\n", "g", "[", "0", "]", "=", "New", "(", "\"", "\"", ")", "\n", ...
// Tree returns the Graph object built from // the events sent to this event handler. //
[ "Tree", "returns", "the", "Graph", "object", "built", "from", "the", "events", "sent", "to", "this", "event", "handler", "." ]
60b0e542a67492da26c19e680662b29786ef1ee3
https://github.com/rveen/ogdl/blob/60b0e542a67492da26c19e680662b29786ef1ee3/event.go#L88-L109
17,212
cloudflare/bm
bm.go
Expand
func (e *Expander) Expand(p []byte) (q []byte, err error) { // This is done to capture the extreme case that an out of // bounds error occurs in the expansion. This should never // happen, but this protects against a corrupt compressed // block. If this occurs then we return no data at all to // prevent any bad data being returned to the client. defer func() { if x := recover(); x != nil { err = errors.New("panic caught inside expander") p = p[:0] } }() q = p A: for { var u uint if u, err = e.readVarUint(); err != nil { break A } // If the value read is zero then it indicates a compressed // section which is formed of two varints indicating the // offset and length, if not then it's an uncompressed section if u == 0 { var offset uint if offset, err = e.readVarUint(); err != nil { break A } var length uint if length, err = e.readVarUint(); err != nil { break A } q = append(q, e.dict[offset:offset+length]...) } else { left := u for left > 0 { buf := make([]byte, left) var n int if n, err = e.r.Read(buf); err != nil { break A } if n > 0 { left -= uint(n) q = append(q, buf[0:n]...) } else { break A } } } } if err == io.EOF { err = nil } return }
go
func (e *Expander) Expand(p []byte) (q []byte, err error) { // This is done to capture the extreme case that an out of // bounds error occurs in the expansion. This should never // happen, but this protects against a corrupt compressed // block. If this occurs then we return no data at all to // prevent any bad data being returned to the client. defer func() { if x := recover(); x != nil { err = errors.New("panic caught inside expander") p = p[:0] } }() q = p A: for { var u uint if u, err = e.readVarUint(); err != nil { break A } // If the value read is zero then it indicates a compressed // section which is formed of two varints indicating the // offset and length, if not then it's an uncompressed section if u == 0 { var offset uint if offset, err = e.readVarUint(); err != nil { break A } var length uint if length, err = e.readVarUint(); err != nil { break A } q = append(q, e.dict[offset:offset+length]...) } else { left := u for left > 0 { buf := make([]byte, left) var n int if n, err = e.r.Read(buf); err != nil { break A } if n > 0 { left -= uint(n) q = append(q, buf[0:n]...) } else { break A } } } } if err == io.EOF { err = nil } return }
[ "func", "(", "e", "*", "Expander", ")", "Expand", "(", "p", "[", "]", "byte", ")", "(", "q", "[", "]", "byte", ",", "err", "error", ")", "{", "// This is done to capture the extreme case that an out of", "// bounds error occurs in the expansion. This should never", ...
// Expand expands the compressed data into a buffer
[ "Expand", "expands", "the", "compressed", "data", "into", "a", "buffer" ]
cf552e842b6ab45d3cd9b2529f935d49f9bc7370
https://github.com/cloudflare/bm/blob/cf552e842b6ab45d3cd9b2529f935d49f9bc7370/bm.go#L472-L534
17,213
hortonworks/gohadoop
hadoop_common/security/digestmd5.go
validateChallengeParameters
func validateChallengeParameters(challengeParams map[string]string) error { var errString string realm, exists := challengeParams["realm"] if !exists || len(realm) == 0 { errString += "missing or invalid realm. " } nonce, exists := challengeParams["nonce"] if !exists || len(nonce) == 0 { errString += "missing or invalid nonce. " } qop, exists := challengeParams["qop"] if !exists || qop != "auth" { errString += "missing, invalid or unsupported qop. " } charset, exists := challengeParams["charset"] if !exists || charset != "utf-8" { errString += "missing, invalid or unsupported charset. " } algorithm, exists := challengeParams["algorithm"] if !exists || algorithm != "md5-sess" { errString += "missing, invalid or unsupported algorithm. " } if len(errString) > 0 { return errors.New(errString) } return nil }
go
func validateChallengeParameters(challengeParams map[string]string) error { var errString string realm, exists := challengeParams["realm"] if !exists || len(realm) == 0 { errString += "missing or invalid realm. " } nonce, exists := challengeParams["nonce"] if !exists || len(nonce) == 0 { errString += "missing or invalid nonce. " } qop, exists := challengeParams["qop"] if !exists || qop != "auth" { errString += "missing, invalid or unsupported qop. " } charset, exists := challengeParams["charset"] if !exists || charset != "utf-8" { errString += "missing, invalid or unsupported charset. " } algorithm, exists := challengeParams["algorithm"] if !exists || algorithm != "md5-sess" { errString += "missing, invalid or unsupported algorithm. " } if len(errString) > 0 { return errors.New(errString) } return nil }
[ "func", "validateChallengeParameters", "(", "challengeParams", "map", "[", "string", "]", "string", ")", "error", "{", "var", "errString", "string", "\n\n", "realm", ",", "exists", ":=", "challengeParams", "[", "\"", "\"", "]", "\n", "if", "!", "exists", "||...
//we only support a very specific digest-md5 mechanism for the moment //multiple realm, qop not supported
[ "we", "only", "support", "a", "very", "specific", "digest", "-", "md5", "mechanism", "for", "the", "moment", "multiple", "realm", "qop", "not", "supported" ]
4e92e1475b38a7c84eed25df0d04b98dfef30982
https://github.com/hortonworks/gohadoop/blob/4e92e1475b38a7c84eed25df0d04b98dfef30982/hadoop_common/security/digestmd5.go#L46-L79
17,214
hortonworks/gohadoop
hadoop_yarn/containermanagement_service.pb.go
DialContainerManagementProtocolService
func DialContainerManagementProtocolService(host string, port int) (ContainerManagementProtocolService, error) { clientId, _ := uuid.NewV4() ugi, _ := gohadoop.CreateSimpleUGIProto() c := &hadoop_ipc_client.Client{ClientId: clientId, Ugi: ugi, ServerAddress: net.JoinHostPort(host, strconv.Itoa(port))} return &ContainerManagementProtocolServiceClient{c}, nil }
go
func DialContainerManagementProtocolService(host string, port int) (ContainerManagementProtocolService, error) { clientId, _ := uuid.NewV4() ugi, _ := gohadoop.CreateSimpleUGIProto() c := &hadoop_ipc_client.Client{ClientId: clientId, Ugi: ugi, ServerAddress: net.JoinHostPort(host, strconv.Itoa(port))} return &ContainerManagementProtocolServiceClient{c}, nil }
[ "func", "DialContainerManagementProtocolService", "(", "host", "string", ",", "port", "int", ")", "(", "ContainerManagementProtocolService", ",", "error", ")", "{", "clientId", ",", "_", ":=", "uuid", ".", "NewV4", "(", ")", "\n", "ugi", ",", "_", ":=", "goh...
// DialContainerManagementProtocolService connects to an ContainerManagementProtocolService at the specified network address.
[ "DialContainerManagementProtocolService", "connects", "to", "an", "ContainerManagementProtocolService", "at", "the", "specified", "network", "address", "." ]
4e92e1475b38a7c84eed25df0d04b98dfef30982
https://github.com/hortonworks/gohadoop/blob/4e92e1475b38a7c84eed25df0d04b98dfef30982/hadoop_yarn/containermanagement_service.pb.go#L50-L55
17,215
hortonworks/gohadoop
hadoop_yarn/applicationclient_service.pb.go
DialApplicationClientProtocolService
func DialApplicationClientProtocolService(conf yarn_conf.YarnConfiguration) (ApplicationClientProtocolService, error) { clientId, _ := uuid.NewV4() ugi, _ := gohadoop.CreateSimpleUGIProto() serverAddress, _ := conf.GetRMAddress() c := &hadoop_ipc_client.Client{ClientId: clientId, Ugi: ugi, ServerAddress: serverAddress} return &ApplicationClientProtocolServiceClient{c}, nil }
go
func DialApplicationClientProtocolService(conf yarn_conf.YarnConfiguration) (ApplicationClientProtocolService, error) { clientId, _ := uuid.NewV4() ugi, _ := gohadoop.CreateSimpleUGIProto() serverAddress, _ := conf.GetRMAddress() c := &hadoop_ipc_client.Client{ClientId: clientId, Ugi: ugi, ServerAddress: serverAddress} return &ApplicationClientProtocolServiceClient{c}, nil }
[ "func", "DialApplicationClientProtocolService", "(", "conf", "yarn_conf", ".", "YarnConfiguration", ")", "(", "ApplicationClientProtocolService", ",", "error", ")", "{", "clientId", ",", "_", ":=", "uuid", ".", "NewV4", "(", ")", "\n", "ugi", ",", "_", ":=", "...
// DialApplicationClientProtocolService connects to an ApplicationClientProtocolService at the specified network address.
[ "DialApplicationClientProtocolService", "connects", "to", "an", "ApplicationClientProtocolService", "at", "the", "specified", "network", "address", "." ]
4e92e1475b38a7c84eed25df0d04b98dfef30982
https://github.com/hortonworks/gohadoop/blob/4e92e1475b38a7c84eed25df0d04b98dfef30982/hadoop_yarn/applicationclient_service.pb.go#L86-L92
17,216
hortonworks/gohadoop
hadoop_yarn/yarn_client/am_rm_client_async.go
periodicAllocate
func (c *AMRMClientAsync) periodicAllocate() { for { select { case <-c.stop: log.Println("stop notification received. stopping allocate routine.") return default: } response, err := c.client.Allocate() if err != nil { log.Println("async allocate failed. terminating periodic allocate. error: ", err) return } if command := response.GetAMCommand(); command != 0 { switch command { case hadoop_yarn.AMCommandProto_AM_RESYNC, hadoop_yarn.AMCommandProto_AM_SHUTDOWN: log.Println("received command: %s. invoking shutdown and stopping allocate routine.", command) c.handler.OnShutDownRequest() return default: log.Printf("unknown command: %s. stopping allocate routine.", command) return } } if completedContainers := response.CompletedContainerStatuses; completedContainers != nil { if len(completedContainers) > 0 { c.handler.OnContainersCompleted(completedContainers) } } if allocatedContainers := response.AllocatedContainers; allocatedContainers != nil { if len(allocatedContainers) > 0 { c.handler.OnContainersAllocated(allocatedContainers) } } if updatedNodes := response.UpdatedNodes; updatedNodes != nil { if len(updatedNodes) > 0 { c.handler.OnNodesUpdated(updatedNodes) } } time.Sleep(time.Duration(c.intervalMs) * time.Millisecond) } }
go
func (c *AMRMClientAsync) periodicAllocate() { for { select { case <-c.stop: log.Println("stop notification received. stopping allocate routine.") return default: } response, err := c.client.Allocate() if err != nil { log.Println("async allocate failed. terminating periodic allocate. error: ", err) return } if command := response.GetAMCommand(); command != 0 { switch command { case hadoop_yarn.AMCommandProto_AM_RESYNC, hadoop_yarn.AMCommandProto_AM_SHUTDOWN: log.Println("received command: %s. invoking shutdown and stopping allocate routine.", command) c.handler.OnShutDownRequest() return default: log.Printf("unknown command: %s. stopping allocate routine.", command) return } } if completedContainers := response.CompletedContainerStatuses; completedContainers != nil { if len(completedContainers) > 0 { c.handler.OnContainersCompleted(completedContainers) } } if allocatedContainers := response.AllocatedContainers; allocatedContainers != nil { if len(allocatedContainers) > 0 { c.handler.OnContainersAllocated(allocatedContainers) } } if updatedNodes := response.UpdatedNodes; updatedNodes != nil { if len(updatedNodes) > 0 { c.handler.OnNodesUpdated(updatedNodes) } } time.Sleep(time.Duration(c.intervalMs) * time.Millisecond) } }
[ "func", "(", "c", "*", "AMRMClientAsync", ")", "periodicAllocate", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "c", ".", "stop", ":", "log", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "\n", "default", ":", "}", "\n\n", "respo...
//Periodically call the the Resource Manager with an allocate call
[ "Periodically", "call", "the", "the", "Resource", "Manager", "with", "an", "allocate", "call" ]
4e92e1475b38a7c84eed25df0d04b98dfef30982
https://github.com/hortonworks/gohadoop/blob/4e92e1475b38a7c84eed25df0d04b98dfef30982/hadoop_yarn/yarn_client/am_rm_client_async.go#L50-L98
17,217
xyproto/term
examples/repeat/main.go
Repeat
func Repeat() { OUT: for { // Retrieve user input, with a prompt. Use ReadLn() for no prompt. line := term.Ask("> ") // Check if the user wants to quit switch line { case "quit", "end", "exit", "q": break OUT } // Repeat what was just said fmt.Println("You said: " + line) } }
go
func Repeat() { OUT: for { // Retrieve user input, with a prompt. Use ReadLn() for no prompt. line := term.Ask("> ") // Check if the user wants to quit switch line { case "quit", "end", "exit", "q": break OUT } // Repeat what was just said fmt.Println("You said: " + line) } }
[ "func", "Repeat", "(", ")", "{", "OUT", ":", "for", "{", "// Retrieve user input, with a prompt. Use ReadLn() for no prompt.", "line", ":=", "term", ".", "Ask", "(", "\"", "\"", ")", "\n\n", "// Check if the user wants to quit", "switch", "line", "{", "case", "\"", ...
// Loop and echo the input until "quit" is typed
[ "Loop", "and", "echo", "the", "input", "until", "quit", "is", "typed" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/examples/repeat/main.go#L10-L25
17,218
xyproto/term
curses.go
Write
func Write(x int, y int, text string, fg termbox.Attribute, bg termbox.Attribute) { //runeCount := utf8.RuneCountInString(text) pos := x for _, r := range text { termbox.SetCell(pos, y, r, fg, bg) pos++ } }
go
func Write(x int, y int, text string, fg termbox.Attribute, bg termbox.Attribute) { //runeCount := utf8.RuneCountInString(text) pos := x for _, r := range text { termbox.SetCell(pos, y, r, fg, bg) pos++ } }
[ "func", "Write", "(", "x", "int", ",", "y", "int", ",", "text", "string", ",", "fg", "termbox", ".", "Attribute", ",", "bg", "termbox", ".", "Attribute", ")", "{", "//runeCount := utf8.RuneCountInString(text)", "pos", ":=", "x", "\n", "for", "_", ",", "r...
// Place text at the given x and y coordinate. // fg is the foreground color, while bg is the background color.
[ "Place", "text", "at", "the", "given", "x", "and", "y", "coordinate", ".", "fg", "is", "the", "foreground", "color", "while", "bg", "is", "the", "background", "color", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/curses.go#L23-L30
17,219
xyproto/term
curses.go
WriteRune
func WriteRune(x int, y int, r rune, fg termbox.Attribute, bg termbox.Attribute) { termbox.SetCell(x, y, r, fg, bg) }
go
func WriteRune(x int, y int, r rune, fg termbox.Attribute, bg termbox.Attribute) { termbox.SetCell(x, y, r, fg, bg) }
[ "func", "WriteRune", "(", "x", "int", ",", "y", "int", ",", "r", "rune", ",", "fg", "termbox", ".", "Attribute", ",", "bg", "termbox", ".", "Attribute", ")", "{", "termbox", ".", "SetCell", "(", "x", ",", "y", ",", "r", ",", "fg", ",", "bg", ")...
// Place a rune at the given x and y coordinate. // fg is the foreground color, while bg is the background color.
[ "Place", "a", "rune", "at", "the", "given", "x", "and", "y", "coordinate", ".", "fg", "is", "the", "foreground", "color", "while", "bg", "is", "the", "background", "color", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/curses.go#L34-L36
17,220
xyproto/term
curses.go
Say
func Say(x int, y int, text string) { pos := x for _, r := range text { termbox.SetCell(pos, y, r, TEXTCOLOR, BG) pos++ } }
go
func Say(x int, y int, text string) { pos := x for _, r := range text { termbox.SetCell(pos, y, r, TEXTCOLOR, BG) pos++ } }
[ "func", "Say", "(", "x", "int", ",", "y", "int", ",", "text", "string", ")", "{", "pos", ":=", "x", "\n", "for", "_", ",", "r", ":=", "range", "text", "{", "termbox", ".", "SetCell", "(", "pos", ",", "y", ",", "r", ",", "TEXTCOLOR", ",", "BG"...
// Place text at the given x and y coordinate, // using the default color scheme.
[ "Place", "text", "at", "the", "given", "x", "and", "y", "coordinate", "using", "the", "default", "color", "scheme", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/curses.go#L40-L46
17,221
xyproto/term
curses.go
WaitForKey
func WaitForKey() { for { e := PollEvent() switch e.Type { case termbox.EventKey: switch e.Key { case termbox.KeyEsc, termbox.KeyEnter, termbox.KeySpace: return } } } }
go
func WaitForKey() { for { e := PollEvent() switch e.Type { case termbox.EventKey: switch e.Key { case termbox.KeyEsc, termbox.KeyEnter, termbox.KeySpace: return } } } }
[ "func", "WaitForKey", "(", ")", "{", "for", "{", "e", ":=", "PollEvent", "(", ")", "\n", "switch", "e", ".", "Type", "{", "case", "termbox", ".", "EventKey", ":", "switch", "e", ".", "Key", "{", "case", "termbox", ".", "KeyEsc", ",", "termbox", "."...
// Wait for Esc, Enter or Space to be pressed
[ "Wait", "for", "Esc", "Enter", "or", "Space", "to", "be", "pressed" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/curses.go#L85-L96
17,222
xyproto/term
misc.go
ReadLn
func ReadLn() string { reader := bufio.NewReader(os.Stdin) line, err := reader.ReadString('\n') if err != nil { return "" } return line[:len(line)-1] }
go
func ReadLn() string { reader := bufio.NewReader(os.Stdin) line, err := reader.ReadString('\n') if err != nil { return "" } return line[:len(line)-1] }
[ "func", "ReadLn", "(", ")", "string", "{", "reader", ":=", "bufio", ".", "NewReader", "(", "os", ".", "Stdin", ")", "\n", "line", ",", "err", ":=", "reader", ".", "ReadString", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"",...
// Read a line from stdin
[ "Read", "a", "line", "from", "stdin" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/misc.go#L26-L33
17,223
xyproto/term
misc.go
MapS
func MapS(f func(string) string, sl []string) (result []string) { result = make([]string, len(sl)) for i := range sl { result[i] = f(sl[i]) } return result }
go
func MapS(f func(string) string, sl []string) (result []string) { result = make([]string, len(sl)) for i := range sl { result[i] = f(sl[i]) } return result }
[ "func", "MapS", "(", "f", "func", "(", "string", ")", "string", ",", "sl", "[", "]", "string", ")", "(", "result", "[", "]", "string", ")", "{", "result", "=", "make", "(", "[", "]", "string", ",", "len", "(", "sl", ")", ")", "\n", "for", "i"...
// Map a function on each element of a slice of strings
[ "Map", "a", "function", "on", "each", "element", "of", "a", "slice", "of", "strings" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/misc.go#L59-L65
17,224
xyproto/term
misc.go
FilterS
func FilterS(f func(string) bool, sl []string) (result []string) { result = make([]string, 0) for i := range sl { if f(sl[i]) { result = append(result, sl[i]) } } return result }
go
func FilterS(f func(string) bool, sl []string) (result []string) { result = make([]string, 0) for i := range sl { if f(sl[i]) { result = append(result, sl[i]) } } return result }
[ "func", "FilterS", "(", "f", "func", "(", "string", ")", "bool", ",", "sl", "[", "]", "string", ")", "(", "result", "[", "]", "string", ")", "{", "result", "=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "i", ":=", "range", ...
// Filter out all strings where the function does not return true
[ "Filter", "out", "all", "strings", "where", "the", "function", "does", "not", "return", "true" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/misc.go#L68-L76
17,225
xyproto/term
misc.go
Repeat
func Repeat(text string, n int) string { var sb strings.Builder for i := 0; i < n; i++ { sb.WriteString(text) } return sb.String() }
go
func Repeat(text string, n int) string { var sb strings.Builder for i := 0; i < n; i++ { sb.WriteString(text) } return sb.String() }
[ "func", "Repeat", "(", "text", "string", ",", "n", "int", ")", "string", "{", "var", "sb", "strings", ".", "Builder", "\n", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "sb", ".", "WriteString", "(", "text", ")", "\n", "}", ...
// Repeat a string n number of times
[ "Repeat", "a", "string", "n", "number", "of", "times" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/misc.go#L96-L102
17,226
xyproto/term
misc.go
RepeatRune
func RepeatRune(r rune, n int) string { var sb strings.Builder for i := 0; i < n; i++ { sb.WriteRune(r) } return sb.String() }
go
func RepeatRune(r rune, n int) string { var sb strings.Builder for i := 0; i < n; i++ { sb.WriteRune(r) } return sb.String() }
[ "func", "RepeatRune", "(", "r", "rune", ",", "n", "int", ")", "string", "{", "var", "sb", "strings", ".", "Builder", "\n", "for", "i", ":=", "0", ";", "i", "<", "n", ";", "i", "++", "{", "sb", ".", "WriteRune", "(", "r", ")", "\n", "}", "\n",...
// Repeat a rune n number of times
[ "Repeat", "a", "rune", "n", "number", "of", "times" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/misc.go#L105-L111
17,227
xyproto/term
term.go
Err
func (o *TextOutput) Err(msg string) { if o.enabled { fmt.Fprintf(os.Stderr, o.DarkRed(msg)+"\n") } }
go
func (o *TextOutput) Err(msg string) { if o.enabled { fmt.Fprintf(os.Stderr, o.DarkRed(msg)+"\n") } }
[ "func", "(", "o", "*", "TextOutput", ")", "Err", "(", "msg", "string", ")", "{", "if", "o", ".", "enabled", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "o", ".", "DarkRed", "(", "msg", ")", "+", "\"", "\\n", "\"", ")", "\n", "}...
// Write an error message in red to stderr if output is enabled
[ "Write", "an", "error", "message", "in", "red", "to", "stderr", "if", "output", "is", "enabled" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/term.go#L23-L27
17,228
xyproto/term
term.go
ErrExit
func (o *TextOutput) ErrExit(msg string) { o.Err(msg) os.Exit(1) }
go
func (o *TextOutput) ErrExit(msg string) { o.Err(msg) os.Exit(1) }
[ "func", "(", "o", "*", "TextOutput", ")", "ErrExit", "(", "msg", "string", ")", "{", "o", ".", "Err", "(", "msg", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}" ]
// Write an error message to stderr and quit with exit code 1
[ "Write", "an", "error", "message", "to", "stderr", "and", "quit", "with", "exit", "code", "1" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/term.go#L30-L33
17,229
xyproto/term
term.go
Println
func (o *TextOutput) Println(msg string) { if o.enabled { fmt.Println(msg) } }
go
func (o *TextOutput) Println(msg string) { if o.enabled { fmt.Println(msg) } }
[ "func", "(", "o", "*", "TextOutput", ")", "Println", "(", "msg", "string", ")", "{", "if", "o", ".", "enabled", "{", "fmt", ".", "Println", "(", "msg", ")", "\n", "}", "\n", "}" ]
// Write a message to stdout if output is enabled
[ "Write", "a", "message", "to", "stdout", "if", "output", "is", "enabled" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/term.go#L36-L40
17,230
xyproto/term
term.go
colorOn
func (o *TextOutput) colorOn(num1 int, num2 int) string { if o.color { return fmt.Sprintf("\033[%d;%dm", num1, num2) } return "" }
go
func (o *TextOutput) colorOn(num1 int, num2 int) string { if o.color { return fmt.Sprintf("\033[%d;%dm", num1, num2) } return "" }
[ "func", "(", "o", "*", "TextOutput", ")", "colorOn", "(", "num1", "int", ",", "num2", "int", ")", "string", "{", "if", "o", ".", "color", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\\033", "\"", ",", "num1", ",", "num2", ")", "\n", "}", ...
// Changes the color state in the terminal emulator
[ "Changes", "the", "color", "state", "in", "the", "terminal", "emulator" ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/term.go#L48-L53
17,231
xyproto/term
guielements.go
DrawBox
func DrawBox(r *Box, extrude bool) *Rect { x := r.frame.X y := r.frame.Y width := r.frame.W height := r.frame.H FG1 := BOXLIGHT FG2 := BOXDARK if !extrude { FG1 = BOXDARK FG2 = BOXLIGHT } WriteRune(x, y, TLCHAR, FG1, BOXBG) Write(x+1, y, RepeatRune(HCHAR, width-2), FG1, BOXBG) WriteRune(x+width-1, y, TRCHAR, FG1, BOXBG) for i := y + 1; i < y+height; i++ { WriteRune(x, i, VCHAR, FG1, BOXBG) Write(x+1, i, RepeatRune(' ', width-2), FG1, BOXBG) WriteRune(x+width-1, i, VCHAR2, FG2, BOXBG) } WriteRune(x, y+height-1, BLCHAR, FG1, BOXBG) Write(x+1, y+height-1, RepeatRune(HCHAR2, width-2), FG2, BOXBG) WriteRune(x+width-1, y+height-1, BRCHAR, FG2, BOXBG) return &Rect{x, y, width, height} }
go
func DrawBox(r *Box, extrude bool) *Rect { x := r.frame.X y := r.frame.Y width := r.frame.W height := r.frame.H FG1 := BOXLIGHT FG2 := BOXDARK if !extrude { FG1 = BOXDARK FG2 = BOXLIGHT } WriteRune(x, y, TLCHAR, FG1, BOXBG) Write(x+1, y, RepeatRune(HCHAR, width-2), FG1, BOXBG) WriteRune(x+width-1, y, TRCHAR, FG1, BOXBG) for i := y + 1; i < y+height; i++ { WriteRune(x, i, VCHAR, FG1, BOXBG) Write(x+1, i, RepeatRune(' ', width-2), FG1, BOXBG) WriteRune(x+width-1, i, VCHAR2, FG2, BOXBG) } WriteRune(x, y+height-1, BLCHAR, FG1, BOXBG) Write(x+1, y+height-1, RepeatRune(HCHAR2, width-2), FG2, BOXBG) WriteRune(x+width-1, y+height-1, BRCHAR, FG2, BOXBG) return &Rect{x, y, width, height} }
[ "func", "DrawBox", "(", "r", "*", "Box", ",", "extrude", "bool", ")", "*", "Rect", "{", "x", ":=", "r", ".", "frame", ".", "X", "\n", "y", ":=", "r", ".", "frame", ".", "Y", "\n", "width", ":=", "r", ".", "frame", ".", "W", "\n", "height", ...
// Draw a box using ASCII graphics. // The given Box struct defines the size and placement. // If extrude is True, the box looks a bit more like it's sticking out.
[ "Draw", "a", "box", "using", "ASCII", "graphics", ".", "The", "given", "Box", "struct", "defines", "the", "size", "and", "placement", ".", "If", "extrude", "is", "True", "the", "box", "looks", "a", "bit", "more", "like", "it", "s", "sticking", "out", "...
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/guielements.go#L11-L34
17,232
xyproto/term
guielements.go
DrawList
func DrawList(r *Box, items []string, selected int) { for i, s := range items { color := LISTTEXT if i == selected { color = LISTFOCUS } Write(r.frame.X, r.frame.Y+i, s, color, BOXBG) } }
go
func DrawList(r *Box, items []string, selected int) { for i, s := range items { color := LISTTEXT if i == selected { color = LISTFOCUS } Write(r.frame.X, r.frame.Y+i, s, color, BOXBG) } }
[ "func", "DrawList", "(", "r", "*", "Box", ",", "items", "[", "]", "string", ",", "selected", "int", ")", "{", "for", "i", ",", "s", ":=", "range", "items", "{", "color", ":=", "LISTTEXT", "\n", "if", "i", "==", "selected", "{", "color", "=", "LIS...
// Draw a list widget. Takes a Box struct for the size and position. // Takes a list of strings to be listed and an int that represents // which item is currently selected. Does not scroll or wrap.
[ "Draw", "a", "list", "widget", ".", "Takes", "a", "Box", "struct", "for", "the", "size", "and", "position", ".", "Takes", "a", "list", "of", "strings", "to", "be", "listed", "and", "an", "int", "that", "represents", "which", "item", "is", "currently", ...
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/guielements.go#L39-L47
17,233
xyproto/term
guielements.go
DrawButton
func DrawButton(x, y int, text string, active bool) { color := BUTTONTEXT if active { color = BUTTONFOCUS } Write(x, y, "< ", color, BG) Write(x+3, y, text, color, BG) Write(x+3+len(text), y, " >", color, BG) }
go
func DrawButton(x, y int, text string, active bool) { color := BUTTONTEXT if active { color = BUTTONFOCUS } Write(x, y, "< ", color, BG) Write(x+3, y, text, color, BG) Write(x+3+len(text), y, " >", color, BG) }
[ "func", "DrawButton", "(", "x", ",", "y", "int", ",", "text", "string", ",", "active", "bool", ")", "{", "color", ":=", "BUTTONTEXT", "\n", "if", "active", "{", "color", "=", "BUTTONFOCUS", "\n", "}", "\n", "Write", "(", "x", ",", "y", ",", "\"", ...
// Draws a button widget at the given placement, // with the given text. If active is False, // it will look more "grayed out".
[ "Draws", "a", "button", "widget", "at", "the", "given", "placement", "with", "the", "given", "text", ".", "If", "active", "is", "False", "it", "will", "look", "more", "grayed", "out", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/guielements.go#L52-L60
17,234
xyproto/term
guielements.go
DrawAsciiArt
func DrawAsciiArt(x, y int, text string) int { var i int for i, line := range Splitlines(text) { Write(x, y+i, line, TEXTCOLOR, BOXBG) } return y + i }
go
func DrawAsciiArt(x, y int, text string) int { var i int for i, line := range Splitlines(text) { Write(x, y+i, line, TEXTCOLOR, BOXBG) } return y + i }
[ "func", "DrawAsciiArt", "(", "x", ",", "y", "int", ",", "text", "string", ")", "int", "{", "var", "i", "int", "\n", "for", "i", ",", "line", ":=", "range", "Splitlines", "(", "text", ")", "{", "Write", "(", "x", ",", "y", "+", "i", ",", "line",...
// Outputs a multiline string at the given coordinates. // Uses the box background color. // Returns the final y coordinate after drawing.
[ "Outputs", "a", "multiline", "string", "at", "the", "given", "coordinates", ".", "Uses", "the", "box", "background", "color", ".", "Returns", "the", "final", "y", "coordinate", "after", "drawing", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/guielements.go#L65-L71
17,235
xyproto/term
guielements.go
DrawRaw
func DrawRaw(x, y int, text string) int { var i int for i, line := range Splitlines(text) { Write(x, y+i, line, TEXTCOLOR, BG) } return y + i }
go
func DrawRaw(x, y int, text string) int { var i int for i, line := range Splitlines(text) { Write(x, y+i, line, TEXTCOLOR, BG) } return y + i }
[ "func", "DrawRaw", "(", "x", ",", "y", "int", ",", "text", "string", ")", "int", "{", "var", "i", "int", "\n", "for", "i", ",", "line", ":=", "range", "Splitlines", "(", "text", ")", "{", "Write", "(", "x", ",", "y", "+", "i", ",", "line", ",...
// Outputs a multiline string at the given coordinates. // Uses the default background color. // Returns the final y coordinate after drawing.
[ "Outputs", "a", "multiline", "string", "at", "the", "given", "coordinates", ".", "Uses", "the", "default", "background", "color", ".", "Returns", "the", "final", "y", "coordinate", "after", "drawing", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/guielements.go#L76-L82
17,236
xyproto/term
boxes.go
Center
func (b *Box) Center(container *Box) { widthleftover := container.inner.W - b.frame.W heightleftover := container.inner.H - b.frame.H b.frame.X = container.inner.X + widthleftover/2 b.frame.Y = container.inner.Y + heightleftover/2 }
go
func (b *Box) Center(container *Box) { widthleftover := container.inner.W - b.frame.W heightleftover := container.inner.H - b.frame.H b.frame.X = container.inner.X + widthleftover/2 b.frame.Y = container.inner.Y + heightleftover/2 }
[ "func", "(", "b", "*", "Box", ")", "Center", "(", "container", "*", "Box", ")", "{", "widthleftover", ":=", "container", ".", "inner", ".", "W", "-", "b", ".", "frame", ".", "W", "\n", "heightleftover", ":=", "container", ".", "inner", ".", "H", "-...
// Place a Box at the center of the given container.
[ "Place", "a", "Box", "at", "the", "center", "of", "the", "given", "container", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/boxes.go#L36-L41
17,237
xyproto/term
boxes.go
FillWithMargins
func (b *Box) FillWithMargins(container *Box, margins int) { b.Fill(container) b.frame.X += margins b.frame.Y += margins b.frame.W -= margins * 2 b.frame.H -= margins * 2 }
go
func (b *Box) FillWithMargins(container *Box, margins int) { b.Fill(container) b.frame.X += margins b.frame.Y += margins b.frame.W -= margins * 2 b.frame.H -= margins * 2 }
[ "func", "(", "b", "*", "Box", ")", "FillWithMargins", "(", "container", "*", "Box", ",", "margins", "int", ")", "{", "b", ".", "Fill", "(", "container", ")", "\n", "b", ".", "frame", ".", "X", "+=", "margins", "\n", "b", ".", "frame", ".", "Y", ...
// Place a Box inside a given container, with the given margins. // Margins are given in number of characters.
[ "Place", "a", "Box", "inside", "a", "given", "container", "with", "the", "given", "margins", ".", "Margins", "are", "given", "in", "number", "of", "characters", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/boxes.go#L53-L59
17,238
xyproto/term
boxes.go
FillWithPercentageMargins
func (b *Box) FillWithPercentageMargins(container *Box, horizmarginp float32, vertmarginp float32) { horizmargin := int(float32(container.inner.W) * horizmarginp) vertmargin := int(float32(container.inner.H) * vertmarginp) b.Fill(container) b.frame.X += horizmargin b.frame.Y += vertmargin b.frame.W -= horizmargin * 2 b.frame.H -= vertmargin * 2 }
go
func (b *Box) FillWithPercentageMargins(container *Box, horizmarginp float32, vertmarginp float32) { horizmargin := int(float32(container.inner.W) * horizmarginp) vertmargin := int(float32(container.inner.H) * vertmarginp) b.Fill(container) b.frame.X += horizmargin b.frame.Y += vertmargin b.frame.W -= horizmargin * 2 b.frame.H -= vertmargin * 2 }
[ "func", "(", "b", "*", "Box", ")", "FillWithPercentageMargins", "(", "container", "*", "Box", ",", "horizmarginp", "float32", ",", "vertmarginp", "float32", ")", "{", "horizmargin", ":=", "int", "(", "float32", "(", "container", ".", "inner", ".", "W", ")"...
// Place a Box inside a given container, using the given percentage wise ratios. // horizmarginp can for example be 0.1 for a 10% horizontal margin around // the inner box. vertmarginp works similarly, but for the vertical margins.
[ "Place", "a", "Box", "inside", "a", "given", "container", "using", "the", "given", "percentage", "wise", "ratios", ".", "horizmarginp", "can", "for", "example", "be", "0", ".", "1", "for", "a", "10%", "horizontal", "margin", "around", "the", "inner", "box"...
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/boxes.go#L64-L72
17,239
xyproto/term
boxes.go
GetContentPos
func (b *Box) GetContentPos() (int, int) { return b.inner.X, b.inner.Y }
go
func (b *Box) GetContentPos() (int, int) { return b.inner.X, b.inner.Y }
[ "func", "(", "b", "*", "Box", ")", "GetContentPos", "(", ")", "(", "int", ",", "int", ")", "{", "return", "b", ".", "inner", ".", "X", ",", "b", ".", "inner", ".", "Y", "\n", "}" ]
// Retrieves the position of the inner rectangle.
[ "Retrieves", "the", "position", "of", "the", "inner", "rectangle", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/boxes.go#L75-L77
17,240
xyproto/term
boxes.go
Place
func (b *Box) Place(container *Box) { b.frame.X = container.inner.X b.frame.Y = container.inner.Y }
go
func (b *Box) Place(container *Box) { b.frame.X = container.inner.X b.frame.Y = container.inner.Y }
[ "func", "(", "b", "*", "Box", ")", "Place", "(", "container", "*", "Box", ")", "{", "b", ".", "frame", ".", "X", "=", "container", ".", "inner", ".", "X", "\n", "b", ".", "frame", ".", "Y", "=", "container", ".", "inner", ".", "Y", "\n", "}" ...
// Place a Box within the given container.
[ "Place", "a", "Box", "within", "the", "given", "container", "." ]
28a7b668c67eafc39c1cb77bd1a397e00d80dd95
https://github.com/xyproto/term/blob/28a7b668c67eafc39c1cb77bd1a397e00d80dd95/boxes.go#L110-L113
17,241
luizbafilho/fusis
fusis/operations.go
GetService
func (b *FusisBalancer) GetService(name string) (*types.Service, error) { return b.store.GetService(name) }
go
func (b *FusisBalancer) GetService(name string) (*types.Service, error) { return b.store.GetService(name) }
[ "func", "(", "b", "*", "FusisBalancer", ")", "GetService", "(", "name", "string", ")", "(", "*", "types", ".", "Service", ",", "error", ")", "{", "return", "b", ".", "store", ".", "GetService", "(", "name", ")", "\n", "}" ]
//GetService get a service
[ "GetService", "get", "a", "service" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/fusis/operations.go#L15-L17
17,242
luizbafilho/fusis
fusis/balancer.go
cleanup
func (b *FusisBalancer) cleanup() error { b.flushVips() if out, err := exec.Command("ipvsadm", "--clear").CombinedOutput(); err != nil { log.Fatal(fmt.Errorf("Running ipvsadm --clear failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)) } return nil }
go
func (b *FusisBalancer) cleanup() error { b.flushVips() if out, err := exec.Command("ipvsadm", "--clear").CombinedOutput(); err != nil { log.Fatal(fmt.Errorf("Running ipvsadm --clear failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)) } return nil }
[ "func", "(", "b", "*", "FusisBalancer", ")", "cleanup", "(", ")", "error", "{", "b", ".", "flushVips", "(", ")", "\n\n", "if", "out", ",", "err", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ")", ".", "CombinedOutput", "(", ")"...
// Utility method to cleanup state for tests
[ "Utility", "method", "to", "cleanup", "state", "for", "tests" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/fusis/balancer.go#L290-L298
17,243
luizbafilho/fusis
net/net.go
AddIp
func AddIp(ip, iface string) error { link, err := netlink.LinkByName(iface) if err != nil { return err } addr, err := netlink.ParseAddr(ip) if err != nil { return err } return netlink.AddrAdd(link, addr) }
go
func AddIp(ip, iface string) error { link, err := netlink.LinkByName(iface) if err != nil { return err } addr, err := netlink.ParseAddr(ip) if err != nil { return err } return netlink.AddrAdd(link, addr) }
[ "func", "AddIp", "(", "ip", ",", "iface", "string", ")", "error", "{", "link", ",", "err", ":=", "netlink", ".", "LinkByName", "(", "iface", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "addr", ",", "err", ":=", "...
//AddIp it receives a CIDR Address and add it to the given interface
[ "AddIp", "it", "receives", "a", "CIDR", "Address", "and", "add", "it", "to", "the", "given", "interface" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/net/net.go#L13-L25
17,244
luizbafilho/fusis
ipam/ipam.go
New
func New(state state.State, config *config.BalancerConfig) (Allocator, error) { var rangeCursor *ipaddr.Cursor var err error ranges := strings.Join(config.Ipam.Ranges, ",") if ranges != "" { rangeCursor, err = ipaddr.Parse(ranges) if err != nil { return nil, errors.Wrap(err, "error parsing IPAM ranges") } } return &Ipam{rangeCursor, state, config}, nil }
go
func New(state state.State, config *config.BalancerConfig) (Allocator, error) { var rangeCursor *ipaddr.Cursor var err error ranges := strings.Join(config.Ipam.Ranges, ",") if ranges != "" { rangeCursor, err = ipaddr.Parse(ranges) if err != nil { return nil, errors.Wrap(err, "error parsing IPAM ranges") } } return &Ipam{rangeCursor, state, config}, nil }
[ "func", "New", "(", "state", "state", ".", "State", ",", "config", "*", "config", ".", "BalancerConfig", ")", "(", "Allocator", ",", "error", ")", "{", "var", "rangeCursor", "*", "ipaddr", ".", "Cursor", "\n", "var", "err", "error", "\n\n", "ranges", "...
//Init initilizes ipam module
[ "Init", "initilizes", "ipam", "module" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/ipam/ipam.go#L29-L42
17,245
luizbafilho/fusis
ipam/ipam.go
AllocateVIP
func (i *Ipam) AllocateVIP(s *types.Service) error { if i.rangeCursor == nil { return ErrNoVipAvailable } for pos := i.rangeCursor.Next(); pos != nil; pos = i.rangeCursor.Next() { //TODO: make it compatible if IPv6 // Verifies if it is a base IP address. example: 10.0.100.0; 192.168.1.0 if pos.IP.To4()[3] == 0 { pos = i.rangeCursor.Next() } assigned := i.ipIsAssigned(pos.IP.String(), i.state) if !assigned { i.rangeCursor.Set(i.rangeCursor.First()) s.Address = pos.IP.String() return nil } } return ErrNoVipAvailable }
go
func (i *Ipam) AllocateVIP(s *types.Service) error { if i.rangeCursor == nil { return ErrNoVipAvailable } for pos := i.rangeCursor.Next(); pos != nil; pos = i.rangeCursor.Next() { //TODO: make it compatible if IPv6 // Verifies if it is a base IP address. example: 10.0.100.0; 192.168.1.0 if pos.IP.To4()[3] == 0 { pos = i.rangeCursor.Next() } assigned := i.ipIsAssigned(pos.IP.String(), i.state) if !assigned { i.rangeCursor.Set(i.rangeCursor.First()) s.Address = pos.IP.String() return nil } } return ErrNoVipAvailable }
[ "func", "(", "i", "*", "Ipam", ")", "AllocateVIP", "(", "s", "*", "types", ".", "Service", ")", "error", "{", "if", "i", ".", "rangeCursor", "==", "nil", "{", "return", "ErrNoVipAvailable", "\n", "}", "\n\n", "for", "pos", ":=", "i", ".", "rangeCurso...
//Allocate allocates a new avaliable ip
[ "Allocate", "allocates", "a", "new", "avaliable", "ip" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/ipam/ipam.go#L45-L67
17,246
luizbafilho/fusis
state/state.go
New
func New() (State, error) { state := &FusisState{ services: Services{}, destinations: Destinations{}, } return state, nil }
go
func New() (State, error) { state := &FusisState{ services: Services{}, destinations: Destinations{}, } return state, nil }
[ "func", "New", "(", ")", "(", "State", ",", "error", ")", "{", "state", ":=", "&", "FusisState", "{", "services", ":", "Services", "{", "}", ",", "destinations", ":", "Destinations", "{", "}", ",", "}", "\n\n", "return", "state", ",", "nil", "\n", ...
// New creates a new Engine
[ "New", "creates", "a", "new", "Engine" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/state/state.go#L40-L47
17,247
luizbafilho/fusis
ipvs/ipvs.go
New
func New() (*Ipvs, error) { handler, err := ipvs.New("") if err != nil { return nil, fmt.Errorf("[ipvs] Initialisation failed: %v", err) } if err := handler.Flush(); err != nil { return nil, fmt.Errorf("[ipvs] Flushing table failed: %v", err) } return &Ipvs{ handler: handler, }, nil }
go
func New() (*Ipvs, error) { handler, err := ipvs.New("") if err != nil { return nil, fmt.Errorf("[ipvs] Initialisation failed: %v", err) } if err := handler.Flush(); err != nil { return nil, fmt.Errorf("[ipvs] Flushing table failed: %v", err) } return &Ipvs{ handler: handler, }, nil }
[ "func", "New", "(", ")", "(", "*", "Ipvs", ",", "error", ")", "{", "handler", ",", "err", ":=", "ipvs", ".", "New", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", ...
//New creates a new ipvs struct and flushes the IPVS Table
[ "New", "creates", "a", "new", "ipvs", "struct", "and", "flushes", "the", "IPVS", "Table" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/ipvs/ipvs.go#L30-L43
17,248
luizbafilho/fusis
ipvs/ipvs.go
Sync
func (ipvs *Ipvs) Sync(state state.State) error { start := time.Now() defer func() { log.Debugf("[ipvs] Sync took %v", time.Since(start)) }() ipvs.Lock() defer ipvs.Unlock() log.Debug("[ipvs] Syncing") stateSet := ipvs.getStateServicesSet(state) currentSet, err := ipvs.getCurrentServicesSet() if err != nil { return err } rulesToAdd := stateSet.Difference(currentSet) rulesToRemove := currentSet.Difference(stateSet) // Adding services and destinations missing for r := range rulesToAdd.Iter() { service := r.(types.Service) dsts := state.GetDestinations(&service) if err := ipvs.addServiceAndDestinations(service, dsts); err != nil { return err } log.Debugf("[ipvs] Added service: %#v with destinations: %#v", service, dsts) } // Cleaning rules for r := range rulesToRemove.Iter() { service := r.(types.Service) err := ipvs.handler.DelService(ToIpvsService(&service)) if err != nil { return err } log.Debugf("[ipvs] Removed service: %#v", service) } // Syncing destination rules for _, s := range state.GetServices() { if err := ipvs.syncDestinations(state, s); err != nil { return err } } return nil }
go
func (ipvs *Ipvs) Sync(state state.State) error { start := time.Now() defer func() { log.Debugf("[ipvs] Sync took %v", time.Since(start)) }() ipvs.Lock() defer ipvs.Unlock() log.Debug("[ipvs] Syncing") stateSet := ipvs.getStateServicesSet(state) currentSet, err := ipvs.getCurrentServicesSet() if err != nil { return err } rulesToAdd := stateSet.Difference(currentSet) rulesToRemove := currentSet.Difference(stateSet) // Adding services and destinations missing for r := range rulesToAdd.Iter() { service := r.(types.Service) dsts := state.GetDestinations(&service) if err := ipvs.addServiceAndDestinations(service, dsts); err != nil { return err } log.Debugf("[ipvs] Added service: %#v with destinations: %#v", service, dsts) } // Cleaning rules for r := range rulesToRemove.Iter() { service := r.(types.Service) err := ipvs.handler.DelService(ToIpvsService(&service)) if err != nil { return err } log.Debugf("[ipvs] Removed service: %#v", service) } // Syncing destination rules for _, s := range state.GetServices() { if err := ipvs.syncDestinations(state, s); err != nil { return err } } return nil }
[ "func", "(", "ipvs", "*", "Ipvs", ")", "Sync", "(", "state", "state", ".", "State", ")", "error", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n", "defer", "func", "(", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "time", ".", ...
// Sync syncs all ipvs rules present in state to kernel
[ "Sync", "syncs", "all", "ipvs", "rules", "present", "in", "state", "to", "kernel" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/ipvs/ipvs.go#L46-L94
17,249
luizbafilho/fusis
iptables/iptables.go
Sync
func (i IptablesMngr) Sync(s state.State) error { start := time.Now() defer func() { log.Debugf("[iptables ] Sync took %v", time.Since(start)) }() log.Debug("[iptables] Syncing") stateSet, err := i.getStateRulesSet(s) if err != nil { return err } kernelSet, err := i.getKernelRulesSet() if err != nil { return err } rulesToAdd := stateSet.Difference(kernelSet) rulesToRemove := kernelSet.Difference(stateSet) // Adding missing rules for r := range rulesToAdd.Iter() { rule := r.(SnatRule) err := i.addRule(rule) if err != nil { return err } log.Debugf("[iptables] Added rule: %#v", rule) } // Cleaning rules for r := range rulesToRemove.Iter() { rule := r.(SnatRule) err := i.removeRule(rule) if err != nil { return err } log.Debugf("[iptables] Removed rule: %#v", rule) } return nil }
go
func (i IptablesMngr) Sync(s state.State) error { start := time.Now() defer func() { log.Debugf("[iptables ] Sync took %v", time.Since(start)) }() log.Debug("[iptables] Syncing") stateSet, err := i.getStateRulesSet(s) if err != nil { return err } kernelSet, err := i.getKernelRulesSet() if err != nil { return err } rulesToAdd := stateSet.Difference(kernelSet) rulesToRemove := kernelSet.Difference(stateSet) // Adding missing rules for r := range rulesToAdd.Iter() { rule := r.(SnatRule) err := i.addRule(rule) if err != nil { return err } log.Debugf("[iptables] Added rule: %#v", rule) } // Cleaning rules for r := range rulesToRemove.Iter() { rule := r.(SnatRule) err := i.removeRule(rule) if err != nil { return err } log.Debugf("[iptables] Removed rule: %#v", rule) } return nil }
[ "func", "(", "i", "IptablesMngr", ")", "Sync", "(", "s", "state", ".", "State", ")", "error", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n", "defer", "func", "(", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "time", ".", "Sinc...
// Sync syncs all iptables rules
[ "Sync", "syncs", "all", "iptables", "rules" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/iptables/iptables.go#L80-L122
17,250
luizbafilho/fusis
store/store.go
AddService
func (s *FusisStore) AddService(svc *types.Service) error { svcKey := s.key("services", svc.GetId()) ipvsKey := s.key("ipvs-ids", "services", svc.IpvsId()) // Validating service if err := s.validateService(svc); err != nil { return err } value, err := json.Marshal(svc) if err != nil { return errors.Wrapf(err, "[store] Error marshaling service: %v", svc) } svcCmp := notFound(svcKey) ipvsCmp := notFound(ipvsKey) svcPut := clientv3.OpPut(svcKey, string(value)) ipvsPut := clientv3.OpPut(ipvsKey, "true") resp, err := s.kv.Txn(context.TODO()). If(svcCmp, ipvsCmp). Then(svcPut, ipvsPut). Commit() if err != nil { return errors.Wrapf(err, "[store] Error sending service to Etcd: %v", svc) } // resp.Succeeded means the compare clause was true if resp.Succeeded == false { return types.ErrValidation{Type: "service", Errors: map[string]string{"ipvs": "service must be unique"}} } return nil }
go
func (s *FusisStore) AddService(svc *types.Service) error { svcKey := s.key("services", svc.GetId()) ipvsKey := s.key("ipvs-ids", "services", svc.IpvsId()) // Validating service if err := s.validateService(svc); err != nil { return err } value, err := json.Marshal(svc) if err != nil { return errors.Wrapf(err, "[store] Error marshaling service: %v", svc) } svcCmp := notFound(svcKey) ipvsCmp := notFound(ipvsKey) svcPut := clientv3.OpPut(svcKey, string(value)) ipvsPut := clientv3.OpPut(ipvsKey, "true") resp, err := s.kv.Txn(context.TODO()). If(svcCmp, ipvsCmp). Then(svcPut, ipvsPut). Commit() if err != nil { return errors.Wrapf(err, "[store] Error sending service to Etcd: %v", svc) } // resp.Succeeded means the compare clause was true if resp.Succeeded == false { return types.ErrValidation{Type: "service", Errors: map[string]string{"ipvs": "service must be unique"}} } return nil }
[ "func", "(", "s", "*", "FusisStore", ")", "AddService", "(", "svc", "*", "types", ".", "Service", ")", "error", "{", "svcKey", ":=", "s", ".", "key", "(", "\"", "\"", ",", "svc", ".", "GetId", "(", ")", ")", "\n", "ipvsKey", ":=", "s", ".", "ke...
// // AddService adds a new services to store. It validates the name // uniqueness and the IPVS uniqueness by saving the IPVS key // in the store, which consists in a combination of address, port // and protocol.
[ "AddService", "adds", "a", "new", "services", "to", "store", ".", "It", "validates", "the", "name", "uniqueness", "and", "the", "IPVS", "uniqueness", "by", "saving", "the", "IPVS", "key", "in", "the", "store", "which", "consists", "in", "a", "combination", ...
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/store/store.go#L227-L260
17,251
luizbafilho/fusis
api/api.go
Serve
func (as ApiService) Serve() { port := os.Getenv("PORT") if port == "" { port = "8000" } host := os.Getenv("HOST") if host == "" { host = "0.0.0.0" } address := host + ":" + port // Start server as.echo.Logger.Fatal(as.echo.Start(address)) }
go
func (as ApiService) Serve() { port := os.Getenv("PORT") if port == "" { port = "8000" } host := os.Getenv("HOST") if host == "" { host = "0.0.0.0" } address := host + ":" + port // Start server as.echo.Logger.Fatal(as.echo.Start(address)) }
[ "func", "(", "as", "ApiService", ")", "Serve", "(", ")", "{", "port", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "port", "==", "\"", "\"", "{", "port", "=", "\"", "\"", "\n", "}", "\n\n", "host", ":=", "os", ".", "Getenv", "...
// Serve starts the api. // Binds IP using HOST env or 0.0.0.0 // Binds to port using PORT env or 8000
[ "Serve", "starts", "the", "api", ".", "Binds", "IP", "using", "HOST", "env", "or", "0", ".", "0", ".", "0", ".", "0", "Binds", "to", "port", "using", "PORT", "env", "or", "8000" ]
22c38b193875a17eeeaf1fd1efd40698ed5ad424
https://github.com/luizbafilho/fusis/blob/22c38b193875a17eeeaf1fd1efd40698ed5ad424/api/api.go#L53-L68
17,252
jeevatkm/go-model
model.go
AddConversion
func AddConversion(in interface{}, out interface{}, converter Converter) { srcType := extractType(in) targetType := extractType(out) AddConversionByType(srcType, targetType, converter) }
go
func AddConversion(in interface{}, out interface{}, converter Converter) { srcType := extractType(in) targetType := extractType(out) AddConversionByType(srcType, targetType, converter) }
[ "func", "AddConversion", "(", "in", "interface", "{", "}", ",", "out", "interface", "{", "}", ",", "converter", "Converter", ")", "{", "srcType", ":=", "extractType", "(", "in", ")", "\n", "targetType", ":=", "extractType", "(", "out", ")", "\n", "AddCon...
// AddConversion mothod allows registering a custom `Converter` into the global `converterMap` // by supplying pointers of the target types.
[ "AddConversion", "mothod", "allows", "registering", "a", "custom", "Converter", "into", "the", "global", "converterMap", "by", "supplying", "pointers", "of", "the", "target", "types", "." ]
da0e6703b9dcc406eb59261cee520054cf6e22e0
https://github.com/jeevatkm/go-model/blob/da0e6703b9dcc406eb59261cee520054cf6e22e0/model.go#L94-L98
17,253
jeevatkm/go-model
model.go
AddConversionByType
func AddConversionByType(srcType reflect.Type, targetType reflect.Type, converter Converter) { if _, ok := converterMap[srcType]; !ok { converterMap[srcType] = map[reflect.Type]Converter{} } converterMap[srcType][targetType] = converter }
go
func AddConversionByType(srcType reflect.Type, targetType reflect.Type, converter Converter) { if _, ok := converterMap[srcType]; !ok { converterMap[srcType] = map[reflect.Type]Converter{} } converterMap[srcType][targetType] = converter }
[ "func", "AddConversionByType", "(", "srcType", "reflect", ".", "Type", ",", "targetType", "reflect", ".", "Type", ",", "converter", "Converter", ")", "{", "if", "_", ",", "ok", ":=", "converterMap", "[", "srcType", "]", ";", "!", "ok", "{", "converterMap",...
// AddConversionByType allows registering a custom `Converter` into golbal `converterMap` by types.
[ "AddConversionByType", "allows", "registering", "a", "custom", "Converter", "into", "golbal", "converterMap", "by", "types", "." ]
da0e6703b9dcc406eb59261cee520054cf6e22e0
https://github.com/jeevatkm/go-model/blob/da0e6703b9dcc406eb59261cee520054cf6e22e0/model.go#L101-L106
17,254
jeevatkm/go-model
model.go
RemoveConversion
func RemoveConversion(in interface{}, out interface{}) { srcType := extractType(in) targetType := extractType(out) if _, ok := converterMap[srcType]; !ok { return } if _, ok := converterMap[srcType][targetType]; !ok { return } delete(converterMap[srcType], targetType) }
go
func RemoveConversion(in interface{}, out interface{}) { srcType := extractType(in) targetType := extractType(out) if _, ok := converterMap[srcType]; !ok { return } if _, ok := converterMap[srcType][targetType]; !ok { return } delete(converterMap[srcType], targetType) }
[ "func", "RemoveConversion", "(", "in", "interface", "{", "}", ",", "out", "interface", "{", "}", ")", "{", "srcType", ":=", "extractType", "(", "in", ")", "\n", "targetType", ":=", "extractType", "(", "out", ")", "\n", "if", "_", ",", "ok", ":=", "co...
// RemoveConversion registered conversions
[ "RemoveConversion", "registered", "conversions" ]
da0e6703b9dcc406eb59261cee520054cf6e22e0
https://github.com/jeevatkm/go-model/blob/da0e6703b9dcc406eb59261cee520054cf6e22e0/model.go#L109-L119
17,255
jeevatkm/go-model
model.go
init
func init() { noTraverseTypeList = map[reflect.Type]bool{} converterMap = map[reflect.Type]map[reflect.Type]Converter{} // Default NoTraverseTypeList // -------------------------- // Auto No Traverse struct list for not traversing Deep Level // However, field value will be evaluated/processed by go-model library AddNoTraverseType( time.Time{}, &time.Time{}, os.File{}, &os.File{}, http.Request{}, &http.Request{}, http.Response{}, &http.Response{}, // it's better to add it to the list for appropriate type(s) ) }
go
func init() { noTraverseTypeList = map[reflect.Type]bool{} converterMap = map[reflect.Type]map[reflect.Type]Converter{} // Default NoTraverseTypeList // -------------------------- // Auto No Traverse struct list for not traversing Deep Level // However, field value will be evaluated/processed by go-model library AddNoTraverseType( time.Time{}, &time.Time{}, os.File{}, &os.File{}, http.Request{}, &http.Request{}, http.Response{}, &http.Response{}, // it's better to add it to the list for appropriate type(s) ) }
[ "func", "init", "(", ")", "{", "noTraverseTypeList", "=", "map", "[", "reflect", ".", "Type", "]", "bool", "{", "}", "\n", "converterMap", "=", "map", "[", "reflect", ".", "Type", "]", "map", "[", "reflect", ".", "Type", "]", "Converter", "{", "}", ...
// // go-model init //
[ "go", "-", "model", "init" ]
da0e6703b9dcc406eb59261cee520054cf6e22e0
https://github.com/jeevatkm/go-model/blob/da0e6703b9dcc406eb59261cee520054cf6e22e0/model.go#L625-L645
17,256
jeevatkm/go-model
model.go
doCopy
func doCopy(dv, sv reflect.Value) []error { dv = indirect(dv) sv = indirect(sv) fields := modelFields(sv) var errs []error for _, f := range fields { sfv := sv.FieldByName(f.Name) tag := newTag(f.Tag.Get(TagName)) if tag.isOmitField() { continue } // check type is in NoTraverseTypeList or has 'notraverse' tag option noTraverse := (isNoTraverseType(sfv) || tag.isNoTraverse()) // check whether field is zero or not var isVal bool if isStruct(sfv) && !noTraverse { isVal = !IsZero(sfv.Interface()) } else { isVal = !isFieldZero(sfv) } // get dst field by name dfv := dv.FieldByName(f.Name) // validate field - exists in dst, kind and type err := validateCopyField(f, sfv, dfv) if err != nil { if err != errFieldNotExists { errs = append(errs, err) } continue } // if value is not exists if !isVal { // field value is zero and check 'omitempty' option present // then don't copy into destination struct // otherwise copy to dst if !tag.isOmitEmpty() { dfv.Set(zeroOf(dfv)) } continue } // check dst field settable or not if dfv.CanSet() { if isStruct(sfv) { // handle embedded or nested struct v, innerErrs := copyVal(dfv.Type(), sfv, noTraverse) // add errors to main stream errs = append(errs, innerErrs...) // handle based on ptr/non-ptr value dfv.Set(v) } else { v, err := copyVal(dfv.Type(), sfv, false) errs = append(errs, err...) dfv.Set(v) } } } return errs }
go
func doCopy(dv, sv reflect.Value) []error { dv = indirect(dv) sv = indirect(sv) fields := modelFields(sv) var errs []error for _, f := range fields { sfv := sv.FieldByName(f.Name) tag := newTag(f.Tag.Get(TagName)) if tag.isOmitField() { continue } // check type is in NoTraverseTypeList or has 'notraverse' tag option noTraverse := (isNoTraverseType(sfv) || tag.isNoTraverse()) // check whether field is zero or not var isVal bool if isStruct(sfv) && !noTraverse { isVal = !IsZero(sfv.Interface()) } else { isVal = !isFieldZero(sfv) } // get dst field by name dfv := dv.FieldByName(f.Name) // validate field - exists in dst, kind and type err := validateCopyField(f, sfv, dfv) if err != nil { if err != errFieldNotExists { errs = append(errs, err) } continue } // if value is not exists if !isVal { // field value is zero and check 'omitempty' option present // then don't copy into destination struct // otherwise copy to dst if !tag.isOmitEmpty() { dfv.Set(zeroOf(dfv)) } continue } // check dst field settable or not if dfv.CanSet() { if isStruct(sfv) { // handle embedded or nested struct v, innerErrs := copyVal(dfv.Type(), sfv, noTraverse) // add errors to main stream errs = append(errs, innerErrs...) // handle based on ptr/non-ptr value dfv.Set(v) } else { v, err := copyVal(dfv.Type(), sfv, false) errs = append(errs, err...) dfv.Set(v) } } } return errs }
[ "func", "doCopy", "(", "dv", ",", "sv", "reflect", ".", "Value", ")", "[", "]", "error", "{", "dv", "=", "indirect", "(", "dv", ")", "\n", "sv", "=", "indirect", "(", "sv", ")", "\n", "fields", ":=", "modelFields", "(", "sv", ")", "\n\n", "var", ...
// // Non-exported methods of model library //
[ "Non", "-", "exported", "methods", "of", "model", "library" ]
da0e6703b9dcc406eb59261cee520054cf6e22e0
https://github.com/jeevatkm/go-model/blob/da0e6703b9dcc406eb59261cee520054cf6e22e0/model.go#L651-L721
17,257
hypebeast/go-osc
osc/osc.go
AddMsgHandler
func (s *OscDispatcher) AddMsgHandler(addr string, handler HandlerFunc) error { if addr == "*" { s.defaultHandler = handler return nil } for _, chr := range "*?,[]{}# " { if strings.Contains(addr, fmt.Sprintf("%c", chr)) { return errors.New("OSC Address string may not contain any characters in \"*?,[]{}#") } } if addressExists(addr, s.handlers) { return errors.New("OSC address exists already") } s.handlers[addr] = handler return nil }
go
func (s *OscDispatcher) AddMsgHandler(addr string, handler HandlerFunc) error { if addr == "*" { s.defaultHandler = handler return nil } for _, chr := range "*?,[]{}# " { if strings.Contains(addr, fmt.Sprintf("%c", chr)) { return errors.New("OSC Address string may not contain any characters in \"*?,[]{}#") } } if addressExists(addr, s.handlers) { return errors.New("OSC address exists already") } s.handlers[addr] = handler return nil }
[ "func", "(", "s", "*", "OscDispatcher", ")", "AddMsgHandler", "(", "addr", "string", ",", "handler", "HandlerFunc", ")", "error", "{", "if", "addr", "==", "\"", "\"", "{", "s", ".", "defaultHandler", "=", "handler", "\n", "return", "nil", "\n", "}", "\...
// AddMsgHandler adds a new message handler for the given OSC address.
[ "AddMsgHandler", "adds", "a", "new", "message", "handler", "for", "the", "given", "OSC", "address", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L119-L136
17,258
hypebeast/go-osc
osc/osc.go
Dispatch
func (s *OscDispatcher) Dispatch(packet Packet) { switch packet.(type) { default: return case *Message: msg, _ := packet.(*Message) for addr, handler := range s.handlers { if msg.Match(addr) { handler.HandleMessage(msg) } } if s.defaultHandler != nil { s.defaultHandler.HandleMessage(msg) } case *Bundle: bundle, _ := packet.(*Bundle) timer := time.NewTimer(bundle.Timetag.ExpiresIn()) go func() { <-timer.C for _, message := range bundle.Messages { for address, handler := range s.handlers { if message.Match(address) { handler.HandleMessage(message) } } if s.defaultHandler != nil { s.defaultHandler.HandleMessage(message) } } // Process all bundles for _, b := range bundle.Bundles { s.Dispatch(b) } }() } }
go
func (s *OscDispatcher) Dispatch(packet Packet) { switch packet.(type) { default: return case *Message: msg, _ := packet.(*Message) for addr, handler := range s.handlers { if msg.Match(addr) { handler.HandleMessage(msg) } } if s.defaultHandler != nil { s.defaultHandler.HandleMessage(msg) } case *Bundle: bundle, _ := packet.(*Bundle) timer := time.NewTimer(bundle.Timetag.ExpiresIn()) go func() { <-timer.C for _, message := range bundle.Messages { for address, handler := range s.handlers { if message.Match(address) { handler.HandleMessage(message) } } if s.defaultHandler != nil { s.defaultHandler.HandleMessage(message) } } // Process all bundles for _, b := range bundle.Bundles { s.Dispatch(b) } }() } }
[ "func", "(", "s", "*", "OscDispatcher", ")", "Dispatch", "(", "packet", "Packet", ")", "{", "switch", "packet", ".", "(", "type", ")", "{", "default", ":", "return", "\n\n", "case", "*", "Message", ":", "msg", ",", "_", ":=", "packet", ".", "(", "*...
// Dispatch dispatches OSC packets. Implements the Dispatcher interface.
[ "Dispatch", "dispatches", "OSC", "packets", ".", "Implements", "the", "Dispatcher", "interface", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L139-L178
17,259
hypebeast/go-osc
osc/osc.go
Append
func (msg *Message) Append(args ...interface{}) { msg.Arguments = append(msg.Arguments, args...) }
go
func (msg *Message) Append(args ...interface{}) { msg.Arguments = append(msg.Arguments, args...) }
[ "func", "(", "msg", "*", "Message", ")", "Append", "(", "args", "...", "interface", "{", "}", ")", "{", "msg", ".", "Arguments", "=", "append", "(", "msg", ".", "Arguments", ",", "args", "...", ")", "\n", "}" ]
// Append appends the given arguments to the arguments list.
[ "Append", "appends", "the", "given", "arguments", "to", "the", "arguments", "list", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L190-L192
17,260
hypebeast/go-osc
osc/osc.go
Equals
func (msg *Message) Equals(m *Message) bool { return reflect.DeepEqual(msg, m) }
go
func (msg *Message) Equals(m *Message) bool { return reflect.DeepEqual(msg, m) }
[ "func", "(", "msg", "*", "Message", ")", "Equals", "(", "m", "*", "Message", ")", "bool", "{", "return", "reflect", ".", "DeepEqual", "(", "msg", ",", "m", ")", "\n", "}" ]
// Equals returns true if the given OSC Message `m` is equal to the current OSC // Message. It checks if the OSC address and the arguments are equal. Returns // true if the current object and `m` are equal.
[ "Equals", "returns", "true", "if", "the", "given", "OSC", "Message", "m", "is", "equal", "to", "the", "current", "OSC", "Message", ".", "It", "checks", "if", "the", "OSC", "address", "and", "the", "arguments", "are", "equal", ".", "Returns", "true", "if"...
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L197-L199
17,261
hypebeast/go-osc
osc/osc.go
ClearData
func (msg *Message) ClearData() { msg.Arguments = msg.Arguments[len(msg.Arguments):] }
go
func (msg *Message) ClearData() { msg.Arguments = msg.Arguments[len(msg.Arguments):] }
[ "func", "(", "msg", "*", "Message", ")", "ClearData", "(", ")", "{", "msg", ".", "Arguments", "=", "msg", ".", "Arguments", "[", "len", "(", "msg", ".", "Arguments", ")", ":", "]", "\n", "}" ]
// ClearData removes all arguments from the OSC Message.
[ "ClearData", "removes", "all", "arguments", "from", "the", "OSC", "Message", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L208-L210
17,262
hypebeast/go-osc
osc/osc.go
Match
func (msg *Message) Match(addr string) bool { exp := getRegEx(msg.Address) if exp.MatchString(addr) { return true } return false }
go
func (msg *Message) Match(addr string) bool { exp := getRegEx(msg.Address) if exp.MatchString(addr) { return true } return false }
[ "func", "(", "msg", "*", "Message", ")", "Match", "(", "addr", "string", ")", "bool", "{", "exp", ":=", "getRegEx", "(", "msg", ".", "Address", ")", "\n", "if", "exp", ".", "MatchString", "(", "addr", ")", "{", "return", "true", "\n", "}", "\n", ...
// Match returns true, if the address of the OSC Message matches the given // address. The match is case sensitive!
[ "Match", "returns", "true", "if", "the", "address", "of", "the", "OSC", "Message", "matches", "the", "given", "address", ".", "The", "match", "is", "case", "sensitive!" ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L214-L220
17,263
hypebeast/go-osc
osc/osc.go
TypeTags
func (msg *Message) TypeTags() (string, error) { if msg == nil { return "", fmt.Errorf("message is nil") } tags := "," for _, m := range msg.Arguments { s, err := getTypeTag(m) if err != nil { return "", err } tags += s } return tags, nil }
go
func (msg *Message) TypeTags() (string, error) { if msg == nil { return "", fmt.Errorf("message is nil") } tags := "," for _, m := range msg.Arguments { s, err := getTypeTag(m) if err != nil { return "", err } tags += s } return tags, nil }
[ "func", "(", "msg", "*", "Message", ")", "TypeTags", "(", ")", "(", "string", ",", "error", ")", "{", "if", "msg", "==", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "tags", ":=", "\"", ...
// TypeTags returns the type tag string.
[ "TypeTags", "returns", "the", "type", "tag", "string", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L223-L238
17,264
hypebeast/go-osc
osc/osc.go
Append
func (b *Bundle) Append(pck Packet) error { switch t := pck.(type) { default: return fmt.Errorf("unsupported OSC packet type: only Bundle and Message are supported") case *Bundle: b.Bundles = append(b.Bundles, t) case *Message: b.Messages = append(b.Messages, t) } return nil }
go
func (b *Bundle) Append(pck Packet) error { switch t := pck.(type) { default: return fmt.Errorf("unsupported OSC packet type: only Bundle and Message are supported") case *Bundle: b.Bundles = append(b.Bundles, t) case *Message: b.Messages = append(b.Messages, t) } return nil }
[ "func", "(", "b", "*", "Bundle", ")", "Append", "(", "pck", "Packet", ")", "error", "{", "switch", "t", ":=", "pck", ".", "(", "type", ")", "{", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n\n", "case", "*", "Bundle", ...
// Append appends an OSC bundle or OSC message to the bundle.
[ "Append", "appends", "an", "OSC", "bundle", "or", "OSC", "message", "to", "the", "bundle", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L391-L404
17,265
hypebeast/go-osc
osc/osc.go
SetLocalAddr
func (c *Client) SetLocalAddr(ip string, port int) error { laddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", ip, port)) if err != nil { return err } c.laddr = laddr return nil }
go
func (c *Client) SetLocalAddr(ip string, port int) error { laddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", ip, port)) if err != nil { return err } c.laddr = laddr return nil }
[ "func", "(", "c", "*", "Client", ")", "SetLocalAddr", "(", "ip", "string", ",", "port", "int", ")", "error", "{", "laddr", ",", "err", ":=", "net", ".", "ResolveUDPAddr", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ip", ",...
// SetLocalAddr sets the local address.
[ "SetLocalAddr", "sets", "the", "local", "address", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L495-L502
17,266
hypebeast/go-osc
osc/osc.go
Send
func (c *Client) Send(packet Packet) error { addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", c.ip, c.port)) if err != nil { return err } conn, err := net.DialUDP("udp", c.laddr, addr) if err != nil { return err } defer conn.Close() data, err := packet.MarshalBinary() if err != nil { return err } if _, err = conn.Write(data); err != nil { return err } return nil }
go
func (c *Client) Send(packet Packet) error { addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", c.ip, c.port)) if err != nil { return err } conn, err := net.DialUDP("udp", c.laddr, addr) if err != nil { return err } defer conn.Close() data, err := packet.MarshalBinary() if err != nil { return err } if _, err = conn.Write(data); err != nil { return err } return nil }
[ "func", "(", "c", "*", "Client", ")", "Send", "(", "packet", "Packet", ")", "error", "{", "addr", ",", "err", ":=", "net", ".", "ResolveUDPAddr", "(", "\"", "\"", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ".", "ip", ",", "c", ".", ...
// Send sends an OSC Bundle or an OSC Message.
[ "Send", "sends", "an", "OSC", "Bundle", "or", "an", "OSC", "Message", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L505-L525
17,267
hypebeast/go-osc
osc/osc.go
ListenAndServe
func (s *Server) ListenAndServe() error { if s.Dispatcher == nil { s.Dispatcher = NewOscDispatcher() } ln, err := net.ListenPacket("udp", s.Addr) if err != nil { return err } return s.Serve(ln) }
go
func (s *Server) ListenAndServe() error { if s.Dispatcher == nil { s.Dispatcher = NewOscDispatcher() } ln, err := net.ListenPacket("udp", s.Addr) if err != nil { return err } return s.Serve(ln) }
[ "func", "(", "s", "*", "Server", ")", "ListenAndServe", "(", ")", "error", "{", "if", "s", ".", "Dispatcher", "==", "nil", "{", "s", ".", "Dispatcher", "=", "NewOscDispatcher", "(", ")", "\n", "}", "\n\n", "ln", ",", "err", ":=", "net", ".", "Liste...
// ListenAndServe retrieves incoming OSC packets and dispatches the retrieved // OSC packets.
[ "ListenAndServe", "retrieves", "incoming", "OSC", "packets", "and", "dispatches", "the", "retrieved", "OSC", "packets", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L542-L552
17,268
hypebeast/go-osc
osc/osc.go
Serve
func (s *Server) Serve(c net.PacketConn) error { var tempDelay time.Duration for { msg, err := s.readFromConnection(c) if err != nil { if ne, ok := err.(net.Error); ok && ne.Temporary() { if tempDelay == 0 { tempDelay = 5 * time.Millisecond } else { tempDelay *= 2 } if max := 1 * time.Second; tempDelay > max { tempDelay = max } time.Sleep(tempDelay) continue } return err } tempDelay = 0 go s.Dispatcher.Dispatch(msg) } }
go
func (s *Server) Serve(c net.PacketConn) error { var tempDelay time.Duration for { msg, err := s.readFromConnection(c) if err != nil { if ne, ok := err.(net.Error); ok && ne.Temporary() { if tempDelay == 0 { tempDelay = 5 * time.Millisecond } else { tempDelay *= 2 } if max := 1 * time.Second; tempDelay > max { tempDelay = max } time.Sleep(tempDelay) continue } return err } tempDelay = 0 go s.Dispatcher.Dispatch(msg) } }
[ "func", "(", "s", "*", "Server", ")", "Serve", "(", "c", "net", ".", "PacketConn", ")", "error", "{", "var", "tempDelay", "time", ".", "Duration", "\n", "for", "{", "msg", ",", "err", ":=", "s", ".", "readFromConnection", "(", "c", ")", "\n", "if",...
// Serve retrieves incoming OSC packets from the given connection and dispatches // retrieved OSC packets. If something goes wrong an error is returned.
[ "Serve", "retrieves", "incoming", "OSC", "packets", "from", "the", "given", "connection", "and", "dispatches", "retrieved", "OSC", "packets", ".", "If", "something", "goes", "wrong", "an", "error", "is", "returned", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L556-L578
17,269
hypebeast/go-osc
osc/osc.go
ReceivePacket
func (s *Server) ReceivePacket(c net.PacketConn) (Packet, error) { return s.readFromConnection(c) }
go
func (s *Server) ReceivePacket(c net.PacketConn) (Packet, error) { return s.readFromConnection(c) }
[ "func", "(", "s", "*", "Server", ")", "ReceivePacket", "(", "c", "net", ".", "PacketConn", ")", "(", "Packet", ",", "error", ")", "{", "return", "s", ".", "readFromConnection", "(", "c", ")", "\n", "}" ]
// ReceivePacket listens for incoming OSC packets and returns the packet if one is received.
[ "ReceivePacket", "listens", "for", "incoming", "OSC", "packets", "and", "returns", "the", "packet", "if", "one", "is", "received", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L581-L583
17,270
hypebeast/go-osc
osc/osc.go
readFromConnection
func (s *Server) readFromConnection(c net.PacketConn) (Packet, error) { if s.ReadTimeout != 0 { if err := c.SetReadDeadline(time.Now().Add(s.ReadTimeout)); err != nil { return nil, err } } data := make([]byte, 65535) n, _, err := c.ReadFrom(data) if err != nil { return nil, err } var start int p, err := readPacket(bufio.NewReader(bytes.NewBuffer(data)), &start, n) if err != nil { return nil, err } return p, nil }
go
func (s *Server) readFromConnection(c net.PacketConn) (Packet, error) { if s.ReadTimeout != 0 { if err := c.SetReadDeadline(time.Now().Add(s.ReadTimeout)); err != nil { return nil, err } } data := make([]byte, 65535) n, _, err := c.ReadFrom(data) if err != nil { return nil, err } var start int p, err := readPacket(bufio.NewReader(bytes.NewBuffer(data)), &start, n) if err != nil { return nil, err } return p, nil }
[ "func", "(", "s", "*", "Server", ")", "readFromConnection", "(", "c", "net", ".", "PacketConn", ")", "(", "Packet", ",", "error", ")", "{", "if", "s", ".", "ReadTimeout", "!=", "0", "{", "if", "err", ":=", "c", ".", "SetReadDeadline", "(", "time", ...
// readFromConnection retrieves OSC packets.
[ "readFromConnection", "retrieves", "OSC", "packets", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L586-L605
17,271
hypebeast/go-osc
osc/osc.go
ParsePacket
func ParsePacket(msg string) (Packet, error) { var start int p, err := readPacket(bufio.NewReader(bytes.NewBufferString(msg)), &start, len(msg)) if err != nil { return nil, err } return p, nil }
go
func ParsePacket(msg string) (Packet, error) { var start int p, err := readPacket(bufio.NewReader(bytes.NewBufferString(msg)), &start, len(msg)) if err != nil { return nil, err } return p, nil }
[ "func", "ParsePacket", "(", "msg", "string", ")", "(", "Packet", ",", "error", ")", "{", "var", "start", "int", "\n", "p", ",", "err", ":=", "readPacket", "(", "bufio", ".", "NewReader", "(", "bytes", ".", "NewBufferString", "(", "msg", ")", ")", ","...
// ParsePacket parses the given msg string and returns a Packet
[ "ParsePacket", "parses", "the", "given", "msg", "string", "and", "returns", "a", "Packet" ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L608-L615
17,272
hypebeast/go-osc
osc/osc.go
readPacket
func readPacket(reader *bufio.Reader, start *int, end int) (Packet, error) { //var buf []byte buf, err := reader.Peek(1) if err != nil { return nil, err } // An OSC Message starts with a '/' if buf[0] == '/' { packet, err := readMessage(reader, start) if err != nil { return nil, err } return packet, nil } if buf[0] == '#' { // An OSC bundle starts with a '#' packet, err := readBundle(reader, start, end) if err != nil { return nil, err } return packet, nil } var p Packet return p, nil }
go
func readPacket(reader *bufio.Reader, start *int, end int) (Packet, error) { //var buf []byte buf, err := reader.Peek(1) if err != nil { return nil, err } // An OSC Message starts with a '/' if buf[0] == '/' { packet, err := readMessage(reader, start) if err != nil { return nil, err } return packet, nil } if buf[0] == '#' { // An OSC bundle starts with a '#' packet, err := readBundle(reader, start, end) if err != nil { return nil, err } return packet, nil } var p Packet return p, nil }
[ "func", "readPacket", "(", "reader", "*", "bufio", ".", "Reader", ",", "start", "*", "int", ",", "end", "int", ")", "(", "Packet", ",", "error", ")", "{", "//var buf []byte", "buf", ",", "err", ":=", "reader", ".", "Peek", "(", "1", ")", "\n", "if"...
// receivePacket receives an OSC packet from the given reader.
[ "receivePacket", "receives", "an", "OSC", "packet", "from", "the", "given", "reader", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L618-L643
17,273
hypebeast/go-osc
osc/osc.go
readBundle
func readBundle(reader *bufio.Reader, start *int, end int) (*Bundle, error) { // Read the '#bundle' OSC string startTag, n, err := readPaddedString(reader) if err != nil { return nil, err } *start += n if startTag != bundleTagString { return nil, fmt.Errorf("Invalid bundle start tag: %s", startTag) } // Read the timetag var timeTag uint64 if err := binary.Read(reader, binary.BigEndian, &timeTag); err != nil { return nil, err } *start += 8 // Create a new bundle bundle := NewBundle(timetagToTime(timeTag)) // Read until the end of the buffer for *start < end { // Read the size of the bundle element var length int32 if err := binary.Read(reader, binary.BigEndian, &length); err != nil { return nil, err } *start += 4 p, err := readPacket(reader, start, end) if err != nil { return nil, err } if err = bundle.Append(p); err != nil { return nil, err } } return bundle, nil }
go
func readBundle(reader *bufio.Reader, start *int, end int) (*Bundle, error) { // Read the '#bundle' OSC string startTag, n, err := readPaddedString(reader) if err != nil { return nil, err } *start += n if startTag != bundleTagString { return nil, fmt.Errorf("Invalid bundle start tag: %s", startTag) } // Read the timetag var timeTag uint64 if err := binary.Read(reader, binary.BigEndian, &timeTag); err != nil { return nil, err } *start += 8 // Create a new bundle bundle := NewBundle(timetagToTime(timeTag)) // Read until the end of the buffer for *start < end { // Read the size of the bundle element var length int32 if err := binary.Read(reader, binary.BigEndian, &length); err != nil { return nil, err } *start += 4 p, err := readPacket(reader, start, end) if err != nil { return nil, err } if err = bundle.Append(p); err != nil { return nil, err } } return bundle, nil }
[ "func", "readBundle", "(", "reader", "*", "bufio", ".", "Reader", ",", "start", "*", "int", ",", "end", "int", ")", "(", "*", "Bundle", ",", "error", ")", "{", "// Read the '#bundle' OSC string", "startTag", ",", "n", ",", "err", ":=", "readPaddedString", ...
// readBundle reads an Bundle from reader.
[ "readBundle", "reads", "an", "Bundle", "from", "reader", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L646-L687
17,274
hypebeast/go-osc
osc/osc.go
readMessage
func readMessage(reader *bufio.Reader, start *int) (*Message, error) { // First, read the OSC address addr, n, err := readPaddedString(reader) if err != nil { return nil, err } *start += n // Read all arguments msg := NewMessage(addr) if err = readArguments(msg, reader, start); err != nil { return nil, err } return msg, nil }
go
func readMessage(reader *bufio.Reader, start *int) (*Message, error) { // First, read the OSC address addr, n, err := readPaddedString(reader) if err != nil { return nil, err } *start += n // Read all arguments msg := NewMessage(addr) if err = readArguments(msg, reader, start); err != nil { return nil, err } return msg, nil }
[ "func", "readMessage", "(", "reader", "*", "bufio", ".", "Reader", ",", "start", "*", "int", ")", "(", "*", "Message", ",", "error", ")", "{", "// First, read the OSC address", "addr", ",", "n", ",", "err", ":=", "readPaddedString", "(", "reader", ")", "...
// readMessage from `reader`.
[ "readMessage", "from", "reader", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L690-L705
17,275
hypebeast/go-osc
osc/osc.go
readArguments
func readArguments(msg *Message, reader *bufio.Reader, start *int) error { // Read the type tag string var n int typetags, n, err := readPaddedString(reader) if err != nil { return err } *start += n // If the typetag doesn't start with ',', it's not valid if typetags[0] != ',' { return errors.New("unsupported type tag string") } // Remove ',' from the type tag typetags = typetags[1:] for _, c := range typetags { switch c { default: return fmt.Errorf("unsupported type tag: %c", c) case 'i': // int32 var i int32 if err = binary.Read(reader, binary.BigEndian, &i); err != nil { return err } *start += 4 msg.Append(i) case 'h': // int64 var i int64 if err = binary.Read(reader, binary.BigEndian, &i); err != nil { return err } *start += 8 msg.Append(i) case 'f': // float32 var f float32 if err = binary.Read(reader, binary.BigEndian, &f); err != nil { return err } *start += 4 msg.Append(f) case 'd': // float64/double var d float64 if err = binary.Read(reader, binary.BigEndian, &d); err != nil { return err } *start += 8 msg.Append(d) case 's': // string // TODO: fix reading string value var s string if s, _, err = readPaddedString(reader); err != nil { return err } *start += len(s) + padBytesNeeded(len(s)) msg.Append(s) case 'b': // blob var buf []byte var n int if buf, n, err = readBlob(reader); err != nil { return err } *start += n msg.Append(buf) case 't': // OSC time tag var tt uint64 if err = binary.Read(reader, binary.BigEndian, &tt); err != nil { return nil } *start += 8 msg.Append(NewTimetagFromTimetag(tt)) case 'T': // true msg.Append(true) case 'F': // false msg.Append(false) } } return nil }
go
func readArguments(msg *Message, reader *bufio.Reader, start *int) error { // Read the type tag string var n int typetags, n, err := readPaddedString(reader) if err != nil { return err } *start += n // If the typetag doesn't start with ',', it's not valid if typetags[0] != ',' { return errors.New("unsupported type tag string") } // Remove ',' from the type tag typetags = typetags[1:] for _, c := range typetags { switch c { default: return fmt.Errorf("unsupported type tag: %c", c) case 'i': // int32 var i int32 if err = binary.Read(reader, binary.BigEndian, &i); err != nil { return err } *start += 4 msg.Append(i) case 'h': // int64 var i int64 if err = binary.Read(reader, binary.BigEndian, &i); err != nil { return err } *start += 8 msg.Append(i) case 'f': // float32 var f float32 if err = binary.Read(reader, binary.BigEndian, &f); err != nil { return err } *start += 4 msg.Append(f) case 'd': // float64/double var d float64 if err = binary.Read(reader, binary.BigEndian, &d); err != nil { return err } *start += 8 msg.Append(d) case 's': // string // TODO: fix reading string value var s string if s, _, err = readPaddedString(reader); err != nil { return err } *start += len(s) + padBytesNeeded(len(s)) msg.Append(s) case 'b': // blob var buf []byte var n int if buf, n, err = readBlob(reader); err != nil { return err } *start += n msg.Append(buf) case 't': // OSC time tag var tt uint64 if err = binary.Read(reader, binary.BigEndian, &tt); err != nil { return nil } *start += 8 msg.Append(NewTimetagFromTimetag(tt)) case 'T': // true msg.Append(true) case 'F': // false msg.Append(false) } } return nil }
[ "func", "readArguments", "(", "msg", "*", "Message", ",", "reader", "*", "bufio", ".", "Reader", ",", "start", "*", "int", ")", "error", "{", "// Read the type tag string", "var", "n", "int", "\n", "typetags", ",", "n", ",", "err", ":=", "readPaddedString"...
// readArguments from `reader` and add them to the OSC message `msg`.
[ "readArguments", "from", "reader", "and", "add", "them", "to", "the", "OSC", "message", "msg", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L708-L797
17,276
hypebeast/go-osc
osc/osc.go
MarshalBinary
func (t *Timetag) MarshalBinary() ([]byte, error) { data := new(bytes.Buffer) if err := binary.Write(data, binary.BigEndian, t.timeTag); err != nil { return []byte{}, err } return data.Bytes(), nil }
go
func (t *Timetag) MarshalBinary() ([]byte, error) { data := new(bytes.Buffer) if err := binary.Write(data, binary.BigEndian, t.timeTag); err != nil { return []byte{}, err } return data.Bytes(), nil }
[ "func", "(", "t", "*", "Timetag", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "data", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", ":=", "binary", ".", "Write", "(", "data", ",", "binary", ...
// MarshalBinary converts the OSC time tag to a byte array.
[ "MarshalBinary", "converts", "the", "OSC", "time", "tag", "to", "a", "byte", "array", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L840-L846
17,277
hypebeast/go-osc
osc/osc.go
SetTime
func (t *Timetag) SetTime(time time.Time) { t.time = time t.timeTag = timeToTimetag(time) }
go
func (t *Timetag) SetTime(time time.Time) { t.time = time t.timeTag = timeToTimetag(time) }
[ "func", "(", "t", "*", "Timetag", ")", "SetTime", "(", "time", "time", ".", "Time", ")", "{", "t", ".", "time", "=", "time", "\n", "t", ".", "timeTag", "=", "timeToTimetag", "(", "time", ")", "\n", "}" ]
// SetTime sets the value of the OSC time tag.
[ "SetTime", "sets", "the", "value", "of", "the", "OSC", "time", "tag", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L849-L852
17,278
hypebeast/go-osc
osc/osc.go
ExpiresIn
func (t *Timetag) ExpiresIn() time.Duration { if t.timeTag <= 1 { return 0 } tt := timetagToTime(t.timeTag) seconds := tt.Sub(time.Now()) if seconds <= 0 { return 0 } return seconds }
go
func (t *Timetag) ExpiresIn() time.Duration { if t.timeTag <= 1 { return 0 } tt := timetagToTime(t.timeTag) seconds := tt.Sub(time.Now()) if seconds <= 0 { return 0 } return seconds }
[ "func", "(", "t", "*", "Timetag", ")", "ExpiresIn", "(", ")", "time", ".", "Duration", "{", "if", "t", ".", "timeTag", "<=", "1", "{", "return", "0", "\n", "}", "\n\n", "tt", ":=", "timetagToTime", "(", "t", ".", "timeTag", ")", "\n", "seconds", ...
// ExpiresIn calculates the number of seconds until the current time is the // same as the value of the time tag. It returns zero if the value of the // time tag is in the past.
[ "ExpiresIn", "calculates", "the", "number", "of", "seconds", "until", "the", "current", "time", "is", "the", "same", "as", "the", "value", "of", "the", "time", "tag", ".", "It", "returns", "zero", "if", "the", "value", "of", "the", "time", "tag", "is", ...
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L857-L870
17,279
hypebeast/go-osc
osc/osc.go
timetagToTime
func timetagToTime(timetag uint64) (t time.Time) { return time.Unix(int64((timetag>>32)-secondsFrom1900To1970), int64(timetag&0xffffffff)) }
go
func timetagToTime(timetag uint64) (t time.Time) { return time.Unix(int64((timetag>>32)-secondsFrom1900To1970), int64(timetag&0xffffffff)) }
[ "func", "timetagToTime", "(", "timetag", "uint64", ")", "(", "t", "time", ".", "Time", ")", "{", "return", "time", ".", "Unix", "(", "int64", "(", "(", "timetag", ">>", "32", ")", "-", "secondsFrom1900To1970", ")", ",", "int64", "(", "timetag", "&", ...
// timetagToTime converts the given timetag to a time object.
[ "timetagToTime", "converts", "the", "given", "timetag", "to", "a", "time", "object", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L888-L890
17,280
hypebeast/go-osc
osc/osc.go
writeBlob
func writeBlob(data []byte, buf *bytes.Buffer) (int, error) { // Add the size of the blob dlen := int32(len(data)) if err := binary.Write(buf, binary.BigEndian, dlen); err != nil { return 0, err } // Write the data if _, err := buf.Write(data); err != nil { return 0, nil } // Add padding bytes if necessary numPadBytes := padBytesNeeded(len(data)) if numPadBytes > 0 { padBytes := make([]byte, numPadBytes) n, err := buf.Write(padBytes) if err != nil { return 0, err } numPadBytes = n } return 4 + len(data) + numPadBytes, nil }
go
func writeBlob(data []byte, buf *bytes.Buffer) (int, error) { // Add the size of the blob dlen := int32(len(data)) if err := binary.Write(buf, binary.BigEndian, dlen); err != nil { return 0, err } // Write the data if _, err := buf.Write(data); err != nil { return 0, nil } // Add padding bytes if necessary numPadBytes := padBytesNeeded(len(data)) if numPadBytes > 0 { padBytes := make([]byte, numPadBytes) n, err := buf.Write(padBytes) if err != nil { return 0, err } numPadBytes = n } return 4 + len(data) + numPadBytes, nil }
[ "func", "writeBlob", "(", "data", "[", "]", "byte", ",", "buf", "*", "bytes", ".", "Buffer", ")", "(", "int", ",", "error", ")", "{", "// Add the size of the blob", "dlen", ":=", "int32", "(", "len", "(", "data", ")", ")", "\n", "if", "err", ":=", ...
// writeBlob writes the data byte array as an OSC blob into buff. If the length // of data isn't 32-bit aligned, padding bytes will be added.
[ "writeBlob", "writes", "the", "data", "byte", "array", "as", "an", "OSC", "blob", "into", "buff", ".", "If", "the", "length", "of", "data", "isn", "t", "32", "-", "bit", "aligned", "padding", "bytes", "will", "be", "added", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L927-L951
17,281
hypebeast/go-osc
osc/osc.go
readPaddedString
func readPaddedString(reader *bufio.Reader) (string, int, error) { // Read the string from the reader str, err := reader.ReadString(0) if err != nil { return "", 0, err } n := len(str) // Remove the string delimiter, in order to calculate the right amount // of padding bytes str = str[:len(str)-1] // Remove the padding bytes padLen := padBytesNeeded(len(str)) - 1 if padLen > 0 { n += padLen padBytes := make([]byte, padLen) if _, err = reader.Read(padBytes); err != nil { return "", 0, err } } return str, n, nil }
go
func readPaddedString(reader *bufio.Reader) (string, int, error) { // Read the string from the reader str, err := reader.ReadString(0) if err != nil { return "", 0, err } n := len(str) // Remove the string delimiter, in order to calculate the right amount // of padding bytes str = str[:len(str)-1] // Remove the padding bytes padLen := padBytesNeeded(len(str)) - 1 if padLen > 0 { n += padLen padBytes := make([]byte, padLen) if _, err = reader.Read(padBytes); err != nil { return "", 0, err } } return str, n, nil }
[ "func", "readPaddedString", "(", "reader", "*", "bufio", ".", "Reader", ")", "(", "string", ",", "int", ",", "error", ")", "{", "// Read the string from the reader", "str", ",", "err", ":=", "reader", ".", "ReadString", "(", "0", ")", "\n", "if", "err", ...
// readPaddedString reads a padded string from the given reader. The padding // bytes are removed from the reader.
[ "readPaddedString", "reads", "a", "padded", "string", "from", "the", "given", "reader", ".", "The", "padding", "bytes", "are", "removed", "from", "the", "reader", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L955-L978
17,282
hypebeast/go-osc
osc/osc.go
writePaddedString
func writePaddedString(str string, buf *bytes.Buffer) (int, error) { // Write the string to the buffer n, err := buf.WriteString(str) if err != nil { return 0, err } // Calculate the padding bytes needed and create a buffer for the padding bytes numPadBytes := padBytesNeeded(len(str)) if numPadBytes > 0 { padBytes := make([]byte, numPadBytes) // Add the padding bytes to the buffer n, err := buf.Write(padBytes) if err != nil { return 0, err } numPadBytes = n } return n + numPadBytes, nil }
go
func writePaddedString(str string, buf *bytes.Buffer) (int, error) { // Write the string to the buffer n, err := buf.WriteString(str) if err != nil { return 0, err } // Calculate the padding bytes needed and create a buffer for the padding bytes numPadBytes := padBytesNeeded(len(str)) if numPadBytes > 0 { padBytes := make([]byte, numPadBytes) // Add the padding bytes to the buffer n, err := buf.Write(padBytes) if err != nil { return 0, err } numPadBytes = n } return n + numPadBytes, nil }
[ "func", "writePaddedString", "(", "str", "string", ",", "buf", "*", "bytes", ".", "Buffer", ")", "(", "int", ",", "error", ")", "{", "// Write the string to the buffer", "n", ",", "err", ":=", "buf", ".", "WriteString", "(", "str", ")", "\n", "if", "err"...
// writePaddedString writes a string with padding bytes to the a buffer. // Returns, the number of written bytes and an error if any.
[ "writePaddedString", "writes", "a", "string", "with", "padding", "bytes", "to", "the", "a", "buffer", ".", "Returns", "the", "number", "of", "written", "bytes", "and", "an", "error", "if", "any", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L982-L1002
17,283
hypebeast/go-osc
osc/osc.go
addressExists
func addressExists(addr string, handlers map[string]Handler) bool { for h := range handlers { if h == addr { return true } } return false }
go
func addressExists(addr string, handlers map[string]Handler) bool { for h := range handlers { if h == addr { return true } } return false }
[ "func", "addressExists", "(", "addr", "string", ",", "handlers", "map", "[", "string", "]", "Handler", ")", "bool", "{", "for", "h", ":=", "range", "handlers", "{", "if", "h", "==", "addr", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return",...
// addressExists returns true if the OSC address `addr` is found in `handlers`.
[ "addressExists", "returns", "true", "if", "the", "OSC", "address", "addr", "is", "found", "in", "handlers", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L1020-L1027
17,284
hypebeast/go-osc
osc/osc.go
getRegEx
func getRegEx(pattern string) *regexp.Regexp { for _, trs := range []struct { old, new string }{ {".", `\.`}, // Escape all '.' in the pattern {"(", `\(`}, // Escape all '(' in the pattern {")", `\)`}, // Escape all ')' in the pattern {"*", ".*"}, // Replace a '*' with '.*' that matches zero or more chars {"{", "("}, // Change a '{' to '(' {",", "|"}, // Change a ',' to '|' {"}", ")"}, // Change a '}' to ')' {"?", "."}, // Change a '?' to '.' } { pattern = strings.Replace(pattern, trs.old, trs.new, -1) } return regexp.MustCompile(pattern) }
go
func getRegEx(pattern string) *regexp.Regexp { for _, trs := range []struct { old, new string }{ {".", `\.`}, // Escape all '.' in the pattern {"(", `\(`}, // Escape all '(' in the pattern {")", `\)`}, // Escape all ')' in the pattern {"*", ".*"}, // Replace a '*' with '.*' that matches zero or more chars {"{", "("}, // Change a '{' to '(' {",", "|"}, // Change a ',' to '|' {"}", ")"}, // Change a '}' to ')' {"?", "."}, // Change a '?' to '.' } { pattern = strings.Replace(pattern, trs.old, trs.new, -1) } return regexp.MustCompile(pattern) }
[ "func", "getRegEx", "(", "pattern", "string", ")", "*", "regexp", ".", "Regexp", "{", "for", "_", ",", "trs", ":=", "range", "[", "]", "struct", "{", "old", ",", "new", "string", "\n", "}", "{", "{", "\"", "\"", ",", "`\\.`", "}", ",", "// Escape...
// getRegEx compiles and returns a regular expression object for the given // address `pattern`.
[ "getRegEx", "compiles", "and", "returns", "a", "regular", "expression", "object", "for", "the", "given", "address", "pattern", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L1031-L1048
17,285
hypebeast/go-osc
osc/osc.go
getTypeTag
func getTypeTag(arg interface{}) (string, error) { switch t := arg.(type) { case bool: if arg.(bool) { return "T", nil } return "F", nil case nil: return "N", nil case int32: return "i", nil case float32: return "f", nil case string: return "s", nil case []byte: return "b", nil case int64: return "h", nil case float64: return "d", nil case Timetag: return "t", nil default: return "", fmt.Errorf("Unsupported type: %T", t) } }
go
func getTypeTag(arg interface{}) (string, error) { switch t := arg.(type) { case bool: if arg.(bool) { return "T", nil } return "F", nil case nil: return "N", nil case int32: return "i", nil case float32: return "f", nil case string: return "s", nil case []byte: return "b", nil case int64: return "h", nil case float64: return "d", nil case Timetag: return "t", nil default: return "", fmt.Errorf("Unsupported type: %T", t) } }
[ "func", "getTypeTag", "(", "arg", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "switch", "t", ":=", "arg", ".", "(", "type", ")", "{", "case", "bool", ":", "if", "arg", ".", "(", "bool", ")", "{", "return", "\"", "\"", ","...
// getTypeTag returns the OSC type tag for the given argument.
[ "getTypeTag", "returns", "the", "OSC", "type", "tag", "for", "the", "given", "argument", "." ]
adefe22206c1207064748f0ab922a6a5f2135e7f
https://github.com/hypebeast/go-osc/blob/adefe22206c1207064748f0ab922a6a5f2135e7f/osc/osc.go#L1051-L1077
17,286
mdlayher/waveform
options.go
Error
func (e *OptionsError) Error() string { return fmt.Sprintf("%s: %s", e.Option, e.Reason) }
go
func (e *OptionsError) Error() string { return fmt.Sprintf("%s: %s", e.Option, e.Reason) }
[ "func", "(", "e", "*", "OptionsError", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Option", ",", "e", ".", "Reason", ")", "\n", "}" ]
// Error returns the string representation of an OptionsError.
[ "Error", "returns", "the", "string", "representation", "of", "an", "OptionsError", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L57-L59
17,287
mdlayher/waveform
options.go
SetOptions
func (w *Waveform) SetOptions(options ...OptionsFunc) error { for _, o := range options { // Do not apply nil function arguments if o == nil { continue } if err := o(w); err != nil { return err } } return nil }
go
func (w *Waveform) SetOptions(options ...OptionsFunc) error { for _, o := range options { // Do not apply nil function arguments if o == nil { continue } if err := o(w); err != nil { return err } } return nil }
[ "func", "(", "w", "*", "Waveform", ")", "SetOptions", "(", "options", "...", "OptionsFunc", ")", "error", "{", "for", "_", ",", "o", ":=", "range", "options", "{", "// Do not apply nil function arguments", "if", "o", "==", "nil", "{", "continue", "\n", "}"...
// SetOptions applies zero or more OptionsFunc to the receiving Waveform // struct, manipulating its properties.
[ "SetOptions", "applies", "zero", "or", "more", "OptionsFunc", "to", "the", "receiving", "Waveform", "struct", "manipulating", "its", "properties", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L67-L80
17,288
mdlayher/waveform
options.go
BGColorFunction
func BGColorFunction(function ColorFunc) OptionsFunc { return func(w *Waveform) error { return w.setBGColorFunction(function) } }
go
func BGColorFunction(function ColorFunc) OptionsFunc { return func(w *Waveform) error { return w.setBGColorFunction(function) } }
[ "func", "BGColorFunction", "(", "function", "ColorFunc", ")", "OptionsFunc", "{", "return", "func", "(", "w", "*", "Waveform", ")", "error", "{", "return", "w", ".", "setBGColorFunction", "(", "function", ")", "\n", "}", "\n", "}" ]
// BGColorFunction generates an OptionsFunc which applies the input background // ColorFunc to an input Waveform struct. // // This function is used to apply a variety of color schemes to the background // of a waveform image, and is called during each drawing loop of the background // image.
[ "BGColorFunction", "generates", "an", "OptionsFunc", "which", "applies", "the", "input", "background", "ColorFunc", "to", "an", "input", "Waveform", "struct", ".", "This", "function", "is", "used", "to", "apply", "a", "variety", "of", "color", "schemes", "to", ...
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L88-L92
17,289
mdlayher/waveform
options.go
SetBGColorFunction
func (w *Waveform) SetBGColorFunction(function ColorFunc) error { return w.SetOptions(BGColorFunction(function)) }
go
func (w *Waveform) SetBGColorFunction(function ColorFunc) error { return w.SetOptions(BGColorFunction(function)) }
[ "func", "(", "w", "*", "Waveform", ")", "SetBGColorFunction", "(", "function", "ColorFunc", ")", "error", "{", "return", "w", ".", "SetOptions", "(", "BGColorFunction", "(", "function", ")", ")", "\n", "}" ]
// SetBGColorFunction applies the input ColorFunc to the receiving Waveform // struct for background use.
[ "SetBGColorFunction", "applies", "the", "input", "ColorFunc", "to", "the", "receiving", "Waveform", "struct", "for", "background", "use", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L96-L98
17,290
mdlayher/waveform
options.go
setBGColorFunction
func (w *Waveform) setBGColorFunction(function ColorFunc) error { // Function cannot be nil if function == nil { return errBGColorFunctionNil } w.bgColorFn = function return nil }
go
func (w *Waveform) setBGColorFunction(function ColorFunc) error { // Function cannot be nil if function == nil { return errBGColorFunctionNil } w.bgColorFn = function return nil }
[ "func", "(", "w", "*", "Waveform", ")", "setBGColorFunction", "(", "function", "ColorFunc", ")", "error", "{", "// Function cannot be nil", "if", "function", "==", "nil", "{", "return", "errBGColorFunctionNil", "\n", "}", "\n\n", "w", ".", "bgColorFn", "=", "f...
// setBGColorFunction directly sets the background ColorFunc member of the // receiving Waveform struct.
[ "setBGColorFunction", "directly", "sets", "the", "background", "ColorFunc", "member", "of", "the", "receiving", "Waveform", "struct", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L102-L111
17,291
mdlayher/waveform
options.go
FGColorFunction
func FGColorFunction(function ColorFunc) OptionsFunc { return func(w *Waveform) error { return w.setFGColorFunction(function) } }
go
func FGColorFunction(function ColorFunc) OptionsFunc { return func(w *Waveform) error { return w.setFGColorFunction(function) } }
[ "func", "FGColorFunction", "(", "function", "ColorFunc", ")", "OptionsFunc", "{", "return", "func", "(", "w", "*", "Waveform", ")", "error", "{", "return", "w", ".", "setFGColorFunction", "(", "function", ")", "\n", "}", "\n", "}" ]
// FGColorFunction generates an OptionsFunc which applies the input foreground // ColorFunc to an input Waveform struct. // // This function is used to apply a variety of color schemes to the foreground // of a waveform image, and is called during each drawing loop of the foreground // image.
[ "FGColorFunction", "generates", "an", "OptionsFunc", "which", "applies", "the", "input", "foreground", "ColorFunc", "to", "an", "input", "Waveform", "struct", ".", "This", "function", "is", "used", "to", "apply", "a", "variety", "of", "color", "schemes", "to", ...
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L119-L123
17,292
mdlayher/waveform
options.go
SetFGColorFunction
func (w *Waveform) SetFGColorFunction(function ColorFunc) error { return w.SetOptions(FGColorFunction(function)) }
go
func (w *Waveform) SetFGColorFunction(function ColorFunc) error { return w.SetOptions(FGColorFunction(function)) }
[ "func", "(", "w", "*", "Waveform", ")", "SetFGColorFunction", "(", "function", "ColorFunc", ")", "error", "{", "return", "w", ".", "SetOptions", "(", "FGColorFunction", "(", "function", ")", ")", "\n", "}" ]
// SetFGColorFunction applies the input ColorFunc to the receiving Waveform // struct for foreground use.
[ "SetFGColorFunction", "applies", "the", "input", "ColorFunc", "to", "the", "receiving", "Waveform", "struct", "for", "foreground", "use", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L127-L129
17,293
mdlayher/waveform
options.go
setFGColorFunction
func (w *Waveform) setFGColorFunction(function ColorFunc) error { // Function cannot be nil if function == nil { return errFGColorFunctionNil } w.fgColorFn = function return nil }
go
func (w *Waveform) setFGColorFunction(function ColorFunc) error { // Function cannot be nil if function == nil { return errFGColorFunctionNil } w.fgColorFn = function return nil }
[ "func", "(", "w", "*", "Waveform", ")", "setFGColorFunction", "(", "function", "ColorFunc", ")", "error", "{", "// Function cannot be nil", "if", "function", "==", "nil", "{", "return", "errFGColorFunctionNil", "\n", "}", "\n\n", "w", ".", "fgColorFn", "=", "f...
// setFGColorFunction directly sets the foreground ColorFunc member of the // receiving Waveform struct.
[ "setFGColorFunction", "directly", "sets", "the", "foreground", "ColorFunc", "member", "of", "the", "receiving", "Waveform", "struct", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L133-L142
17,294
mdlayher/waveform
options.go
Resolution
func Resolution(resolution uint) OptionsFunc { return func(w *Waveform) error { return w.setResolution(resolution) } }
go
func Resolution(resolution uint) OptionsFunc { return func(w *Waveform) error { return w.setResolution(resolution) } }
[ "func", "Resolution", "(", "resolution", "uint", ")", "OptionsFunc", "{", "return", "func", "(", "w", "*", "Waveform", ")", "error", "{", "return", "w", ".", "setResolution", "(", "resolution", ")", "\n", "}", "\n", "}" ]
// Resolution generates an OptionsFunc which applies the input resolution // value to an input Waveform struct. // // This value indicates the number of times audio is read and drawn // as a waveform, per second of audio.
[ "Resolution", "generates", "an", "OptionsFunc", "which", "applies", "the", "input", "resolution", "value", "to", "an", "input", "Waveform", "struct", ".", "This", "value", "indicates", "the", "number", "of", "times", "audio", "is", "read", "and", "drawn", "as"...
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L149-L153
17,295
mdlayher/waveform
options.go
SetResolution
func (w *Waveform) SetResolution(resolution uint) error { return w.SetOptions(Resolution(resolution)) }
go
func (w *Waveform) SetResolution(resolution uint) error { return w.SetOptions(Resolution(resolution)) }
[ "func", "(", "w", "*", "Waveform", ")", "SetResolution", "(", "resolution", "uint", ")", "error", "{", "return", "w", ".", "SetOptions", "(", "Resolution", "(", "resolution", ")", ")", "\n", "}" ]
// SetResolution applies the input resolution to the receiving Waveform struct.
[ "SetResolution", "applies", "the", "input", "resolution", "to", "the", "receiving", "Waveform", "struct", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L156-L158
17,296
mdlayher/waveform
options.go
setResolution
func (w *Waveform) setResolution(resolution uint) error { // Resolution cannot be zero if resolution == 0 { return errResolutionZero } w.resolution = resolution return nil }
go
func (w *Waveform) setResolution(resolution uint) error { // Resolution cannot be zero if resolution == 0 { return errResolutionZero } w.resolution = resolution return nil }
[ "func", "(", "w", "*", "Waveform", ")", "setResolution", "(", "resolution", "uint", ")", "error", "{", "// Resolution cannot be zero", "if", "resolution", "==", "0", "{", "return", "errResolutionZero", "\n", "}", "\n\n", "w", ".", "resolution", "=", "resolutio...
// setResolution directly sets the resolution member of the receiving Waveform // struct.
[ "setResolution", "directly", "sets", "the", "resolution", "member", "of", "the", "receiving", "Waveform", "struct", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L162-L171
17,297
mdlayher/waveform
options.go
SampleFunction
func SampleFunction(function SampleReduceFunc) OptionsFunc { return func(w *Waveform) error { return w.setSampleFunction(function) } }
go
func SampleFunction(function SampleReduceFunc) OptionsFunc { return func(w *Waveform) error { return w.setSampleFunction(function) } }
[ "func", "SampleFunction", "(", "function", "SampleReduceFunc", ")", "OptionsFunc", "{", "return", "func", "(", "w", "*", "Waveform", ")", "error", "{", "return", "w", ".", "setSampleFunction", "(", "function", ")", "\n", "}", "\n", "}" ]
// SampleFunc generates an OptionsFunc which applies the input SampleReduceFunc // to an input Waveform struct. // // This function is used to compute values from audio samples, for use in // waveform generation. The function is applied over a slice of float64 // audio samples, reducing them to a single value.
[ "SampleFunc", "generates", "an", "OptionsFunc", "which", "applies", "the", "input", "SampleReduceFunc", "to", "an", "input", "Waveform", "struct", ".", "This", "function", "is", "used", "to", "compute", "values", "from", "audio", "samples", "for", "use", "in", ...
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L179-L183
17,298
mdlayher/waveform
options.go
SetSampleFunction
func (w *Waveform) SetSampleFunction(function SampleReduceFunc) error { return w.SetOptions(SampleFunction(function)) }
go
func (w *Waveform) SetSampleFunction(function SampleReduceFunc) error { return w.SetOptions(SampleFunction(function)) }
[ "func", "(", "w", "*", "Waveform", ")", "SetSampleFunction", "(", "function", "SampleReduceFunc", ")", "error", "{", "return", "w", ".", "SetOptions", "(", "SampleFunction", "(", "function", ")", ")", "\n", "}" ]
// SetSampleFunction applies the input SampleReduceFunc to the receiving Waveform // struct.
[ "SetSampleFunction", "applies", "the", "input", "SampleReduceFunc", "to", "the", "receiving", "Waveform", "struct", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L187-L189
17,299
mdlayher/waveform
options.go
setSampleFunction
func (w *Waveform) setSampleFunction(function SampleReduceFunc) error { // Function cannot be nil if function == nil { return errSampleFunctionNil } w.sampleFn = function return nil }
go
func (w *Waveform) setSampleFunction(function SampleReduceFunc) error { // Function cannot be nil if function == nil { return errSampleFunctionNil } w.sampleFn = function return nil }
[ "func", "(", "w", "*", "Waveform", ")", "setSampleFunction", "(", "function", "SampleReduceFunc", ")", "error", "{", "// Function cannot be nil", "if", "function", "==", "nil", "{", "return", "errSampleFunctionNil", "\n", "}", "\n\n", "w", ".", "sampleFn", "=", ...
// setSampleFunction directly sets the SampleReduceFunc member of the receiving // Waveform struct.
[ "setSampleFunction", "directly", "sets", "the", "SampleReduceFunc", "member", "of", "the", "receiving", "Waveform", "struct", "." ]
6b28917edfbacd50bff4d58f951cf80499c952c4
https://github.com/mdlayher/waveform/blob/6b28917edfbacd50bff4d58f951cf80499c952c4/options.go#L193-L202