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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
15,800
mna/pigeon
bootstrap/scan.go
fatalError
func (s *Scanner) fatalError(err error) { s.cur = -1 s.eof = true if err != io.EOF { s.error(s.cpos, err) } }
go
func (s *Scanner) fatalError(err error) { s.cur = -1 s.eof = true if err != io.EOF { s.error(s.cpos, err) } }
[ "func", "(", "s", "*", "Scanner", ")", "fatalError", "(", "err", "error", ")", "{", "s", ".", "cur", "=", "-", "1", "\n", "s", ".", "eof", "=", "true", "\n", "if", "err", "!=", "io", ".", "EOF", "{", "s", ".", "error", "(", "s", ".", "cpos"...
// notify a non-recoverable error that terminates the scanning.
[ "notify", "a", "non", "-", "recoverable", "error", "that", "terminates", "the", "scanning", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L545-L551
15,801
mna/pigeon
bootstrap/scan.go
runeReader
func runeReader(r io.Reader) io.RuneReader { if rr, ok := r.(io.RuneReader); ok { return rr } return bufio.NewReader(r) }
go
func runeReader(r io.Reader) io.RuneReader { if rr, ok := r.(io.RuneReader); ok { return rr } return bufio.NewReader(r) }
[ "func", "runeReader", "(", "r", "io", ".", "Reader", ")", "io", ".", "RuneReader", "{", "if", "rr", ",", "ok", ":=", "r", ".", "(", "io", ".", "RuneReader", ")", ";", "ok", "{", "return", "rr", "\n", "}", "\n", "return", "bufio", ".", "NewReader"...
// convert the reader to a rune reader if required.
[ "convert", "the", "reader", "to", "a", "rune", "reader", "if", "required", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/scan.go#L554-L559
15,802
mna/pigeon
builder/static_code.go
cloneState
func (p *parser) cloneState() storeDict { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("cloneState")) } // {{ end }} ==template== state := make(storeDict, len(p.cur.state)) for k, v := range p.cur.state { if c, ok := v.(Cloner); ok { state[k] = c.Clone() } else { state[k] = v } } return state }
go
func (p *parser) cloneState() storeDict { // ==template== {{ if not .Optimize }} if p.debug { defer p.out(p.in("cloneState")) } // {{ end }} ==template== state := make(storeDict, len(p.cur.state)) for k, v := range p.cur.state { if c, ok := v.(Cloner); ok { state[k] = c.Clone() } else { state[k] = v } } return state }
[ "func", "(", "p", "*", "parser", ")", "cloneState", "(", ")", "storeDict", "{", "// ==template== {{ if not .Optimize }}", "if", "p", ".", "debug", "{", "defer", "p", ".", "out", "(", "p", ".", "in", "(", "\"", "\"", ")", ")", "\n", "}", "\n", "// {{ ...
// clone and return parser current state.
[ "clone", "and", "return", "parser", "current", "state", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/builder/static_code.go#L726-L742
15,803
mna/pigeon
ast/ast_optimize.go
init
func (r *grammarOptimizer) init(expr Expression) Visitor { switch expr := expr.(type) { case *Rule: // Keep track of current rule, which is processed r.rule = expr.Name.Val r.rules[expr.Name.Val] = expr case *RuleRefExpr: // Fill ruleUsesRules and ruleUsedByRules for every RuleRefExpr set(r.ruleUsesRules, r.rule, expr.Name.Val) set(r.ruleUsedByRules, expr.Name.Val, r.rule) } return r }
go
func (r *grammarOptimizer) init(expr Expression) Visitor { switch expr := expr.(type) { case *Rule: // Keep track of current rule, which is processed r.rule = expr.Name.Val r.rules[expr.Name.Val] = expr case *RuleRefExpr: // Fill ruleUsesRules and ruleUsedByRules for every RuleRefExpr set(r.ruleUsesRules, r.rule, expr.Name.Val) set(r.ruleUsedByRules, expr.Name.Val, r.rule) } return r }
[ "func", "(", "r", "*", "grammarOptimizer", ")", "init", "(", "expr", "Expression", ")", "Visitor", "{", "switch", "expr", ":=", "expr", ".", "(", "type", ")", "{", "case", "*", "Rule", ":", "// Keep track of current rule, which is processed", "r", ".", "rule...
// init is a Visitor, which is used with the Walk function // The purpose of this function is to initialize the reference // maps rules, ruleUsesRules and ruleUsedByRules.
[ "init", "is", "a", "Visitor", "which", "is", "used", "with", "the", "Walk", "function", "The", "purpose", "of", "this", "function", "is", "to", "initialize", "the", "reference", "maps", "rules", "ruleUsesRules", "and", "ruleUsedByRules", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast_optimize.go#L45-L57
15,804
mna/pigeon
ast/ast_optimize.go
set
func set(m map[string]map[string]struct{}, src, dst string) { if _, ok := m[src]; !ok { m[src] = make(map[string]struct{}) } m[src][dst] = struct{}{} }
go
func set(m map[string]map[string]struct{}, src, dst string) { if _, ok := m[src]; !ok { m[src] = make(map[string]struct{}) } m[src][dst] = struct{}{} }
[ "func", "set", "(", "m", "map", "[", "string", "]", "map", "[", "string", "]", "struct", "{", "}", ",", "src", ",", "dst", "string", ")", "{", "if", "_", ",", "ok", ":=", "m", "[", "src", "]", ";", "!", "ok", "{", "m", "[", "src", "]", "=...
// Add element to map of maps, initialize the inner map // if necessary.
[ "Add", "element", "to", "map", "of", "maps", "initialize", "the", "inner", "map", "if", "necessary", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/ast/ast_optimize.go#L61-L66
15,805
mna/pigeon
bootstrap/parser.go
Parse
func (p *Parser) Parse(filename string, r io.Reader) (*ast.Grammar, error) { p.errs.reset() p.s.Init(filename, r, p.errs.add) g := p.grammar() return g, p.errs.err() }
go
func (p *Parser) Parse(filename string, r io.Reader) (*ast.Grammar, error) { p.errs.reset() p.s.Init(filename, r, p.errs.add) g := p.grammar() return g, p.errs.err() }
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", "filename", "string", ",", "r", "io", ".", "Reader", ")", "(", "*", "ast", ".", "Grammar", ",", "error", ")", "{", "p", ".", "errs", ".", "reset", "(", ")", "\n", "p", ".", "s", ".", "Init",...
// Parse parses the data from the reader r and generates the AST // or returns an error if it fails. The filename is used as information // in the error messages.
[ "Parse", "parses", "the", "data", "from", "the", "reader", "r", "and", "generates", "the", "AST", "or", "returns", "an", "error", "if", "it", "fails", ".", "The", "filename", "is", "used", "as", "information", "in", "the", "error", "messages", "." ]
4412d0f0bd75356045e0f757c19b0be1bfff2cf3
https://github.com/mna/pigeon/blob/4412d0f0bd75356045e0f757c19b0be1bfff2cf3/bootstrap/parser.go#L82-L88
15,806
cloudfoundry/gorouter
logger/logger.go
NewLogger
func NewLogger(component string, options ...zap.Option) Logger { enc := zap.NewJSONEncoder( zap.LevelString("log_level"), zap.MessageKey("message"), zap.EpochFormatter("timestamp"), numberLevelFormatter(), ) origLogger := zap.New(enc, options...) return &logger{ source: component, origLogger: origLogger, Logger: origLogger.With(zap.String("source", component)), } }
go
func NewLogger(component string, options ...zap.Option) Logger { enc := zap.NewJSONEncoder( zap.LevelString("log_level"), zap.MessageKey("message"), zap.EpochFormatter("timestamp"), numberLevelFormatter(), ) origLogger := zap.New(enc, options...) return &logger{ source: component, origLogger: origLogger, Logger: origLogger.With(zap.String("source", component)), } }
[ "func", "NewLogger", "(", "component", "string", ",", "options", "...", "zap", ".", "Option", ")", "Logger", "{", "enc", ":=", "zap", ".", "NewJSONEncoder", "(", "zap", ".", "LevelString", "(", "\"", "\"", ")", ",", "zap", ".", "MessageKey", "(", "\"",...
// NewLogger returns a new zap logger that implements the Logger interface.
[ "NewLogger", "returns", "a", "new", "zap", "logger", "that", "implements", "the", "Logger", "interface", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/logger/logger.go#L30-L44
15,807
cloudfoundry/gorouter
handlers/proxy_healthcheck.go
NewProxyHealthcheck
func NewProxyHealthcheck(userAgent string, heartbeatOK *threading.SharedBoolean, logger logger.Logger) negroni.Handler { return &proxyHealthcheck{ userAgent: userAgent, heartbeatOK: heartbeatOK, logger: logger, } }
go
func NewProxyHealthcheck(userAgent string, heartbeatOK *threading.SharedBoolean, logger logger.Logger) negroni.Handler { return &proxyHealthcheck{ userAgent: userAgent, heartbeatOK: heartbeatOK, logger: logger, } }
[ "func", "NewProxyHealthcheck", "(", "userAgent", "string", ",", "heartbeatOK", "*", "threading", ".", "SharedBoolean", ",", "logger", "logger", ".", "Logger", ")", "negroni", ".", "Handler", "{", "return", "&", "proxyHealthcheck", "{", "userAgent", ":", "userAge...
// NewHealthcheck creates a handler that responds to healthcheck requests. // If userAgent is set to a non-empty string, it will use that user agent to // differentiate between healthcheck requests and non-healthcheck requests. // Otherwise, it will treat all requests as healthcheck requests.
[ "NewHealthcheck", "creates", "a", "handler", "that", "responds", "to", "healthcheck", "requests", ".", "If", "userAgent", "is", "set", "to", "a", "non", "-", "empty", "string", "it", "will", "use", "that", "user", "agent", "to", "differentiate", "between", "...
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/proxy_healthcheck.go#L20-L26
15,808
cloudfoundry/gorouter
handlers/access_log.go
NewAccessLog
func NewAccessLog( accessLogger accesslog.AccessLogger, extraHeadersToLog []string, logger logger.Logger, ) negroni.Handler { return &accessLog{ accessLogger: accessLogger, extraHeadersToLog: extraHeadersToLog, logger: logger, } }
go
func NewAccessLog( accessLogger accesslog.AccessLogger, extraHeadersToLog []string, logger logger.Logger, ) negroni.Handler { return &accessLog{ accessLogger: accessLogger, extraHeadersToLog: extraHeadersToLog, logger: logger, } }
[ "func", "NewAccessLog", "(", "accessLogger", "accesslog", ".", "AccessLogger", ",", "extraHeadersToLog", "[", "]", "string", ",", "logger", "logger", ".", "Logger", ",", ")", "negroni", ".", "Handler", "{", "return", "&", "accessLog", "{", "accessLogger", ":",...
// NewAccessLog creates a new handler that handles logging requests to the // access log
[ "NewAccessLog", "creates", "a", "new", "handler", "that", "handles", "logging", "requests", "to", "the", "access", "log" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/access_log.go#L26-L36
15,809
cloudfoundry/gorouter
handlers/routeservice.go
NewRouteService
func NewRouteService(config *routeservice.RouteServiceConfig, routeRegistry registry.Registry, logger logger.Logger) negroni.Handler { return &RouteService{ config: config, registry: routeRegistry, logger: logger, } }
go
func NewRouteService(config *routeservice.RouteServiceConfig, routeRegistry registry.Registry, logger logger.Logger) negroni.Handler { return &RouteService{ config: config, registry: routeRegistry, logger: logger, } }
[ "func", "NewRouteService", "(", "config", "*", "routeservice", ".", "RouteServiceConfig", ",", "routeRegistry", "registry", ".", "Registry", ",", "logger", "logger", ".", "Logger", ")", "negroni", ".", "Handler", "{", "return", "&", "RouteService", "{", "config"...
// NewRouteService creates a handler responsible for handling route services
[ "NewRouteService", "creates", "a", "handler", "responsible", "for", "handling", "route", "services" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/routeservice.go#L25-L31
15,810
cloudfoundry/gorouter
handlers/zipkin.go
NewZipkin
func NewZipkin(enabled bool, headersToLog []string, logger logger.Logger) *Zipkin { return &Zipkin{ zipkinEnabled: enabled, headersToLog: headersToLog, logger: logger, } }
go
func NewZipkin(enabled bool, headersToLog []string, logger logger.Logger) *Zipkin { return &Zipkin{ zipkinEnabled: enabled, headersToLog: headersToLog, logger: logger, } }
[ "func", "NewZipkin", "(", "enabled", "bool", ",", "headersToLog", "[", "]", "string", ",", "logger", "logger", ".", "Logger", ")", "*", "Zipkin", "{", "return", "&", "Zipkin", "{", "zipkinEnabled", ":", "enabled", ",", "headersToLog", ":", "headersToLog", ...
// NewZipkin creates a new handler that sets Zipkin headers on requests
[ "NewZipkin", "creates", "a", "new", "handler", "that", "sets", "Zipkin", "headers", "on", "requests" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/zipkin.go#L35-L41
15,811
cloudfoundry/gorouter
handlers/zipkin.go
BuildB3SingleHeader
func BuildB3SingleHeader(traceID, spanID, sampling, flags, parentSpanID string) string { if traceID == "" || spanID == "" { return "" } if sampling == "" && flags == "" { return traceID + "-" + spanID } samplingBit := "0" if flags == "1" { samplingBit = "d" } else if s, err := strconv.ParseBool(sampling); err == nil { if s { samplingBit = "1" } } else { return traceID + "-" + spanID } if parentSpanID == "" { return traceID + "-" + spanID + "-" + samplingBit } return traceID + "-" + spanID + "-" + samplingBit + "-" + parentSpanID }
go
func BuildB3SingleHeader(traceID, spanID, sampling, flags, parentSpanID string) string { if traceID == "" || spanID == "" { return "" } if sampling == "" && flags == "" { return traceID + "-" + spanID } samplingBit := "0" if flags == "1" { samplingBit = "d" } else if s, err := strconv.ParseBool(sampling); err == nil { if s { samplingBit = "1" } } else { return traceID + "-" + spanID } if parentSpanID == "" { return traceID + "-" + spanID + "-" + samplingBit } return traceID + "-" + spanID + "-" + samplingBit + "-" + parentSpanID }
[ "func", "BuildB3SingleHeader", "(", "traceID", ",", "spanID", ",", "sampling", ",", "flags", ",", "parentSpanID", "string", ")", "string", "{", "if", "traceID", "==", "\"", "\"", "||", "spanID", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "...
// BuildB3SingleHeader assembles the B3 single header based on existing trace // values
[ "BuildB3SingleHeader", "assembles", "the", "B3", "single", "header", "based", "on", "existing", "trace", "values" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/zipkin.go#L97-L122
15,812
cloudfoundry/gorouter
handlers/zipkin.go
HeadersToLog
func (z *Zipkin) HeadersToLog() []string { if !z.zipkinEnabled { return z.headersToLog } headersToLog := z.headersToLog if !contains(headersToLog, B3TraceIdHeader) { headersToLog = append(headersToLog, B3TraceIdHeader) } if !contains(headersToLog, B3SpanIdHeader) { headersToLog = append(headersToLog, B3SpanIdHeader) } if !contains(headersToLog, B3ParentSpanIdHeader) { headersToLog = append(headersToLog, B3ParentSpanIdHeader) } if !contains(headersToLog, B3Header) { headersToLog = append(headersToLog, B3Header) } return headersToLog }
go
func (z *Zipkin) HeadersToLog() []string { if !z.zipkinEnabled { return z.headersToLog } headersToLog := z.headersToLog if !contains(headersToLog, B3TraceIdHeader) { headersToLog = append(headersToLog, B3TraceIdHeader) } if !contains(headersToLog, B3SpanIdHeader) { headersToLog = append(headersToLog, B3SpanIdHeader) } if !contains(headersToLog, B3ParentSpanIdHeader) { headersToLog = append(headersToLog, B3ParentSpanIdHeader) } if !contains(headersToLog, B3Header) { headersToLog = append(headersToLog, B3Header) } return headersToLog }
[ "func", "(", "z", "*", "Zipkin", ")", "HeadersToLog", "(", ")", "[", "]", "string", "{", "if", "!", "z", ".", "zipkinEnabled", "{", "return", "z", ".", "headersToLog", "\n", "}", "\n", "headersToLog", ":=", "z", ".", "headersToLog", "\n", "if", "!", ...
// HeadersToLog returns headers that should be logged in the access logs and // includes Zipkin headers in this set if necessary
[ "HeadersToLog", "returns", "headers", "that", "should", "be", "logged", "in", "the", "access", "logs", "and", "includes", "Zipkin", "headers", "in", "this", "set", "if", "necessary" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/zipkin.go#L126-L148
15,813
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
WriteIntValue
func (b *recordBuffer) WriteIntValue(v int) { _, _ = b.WriteString(strconv.Itoa(v)) b.writeSpace() }
go
func (b *recordBuffer) WriteIntValue(v int) { _, _ = b.WriteString(strconv.Itoa(v)) b.writeSpace() }
[ "func", "(", "b", "*", "recordBuffer", ")", "WriteIntValue", "(", "v", "int", ")", "{", "_", ",", "_", "=", "b", ".", "WriteString", "(", "strconv", ".", "Itoa", "(", "v", ")", ")", "\n", "b", ".", "writeSpace", "(", ")", "\n", "}" ]
// WriteIntValue writes an int to the buffer
[ "WriteIntValue", "writes", "an", "int", "to", "the", "buffer" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L34-L37
15,814
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
WriteDashOrIntValue
func (b *recordBuffer) WriteDashOrIntValue(v int) { if v == 0 { _, _ = b.WriteString(`"-"`) b.writeSpace() } else { b.WriteIntValue(v) } }
go
func (b *recordBuffer) WriteDashOrIntValue(v int) { if v == 0 { _, _ = b.WriteString(`"-"`) b.writeSpace() } else { b.WriteIntValue(v) } }
[ "func", "(", "b", "*", "recordBuffer", ")", "WriteDashOrIntValue", "(", "v", "int", ")", "{", "if", "v", "==", "0", "{", "_", ",", "_", "=", "b", ".", "WriteString", "(", "`\"-\"`", ")", "\n", "b", ".", "writeSpace", "(", ")", "\n", "}", "else", ...
// WriteDashOrStringValue writes an int or a "-" to the buffer if the int is // equal to 0
[ "WriteDashOrStringValue", "writes", "an", "int", "or", "a", "-", "to", "the", "buffer", "if", "the", "int", "is", "equal", "to", "0" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L41-L48
15,815
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
WriteDashOrFloatValue
func (b *recordBuffer) WriteDashOrFloatValue(v float64) { if v >= 0 { _, _ = b.WriteString(strconv.FormatFloat(v, 'f', -1, 64)) } else { _, _ = b.WriteString(`"-"`) } b.writeSpace() }
go
func (b *recordBuffer) WriteDashOrFloatValue(v float64) { if v >= 0 { _, _ = b.WriteString(strconv.FormatFloat(v, 'f', -1, 64)) } else { _, _ = b.WriteString(`"-"`) } b.writeSpace() }
[ "func", "(", "b", "*", "recordBuffer", ")", "WriteDashOrFloatValue", "(", "v", "float64", ")", "{", "if", "v", ">=", "0", "{", "_", ",", "_", "=", "b", ".", "WriteString", "(", "strconv", ".", "FormatFloat", "(", "v", ",", "'f'", ",", "-", "1", "...
// WriteDashOrStringValue writes a float or a "-" to the buffer if the float is // 0 or lower
[ "WriteDashOrStringValue", "writes", "a", "float", "or", "a", "-", "to", "the", "buffer", "if", "the", "float", "is", "0", "or", "lower" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L52-L59
15,816
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
WriteStringValues
func (b *recordBuffer) WriteStringValues(s ...string) { var t []byte t = strconv.AppendQuote(t, strings.Join(s, ` `)) _, _ = b.Write(t) b.writeSpace() }
go
func (b *recordBuffer) WriteStringValues(s ...string) { var t []byte t = strconv.AppendQuote(t, strings.Join(s, ` `)) _, _ = b.Write(t) b.writeSpace() }
[ "func", "(", "b", "*", "recordBuffer", ")", "WriteStringValues", "(", "s", "...", "string", ")", "{", "var", "t", "[", "]", "byte", "\n", "t", "=", "strconv", ".", "AppendQuote", "(", "t", ",", "strings", ".", "Join", "(", "s", ",", "` `", ")", "...
// WriteStringValues always writes quoted strings to the buffer
[ "WriteStringValues", "always", "writes", "quoted", "strings", "to", "the", "buffer" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L62-L67
15,817
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
WriteDashOrStringValue
func (b *recordBuffer) WriteDashOrStringValue(s string) { if s == "" { _, _ = b.WriteString(`"-"`) b.writeSpace() } else { b.WriteStringValues(s) } }
go
func (b *recordBuffer) WriteDashOrStringValue(s string) { if s == "" { _, _ = b.WriteString(`"-"`) b.writeSpace() } else { b.WriteStringValues(s) } }
[ "func", "(", "b", "*", "recordBuffer", ")", "WriteDashOrStringValue", "(", "s", "string", ")", "{", "if", "s", "==", "\"", "\"", "{", "_", ",", "_", "=", "b", ".", "WriteString", "(", "`\"-\"`", ")", "\n", "b", ".", "writeSpace", "(", ")", "\n", ...
// WriteDashOrStringValue writes quoted strings or a "-" if the string is empty
[ "WriteDashOrStringValue", "writes", "quoted", "strings", "or", "a", "-", "if", "the", "string", "is", "empty" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L70-L77
15,818
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
WriteTo
func (r *AccessLogRecord) WriteTo(w io.Writer) (int64, error) { bytesWritten, err := w.Write(r.getRecord()) return int64(bytesWritten), err }
go
func (r *AccessLogRecord) WriteTo(w io.Writer) (int64, error) { bytesWritten, err := w.Write(r.getRecord()) return int64(bytesWritten), err }
[ "func", "(", "r", "*", "AccessLogRecord", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "bytesWritten", ",", "err", ":=", "w", ".", "Write", "(", "r", ".", "getRecord", "(", ")", ")", "\n", "return", "i...
// WriteTo allows the AccessLogRecord to implement the io.WriterTo interface
[ "WriteTo", "allows", "the", "AccessLogRecord", "to", "implement", "the", "io", ".", "WriterTo", "interface" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L180-L183
15,819
cloudfoundry/gorouter
accesslog/schema/access_log_record.go
ApplicationID
func (r *AccessLogRecord) ApplicationID() string { if r.RouteEndpoint == nil { return "" } return r.RouteEndpoint.ApplicationId }
go
func (r *AccessLogRecord) ApplicationID() string { if r.RouteEndpoint == nil { return "" } return r.RouteEndpoint.ApplicationId }
[ "func", "(", "r", "*", "AccessLogRecord", ")", "ApplicationID", "(", ")", "string", "{", "if", "r", ".", "RouteEndpoint", "==", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "r", ".", "RouteEndpoint", ".", "ApplicationId", "\n", "}" ]
// ApplicationID returns the application ID that corresponds with the access log
[ "ApplicationID", "returns", "the", "application", "ID", "that", "corresponds", "with", "the", "access", "log" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/accesslog/schema/access_log_record.go#L186-L192
15,820
cloudfoundry/gorouter
proxy/handler/forwarder.go
ForwardIO
func (f *Forwarder) ForwardIO(clientConn, backendConn io.ReadWriter) int { done := make(chan bool, 2) copy := func(dst io.Writer, src io.Reader) { // don't care about errors here _, _ = io.Copy(dst, src) done <- true } headerWasRead := make(chan struct{}) headerBytes := &bytes.Buffer{} teedReader := io.TeeReader(backendConn, headerBytes) var resp *http.Response var err error go func() { resp, err = http.ReadResponse(bufio.NewReader(teedReader), nil) headerWasRead <- struct{}{} }() select { case <-headerWasRead: if err != nil { return 0 } case <-time.After(f.BackendReadTimeout): f.Logger.Error("websocket-forwardio", zap.Error(errors.New("timeout waiting for http response from backend"))) return 0 } // we always write the header... _, err = io.Copy(clientConn, headerBytes) // don't care about errors if err != nil { f.Logger.Error("websocket-copy", zap.Error(err)) return 0 } if !isValidWebsocketResponse(resp) { return resp.StatusCode } // only now do we start copying body data go copy(clientConn, backendConn) go copy(backendConn, clientConn) <-done return http.StatusSwitchingProtocols }
go
func (f *Forwarder) ForwardIO(clientConn, backendConn io.ReadWriter) int { done := make(chan bool, 2) copy := func(dst io.Writer, src io.Reader) { // don't care about errors here _, _ = io.Copy(dst, src) done <- true } headerWasRead := make(chan struct{}) headerBytes := &bytes.Buffer{} teedReader := io.TeeReader(backendConn, headerBytes) var resp *http.Response var err error go func() { resp, err = http.ReadResponse(bufio.NewReader(teedReader), nil) headerWasRead <- struct{}{} }() select { case <-headerWasRead: if err != nil { return 0 } case <-time.After(f.BackendReadTimeout): f.Logger.Error("websocket-forwardio", zap.Error(errors.New("timeout waiting for http response from backend"))) return 0 } // we always write the header... _, err = io.Copy(clientConn, headerBytes) // don't care about errors if err != nil { f.Logger.Error("websocket-copy", zap.Error(err)) return 0 } if !isValidWebsocketResponse(resp) { return resp.StatusCode } // only now do we start copying body data go copy(clientConn, backendConn) go copy(backendConn, clientConn) <-done return http.StatusSwitchingProtocols }
[ "func", "(", "f", "*", "Forwarder", ")", "ForwardIO", "(", "clientConn", ",", "backendConn", "io", ".", "ReadWriter", ")", "int", "{", "done", ":=", "make", "(", "chan", "bool", ",", "2", ")", "\n\n", "copy", ":=", "func", "(", "dst", "io", ".", "W...
// ForwardIO sets up websocket forwarding with a backend // // It returns after one of the connections closes. // // If the backend response code is not 101 Switching Protocols, then // ForwardIO will return immediately, allowing the caller to close the connections.
[ "ForwardIO", "sets", "up", "websocket", "forwarding", "with", "a", "backend", "It", "returns", "after", "one", "of", "the", "connections", "closes", ".", "If", "the", "backend", "response", "code", "is", "not", "101", "Switching", "Protocols", "then", "Forward...
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/proxy/handler/forwarder.go#L26-L72
15,821
cloudfoundry/gorouter
handlers/lookup.go
NewLookup
func NewLookup(registry registry.Registry, rep metrics.ProxyReporter, logger logger.Logger) negroni.Handler { return &lookupHandler{ registry: registry, reporter: rep, logger: logger, } }
go
func NewLookup(registry registry.Registry, rep metrics.ProxyReporter, logger logger.Logger) negroni.Handler { return &lookupHandler{ registry: registry, reporter: rep, logger: logger, } }
[ "func", "NewLookup", "(", "registry", "registry", ".", "Registry", ",", "rep", "metrics", ".", "ProxyReporter", ",", "logger", "logger", ".", "Logger", ")", "negroni", ".", "Handler", "{", "return", "&", "lookupHandler", "{", "registry", ":", "registry", ","...
// NewLookup creates a handler responsible for looking up a route.
[ "NewLookup", "creates", "a", "handler", "responsible", "for", "looking", "up", "a", "route", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/lookup.go#L30-L36
15,822
cloudfoundry/gorouter
stats/top_apps.go
Trim
func (x *topAppsEntry) Trim(t int64) { var i int var n int64 // Collect slots that can be removed l := len(x.t) for i = 0; i < l; i++ { if x.t[i].t > t { break } n += x.t[i].n } copy(x.t, x.t[i:]) x.t = x.t[0:(l - i)] x.n -= n }
go
func (x *topAppsEntry) Trim(t int64) { var i int var n int64 // Collect slots that can be removed l := len(x.t) for i = 0; i < l; i++ { if x.t[i].t > t { break } n += x.t[i].n } copy(x.t, x.t[i:]) x.t = x.t[0:(l - i)] x.n -= n }
[ "func", "(", "x", "*", "topAppsEntry", ")", "Trim", "(", "t", "int64", ")", "{", "var", "i", "int", "\n", "var", "n", "int64", "\n\n", "// Collect slots that can be removed", "l", ":=", "len", "(", "x", ".", "t", ")", "\n", "for", "i", "=", "0", ";...
// Trim time slots up to and including time t.
[ "Trim", "time", "slots", "up", "to", "and", "including", "time", "t", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/stats/top_apps.go#L44-L61
15,823
cloudfoundry/gorouter
logger/lager_adapter.go
Session
func (l *LagerAdapter) Session(task string, data ...lager.Data) lager.Logger { tmpLogger := l.originalLogger.Session(task) if data != nil { tmpLogger = l.originalLogger.With(dataToFields(data)...) } return &LagerAdapter{ originalLogger: tmpLogger, } }
go
func (l *LagerAdapter) Session(task string, data ...lager.Data) lager.Logger { tmpLogger := l.originalLogger.Session(task) if data != nil { tmpLogger = l.originalLogger.With(dataToFields(data)...) } return &LagerAdapter{ originalLogger: tmpLogger, } }
[ "func", "(", "l", "*", "LagerAdapter", ")", "Session", "(", "task", "string", ",", "data", "...", "lager", ".", "Data", ")", "lager", ".", "Logger", "{", "tmpLogger", ":=", "l", ".", "originalLogger", ".", "Session", "(", "task", ")", "\n\n", "if", "...
// Session returns a new logger with a nested session.
[ "Session", "returns", "a", "new", "logger", "with", "a", "nested", "session", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/logger/lager_adapter.go#L27-L37
15,824
cloudfoundry/gorouter
logger/lager_adapter.go
Debug
func (l *LagerAdapter) Debug(action string, data ...lager.Data) { l.originalLogger.Debug(action, dataToFields(data)...) }
go
func (l *LagerAdapter) Debug(action string, data ...lager.Data) { l.originalLogger.Debug(action, dataToFields(data)...) }
[ "func", "(", "l", "*", "LagerAdapter", ")", "Debug", "(", "action", "string", ",", "data", "...", "lager", ".", "Data", ")", "{", "l", ".", "originalLogger", ".", "Debug", "(", "action", ",", "dataToFields", "(", "data", ")", "...", ")", "\n", "}" ]
// Debug logs a message at the debug log level.
[ "Debug", "logs", "a", "message", "at", "the", "debug", "log", "level", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/logger/lager_adapter.go#L45-L47
15,825
cloudfoundry/gorouter
logger/lager_adapter.go
Error
func (l *LagerAdapter) Error(action string, err error, data ...lager.Data) { l.originalLogger.Error(action, appendError(err, dataToFields(data))...) }
go
func (l *LagerAdapter) Error(action string, err error, data ...lager.Data) { l.originalLogger.Error(action, appendError(err, dataToFields(data))...) }
[ "func", "(", "l", "*", "LagerAdapter", ")", "Error", "(", "action", "string", ",", "err", "error", ",", "data", "...", "lager", ".", "Data", ")", "{", "l", ".", "originalLogger", ".", "Error", "(", "action", ",", "appendError", "(", "err", ",", "data...
// Error logs a message at the error log level.
[ "Error", "logs", "a", "message", "at", "the", "error", "log", "level", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/logger/lager_adapter.go#L55-L57
15,826
cloudfoundry/gorouter
logger/lager_adapter.go
WithData
func (l *LagerAdapter) WithData(data lager.Data) lager.Logger { return &LagerAdapter{ originalLogger: l.originalLogger.With(dataToFields([]lager.Data{data})...), } }
go
func (l *LagerAdapter) WithData(data lager.Data) lager.Logger { return &LagerAdapter{ originalLogger: l.originalLogger.With(dataToFields([]lager.Data{data})...), } }
[ "func", "(", "l", "*", "LagerAdapter", ")", "WithData", "(", "data", "lager", ".", "Data", ")", "lager", ".", "Logger", "{", "return", "&", "LagerAdapter", "{", "originalLogger", ":", "l", ".", "originalLogger", ".", "With", "(", "dataToFields", "(", "["...
// WithData returns a logger with newly added data.
[ "WithData", "returns", "a", "logger", "with", "newly", "added", "data", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/logger/lager_adapter.go#L65-L69
15,827
cloudfoundry/gorouter
handlers/reporter.go
NewReporter
func NewReporter(reporter metrics.ProxyReporter, logger logger.Logger) negroni.Handler { return &reporterHandler{ reporter: reporter, logger: logger, } }
go
func NewReporter(reporter metrics.ProxyReporter, logger logger.Logger) negroni.Handler { return &reporterHandler{ reporter: reporter, logger: logger, } }
[ "func", "NewReporter", "(", "reporter", "metrics", ".", "ProxyReporter", ",", "logger", "logger", ".", "Logger", ")", "negroni", ".", "Handler", "{", "return", "&", "reporterHandler", "{", "reporter", ":", "reporter", ",", "logger", ":", "logger", ",", "}", ...
// NewReporter creates a new handler that handles reporting backend // responses to metrics
[ "NewReporter", "creates", "a", "new", "handler", "that", "handles", "reporting", "backend", "responses", "to", "metrics" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/reporter.go#L22-L27
15,828
cloudfoundry/gorouter
handlers/reporter.go
ServeHTTP
func (rh *reporterHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { next(rw, r) requestInfo, err := ContextRequestInfo(r) // logger.Fatal does not cause gorouter to exit 1 but rather throw panic with // stacktrace in error log if err != nil { rh.logger.Fatal("request-info-err", zap.Error(err)) return } if requestInfo.RouteEndpoint == nil { return } proxyWriter := rw.(utils.ProxyResponseWriter) rh.reporter.CaptureRoutingResponse(proxyWriter.Status()) if requestInfo.StoppedAt.Equal(time.Time{}) { return } rh.reporter.CaptureRoutingResponseLatency( requestInfo.RouteEndpoint, proxyWriter.Status(), requestInfo.StartedAt, requestInfo.StoppedAt.Sub(requestInfo.StartedAt), ) }
go
func (rh *reporterHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { next(rw, r) requestInfo, err := ContextRequestInfo(r) // logger.Fatal does not cause gorouter to exit 1 but rather throw panic with // stacktrace in error log if err != nil { rh.logger.Fatal("request-info-err", zap.Error(err)) return } if requestInfo.RouteEndpoint == nil { return } proxyWriter := rw.(utils.ProxyResponseWriter) rh.reporter.CaptureRoutingResponse(proxyWriter.Status()) if requestInfo.StoppedAt.Equal(time.Time{}) { return } rh.reporter.CaptureRoutingResponseLatency( requestInfo.RouteEndpoint, proxyWriter.Status(), requestInfo.StartedAt, requestInfo.StoppedAt.Sub(requestInfo.StartedAt), ) }
[ "func", "(", "rh", "*", "reporterHandler", ")", "ServeHTTP", "(", "rw", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "next", "http", ".", "HandlerFunc", ")", "{", "next", "(", "rw", ",", "r", ")", "\n\n", "requestInfo", ...
// ServeHTTP handles reporting the response after the request has been completed
[ "ServeHTTP", "handles", "reporting", "the", "response", "after", "the", "request", "has", "been", "completed" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/reporter.go#L30-L55
15,829
cloudfoundry/gorouter
router/router.go
closeIdleConns
func (r *Router) closeIdleConns() { r.closeConnections = true for conn, _ := range r.idleConns { conn.Close() } }
go
func (r *Router) closeIdleConns() { r.closeConnections = true for conn, _ := range r.idleConns { conn.Close() } }
[ "func", "(", "r", "*", "Router", ")", "closeIdleConns", "(", ")", "{", "r", ".", "closeConnections", "=", "true", "\n\n", "for", "conn", ",", "_", ":=", "range", "r", ".", "idleConns", "{", "conn", ".", "Close", "(", ")", "\n", "}", "\n", "}" ]
// connLock must be locked
[ "connLock", "must", "be", "locked" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/router/router.go#L366-L372
15,830
cloudfoundry/gorouter
proxy/fails/classifier_group.go
Classify
func (cg ClassifierGroup) Classify(err error) bool { for _, classifier := range cg { if classifier.Classify(err) { return true } } return false }
go
func (cg ClassifierGroup) Classify(err error) bool { for _, classifier := range cg { if classifier.Classify(err) { return true } } return false }
[ "func", "(", "cg", "ClassifierGroup", ")", "Classify", "(", "err", "error", ")", "bool", "{", "for", "_", ",", "classifier", ":=", "range", "cg", "{", "if", "classifier", ".", "Classify", "(", "err", ")", "{", "return", "true", "\n", "}", "\n", "}", ...
// Classify returns true on errors that are retryable
[ "Classify", "returns", "true", "on", "errors", "that", "are", "retryable" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/proxy/fails/classifier_group.go#L22-L29
15,831
cloudfoundry/gorouter
handlers/proxywriter.go
ServeHTTP
func (p *proxyWriterHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { reqInfo, err := ContextRequestInfo(r) if err != nil { p.logger.Fatal("request-info-err", zap.Error(err)) return } proxyWriter := utils.NewProxyResponseWriter(rw) reqInfo.ProxyResponseWriter = proxyWriter next(proxyWriter, r) }
go
func (p *proxyWriterHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { reqInfo, err := ContextRequestInfo(r) if err != nil { p.logger.Fatal("request-info-err", zap.Error(err)) return } proxyWriter := utils.NewProxyResponseWriter(rw) reqInfo.ProxyResponseWriter = proxyWriter next(proxyWriter, r) }
[ "func", "(", "p", "*", "proxyWriterHandler", ")", "ServeHTTP", "(", "rw", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "next", "http", ".", "HandlerFunc", ")", "{", "reqInfo", ",", "err", ":=", "ContextRequestInfo", "(", "r"...
// ServeHTTP wraps the responseWriter in a ProxyResponseWriter
[ "ServeHTTP", "wraps", "the", "responseWriter", "in", "a", "ProxyResponseWriter" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/proxywriter.go#L26-L35
15,832
cloudfoundry/gorouter
route/pool.go
Put
func (p *Pool) Put(endpoint *Endpoint) PoolPutResult { p.Lock() defer p.Unlock() var result PoolPutResult e, found := p.index[endpoint.CanonicalAddr()] if found { result = UPDATED if e.endpoint != endpoint { e.Lock() defer e.Unlock() if !e.endpoint.ModificationTag.SucceededBy(&endpoint.ModificationTag) { return UNMODIFIED } oldEndpoint := e.endpoint e.endpoint = endpoint if oldEndpoint.PrivateInstanceId != endpoint.PrivateInstanceId { delete(p.index, oldEndpoint.PrivateInstanceId) p.index[endpoint.PrivateInstanceId] = e } if oldEndpoint.ServerCertDomainSAN == endpoint.ServerCertDomainSAN { endpoint.SetRoundTripper(oldEndpoint.RoundTripper()) } } } else { result = ADDED e = &endpointElem{ endpoint: endpoint, index: len(p.endpoints), maxConnsPerBackend: p.maxConnsPerBackend, } p.endpoints = append(p.endpoints, e) p.index[endpoint.CanonicalAddr()] = e p.index[endpoint.PrivateInstanceId] = e } e.updated = time.Now() return result }
go
func (p *Pool) Put(endpoint *Endpoint) PoolPutResult { p.Lock() defer p.Unlock() var result PoolPutResult e, found := p.index[endpoint.CanonicalAddr()] if found { result = UPDATED if e.endpoint != endpoint { e.Lock() defer e.Unlock() if !e.endpoint.ModificationTag.SucceededBy(&endpoint.ModificationTag) { return UNMODIFIED } oldEndpoint := e.endpoint e.endpoint = endpoint if oldEndpoint.PrivateInstanceId != endpoint.PrivateInstanceId { delete(p.index, oldEndpoint.PrivateInstanceId) p.index[endpoint.PrivateInstanceId] = e } if oldEndpoint.ServerCertDomainSAN == endpoint.ServerCertDomainSAN { endpoint.SetRoundTripper(oldEndpoint.RoundTripper()) } } } else { result = ADDED e = &endpointElem{ endpoint: endpoint, index: len(p.endpoints), maxConnsPerBackend: p.maxConnsPerBackend, } p.endpoints = append(p.endpoints, e) p.index[endpoint.CanonicalAddr()] = e p.index[endpoint.PrivateInstanceId] = e } e.updated = time.Now() return result }
[ "func", "(", "p", "*", "Pool", ")", "Put", "(", "endpoint", "*", "Endpoint", ")", "PoolPutResult", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "var", "result", "PoolPutResult", "\n", "e", ",", "found", ":="...
// Returns true if endpoint was added or updated, false otherwise
[ "Returns", "true", "if", "endpoint", "was", "added", "or", "updated", "false", "otherwise" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/route/pool.go#L214-L259
15,833
cloudfoundry/gorouter
route/pool.go
Remove
func (p *Pool) Remove(endpoint *Endpoint) bool { var e *endpointElem p.Lock() defer p.Unlock() l := len(p.endpoints) if l > 0 { e = p.index[endpoint.CanonicalAddr()] if e != nil && e.endpoint.modificationTagSameOrNewer(endpoint) { p.removeEndpoint(e) return true } } return false }
go
func (p *Pool) Remove(endpoint *Endpoint) bool { var e *endpointElem p.Lock() defer p.Unlock() l := len(p.endpoints) if l > 0 { e = p.index[endpoint.CanonicalAddr()] if e != nil && e.endpoint.modificationTagSameOrNewer(endpoint) { p.removeEndpoint(e) return true } } return false }
[ "func", "(", "p", "*", "Pool", ")", "Remove", "(", "endpoint", "*", "Endpoint", ")", "bool", "{", "var", "e", "*", "endpointElem", "\n\n", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "l", ":=", "len", "(", "p"...
// Returns true if the endpoint was removed from the Pool, false otherwise.
[ "Returns", "true", "if", "the", "endpoint", "was", "removed", "from", "the", "Pool", "false", "otherwise", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/route/pool.go#L305-L320
15,834
cloudfoundry/gorouter
mbus/subscriber.go
ValidateMessage
func (rm *RegistryMessage) ValidateMessage() bool { return rm.RouteServiceURL == "" || strings.HasPrefix(rm.RouteServiceURL, "https") }
go
func (rm *RegistryMessage) ValidateMessage() bool { return rm.RouteServiceURL == "" || strings.HasPrefix(rm.RouteServiceURL, "https") }
[ "func", "(", "rm", "*", "RegistryMessage", ")", "ValidateMessage", "(", ")", "bool", "{", "return", "rm", ".", "RouteServiceURL", "==", "\"", "\"", "||", "strings", ".", "HasPrefix", "(", "rm", ".", "RouteServiceURL", ",", "\"", "\"", ")", "\n", "}" ]
// ValidateMessage checks to ensure the registry message is valid
[ "ValidateMessage", "checks", "to", "ensure", "the", "registry", "message", "is", "valid" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/mbus/subscriber.go#L72-L74
15,835
cloudfoundry/gorouter
mbus/subscriber.go
port
func (rm *RegistryMessage) port() (uint16, bool, error) { if rm.TLSPort != 0 { return rm.TLSPort, true, nil } return rm.Port, false, nil }
go
func (rm *RegistryMessage) port() (uint16, bool, error) { if rm.TLSPort != 0 { return rm.TLSPort, true, nil } return rm.Port, false, nil }
[ "func", "(", "rm", "*", "RegistryMessage", ")", "port", "(", ")", "(", "uint16", ",", "bool", ",", "error", ")", "{", "if", "rm", ".", "TLSPort", "!=", "0", "{", "return", "rm", ".", "TLSPort", ",", "true", ",", "nil", "\n", "}", "\n", "return", ...
// Prefer TLS Port instead of HTTP Port in Registrty Message
[ "Prefer", "TLS", "Port", "instead", "of", "HTTP", "Port", "in", "Registrty", "Message" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/mbus/subscriber.go#L77-L82
15,836
cloudfoundry/gorouter
mbus/subscriber.go
NewSubscriber
func NewSubscriber( mbusClient Client, routeRegistry registry.Registry, c *config.Config, reconnected <-chan Signal, l logger.Logger, ) *Subscriber { guid, err := uuid.GenerateUUID() if err != nil { l.Fatal("failed-to-generate-uuid", zap.Error(err)) } return &Subscriber{ mbusClient: mbusClient, routeRegistry: routeRegistry, params: startMessageParams{ id: fmt.Sprintf("%d-%s", c.Index, guid), minimumRegisterIntervalInSeconds: int(c.StartResponseDelayInterval.Seconds()), pruneThresholdInSeconds: int(c.DropletStaleThreshold.Seconds()), }, reconnected: reconnected, natsPendingLimit: c.NatsClientMessageBufferSize, logger: l, } }
go
func NewSubscriber( mbusClient Client, routeRegistry registry.Registry, c *config.Config, reconnected <-chan Signal, l logger.Logger, ) *Subscriber { guid, err := uuid.GenerateUUID() if err != nil { l.Fatal("failed-to-generate-uuid", zap.Error(err)) } return &Subscriber{ mbusClient: mbusClient, routeRegistry: routeRegistry, params: startMessageParams{ id: fmt.Sprintf("%d-%s", c.Index, guid), minimumRegisterIntervalInSeconds: int(c.StartResponseDelayInterval.Seconds()), pruneThresholdInSeconds: int(c.DropletStaleThreshold.Seconds()), }, reconnected: reconnected, natsPendingLimit: c.NatsClientMessageBufferSize, logger: l, } }
[ "func", "NewSubscriber", "(", "mbusClient", "Client", ",", "routeRegistry", "registry", ".", "Registry", ",", "c", "*", "config", ".", "Config", ",", "reconnected", "<-", "chan", "Signal", ",", "l", "logger", ".", "Logger", ",", ")", "*", "Subscriber", "{"...
// NewSubscriber returns a new Subscriber
[ "NewSubscriber", "returns", "a", "new", "Subscriber" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/mbus/subscriber.go#L104-L128
15,837
cloudfoundry/gorouter
mbus/subscriber.go
Run
func (s *Subscriber) Run(signals <-chan os.Signal, ready chan<- struct{}) error { s.logger.Info("subscriber-starting") if s.mbusClient == nil { return errors.New("subscriber: nil mbus client") } err := s.sendStartMessage() if err != nil { return err } err = s.subscribeToGreetMessage() if err != nil { return err } s.subscription, err = s.subscribeRoutes() if err != nil { return err } close(ready) s.logger.Info("subscriber-started") for { select { case <-s.reconnected: err := s.sendStartMessage() if err != nil { s.logger.Error("failed-to-send-start-message", zap.Error(err)) } case <-signals: s.logger.Info("exited") return nil } } }
go
func (s *Subscriber) Run(signals <-chan os.Signal, ready chan<- struct{}) error { s.logger.Info("subscriber-starting") if s.mbusClient == nil { return errors.New("subscriber: nil mbus client") } err := s.sendStartMessage() if err != nil { return err } err = s.subscribeToGreetMessage() if err != nil { return err } s.subscription, err = s.subscribeRoutes() if err != nil { return err } close(ready) s.logger.Info("subscriber-started") for { select { case <-s.reconnected: err := s.sendStartMessage() if err != nil { s.logger.Error("failed-to-send-start-message", zap.Error(err)) } case <-signals: s.logger.Info("exited") return nil } } }
[ "func", "(", "s", "*", "Subscriber", ")", "Run", "(", "signals", "<-", "chan", "os", ".", "Signal", ",", "ready", "chan", "<-", "struct", "{", "}", ")", "error", "{", "s", ".", "logger", ".", "Info", "(", "\"", "\"", ")", "\n", "if", "s", ".", ...
// Run manages the lifecycle of the subscriber process
[ "Run", "manages", "the", "lifecycle", "of", "the", "subscriber", "process" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/mbus/subscriber.go#L131-L164
15,838
cloudfoundry/gorouter
registry/container/trie.go
Snip
func (r *Trie) Snip() { if r.Pool != nil && r.Pool.IsEmpty() { r.Pool = nil } if (r.Pool != nil && !r.Pool.IsEmpty()) || r.isRoot() || !r.isLeaf() { return } delete(r.Parent.ChildNodes, r.Segment) r.Parent.Snip() }
go
func (r *Trie) Snip() { if r.Pool != nil && r.Pool.IsEmpty() { r.Pool = nil } if (r.Pool != nil && !r.Pool.IsEmpty()) || r.isRoot() || !r.isLeaf() { return } delete(r.Parent.ChildNodes, r.Segment) r.Parent.Snip() }
[ "func", "(", "r", "*", "Trie", ")", "Snip", "(", ")", "{", "if", "r", ".", "Pool", "!=", "nil", "&&", "r", ".", "Pool", ".", "IsEmpty", "(", ")", "{", "r", ".", "Pool", "=", "nil", "\n", "}", "\n", "if", "(", "r", ".", "Pool", "!=", "nil"...
// Snip removes an empty Pool from a node and trims empty leaf nodes from the Trie
[ "Snip", "removes", "an", "empty", "Pool", "from", "a", "node", "and", "trims", "empty", "leaf", "nodes", "from", "the", "Trie" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/registry/container/trie.go#L234-L243
15,839
cloudfoundry/gorouter
handlers/paniccheck.go
NewPanicCheck
func NewPanicCheck(healthcheck *threading.SharedBoolean, logger logger.Logger) negroni.Handler { return &panicCheck{ heartbeatOK: healthcheck, logger: logger, } }
go
func NewPanicCheck(healthcheck *threading.SharedBoolean, logger logger.Logger) negroni.Handler { return &panicCheck{ heartbeatOK: healthcheck, logger: logger, } }
[ "func", "NewPanicCheck", "(", "healthcheck", "*", "threading", ".", "SharedBoolean", ",", "logger", "logger", ".", "Logger", ")", "negroni", ".", "Handler", "{", "return", "&", "panicCheck", "{", "heartbeatOK", ":", "healthcheck", ",", "logger", ":", "logger",...
// NewPanicCheck creates a handler responsible for checking for panics and setting the Healthcheck to fail.
[ "NewPanicCheck", "creates", "a", "handler", "responsible", "for", "checking", "for", "panics", "and", "setting", "the", "Healthcheck", "to", "fail", "." ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/paniccheck.go#L20-L25
15,840
cloudfoundry/gorouter
handlers/httpstartstop.go
NewHTTPStartStop
func NewHTTPStartStop(emitter dropsonde.EventEmitter, logger logger.Logger) negroni.Handler { return &httpStartStopHandler{ emitter: emitter, logger: logger, } }
go
func NewHTTPStartStop(emitter dropsonde.EventEmitter, logger logger.Logger) negroni.Handler { return &httpStartStopHandler{ emitter: emitter, logger: logger, } }
[ "func", "NewHTTPStartStop", "(", "emitter", "dropsonde", ".", "EventEmitter", ",", "logger", "logger", ".", "Logger", ")", "negroni", ".", "Handler", "{", "return", "&", "httpStartStopHandler", "{", "emitter", ":", "emitter", ",", "logger", ":", "logger", ",",...
// NewHTTPStartStop creates a new handler that handles emitting frontent // HTTP StartStop events
[ "NewHTTPStartStop", "creates", "a", "new", "handler", "that", "handles", "emitting", "frontent", "HTTP", "StartStop", "events" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/httpstartstop.go#L25-L30
15,841
cloudfoundry/gorouter
handlers/httpstartstop.go
ServeHTTP
func (hh *httpStartStopHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { prw, ok := rw.(utils.ProxyResponseWriter) if !ok { hh.logger.Fatal("request-info-err", zap.String("error", "ProxyResponseWriter not found")) return } requestID, err := uuid.ParseHex(r.Header.Get(VcapRequestIdHeader)) if err != nil { hh.logger.Fatal("start-stop-handler-err", zap.String("error", "X-Vcap-Request-Id not found")) return } startTime := time.Now() next(rw, r) startStopEvent := factories.NewHttpStartStop(r, prw.Status(), int64(prw.Size()), events.PeerType_Server, requestID) startStopEvent.StartTimestamp = proto.Int64(startTime.UnixNano()) err = hh.emitter.Emit(startStopEvent) if err != nil { hh.logger.Info("failed-to-emit-startstop-event", zap.Error(err)) } }
go
func (hh *httpStartStopHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { prw, ok := rw.(utils.ProxyResponseWriter) if !ok { hh.logger.Fatal("request-info-err", zap.String("error", "ProxyResponseWriter not found")) return } requestID, err := uuid.ParseHex(r.Header.Get(VcapRequestIdHeader)) if err != nil { hh.logger.Fatal("start-stop-handler-err", zap.String("error", "X-Vcap-Request-Id not found")) return } startTime := time.Now() next(rw, r) startStopEvent := factories.NewHttpStartStop(r, prw.Status(), int64(prw.Size()), events.PeerType_Server, requestID) startStopEvent.StartTimestamp = proto.Int64(startTime.UnixNano()) err = hh.emitter.Emit(startStopEvent) if err != nil { hh.logger.Info("failed-to-emit-startstop-event", zap.Error(err)) } }
[ "func", "(", "hh", "*", "httpStartStopHandler", ")", "ServeHTTP", "(", "rw", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "next", "http", ".", "HandlerFunc", ")", "{", "prw", ",", "ok", ":=", "rw", ".", "(", "utils", "."...
// ServeHTTP handles emitting a StartStop event after the request has been completed
[ "ServeHTTP", "handles", "emitting", "a", "StartStop", "event", "after", "the", "request", "has", "been", "completed" ]
d0c01116b5bb30786dacc2666082c6d7f9e47e18
https://github.com/cloudfoundry/gorouter/blob/d0c01116b5bb30786dacc2666082c6d7f9e47e18/handlers/httpstartstop.go#L33-L56
15,842
clockworksoul/smudge
registry.go
GetLocalIP
func GetLocalIP() (net.IP, error) { var ip net.IP addrs, err := net.InterfaceAddrs() if err != nil { return ip, err } for _, a := range addrs { if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet.IP.To4() != nil { ip = ipnet.IP.To4() } else { ip = ipnet.IP break } } } return ip, nil }
go
func GetLocalIP() (net.IP, error) { var ip net.IP addrs, err := net.InterfaceAddrs() if err != nil { return ip, err } for _, a := range addrs { if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet.IP.To4() != nil { ip = ipnet.IP.To4() } else { ip = ipnet.IP break } } } return ip, nil }
[ "func", "GetLocalIP", "(", ")", "(", "net", ".", "IP", ",", "error", ")", "{", "var", "ip", "net", ".", "IP", "\n\n", "addrs", ",", "err", ":=", "net", ".", "InterfaceAddrs", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ip", ",", "...
// GetLocalIP queries the host interface to determine the local IP address of this // machine. If a local IP address cannot be found, then nil is returned. Local IPv6 // address takes presedence over a local IPv4 address. If the query to the underlying // OS fails, an error is returned.
[ "GetLocalIP", "queries", "the", "host", "interface", "to", "determine", "the", "local", "IP", "address", "of", "this", "machine", ".", "If", "a", "local", "IP", "address", "cannot", "be", "found", "then", "nil", "is", "returned", ".", "Local", "IPv6", "add...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/registry.go#L114-L134
15,843
clockworksoul/smudge
registry.go
HealthyNodes
func HealthyNodes() []*Node { values := knownNodes.values() filtered := make([]*Node, 0, len(values)) for _, v := range values { if v.Status() == StatusAlive { filtered = append(filtered, v) } } return filtered }
go
func HealthyNodes() []*Node { values := knownNodes.values() filtered := make([]*Node, 0, len(values)) for _, v := range values { if v.Status() == StatusAlive { filtered = append(filtered, v) } } return filtered }
[ "func", "HealthyNodes", "(", ")", "[", "]", "*", "Node", "{", "values", ":=", "knownNodes", ".", "values", "(", ")", "\n", "filtered", ":=", "make", "(", "[", "]", "*", "Node", ",", "0", ",", "len", "(", "values", ")", ")", "\n\n", "for", "_", ...
// HealthyNodes will return a list of all nodes known at the time of the // request with a healthy status.
[ "HealthyNodes", "will", "return", "a", "list", "of", "all", "nodes", "known", "at", "the", "time", "of", "the", "request", "with", "a", "healthy", "status", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/registry.go#L145-L156
15,844
clockworksoul/smudge
registry.go
RemoveNode
func RemoveNode(node *Node) (*Node, error) { if knownNodes.contains(node) { node.Touch() _, n, err := knownNodes.delete(node) logfInfo("Removing host: %s (total=%d live=%d dead=%d)", node.Address(), knownNodes.length(), knownNodes.lengthWithStatus(StatusAlive), knownNodes.lengthWithStatus(StatusDead)) knownNodesModifiedFlag = true return n, err } return node, nil }
go
func RemoveNode(node *Node) (*Node, error) { if knownNodes.contains(node) { node.Touch() _, n, err := knownNodes.delete(node) logfInfo("Removing host: %s (total=%d live=%d dead=%d)", node.Address(), knownNodes.length(), knownNodes.lengthWithStatus(StatusAlive), knownNodes.lengthWithStatus(StatusDead)) knownNodesModifiedFlag = true return n, err } return node, nil }
[ "func", "RemoveNode", "(", "node", "*", "Node", ")", "(", "*", "Node", ",", "error", ")", "{", "if", "knownNodes", ".", "contains", "(", "node", ")", "{", "node", ".", "Touch", "(", ")", "\n\n", "_", ",", "n", ",", "err", ":=", "knownNodes", ".",...
// RemoveNode can be used to explicitly remove a node from the list of known // live nodes. Updates the node timestamp but DOES NOT implicitly update the // node's status; you need to do this explicitly.
[ "RemoveNode", "can", "be", "used", "to", "explicitly", "remove", "a", "node", "from", "the", "list", "of", "known", "live", "nodes", ".", "Updates", "the", "node", "timestamp", "but", "DOES", "NOT", "implicitly", "update", "the", "node", "s", "status", ";"...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/registry.go#L161-L179
15,845
clockworksoul/smudge
properties.go
GetListenIP
func GetListenIP() net.IP { if listenIP == nil { listenIP = net.ParseIP(getStringVar(EnvVarListenIP, DefaultListenIP)) } return listenIP }
go
func GetListenIP() net.IP { if listenIP == nil { listenIP = net.ParseIP(getStringVar(EnvVarListenIP, DefaultListenIP)) } return listenIP }
[ "func", "GetListenIP", "(", ")", "net", ".", "IP", "{", "if", "listenIP", "==", "nil", "{", "listenIP", "=", "net", ".", "ParseIP", "(", "getStringVar", "(", "EnvVarListenIP", ",", "DefaultListenIP", ")", ")", "\n", "}", "\n\n", "return", "listenIP", "\n...
// GetListenIP returns the IP that this host will listen on.
[ "GetListenIP", "returns", "the", "IP", "that", "this", "host", "will", "listen", "on", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/properties.go#L209-L215
15,846
clockworksoul/smudge
properties.go
GetMulticastEnabled
func GetMulticastEnabled() bool { if multicastEnabledString == "" { multicastEnabledString = strings.ToLower(getStringVar(EnvVarMulticastEnabled, DefaultMulticastEnabled)) } multicastEnabled = len(multicastEnabledString) > 0 && []rune(multicastEnabledString)[0] == 't' return multicastEnabled }
go
func GetMulticastEnabled() bool { if multicastEnabledString == "" { multicastEnabledString = strings.ToLower(getStringVar(EnvVarMulticastEnabled, DefaultMulticastEnabled)) } multicastEnabled = len(multicastEnabledString) > 0 && []rune(multicastEnabledString)[0] == 't' return multicastEnabled }
[ "func", "GetMulticastEnabled", "(", ")", "bool", "{", "if", "multicastEnabledString", "==", "\"", "\"", "{", "multicastEnabledString", "=", "strings", ".", "ToLower", "(", "getStringVar", "(", "EnvVarMulticastEnabled", ",", "DefaultMulticastEnabled", ")", ")", "\n",...
// GetMulticastEnabled returns whether multicast announcements are enabled.
[ "GetMulticastEnabled", "returns", "whether", "multicast", "announcements", "are", "enabled", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/properties.go#L237-L244
15,847
clockworksoul/smudge
properties.go
getIntVar
func getIntVar(key string, defaultVal int) int { valueString := os.Getenv(key) valueInt := defaultVal if valueString != "" { i, err := strconv.Atoi(valueString) if err != nil { logfWarn("Failed to parse env property %s: %s is not "+ "an integer. Using default.", key, valueString) } else { valueInt = i } } return valueInt }
go
func getIntVar(key string, defaultVal int) int { valueString := os.Getenv(key) valueInt := defaultVal if valueString != "" { i, err := strconv.Atoi(valueString) if err != nil { logfWarn("Failed to parse env property %s: %s is not "+ "an integer. Using default.", key, valueString) } else { valueInt = i } } return valueInt }
[ "func", "getIntVar", "(", "key", "string", ",", "defaultVal", "int", ")", "int", "{", "valueString", ":=", "os", ".", "Getenv", "(", "key", ")", "\n", "valueInt", ":=", "defaultVal", "\n\n", "if", "valueString", "!=", "\"", "\"", "{", "i", ",", "err", ...
// Gets an environmental variable "key". If it does not exist, "defaultVal" is // returned; if it does, it attempts to convert to an integer, returning // "defaultVal" if it fails.
[ "Gets", "an", "environmental", "variable", "key", ".", "If", "it", "does", "not", "exist", "defaultVal", "is", "returned", ";", "if", "it", "does", "it", "attempts", "to", "convert", "to", "an", "integer", "returning", "defaultVal", "if", "it", "fails", "....
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/properties.go#L396-L412
15,848
clockworksoul/smudge
properties.go
getStringArrayVar
func getStringArrayVar(key string, defaultVal string) []string { valueString := os.Getenv(key) if valueString == "" { valueString = defaultVal } valueSlice := splitDelimmitedString(valueString, stringListDelimitRegex) return valueSlice }
go
func getStringArrayVar(key string, defaultVal string) []string { valueString := os.Getenv(key) if valueString == "" { valueString = defaultVal } valueSlice := splitDelimmitedString(valueString, stringListDelimitRegex) return valueSlice }
[ "func", "getStringArrayVar", "(", "key", "string", ",", "defaultVal", "string", ")", "[", "]", "string", "{", "valueString", ":=", "os", ".", "Getenv", "(", "key", ")", "\n\n", "if", "valueString", "==", "\"", "\"", "{", "valueString", "=", "defaultVal", ...
// Gets an environmental variable "key". If it does not exist, "defaultVal" is // returned; if it does, it attempts to convert to a string slice, returning // "defaultVal" if it fails.
[ "Gets", "an", "environmental", "variable", "key", ".", "If", "it", "does", "not", "exist", "defaultVal", "is", "returned", ";", "if", "it", "does", "it", "attempts", "to", "convert", "to", "a", "string", "slice", "returning", "defaultVal", "if", "it", "fai...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/properties.go#L417-L427
15,849
clockworksoul/smudge
properties.go
getStringVar
func getStringVar(key string, defaultVal string) string { valueString := os.Getenv(key) if valueString == "" { valueString = defaultVal } return valueString }
go
func getStringVar(key string, defaultVal string) string { valueString := os.Getenv(key) if valueString == "" { valueString = defaultVal } return valueString }
[ "func", "getStringVar", "(", "key", "string", ",", "defaultVal", "string", ")", "string", "{", "valueString", ":=", "os", ".", "Getenv", "(", "key", ")", "\n\n", "if", "valueString", "==", "\"", "\"", "{", "valueString", "=", "defaultVal", "\n", "}", "\n...
// Gets an environmental variable "key". If it does not exist, "defaultVal" is // returned; if it does, it attempts to convert to a string, returning // "defaultVal" if it fails.
[ "Gets", "an", "environmental", "variable", "key", ".", "If", "it", "does", "not", "exist", "defaultVal", "is", "returned", ";", "if", "it", "does", "it", "attempts", "to", "convert", "to", "a", "string", "returning", "defaultVal", "if", "it", "fails", "." ...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/properties.go#L432-L440
15,850
clockworksoul/smudge
properties.go
splitDelimmitedString
func splitDelimmitedString(str string, regex string) []string { var result []string str = strings.TrimSpace(str) if str != "" { reg := regexp.MustCompile(regex) indices := reg.FindAllStringIndex(str, -1) result = make([]string, len(indices)+1) lastStart := 0 for i, val := range indices { result[i] = str[lastStart:val[0]] lastStart = val[1] } result[len(indices)] = str[lastStart:] // Special case of single empty string if len(result) == 1 && result[0] == "" { result = make([]string, 0, 0) } } return result }
go
func splitDelimmitedString(str string, regex string) []string { var result []string str = strings.TrimSpace(str) if str != "" { reg := regexp.MustCompile(regex) indices := reg.FindAllStringIndex(str, -1) result = make([]string, len(indices)+1) lastStart := 0 for i, val := range indices { result[i] = str[lastStart:val[0]] lastStart = val[1] } result[len(indices)] = str[lastStart:] // Special case of single empty string if len(result) == 1 && result[0] == "" { result = make([]string, 0, 0) } } return result }
[ "func", "splitDelimmitedString", "(", "str", "string", ",", "regex", "string", ")", "[", "]", "string", "{", "var", "result", "[", "]", "string", "\n\n", "str", "=", "strings", ".", "TrimSpace", "(", "str", ")", "\n\n", "if", "str", "!=", "\"", "\"", ...
// Splits a string on a regular expression.
[ "Splits", "a", "string", "on", "a", "regular", "expression", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/properties.go#L443-L469
15,851
clockworksoul/smudge
membership.go
getListenInterface
func getListenInterface() (*net.Interface, error) { ifaces, err := net.Interfaces() if err == nil { for _, iface := range ifaces { addrs, err := iface.Addrs() if err != nil { logfWarn("Can not get addresses of interface %s", iface.Name) continue } for _, addr := range addrs { ip, _, err := net.ParseCIDR(addr.String()) if err != nil { continue } if ip.String() == GetListenIP().String() { logfInfo("Found interface with listen IP: %s", iface.Name) return &iface, nil } } } } return nil, errors.New("Could not determine the interface of the listen IP address") }
go
func getListenInterface() (*net.Interface, error) { ifaces, err := net.Interfaces() if err == nil { for _, iface := range ifaces { addrs, err := iface.Addrs() if err != nil { logfWarn("Can not get addresses of interface %s", iface.Name) continue } for _, addr := range addrs { ip, _, err := net.ParseCIDR(addr.String()) if err != nil { continue } if ip.String() == GetListenIP().String() { logfInfo("Found interface with listen IP: %s", iface.Name) return &iface, nil } } } } return nil, errors.New("Could not determine the interface of the listen IP address") }
[ "func", "getListenInterface", "(", ")", "(", "*", "net", ".", "Interface", ",", "error", ")", "{", "ifaces", ",", "err", ":=", "net", ".", "Interfaces", "(", ")", "\n", "if", "err", "==", "nil", "{", "for", "_", ",", "iface", ":=", "range", "ifaces...
// getListenInterface gets the network interface for the listen IP
[ "getListenInterface", "gets", "the", "network", "interface", "for", "the", "listen", "IP" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/membership.go#L288-L310
15,852
clockworksoul/smudge
membership.go
multicastAnnounce
func multicastAnnounce(addr string) error { if addr == "" { addr = guessMulticastAddress() } fullAddr := addr + ":" + strconv.FormatInt(int64(GetMulticastPort()), 10) logInfo("Announcing presence on", fullAddr) address, err := net.ResolveUDPAddr("udp", fullAddr) if err != nil { logError(err) return err } laddr := &net.UDPAddr{ IP: GetListenIP(), Port: 0, } for { c, err := net.DialUDP("udp", laddr, address) if err != nil { logError(err) return err } // Compose and send the multicast announcement msgBytes := encodeMulticastAnnounceBytes() _, err = c.Write(msgBytes) if err != nil { logError(err) return err } logfTrace("Sent announcement multicast from %v to %v", laddr, fullAddr) if GetMulticastAnnounceIntervalSeconds() > 0 { time.Sleep(time.Second * time.Duration(GetMulticastAnnounceIntervalSeconds())) } else { return nil } } }
go
func multicastAnnounce(addr string) error { if addr == "" { addr = guessMulticastAddress() } fullAddr := addr + ":" + strconv.FormatInt(int64(GetMulticastPort()), 10) logInfo("Announcing presence on", fullAddr) address, err := net.ResolveUDPAddr("udp", fullAddr) if err != nil { logError(err) return err } laddr := &net.UDPAddr{ IP: GetListenIP(), Port: 0, } for { c, err := net.DialUDP("udp", laddr, address) if err != nil { logError(err) return err } // Compose and send the multicast announcement msgBytes := encodeMulticastAnnounceBytes() _, err = c.Write(msgBytes) if err != nil { logError(err) return err } logfTrace("Sent announcement multicast from %v to %v", laddr, fullAddr) if GetMulticastAnnounceIntervalSeconds() > 0 { time.Sleep(time.Second * time.Duration(GetMulticastAnnounceIntervalSeconds())) } else { return nil } } }
[ "func", "multicastAnnounce", "(", "addr", "string", ")", "error", "{", "if", "addr", "==", "\"", "\"", "{", "addr", "=", "guessMulticastAddress", "(", ")", "\n", "}", "\n\n", "fullAddr", ":=", "addr", "+", "\"", "\"", "+", "strconv", ".", "FormatInt", ...
// multicastAnnounce is called when the server first starts to broadcast its // presence to all listening servers within the specified subnet and continues // to broadcast its presence every multicastAnnounceIntervalSeconds in case // this value is larger than zero.
[ "multicastAnnounce", "is", "called", "when", "the", "server", "first", "starts", "to", "broadcast", "its", "presence", "to", "all", "listening", "servers", "within", "the", "specified", "subnet", "and", "continues", "to", "broadcast", "its", "presence", "every", ...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/membership.go#L420-L460
15,853
clockworksoul/smudge
log.go
Log
func (d DefaultLogger) Log(level LogLevel, a ...interface{}) (n int, err error) { if level >= logThreshhold { fmt.Fprint(os.Stderr, prefix(level)+" ") return fmt.Fprintln(os.Stderr, a...) } return 0, nil }
go
func (d DefaultLogger) Log(level LogLevel, a ...interface{}) (n int, err error) { if level >= logThreshhold { fmt.Fprint(os.Stderr, prefix(level)+" ") return fmt.Fprintln(os.Stderr, a...) } return 0, nil }
[ "func", "(", "d", "DefaultLogger", ")", "Log", "(", "level", "LogLevel", ",", "a", "...", "interface", "{", "}", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "level", ">=", "logThreshhold", "{", "fmt", ".", "Fprint", "(", "os", ".", ...
// Log writes a log message of a certain level to the logger
[ "Log", "writes", "a", "log", "message", "of", "a", "certain", "level", "to", "the", "logger" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/log.go#L104-L110
15,854
clockworksoul/smudge
log.go
Logf
func (d DefaultLogger) Logf(level LogLevel, format string, a ...interface{}) (n int, err error) { if level >= logThreshhold { return fmt.Fprintf(os.Stderr, prefix(level)+" "+format+"\n", a...) } return 0, nil }
go
func (d DefaultLogger) Logf(level LogLevel, format string, a ...interface{}) (n int, err error) { if level >= logThreshhold { return fmt.Fprintf(os.Stderr, prefix(level)+" "+format+"\n", a...) } return 0, nil }
[ "func", "(", "d", "DefaultLogger", ")", "Logf", "(", "level", "LogLevel", ",", "format", "string", ",", "a", "...", "interface", "{", "}", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "level", ">=", "logThreshhold", "{", "return", "fmt"...
// Logf writes a log message with a specific format to the logger
[ "Logf", "writes", "a", "log", "message", "with", "a", "specific", "format", "to", "the", "logger" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/log.go#L113-L119
15,855
clockworksoul/smudge
node.go
Address
func (n *Node) Address() string { if n.address == "" { n.address = nodeAddressString(n.ip, n.port) } return n.address }
go
func (n *Node) Address() string { if n.address == "" { n.address = nodeAddressString(n.ip, n.port) } return n.address }
[ "func", "(", "n", "*", "Node", ")", "Address", "(", ")", "string", "{", "if", "n", ".", "address", "==", "\"", "\"", "{", "n", ".", "address", "=", "nodeAddressString", "(", "n", ".", "ip", ",", "n", ".", "port", ")", "\n", "}", "\n\n", "return...
// Address rReturns the address for this node in string format, which is simply // the node's local IP and listen port. This is used as a unique identifier // throughout the code base.
[ "Address", "rReturns", "the", "address", "for", "this", "node", "in", "string", "format", "which", "is", "simply", "the", "node", "s", "local", "IP", "and", "listen", "port", ".", "This", "is", "used", "as", "a", "unique", "identifier", "throughout", "the"...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/node.go#L51-L57
15,856
clockworksoul/smudge
message.go
newMessage
func newMessage(verb messageVerb, sender *Node, senderHeartbeat uint32) message { return message{ sender: sender, senderHeartbeat: senderHeartbeat, verb: verb, } }
go
func newMessage(verb messageVerb, sender *Node, senderHeartbeat uint32) message { return message{ sender: sender, senderHeartbeat: senderHeartbeat, verb: verb, } }
[ "func", "newMessage", "(", "verb", "messageVerb", ",", "sender", "*", "Node", ",", "senderHeartbeat", "uint32", ")", "message", "{", "return", "message", "{", "sender", ":", "sender", ",", "senderHeartbeat", ":", "senderHeartbeat", ",", "verb", ":", "verb", ...
// Convenience function. Creates a new message instance.
[ "Convenience", "function", ".", "Creates", "a", "new", "message", "instance", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/message.go#L68-L74
15,857
clockworksoul/smudge
message.go
getForwardTo
func (m *message) getForwardTo() *messageMember { if len(m.members) > 0 && m.members[0].status == StatusForwardTo { return m.members[0] } return nil }
go
func (m *message) getForwardTo() *messageMember { if len(m.members) > 0 && m.members[0].status == StatusForwardTo { return m.members[0] } return nil }
[ "func", "(", "m", "*", "message", ")", "getForwardTo", "(", ")", "*", "messageMember", "{", "if", "len", "(", "m", ".", "members", ")", ">", "0", "&&", "m", ".", "members", "[", "0", "]", ".", "status", "==", "StatusForwardTo", "{", "return", "m", ...
// If members exist on this message, and that message has the "forward to" // status, this function returns it; otherwise it returns nil.
[ "If", "members", "exist", "on", "this", "message", "and", "that", "message", "has", "the", "forward", "to", "status", "this", "function", "returns", "it", ";", "otherwise", "it", "returns", "nil", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/message.go#L224-L230
15,858
clockworksoul/smudge
pingData.go
nSigma
func (pd *pingData) nSigma(sigmas float64) float64 { mean, stddev := pd.data() return mean + (sigmas * stddev) }
go
func (pd *pingData) nSigma(sigmas float64) float64 { mean, stddev := pd.data() return mean + (sigmas * stddev) }
[ "func", "(", "pd", "*", "pingData", ")", "nSigma", "(", "sigmas", "float64", ")", "float64", "{", "mean", ",", "stddev", ":=", "pd", ".", "data", "(", ")", "\n\n", "return", "mean", "+", "(", "sigmas", "*", "stddev", ")", "\n", "}" ]
// Returns the mean modified by the requested number of sigmas
[ "Returns", "the", "mean", "modified", "by", "the", "requested", "number", "of", "sigmas" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/pingData.go#L75-L79
15,859
clockworksoul/smudge
pingData.go
data
func (pd *pingData) data() (float64, float64) { if pd.updated { pd.Lock() // Calculate the mean var accumulator float64 for _, d := range pd.pings { accumulator += float64(d) } pd.lastMean = accumulator / float64(len(pd.pings)) // Subtract the mean and square the result; calculcate the mean accumulator = 0.0 // Reusing accumulator. for _, d := range pd.pings { diff := pd.lastMean - float64(d) accumulator += math.Pow(diff, 2.0) } squareDiffMean := accumulator / float64(len(pd.pings)) // Sqrt the square diffs mean and we have our stddev pd.lastStddev = math.Sqrt(squareDiffMean) pd.updated = false pd.Unlock() } return pd.lastMean, pd.lastStddev }
go
func (pd *pingData) data() (float64, float64) { if pd.updated { pd.Lock() // Calculate the mean var accumulator float64 for _, d := range pd.pings { accumulator += float64(d) } pd.lastMean = accumulator / float64(len(pd.pings)) // Subtract the mean and square the result; calculcate the mean accumulator = 0.0 // Reusing accumulator. for _, d := range pd.pings { diff := pd.lastMean - float64(d) accumulator += math.Pow(diff, 2.0) } squareDiffMean := accumulator / float64(len(pd.pings)) // Sqrt the square diffs mean and we have our stddev pd.lastStddev = math.Sqrt(squareDiffMean) pd.updated = false pd.Unlock() } return pd.lastMean, pd.lastStddev }
[ "func", "(", "pd", "*", "pingData", ")", "data", "(", ")", "(", "float64", ",", "float64", ")", "{", "if", "pd", ".", "updated", "{", "pd", ".", "Lock", "(", ")", "\n\n", "// Calculate the mean", "var", "accumulator", "float64", "\n", "for", "_", ","...
// Returns both mean and standard deviation
[ "Returns", "both", "mean", "and", "standard", "deviation" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/pingData.go#L89-L117
15,860
clockworksoul/smudge
nodeMap.go
getByAddress
func (m *nodeMap) getByAddress(address string) *Node { m.RLock() node, _ := m.nodes[address] m.RUnlock() return node }
go
func (m *nodeMap) getByAddress(address string) *Node { m.RLock() node, _ := m.nodes[address] m.RUnlock() return node }
[ "func", "(", "m", "*", "nodeMap", ")", "getByAddress", "(", "address", "string", ")", "*", "Node", "{", "m", ".", "RLock", "(", ")", "\n", "node", ",", "_", ":=", "m", ".", "nodes", "[", "address", "]", "\n", "m", ".", "RUnlock", "(", ")", "\n\...
// Returns a pointer to the requested Node
[ "Returns", "a", "pointer", "to", "the", "requested", "Node" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/nodeMap.go#L73-L79
15,861
clockworksoul/smudge
broadcast.go
Bytes
func (b *Broadcast) Bytes() []byte { length := len(b.bytes) bytesCopy := make([]byte, length, length) copy(bytesCopy, b.bytes) return bytesCopy }
go
func (b *Broadcast) Bytes() []byte { length := len(b.bytes) bytesCopy := make([]byte, length, length) copy(bytesCopy, b.bytes) return bytesCopy }
[ "func", "(", "b", "*", "Broadcast", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "length", ":=", "len", "(", "b", ".", "bytes", ")", "\n", "bytesCopy", ":=", "make", "(", "[", "]", "byte", ",", "length", ",", "length", ")", "\n", "copy", "(",...
// Bytes returns a copy of this broadcast's bytes. Manipulating the contents // of this slice will not be reflected in the contents of the broadcast.
[ "Bytes", "returns", "a", "copy", "of", "this", "broadcast", "s", "bytes", ".", "Manipulating", "the", "contents", "of", "this", "slice", "will", "not", "be", "reflected", "in", "the", "contents", "of", "the", "broadcast", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/broadcast.go#L58-L64
15,862
clockworksoul/smudge
broadcast.go
BroadcastBytes
func BroadcastBytes(bytes []byte) error { if len(bytes) > GetMaxBroadcastBytes() { emsg := fmt.Sprintf( "broadcast payload length exceeds %d bytes", GetMaxBroadcastBytes()) return errors.New(emsg) } broadcasts.Lock() bcast := Broadcast{ origin: thisHost, index: indexCounter, bytes: bytes, emitCounter: int8(emitCount())} broadcasts.m[bcast.Label()] = &bcast indexCounter++ broadcasts.Unlock() return nil }
go
func BroadcastBytes(bytes []byte) error { if len(bytes) > GetMaxBroadcastBytes() { emsg := fmt.Sprintf( "broadcast payload length exceeds %d bytes", GetMaxBroadcastBytes()) return errors.New(emsg) } broadcasts.Lock() bcast := Broadcast{ origin: thisHost, index: indexCounter, bytes: bytes, emitCounter: int8(emitCount())} broadcasts.m[bcast.Label()] = &bcast indexCounter++ broadcasts.Unlock() return nil }
[ "func", "BroadcastBytes", "(", "bytes", "[", "]", "byte", ")", "error", "{", "if", "len", "(", "bytes", ")", ">", "GetMaxBroadcastBytes", "(", ")", "{", "emsg", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "GetMaxBroadcastBytes", "(", ")", ")", ...
// BroadcastBytes allows a user to emit a short broadcast in the form of a byte // slice, which will be transmitted at most once to all other healthy current // members. Members that join after the broadcast has already propagated // through the cluster will not receive the message. The maximum broadcast // length is 256 bytes.
[ "BroadcastBytes", "allows", "a", "user", "to", "emit", "a", "short", "broadcast", "in", "the", "form", "of", "a", "byte", "slice", "which", "will", "be", "transmitted", "at", "most", "once", "to", "all", "other", "healthy", "current", "members", ".", "Memb...
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/broadcast.go#L95-L119
15,863
clockworksoul/smudge
broadcast.go
receiveBroadcast
func receiveBroadcast(broadcast *Broadcast) { if broadcast == nil { return } err := checkOrigin(broadcast.Origin()) if err != nil { logWarn(err) return } label := broadcast.Label() broadcasts.Lock() _, contains := broadcasts.m[label] if !contains { broadcasts.m[label] = broadcast } broadcasts.Unlock() if !contains { logfInfo("Broadcast [%s]=%s", label, string(broadcast.Bytes())) doBroadcastUpdate(broadcast) } }
go
func receiveBroadcast(broadcast *Broadcast) { if broadcast == nil { return } err := checkOrigin(broadcast.Origin()) if err != nil { logWarn(err) return } label := broadcast.Label() broadcasts.Lock() _, contains := broadcasts.m[label] if !contains { broadcasts.m[label] = broadcast } broadcasts.Unlock() if !contains { logfInfo("Broadcast [%s]=%s", label, string(broadcast.Bytes())) doBroadcastUpdate(broadcast) } }
[ "func", "receiveBroadcast", "(", "broadcast", "*", "Broadcast", ")", "{", "if", "broadcast", "==", "nil", "{", "return", "\n", "}", "\n\n", "err", ":=", "checkOrigin", "(", "broadcast", ".", "Origin", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{",...
// receiveBroadcast is called by receiveMessageUDP when a broadcast payload // is found in a message.
[ "receiveBroadcast", "is", "called", "by", "receiveMessageUDP", "when", "a", "broadcast", "payload", "is", "found", "in", "a", "message", "." ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/broadcast.go#L278-L305
15,864
clockworksoul/smudge
broadcast.go
checkOrigin
func checkOrigin(origin *Node) error { // normalize to IPv4 or IPv6 to check below ip := origin.IP() if ip.To4() != nil { ip = ip.To4() } if (ip[0] == 0) || origin.Port() == 0 { return errors.New("Received originless broadcast") } return nil }
go
func checkOrigin(origin *Node) error { // normalize to IPv4 or IPv6 to check below ip := origin.IP() if ip.To4() != nil { ip = ip.To4() } if (ip[0] == 0) || origin.Port() == 0 { return errors.New("Received originless broadcast") } return nil }
[ "func", "checkOrigin", "(", "origin", "*", "Node", ")", "error", "{", "// normalize to IPv4 or IPv6 to check below", "ip", ":=", "origin", ".", "IP", "(", ")", "\n", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "ip", "=", "ip", ".", "To4", "(", ...
// checkBroadcastOrigin checks wether the origin is set correctly
[ "checkBroadcastOrigin", "checks", "wether", "the", "origin", "is", "set", "correctly" ]
4887b3f8af71805a89ec8b1fd9b08d39a7c6556d
https://github.com/clockworksoul/smudge/blob/4887b3f8af71805a89ec8b1fd9b08d39a7c6556d/broadcast.go#L308-L319
15,865
hillu/go-yara
config.go
SetConfiguration
func SetConfiguration(name ConfigName, src interface{}) error { i, ok := src.(int) if !ok { return newError(C.ERROR_INTERNAL_FATAL_ERROR) } u := C.uint32_t(i) return newError( C.yr_set_configuration(C.YR_CONFIG_NAME(name), unsafe.Pointer(&u))) }
go
func SetConfiguration(name ConfigName, src interface{}) error { i, ok := src.(int) if !ok { return newError(C.ERROR_INTERNAL_FATAL_ERROR) } u := C.uint32_t(i) return newError( C.yr_set_configuration(C.YR_CONFIG_NAME(name), unsafe.Pointer(&u))) }
[ "func", "SetConfiguration", "(", "name", "ConfigName", ",", "src", "interface", "{", "}", ")", "error", "{", "i", ",", "ok", ":=", "src", ".", "(", "int", ")", "\n", "if", "!", "ok", "{", "return", "newError", "(", "C", ".", "ERROR_INTERNAL_FATAL_ERROR...
// SetConfiguration sets a global YARA configuration option.
[ "SetConfiguration", "sets", "a", "global", "YARA", "configuration", "option", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/config.go#L19-L27
15,866
hillu/go-yara
config.go
GetConfiguration
func GetConfiguration(name ConfigName) (interface{}, error) { var u C.uint32_t if err := newError(C.yr_get_configuration( C.YR_CONFIG_NAME(name), unsafe.Pointer(&u)), ); err != nil { return nil, err } return int(u), nil }
go
func GetConfiguration(name ConfigName) (interface{}, error) { var u C.uint32_t if err := newError(C.yr_get_configuration( C.YR_CONFIG_NAME(name), unsafe.Pointer(&u)), ); err != nil { return nil, err } return int(u), nil }
[ "func", "GetConfiguration", "(", "name", "ConfigName", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "var", "u", "C", ".", "uint32_t", "\n", "if", "err", ":=", "newError", "(", "C", ".", "yr_get_configuration", "(", "C", ".", "YR_CONFIG_NAME",...
// GetConfiguration gets a global YARA configuration option.
[ "GetConfiguration", "gets", "a", "global", "YARA", "configuration", "option", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/config.go#L30-L38
15,867
hillu/go-yara
rules_callback.go
destroy
func (c *scanCallbackContainer) destroy() { for _, p := range c.cdata { C.free(p) } c.cdata = nil }
go
func (c *scanCallbackContainer) destroy() { for _, p := range c.cdata { C.free(p) } c.cdata = nil }
[ "func", "(", "c", "*", "scanCallbackContainer", ")", "destroy", "(", ")", "{", "for", "_", ",", "p", ":=", "range", "c", ".", "cdata", "{", "C", ".", "free", "(", "p", ")", "\n", "}", "\n", "c", ".", "cdata", "=", "nil", "\n", "}" ]
// destroy frees stored C pointers
[ "destroy", "frees", "stored", "C", "pointers" ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules_callback.go#L71-L76
15,868
hillu/go-yara
rules_callback.go
RuleMatching
func (mr *MatchRules) RuleMatching(r *Rule) (abort bool, err error) { metas := r.Metas() // convert int to int32 for code that relies on previous behavior for s := range metas { if i, ok := metas[s].(int); ok { metas[s] = int32(i) } } *mr = append(*mr, MatchRule{ Rule: r.Identifier(), Namespace: r.Namespace(), Tags: r.Tags(), Meta: metas, Strings: r.getMatchStrings(), }) return }
go
func (mr *MatchRules) RuleMatching(r *Rule) (abort bool, err error) { metas := r.Metas() // convert int to int32 for code that relies on previous behavior for s := range metas { if i, ok := metas[s].(int); ok { metas[s] = int32(i) } } *mr = append(*mr, MatchRule{ Rule: r.Identifier(), Namespace: r.Namespace(), Tags: r.Tags(), Meta: metas, Strings: r.getMatchStrings(), }) return }
[ "func", "(", "mr", "*", "MatchRules", ")", "RuleMatching", "(", "r", "*", "Rule", ")", "(", "abort", "bool", ",", "err", "error", ")", "{", "metas", ":=", "r", ".", "Metas", "(", ")", "\n", "// convert int to int32 for code that relies on previous behavior", ...
// RuleMatching implements the ScanCallbackMatch interface for // MatchRules.
[ "RuleMatching", "implements", "the", "ScanCallbackMatch", "interface", "for", "MatchRules", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules_callback.go#L138-L154
15,869
hillu/go-yara
stream.go
writeFull
func writeFull(w io.Writer, buf []byte) (n int, err error) { var i int for n < len(buf) { i, err = w.Write(buf[n:]) n += i if err != nil { break } } return }
go
func writeFull(w io.Writer, buf []byte) (n int, err error) { var i int for n < len(buf) { i, err = w.Write(buf[n:]) n += i if err != nil { break } } return }
[ "func", "writeFull", "(", "w", "io", ".", "Writer", ",", "buf", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "var", "i", "int", "\n", "for", "n", "<", "len", "(", "buf", ")", "{", "i", ",", "err", "=", "w", ".", ...
// writeFull does its best to write all of buf to w. See io.ReadFull.
[ "writeFull", "does", "its", "best", "to", "write", "all", "of", "buf", "to", "w", ".", "See", "io", ".", "ReadFull", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/stream.go#L39-L49
15,870
hillu/go-yara
compiler.go
NewCompiler
func NewCompiler() (*Compiler, error) { var yrCompiler *C.YR_COMPILER if err := newError(C.yr_compiler_create(&yrCompiler)); err != nil { return nil, err } c := &Compiler{compiler: &compiler{cptr: yrCompiler}} runtime.SetFinalizer(c.compiler, (*compiler).finalize) return c, nil }
go
func NewCompiler() (*Compiler, error) { var yrCompiler *C.YR_COMPILER if err := newError(C.yr_compiler_create(&yrCompiler)); err != nil { return nil, err } c := &Compiler{compiler: &compiler{cptr: yrCompiler}} runtime.SetFinalizer(c.compiler, (*compiler).finalize) return c, nil }
[ "func", "NewCompiler", "(", ")", "(", "*", "Compiler", ",", "error", ")", "{", "var", "yrCompiler", "*", "C", ".", "YR_COMPILER", "\n", "if", "err", ":=", "newError", "(", "C", ".", "yr_compiler_create", "(", "&", "yrCompiler", ")", ")", ";", "err", ...
// NewCompiler creates a YARA compiler.
[ "NewCompiler", "creates", "a", "YARA", "compiler", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler.go#L68-L76
15,871
hillu/go-yara
compiler.go
Destroy
func (c *Compiler) Destroy() { c.setCallbackData(nil) if c.compiler != nil { c.compiler.finalize() c.compiler = nil } }
go
func (c *Compiler) Destroy() { c.setCallbackData(nil) if c.compiler != nil { c.compiler.finalize() c.compiler = nil } }
[ "func", "(", "c", "*", "Compiler", ")", "Destroy", "(", ")", "{", "c", ".", "setCallbackData", "(", "nil", ")", "\n", "if", "c", ".", "compiler", "!=", "nil", "{", "c", ".", "compiler", ".", "finalize", "(", ")", "\n", "c", ".", "compiler", "=", ...
// Destroy destroys the YARA data structure representing a compiler. // Since a Finalizer for the underlying YR_COMPILER structure is // automatically set up on creation, it should not be necessary to // explicitly call this method.
[ "Destroy", "destroys", "the", "YARA", "data", "structure", "representing", "a", "compiler", ".", "Since", "a", "Finalizer", "for", "the", "underlying", "YR_COMPILER", "structure", "is", "automatically", "set", "up", "on", "creation", "it", "should", "not", "be",...
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler.go#L94-L100
15,872
hillu/go-yara
compiler.go
AddString
func (c *Compiler) AddString(rules string, namespace string) (err error) { if c.cptr.errors != 0 { return errors.New("Compiler cannot be used after parse error") } var ns *C.char if namespace != "" { ns = C.CString(namespace) defer C.free(unsafe.Pointer(ns)) } crules := C.CString(rules) defer C.free(unsafe.Pointer(crules)) id := callbackData.Put(c) defer callbackData.Delete(id) C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), id) numErrors := int(C.yr_compiler_add_string(c.cptr, crules, ns)) if numErrors > 0 { var buf [1024]C.char msg := C.GoString(C.yr_compiler_get_error_message( c.cptr, (*C.char)(unsafe.Pointer(&buf[0])), 1024)) err = errors.New(msg) } keepAlive(c) return }
go
func (c *Compiler) AddString(rules string, namespace string) (err error) { if c.cptr.errors != 0 { return errors.New("Compiler cannot be used after parse error") } var ns *C.char if namespace != "" { ns = C.CString(namespace) defer C.free(unsafe.Pointer(ns)) } crules := C.CString(rules) defer C.free(unsafe.Pointer(crules)) id := callbackData.Put(c) defer callbackData.Delete(id) C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), id) numErrors := int(C.yr_compiler_add_string(c.cptr, crules, ns)) if numErrors > 0 { var buf [1024]C.char msg := C.GoString(C.yr_compiler_get_error_message( c.cptr, (*C.char)(unsafe.Pointer(&buf[0])), 1024)) err = errors.New(msg) } keepAlive(c) return }
[ "func", "(", "c", "*", "Compiler", ")", "AddString", "(", "rules", "string", ",", "namespace", "string", ")", "(", "err", "error", ")", "{", "if", "c", ".", "cptr", ".", "errors", "!=", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", "...
// AddString compiles rules from a string. Rules are added to the // specified namespace. // // If this function returns an error, the Compiler object will become // unusable.
[ "AddString", "compiles", "rules", "from", "a", "string", ".", "Rules", "are", "added", "to", "the", "specified", "namespace", ".", "If", "this", "function", "returns", "an", "error", "the", "Compiler", "object", "will", "become", "unusable", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler.go#L107-L130
15,873
hillu/go-yara
compiler.go
GetRules
func (c *Compiler) GetRules() (*Rules, error) { if c.cptr.errors != 0 { return nil, errors.New("Compiler cannot be used after parse error") } var yrRules *C.YR_RULES if err := newError(C.yr_compiler_get_rules(c.cptr, &yrRules)); err != nil { return nil, err } r := &Rules{rules: &rules{cptr: yrRules}} runtime.SetFinalizer(r.rules, (*rules).finalize) keepAlive(c) return r, nil }
go
func (c *Compiler) GetRules() (*Rules, error) { if c.cptr.errors != 0 { return nil, errors.New("Compiler cannot be used after parse error") } var yrRules *C.YR_RULES if err := newError(C.yr_compiler_get_rules(c.cptr, &yrRules)); err != nil { return nil, err } r := &Rules{rules: &rules{cptr: yrRules}} runtime.SetFinalizer(r.rules, (*rules).finalize) keepAlive(c) return r, nil }
[ "func", "(", "c", "*", "Compiler", ")", "GetRules", "(", ")", "(", "*", "Rules", ",", "error", ")", "{", "if", "c", ".", "cptr", ".", "errors", "!=", "0", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n",...
// GetRules returns the compiled ruleset.
[ "GetRules", "returns", "the", "compiled", "ruleset", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler.go#L165-L177
15,874
hillu/go-yara
compiler.go
MustCompile
func MustCompile(rules string, variables map[string]interface{}) (r *Rules) { r, err := Compile(rules, variables) if err != nil { panic(err) } return }
go
func MustCompile(rules string, variables map[string]interface{}) (r *Rules) { r, err := Compile(rules, variables) if err != nil { panic(err) } return }
[ "func", "MustCompile", "(", "rules", "string", ",", "variables", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "r", "*", "Rules", ")", "{", "r", ",", "err", ":=", "Compile", "(", "rules", ",", "variables", ")", "\n", "if", "err", "!="...
// MustCompile is like Compile but panics if the rules and optional // variables can't be compiled. Like regexp.MustCompile, it allows for // simple, safe initialization of global or test data.
[ "MustCompile", "is", "like", "Compile", "but", "panics", "if", "the", "rules", "and", "optional", "variables", "can", "t", "be", "compiled", ".", "Like", "regexp", ".", "MustCompile", "it", "allows", "for", "simple", "safe", "initialization", "of", "global", ...
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler.go#L202-L208
15,875
hillu/go-yara
compiler_yara37.go
DisableIncludes
func (c *Compiler) DisableIncludes() { C.yr_compiler_set_include_callback(c.compiler.cptr, nil, nil, nil) c.setCallbackData(nil) keepAlive(c) return }
go
func (c *Compiler) DisableIncludes() { C.yr_compiler_set_include_callback(c.compiler.cptr, nil, nil, nil) c.setCallbackData(nil) keepAlive(c) return }
[ "func", "(", "c", "*", "Compiler", ")", "DisableIncludes", "(", ")", "{", "C", ".", "yr_compiler_set_include_callback", "(", "c", ".", "compiler", ".", "cptr", ",", "nil", ",", "nil", ",", "nil", ")", "\n", "c", ".", "setCallbackData", "(", "nil", ")",...
// DisableIncludes disables all include statements in the compiler. // See yr_compiler_set_include_callbacks.
[ "DisableIncludes", "disables", "all", "include", "statements", "in", "the", "compiler", ".", "See", "yr_compiler_set_include_callbacks", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler_yara37.go#L41-L46
15,876
hillu/go-yara
rules.go
ScanMem
func (r *Rules) ScanMem(buf []byte, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanMemWithCallback(buf, flags, timeout, &cb) matches = cb return }
go
func (r *Rules) ScanMem(buf []byte, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanMemWithCallback(buf, flags, timeout, &cb) matches = cb return }
[ "func", "(", "r", "*", "Rules", ")", "ScanMem", "(", "buf", "[", "]", "byte", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ")", "(", "matches", "[", "]", "MatchRule", ",", "err", "error", ")", "{", "cb", ":=", "MatchRules", "...
// ScanMem scans an in-memory buffer using the ruleset, returning // matches via a list of MatchRule objects.
[ "ScanMem", "scans", "an", "in", "-", "memory", "buffer", "using", "the", "ruleset", "returning", "matches", "via", "a", "list", "of", "MatchRule", "objects", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L66-L71
15,877
hillu/go-yara
rules.go
ScanMemWithCallback
func (r *Rules) ScanMemWithCallback(buf []byte, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { var ptr *C.uint8_t if len(buf) > 0 { ptr = (*C.uint8_t)(unsafe.Pointer(&(buf[0]))) } cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C.yr_rules_scan_mem( r.cptr, ptr, C.size_t(len(buf)), C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
go
func (r *Rules) ScanMemWithCallback(buf []byte, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { var ptr *C.uint8_t if len(buf) > 0 { ptr = (*C.uint8_t)(unsafe.Pointer(&(buf[0]))) } cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C.yr_rules_scan_mem( r.cptr, ptr, C.size_t(len(buf)), C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
[ "func", "(", "r", "*", "Rules", ")", "ScanMemWithCallback", "(", "buf", "[", "]", "byte", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ",", "cb", "ScanCallback", ")", "(", "err", "error", ")", "{", "var", "ptr", "*", "C", ".", ...
// ScanMemWithCallback scans an in-memory buffer using the ruleset. // For every event emitted by libyara, the appropriate method on the // ScanCallback object is called.
[ "ScanMemWithCallback", "scans", "an", "in", "-", "memory", "buffer", "using", "the", "ruleset", ".", "For", "every", "event", "emitted", "by", "libyara", "the", "appropriate", "method", "on", "the", "ScanCallback", "object", "is", "called", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L76-L95
15,878
hillu/go-yara
rules.go
ScanFile
func (r *Rules) ScanFile(filename string, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanFileWithCallback(filename, flags, timeout, &cb) matches = cb return }
go
func (r *Rules) ScanFile(filename string, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanFileWithCallback(filename, flags, timeout, &cb) matches = cb return }
[ "func", "(", "r", "*", "Rules", ")", "ScanFile", "(", "filename", "string", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ")", "(", "matches", "[", "]", "MatchRule", ",", "err", "error", ")", "{", "cb", ":=", "MatchRules", "{", ...
// ScanFile scans a file using the ruleset, returning matches via a // list of MatchRule objects.
[ "ScanFile", "scans", "a", "file", "using", "the", "ruleset", "returning", "matches", "via", "a", "list", "of", "MatchRule", "objects", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L99-L104
15,879
hillu/go-yara
rules.go
ScanFileWithCallback
func (r *Rules) ScanFileWithCallback(filename string, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C.yr_rules_scan_file( r.cptr, cfilename, C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
go
func (r *Rules) ScanFileWithCallback(filename string, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C.yr_rules_scan_file( r.cptr, cfilename, C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
[ "func", "(", "r", "*", "Rules", ")", "ScanFileWithCallback", "(", "filename", "string", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ",", "cb", "ScanCallback", ")", "(", "err", "error", ")", "{", "cfilename", ":=", "C", ".", "CStri...
// ScanFileWithCallback scans a file using the ruleset. For every // event emitted by libyara, the appropriate method on the // ScanCallback object is called.
[ "ScanFileWithCallback", "scans", "a", "file", "using", "the", "ruleset", ".", "For", "every", "event", "emitted", "by", "libyara", "the", "appropriate", "method", "on", "the", "ScanCallback", "object", "is", "called", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L109-L125
15,880
hillu/go-yara
rules.go
ScanProc
func (r *Rules) ScanProc(pid int, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanProcWithCallback(pid, flags, timeout, &cb) matches = cb return }
go
func (r *Rules) ScanProc(pid int, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanProcWithCallback(pid, flags, timeout, &cb) matches = cb return }
[ "func", "(", "r", "*", "Rules", ")", "ScanProc", "(", "pid", "int", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ")", "(", "matches", "[", "]", "MatchRule", ",", "err", "error", ")", "{", "cb", ":=", "MatchRules", "{", "}", "...
// ScanProc scans a live process using the ruleset, returning matches // via a list of MatchRule objects.
[ "ScanProc", "scans", "a", "live", "process", "using", "the", "ruleset", "returning", "matches", "via", "a", "list", "of", "MatchRule", "objects", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L129-L134
15,881
hillu/go-yara
rules.go
ScanProcWithCallback
func (r *Rules) ScanProcWithCallback(pid int, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C.yr_rules_scan_proc( r.cptr, C.int(pid), C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
go
func (r *Rules) ScanProcWithCallback(pid int, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C.yr_rules_scan_proc( r.cptr, C.int(pid), C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
[ "func", "(", "r", "*", "Rules", ")", "ScanProcWithCallback", "(", "pid", "int", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ",", "cb", "ScanCallback", ")", "(", "err", "error", ")", "{", "cbc", ":=", "&", "scanCallbackContainer", ...
// ScanProcWithCallback scans a live process using the ruleset. For // every event emitted by libyara, the appropriate method on the // ScanCallback object is called.
[ "ScanProcWithCallback", "scans", "a", "live", "process", "using", "the", "ruleset", ".", "For", "every", "event", "emitted", "by", "libyara", "the", "appropriate", "method", "on", "the", "ScanCallback", "object", "is", "called", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L139-L153
15,882
hillu/go-yara
rules.go
Save
func (r *Rules) Save(filename string) (err error) { cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) err = newError(C.yr_rules_save(r.cptr, cfilename)) keepAlive(r) return }
go
func (r *Rules) Save(filename string) (err error) { cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) err = newError(C.yr_rules_save(r.cptr, cfilename)) keepAlive(r) return }
[ "func", "(", "r", "*", "Rules", ")", "Save", "(", "filename", "string", ")", "(", "err", "error", ")", "{", "cfilename", ":=", "C", ".", "CString", "(", "filename", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "cfilenam...
// Save writes a compiled ruleset to filename.
[ "Save", "writes", "a", "compiled", "ruleset", "to", "filename", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L156-L162
15,883
hillu/go-yara
rules.go
LoadRules
func LoadRules(filename string) (*Rules, error) { r := &Rules{rules: &rules{}} cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) if err := newError(C.yr_rules_load(cfilename, &(r.rules.cptr))); err != nil { return nil, err } runtime.SetFinalizer(r.rules, (*rules).finalize) return r, nil }
go
func LoadRules(filename string) (*Rules, error) { r := &Rules{rules: &rules{}} cfilename := C.CString(filename) defer C.free(unsafe.Pointer(cfilename)) if err := newError(C.yr_rules_load(cfilename, &(r.rules.cptr))); err != nil { return nil, err } runtime.SetFinalizer(r.rules, (*rules).finalize) return r, nil }
[ "func", "LoadRules", "(", "filename", "string", ")", "(", "*", "Rules", ",", "error", ")", "{", "r", ":=", "&", "Rules", "{", "rules", ":", "&", "rules", "{", "}", "}", "\n", "cfilename", ":=", "C", ".", "CString", "(", "filename", ")", "\n", "de...
// LoadRules retrieves a compiled ruleset from filename.
[ "LoadRules", "retrieves", "a", "compiled", "ruleset", "from", "filename", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L165-L175
15,884
hillu/go-yara
rules.go
Destroy
func (r *Rules) Destroy() { if r.rules != nil { r.rules.finalize() r.rules = nil } }
go
func (r *Rules) Destroy() { if r.rules != nil { r.rules.finalize() r.rules = nil } }
[ "func", "(", "r", "*", "Rules", ")", "Destroy", "(", ")", "{", "if", "r", ".", "rules", "!=", "nil", "{", "r", ".", "rules", ".", "finalize", "(", ")", "\n", "r", ".", "rules", "=", "nil", "\n", "}", "\n", "}" ]
// Destroy destroys the YARA data structure representing a ruleset. // Since a Finalizer for the underlying YR_RULES structure is // automatically set up on creation, it should not be necessary to // explicitly call this method.
[ "Destroy", "destroys", "the", "YARA", "data", "structure", "representing", "a", "ruleset", ".", "Since", "a", "Finalizer", "for", "the", "underlying", "YR_RULES", "structure", "is", "automatically", "set", "up", "on", "creation", "it", "should", "not", "be", "...
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L186-L191
15,885
hillu/go-yara
rules.go
GetRules
func (r *Rules) GetRules() (rv []Rule) { for p := unsafe.Pointer(r.cptr.rules_list_head); (*C.YR_RULE)(p).g_flags&C.RULE_GFLAGS_NULL == 0; p = unsafe.Pointer(uintptr(p) + unsafe.Sizeof(*r.cptr.rules_list_head)) { rv = append(rv, Rule{(*C.YR_RULE)(p)}) } return }
go
func (r *Rules) GetRules() (rv []Rule) { for p := unsafe.Pointer(r.cptr.rules_list_head); (*C.YR_RULE)(p).g_flags&C.RULE_GFLAGS_NULL == 0; p = unsafe.Pointer(uintptr(p) + unsafe.Sizeof(*r.cptr.rules_list_head)) { rv = append(rv, Rule{(*C.YR_RULE)(p)}) } return }
[ "func", "(", "r", "*", "Rules", ")", "GetRules", "(", ")", "(", "rv", "[", "]", "Rule", ")", "{", "for", "p", ":=", "unsafe", ".", "Pointer", "(", "r", ".", "cptr", ".", "rules_list_head", ")", ";", "(", "*", "C", ".", "YR_RULE", ")", "(", "p...
// GetRules returns a slice of rule objects that are part of the // ruleset
[ "GetRules", "returns", "a", "slice", "of", "rule", "objects", "that", "are", "part", "of", "the", "ruleset" ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules.go#L227-L232
15,886
hillu/go-yara
compiler_addfile_yara36.go
AddFile
func (c *Compiler) AddFile(file *os.File, namespace string) (err error) { if c.cptr.errors != 0 { return errors.New("Compiler cannot be used after parse error") } var ns *C.char if namespace != "" { ns = C.CString(namespace) defer C.free(unsafe.Pointer(ns)) } filename := C.CString(file.Name()) defer C.free(unsafe.Pointer(filename)) id := callbackData.Put(c) defer callbackData.Delete(id) C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), id) numErrors := int(C.yr_compiler_add_fd(c.cptr, (C.YR_FILE_DESCRIPTOR)(file.Fd()), ns, filename)) if numErrors > 0 { var buf [1024]C.char msg := C.GoString(C.yr_compiler_get_error_message( c.cptr, (*C.char)(unsafe.Pointer(&buf[0])), 1024)) err = errors.New(msg) } keepAlive(c) return }
go
func (c *Compiler) AddFile(file *os.File, namespace string) (err error) { if c.cptr.errors != 0 { return errors.New("Compiler cannot be used after parse error") } var ns *C.char if namespace != "" { ns = C.CString(namespace) defer C.free(unsafe.Pointer(ns)) } filename := C.CString(file.Name()) defer C.free(unsafe.Pointer(filename)) id := callbackData.Put(c) defer callbackData.Delete(id) C.yr_compiler_set_callback(c.cptr, C.YR_COMPILER_CALLBACK_FUNC(C.compilerCallback), id) numErrors := int(C.yr_compiler_add_fd(c.cptr, (C.YR_FILE_DESCRIPTOR)(file.Fd()), ns, filename)) if numErrors > 0 { var buf [1024]C.char msg := C.GoString(C.yr_compiler_get_error_message( c.cptr, (*C.char)(unsafe.Pointer(&buf[0])), 1024)) err = errors.New(msg) } keepAlive(c) return }
[ "func", "(", "c", "*", "Compiler", ")", "AddFile", "(", "file", "*", "os", ".", "File", ",", "namespace", "string", ")", "(", "err", "error", ")", "{", "if", "c", ".", "cptr", ".", "errors", "!=", "0", "{", "return", "errors", ".", "New", "(", ...
// AddFile compiles rules from a file. Rules are added to the // specified namespace. // // If this function returns an error, the Compiler object will become // unusable.
[ "AddFile", "compiles", "rules", "from", "a", "file", ".", "Rules", "are", "added", "to", "the", "specified", "namespace", ".", "If", "this", "function", "returns", "an", "error", "the", "Compiler", "object", "will", "become", "unusable", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/compiler_addfile_yara36.go#L29-L52
15,887
hillu/go-yara
cbpool.go
makecbPool
func makecbPool(n int) *cbPool { p := &cbPool{ indices: make([]int, 0), objects: make([]interface{}, n), } hdr := (*reflect.SliceHeader)(unsafe.Pointer(&p.indices)) hdr.Data = uintptr(C.calloc(C.size_t(n), C.size_t(unsafe.Sizeof(int(0))))) hdr.Len = n runtime.SetFinalizer(p, (*cbPool).Finalize) return p }
go
func makecbPool(n int) *cbPool { p := &cbPool{ indices: make([]int, 0), objects: make([]interface{}, n), } hdr := (*reflect.SliceHeader)(unsafe.Pointer(&p.indices)) hdr.Data = uintptr(C.calloc(C.size_t(n), C.size_t(unsafe.Sizeof(int(0))))) hdr.Len = n runtime.SetFinalizer(p, (*cbPool).Finalize) return p }
[ "func", "makecbPool", "(", "n", "int", ")", "*", "cbPool", "{", "p", ":=", "&", "cbPool", "{", "indices", ":", "make", "(", "[", "]", "int", ",", "0", ")", ",", "objects", ":", "make", "(", "[", "]", "interface", "{", "}", ",", "n", ")", ",",...
// MakePool creates a Pool that can hold n elements.
[ "MakePool", "creates", "a", "Pool", "that", "can", "hold", "n", "elements", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/cbpool.go#L31-L41
15,888
hillu/go-yara
cbpool.go
Put
func (p *cbPool) Put(obj interface{}) unsafe.Pointer { p.m.Lock() defer p.m.Unlock() for id, val := range p.indices { if val != 0 { continue } p.indices[id] = id + 1 p.objects[id] = obj return unsafe.Pointer(&p.indices[id]) } panic("cbPool storage exhausted") }
go
func (p *cbPool) Put(obj interface{}) unsafe.Pointer { p.m.Lock() defer p.m.Unlock() for id, val := range p.indices { if val != 0 { continue } p.indices[id] = id + 1 p.objects[id] = obj return unsafe.Pointer(&p.indices[id]) } panic("cbPool storage exhausted") }
[ "func", "(", "p", "*", "cbPool", ")", "Put", "(", "obj", "interface", "{", "}", ")", "unsafe", ".", "Pointer", "{", "p", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "m", ".", "Unlock", "(", ")", "\n", "for", "id", ",", "val", ...
// Put adds an element to the cbPool, returning a stable pointer // suitable for passing through CGO. It panics if the pool is full.
[ "Put", "adds", "an", "element", "to", "the", "cbPool", "returning", "a", "stable", "pointer", "suitable", "for", "passing", "through", "CGO", ".", "It", "panics", "if", "the", "pool", "is", "full", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/cbpool.go#L45-L57
15,889
hillu/go-yara
cbpool.go
Get
func (p *cbPool) Get(ptr unsafe.Pointer) interface{} { p.m.RLock() defer p.m.RUnlock() p.checkPointer(ptr) id := *(*int)(ptr) - 1 if id == -1 { panic("Attempt to get nonexistent value from pool") } return p.objects[id] }
go
func (p *cbPool) Get(ptr unsafe.Pointer) interface{} { p.m.RLock() defer p.m.RUnlock() p.checkPointer(ptr) id := *(*int)(ptr) - 1 if id == -1 { panic("Attempt to get nonexistent value from pool") } return p.objects[id] }
[ "func", "(", "p", "*", "cbPool", ")", "Get", "(", "ptr", "unsafe", ".", "Pointer", ")", "interface", "{", "}", "{", "p", ".", "m", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "m", ".", "RUnlock", "(", ")", "\n", "p", ".", "checkPointer", ...
// Put accesses an element stored in the cbPool, using a pointer // previously returned by Put. It panics if the pointer is invalid or // if it references an empty slot.
[ "Put", "accesses", "an", "element", "stored", "in", "the", "cbPool", "using", "a", "pointer", "previously", "returned", "by", "Put", ".", "It", "panics", "if", "the", "pointer", "is", "invalid", "or", "if", "it", "references", "an", "empty", "slot", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/cbpool.go#L69-L78
15,890
hillu/go-yara
cbpool.go
Delete
func (p *cbPool) Delete(ptr unsafe.Pointer) { p.m.Lock() defer p.m.Unlock() p.checkPointer(ptr) id := *(*int)(ptr) - 1 if id == -1 { panic("Attempt to delete nonexistent value from pool") } p.indices[id] = 0 p.objects[id] = nil return }
go
func (p *cbPool) Delete(ptr unsafe.Pointer) { p.m.Lock() defer p.m.Unlock() p.checkPointer(ptr) id := *(*int)(ptr) - 1 if id == -1 { panic("Attempt to delete nonexistent value from pool") } p.indices[id] = 0 p.objects[id] = nil return }
[ "func", "(", "p", "*", "cbPool", ")", "Delete", "(", "ptr", "unsafe", ".", "Pointer", ")", "{", "p", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "m", ".", "Unlock", "(", ")", "\n", "p", ".", "checkPointer", "(", "ptr", ")", "\n"...
// Delete removes an element from the cbPool, using a pointer previously // returned by Put. It panics if the pointer is invalid or if it // references an empty slot.
[ "Delete", "removes", "an", "element", "from", "the", "cbPool", "using", "a", "pointer", "previously", "returned", "by", "Put", ".", "It", "panics", "if", "the", "pointer", "is", "invalid", "or", "if", "it", "references", "an", "empty", "slot", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/cbpool.go#L83-L94
15,891
hillu/go-yara
rules_yara34.go
ScanFileDescriptor
func (r *Rules) ScanFileDescriptor(fd uintptr, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanFileDescriptorWithCallback(fd, flags, timeout, &cb) matches = cb return }
go
func (r *Rules) ScanFileDescriptor(fd uintptr, flags ScanFlags, timeout time.Duration) (matches []MatchRule, err error) { cb := MatchRules{} err = r.ScanFileDescriptorWithCallback(fd, flags, timeout, &cb) matches = cb return }
[ "func", "(", "r", "*", "Rules", ")", "ScanFileDescriptor", "(", "fd", "uintptr", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ")", "(", "matches", "[", "]", "MatchRule", ",", "err", "error", ")", "{", "cb", ":=", "MatchRules", "{...
// ScanFileDescriptor scans a file using the ruleset, returning // matches via a list of MatchRule objects.
[ "ScanFileDescriptor", "scans", "a", "file", "using", "the", "ruleset", "returning", "matches", "via", "a", "list", "of", "MatchRule", "objects", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules_yara34.go#L51-L56
15,892
hillu/go-yara
rules_yara34.go
ScanFileDescriptorWithCallback
func (r *Rules) ScanFileDescriptorWithCallback(fd uintptr, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C._yr_rules_scan_fd( r.cptr, C.int(fd), C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
go
func (r *Rules) ScanFileDescriptorWithCallback(fd uintptr, flags ScanFlags, timeout time.Duration, cb ScanCallback) (err error) { cbc := &scanCallbackContainer{ScanCallback: cb} defer cbc.destroy() id := callbackData.Put(cbc) defer callbackData.Delete(id) err = newError(C._yr_rules_scan_fd( r.cptr, C.int(fd), C.int(flags), C.YR_CALLBACK_FUNC(C.scanCallbackFunc), id, C.int(timeout/time.Second))) keepAlive(r) return }
[ "func", "(", "r", "*", "Rules", ")", "ScanFileDescriptorWithCallback", "(", "fd", "uintptr", ",", "flags", "ScanFlags", ",", "timeout", "time", ".", "Duration", ",", "cb", "ScanCallback", ")", "(", "err", "error", ")", "{", "cbc", ":=", "&", "scanCallbackC...
// ScanFileDescriptorWithCallback scans a file using the ruleset. For every event // emitted by libyara, the appropriate method on the ScanCallback // object is called.
[ "ScanFileDescriptorWithCallback", "scans", "a", "file", "using", "the", "ruleset", ".", "For", "every", "event", "emitted", "by", "libyara", "the", "appropriate", "method", "on", "the", "ScanCallback", "object", "is", "called", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules_yara34.go#L61-L75
15,893
hillu/go-yara
rules_yara34.go
Write
func (r *Rules) Write(wr io.Writer) (err error) { id := callbackData.Put(wr) defer callbackData.Delete(id) stream := C.YR_STREAM{ write: C.YR_STREAM_WRITE_FUNC(C.streamWrite), // The complaint from go vet about possible misuse of // unsafe.Pointer is wrong: user_data will be interpreted as // an uintptr on the other side of the callback user_data: id, } err = newError(C.yr_rules_save_stream(r.cptr, &stream)) keepAlive(r) return }
go
func (r *Rules) Write(wr io.Writer) (err error) { id := callbackData.Put(wr) defer callbackData.Delete(id) stream := C.YR_STREAM{ write: C.YR_STREAM_WRITE_FUNC(C.streamWrite), // The complaint from go vet about possible misuse of // unsafe.Pointer is wrong: user_data will be interpreted as // an uintptr on the other side of the callback user_data: id, } err = newError(C.yr_rules_save_stream(r.cptr, &stream)) keepAlive(r) return }
[ "func", "(", "r", "*", "Rules", ")", "Write", "(", "wr", "io", ".", "Writer", ")", "(", "err", "error", ")", "{", "id", ":=", "callbackData", ".", "Put", "(", "wr", ")", "\n", "defer", "callbackData", ".", "Delete", "(", "id", ")", "\n\n", "strea...
// Write writes a compiled ruleset to an io.Writer.
[ "Write", "writes", "a", "compiled", "ruleset", "to", "an", "io", ".", "Writer", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules_yara34.go#L78-L92
15,894
hillu/go-yara
rules_yara34.go
ReadRules
func ReadRules(rd io.Reader) (*Rules, error) { r := &Rules{rules: &rules{}} id := callbackData.Put(rd) defer callbackData.Delete(id) stream := C.YR_STREAM{ read: C.YR_STREAM_READ_FUNC(C.streamRead), // The complaint from go vet about possible misuse of // unsafe.Pointer is wrong, see above. user_data: id, } if err := newError(C.yr_rules_load_stream(&stream, &(r.rules.cptr))); err != nil { return nil, err } runtime.SetFinalizer(r.rules, (*rules).finalize) return r, nil }
go
func ReadRules(rd io.Reader) (*Rules, error) { r := &Rules{rules: &rules{}} id := callbackData.Put(rd) defer callbackData.Delete(id) stream := C.YR_STREAM{ read: C.YR_STREAM_READ_FUNC(C.streamRead), // The complaint from go vet about possible misuse of // unsafe.Pointer is wrong, see above. user_data: id, } if err := newError(C.yr_rules_load_stream(&stream, &(r.rules.cptr))); err != nil { return nil, err } runtime.SetFinalizer(r.rules, (*rules).finalize) return r, nil }
[ "func", "ReadRules", "(", "rd", "io", ".", "Reader", ")", "(", "*", "Rules", ",", "error", ")", "{", "r", ":=", "&", "Rules", "{", "rules", ":", "&", "rules", "{", "}", "}", "\n", "id", ":=", "callbackData", ".", "Put", "(", "rd", ")", "\n", ...
// ReadRules retrieves a compiled ruleset from an io.Reader
[ "ReadRules", "retrieves", "a", "compiled", "ruleset", "from", "an", "io", ".", "Reader" ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rules_yara34.go#L95-L112
15,895
hillu/go-yara
rule.go
Identifier
func (r *Rule) Identifier() string { return C.GoString(C.rule_identifier(r.cptr)) }
go
func (r *Rule) Identifier() string { return C.GoString(C.rule_identifier(r.cptr)) }
[ "func", "(", "r", "*", "Rule", ")", "Identifier", "(", ")", "string", "{", "return", "C", ".", "GoString", "(", "C", ".", "rule_identifier", "(", "r", ".", "cptr", ")", ")", "\n", "}" ]
// Identifier returns the rule's name.
[ "Identifier", "returns", "the", "rule", "s", "name", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L97-L99
15,896
hillu/go-yara
rule.go
Namespace
func (r *Rule) Namespace() string { return C.GoString(C.rule_namespace(r.cptr)) }
go
func (r *Rule) Namespace() string { return C.GoString(C.rule_namespace(r.cptr)) }
[ "func", "(", "r", "*", "Rule", ")", "Namespace", "(", ")", "string", "{", "return", "C", ".", "GoString", "(", "C", ".", "rule_namespace", "(", "r", ".", "cptr", ")", ")", "\n", "}" ]
// Namespace returns the rule's namespace.
[ "Namespace", "returns", "the", "rule", "s", "namespace", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L102-L104
15,897
hillu/go-yara
rule.go
Tags
func (r *Rule) Tags() (tags []string) { var size C.int C.rule_tags(r.cptr, nil, &size) if size == 0 { return } tagptrs := make([]*C.char, int(size)) C.rule_tags(r.cptr, &tagptrs[0], &size) for _, t := range tagptrs { tags = append(tags, C.GoString(t)) } return }
go
func (r *Rule) Tags() (tags []string) { var size C.int C.rule_tags(r.cptr, nil, &size) if size == 0 { return } tagptrs := make([]*C.char, int(size)) C.rule_tags(r.cptr, &tagptrs[0], &size) for _, t := range tagptrs { tags = append(tags, C.GoString(t)) } return }
[ "func", "(", "r", "*", "Rule", ")", "Tags", "(", ")", "(", "tags", "[", "]", "string", ")", "{", "var", "size", "C", ".", "int", "\n", "C", ".", "rule_tags", "(", "r", ".", "cptr", ",", "nil", ",", "&", "size", ")", "\n", "if", "size", "=="...
// Tags returns the rule's tags.
[ "Tags", "returns", "the", "rule", "s", "tags", "." ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L107-L119
15,898
hillu/go-yara
rule.go
Metas
func (r *Rule) Metas() (metas map[string]interface{}) { metas = make(map[string]interface{}) var size C.int C.rule_metas(r.cptr, nil, &size) if size == 0 { return } mptrs := make([]*C.YR_META, int(size)) C.rule_metas(r.cptr, &mptrs[0], &size) for _, m := range mptrs { var cid, cstr *C.char C.meta_get(m, &cid, &cstr) id := C.GoString(cid) switch m._type { case C.META_TYPE_NULL: metas[id] = nil case C.META_TYPE_STRING: metas[id] = C.GoString(cstr) case C.META_TYPE_INTEGER: metas[id] = int(m.integer) case C.META_TYPE_BOOLEAN: metas[id] = m.integer != 0 } } return }
go
func (r *Rule) Metas() (metas map[string]interface{}) { metas = make(map[string]interface{}) var size C.int C.rule_metas(r.cptr, nil, &size) if size == 0 { return } mptrs := make([]*C.YR_META, int(size)) C.rule_metas(r.cptr, &mptrs[0], &size) for _, m := range mptrs { var cid, cstr *C.char C.meta_get(m, &cid, &cstr) id := C.GoString(cid) switch m._type { case C.META_TYPE_NULL: metas[id] = nil case C.META_TYPE_STRING: metas[id] = C.GoString(cstr) case C.META_TYPE_INTEGER: metas[id] = int(m.integer) case C.META_TYPE_BOOLEAN: metas[id] = m.integer != 0 } } return }
[ "func", "(", "r", "*", "Rule", ")", "Metas", "(", ")", "(", "metas", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "metas", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "var", "size", "C", ".", ...
// Metas returns a map containing the rule's meta variables. Values // can be of type string, int, bool, or nil. // // If a rule contains multiple meta variables with the same name, only // the last meta variable is returned as part of the map.
[ "Metas", "returns", "a", "map", "containing", "the", "rule", "s", "meta", "variables", ".", "Values", "can", "be", "of", "type", "string", "int", "bool", "or", "nil", ".", "If", "a", "rule", "contains", "multiple", "meta", "variables", "with", "the", "sa...
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L126-L151
15,899
hillu/go-yara
rule.go
Strings
func (r *Rule) Strings() (strs []String) { var size C.int C.rule_strings(r.cptr, nil, &size) if size == 0 { return } ptrs := make([]*C.YR_STRING, int(size)) C.rule_strings(r.cptr, &ptrs[0], &size) for _, ptr := range ptrs { strs = append(strs, String{ptr}) } return }
go
func (r *Rule) Strings() (strs []String) { var size C.int C.rule_strings(r.cptr, nil, &size) if size == 0 { return } ptrs := make([]*C.YR_STRING, int(size)) C.rule_strings(r.cptr, &ptrs[0], &size) for _, ptr := range ptrs { strs = append(strs, String{ptr}) } return }
[ "func", "(", "r", "*", "Rule", ")", "Strings", "(", ")", "(", "strs", "[", "]", "String", ")", "{", "var", "size", "C", ".", "int", "\n", "C", ".", "rule_strings", "(", "r", ".", "cptr", ",", "nil", ",", "&", "size", ")", "\n", "if", "size", ...
// Strings returns the rule's strings
[ "Strings", "returns", "the", "rule", "s", "strings" ]
62cc1506ae60c3f5fd56e992776dddd08d74891f
https://github.com/hillu/go-yara/blob/62cc1506ae60c3f5fd56e992776dddd08d74891f/rule.go#L167-L179