id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
4,300
uber-go/dosa
connectors/routing/connector.go
Shutdown
func (rc *Connector) Shutdown() error { hasError := false rConnErr := errors.New("failed to shutdown") for _, c := range rc.connectors { err := c.Shutdown() if err != nil { // save errors here, continue to shut down other connectors hasError = true err = errors.Wrap(rConnErr, err.Error()) continue } } if hasError { return rConnErr } return nil }
go
func (rc *Connector) Shutdown() error { hasError := false rConnErr := errors.New("failed to shutdown") for _, c := range rc.connectors { err := c.Shutdown() if err != nil { // save errors here, continue to shut down other connectors hasError = true err = errors.Wrap(rConnErr, err.Error()) continue } } if hasError { return rConnErr } return nil }
[ "func", "(", "rc", "*", "Connector", ")", "Shutdown", "(", ")", "error", "{", "hasError", ":=", "false", "\n", "rConnErr", ":=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "for", "_", ",", "c", ":=", "range", "rc", ".", "connectors", "{", "err", ":=", "c", ".", "Shutdown", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// save errors here, continue to shut down other connectors", "hasError", "=", "true", "\n", "err", "=", "errors", ".", "Wrap", "(", "rConnErr", ",", "err", ".", "Error", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "}", "\n\n", "if", "hasError", "{", "return", "rConnErr", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Shutdown shut down all connectors that routing connector talks to
[ "Shutdown", "shut", "down", "all", "connectors", "that", "routing", "connector", "talks", "to" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/routing/connector.go#L240-L257
4,301
uber-go/dosa
mocks/metrics.go
Counter
func (m *MockScope) Counter(name string) metrics.Counter { ret := m.ctrl.Call(m, "Counter", name) ret0, _ := ret[0].(metrics.Counter) return ret0 }
go
func (m *MockScope) Counter(name string) metrics.Counter { ret := m.ctrl.Call(m, "Counter", name) ret0, _ := ret[0].(metrics.Counter) return ret0 }
[ "func", "(", "m", "*", "MockScope", ")", "Counter", "(", "name", "string", ")", "metrics", ".", "Counter", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "name", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "metrics", ".", "Counter", ")", "\n", "return", "ret0", "\n", "}" ]
// Counter mocks base method
[ "Counter", "mocks", "base", "method" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/metrics.go#L59-L63
4,302
uber-go/dosa
mocks/metrics.go
Tagged
func (m *MockScope) Tagged(tags map[string]string) metrics.Scope { ret := m.ctrl.Call(m, "Tagged", tags) ret0, _ := ret[0].(metrics.Scope) return ret0 }
go
func (m *MockScope) Tagged(tags map[string]string) metrics.Scope { ret := m.ctrl.Call(m, "Tagged", tags) ret0, _ := ret[0].(metrics.Scope) return ret0 }
[ "func", "(", "m", "*", "MockScope", ")", "Tagged", "(", "tags", "map", "[", "string", "]", "string", ")", "metrics", ".", "Scope", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "tags", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "metrics", ".", "Scope", ")", "\n", "return", "ret0", "\n", "}" ]
// Tagged mocks base method
[ "Tagged", "mocks", "base", "method" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/metrics.go#L71-L75
4,303
uber-go/dosa
mocks/metrics.go
Tagged
func (mr *MockScopeMockRecorder) Tagged(tags interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tagged", reflect.TypeOf((*MockScope)(nil).Tagged), tags) }
go
func (mr *MockScopeMockRecorder) Tagged(tags interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tagged", reflect.TypeOf((*MockScope)(nil).Tagged), tags) }
[ "func", "(", "mr", "*", "MockScopeMockRecorder", ")", "Tagged", "(", "tags", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockScope", ")", "(", "nil", ")", ".", "Tagged", ")", ",", "tags", ")", "\n", "}" ]
// Tagged indicates an expected call of Tagged
[ "Tagged", "indicates", "an", "expected", "call", "of", "Tagged" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/metrics.go#L78-L80
4,304
uber-go/dosa
mocks/metrics.go
SubScope
func (m *MockScope) SubScope(name string) metrics.Scope { ret := m.ctrl.Call(m, "SubScope", name) ret0, _ := ret[0].(metrics.Scope) return ret0 }
go
func (m *MockScope) SubScope(name string) metrics.Scope { ret := m.ctrl.Call(m, "SubScope", name) ret0, _ := ret[0].(metrics.Scope) return ret0 }
[ "func", "(", "m", "*", "MockScope", ")", "SubScope", "(", "name", "string", ")", "metrics", ".", "Scope", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "name", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "metrics", ".", "Scope", ")", "\n", "return", "ret0", "\n", "}" ]
// SubScope mocks base method
[ "SubScope", "mocks", "base", "method" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/metrics.go#L83-L87
4,305
uber-go/dosa
mocks/metrics.go
Timer
func (mr *MockScopeMockRecorder) Timer(name interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timer", reflect.TypeOf((*MockScope)(nil).Timer), name) }
go
func (mr *MockScopeMockRecorder) Timer(name interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timer", reflect.TypeOf((*MockScope)(nil).Timer), name) }
[ "func", "(", "mr", "*", "MockScopeMockRecorder", ")", "Timer", "(", "name", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockScope", ")", "(", "nil", ")", ".", "Timer", ")", ",", "name", ")", "\n", "}" ]
// Timer indicates an expected call of Timer
[ "Timer", "indicates", "an", "expected", "call", "of", "Timer" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/metrics.go#L102-L104
4,306
uber-go/dosa
mocks/metrics.go
Inc
func (m *MockCounter) Inc(delta int64) { m.ctrl.Call(m, "Inc", delta) }
go
func (m *MockCounter) Inc(delta int64) { m.ctrl.Call(m, "Inc", delta) }
[ "func", "(", "m", "*", "MockCounter", ")", "Inc", "(", "delta", "int64", ")", "{", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "delta", ")", "\n", "}" ]
// Inc mocks base method
[ "Inc", "mocks", "base", "method" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/mocks/metrics.go#L130-L132
4,307
uber-go/dosa
cmd/dosa/scope.go
Execute
func (c *ScopeCreate) Execute(args []string) error { typ, err := parseType(c.Type) if err != nil { return err } if len(c.Owner) == 0 { return errors.New("the owning ublame-group must be specified") } return c.doScopeOp("create", func(client dosa.AdminClient, ctx context.Context, scope string) error { return dosa.AdminClient.CreateScope(client, ctx, &dosa.ScopeMetadata{ Name: scope, Owner: c.Owner, Type: int32(typ), Creator: *dosa.GetUsername(), Cluster: c.Cluster, ReadMaxRPS: c.ReadRPS, WriteMaxRPS: c.WriteRPS, }) }, c.Args.Scopes) }
go
func (c *ScopeCreate) Execute(args []string) error { typ, err := parseType(c.Type) if err != nil { return err } if len(c.Owner) == 0 { return errors.New("the owning ublame-group must be specified") } return c.doScopeOp("create", func(client dosa.AdminClient, ctx context.Context, scope string) error { return dosa.AdminClient.CreateScope(client, ctx, &dosa.ScopeMetadata{ Name: scope, Owner: c.Owner, Type: int32(typ), Creator: *dosa.GetUsername(), Cluster: c.Cluster, ReadMaxRPS: c.ReadRPS, WriteMaxRPS: c.WriteRPS, }) }, c.Args.Scopes) }
[ "func", "(", "c", "*", "ScopeCreate", ")", "Execute", "(", "args", "[", "]", "string", ")", "error", "{", "typ", ",", "err", ":=", "parseType", "(", "c", ".", "Type", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "c", ".", "Owner", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "c", ".", "doScopeOp", "(", "\"", "\"", ",", "func", "(", "client", "dosa", ".", "AdminClient", ",", "ctx", "context", ".", "Context", ",", "scope", "string", ")", "error", "{", "return", "dosa", ".", "AdminClient", ".", "CreateScope", "(", "client", ",", "ctx", ",", "&", "dosa", ".", "ScopeMetadata", "{", "Name", ":", "scope", ",", "Owner", ":", "c", ".", "Owner", ",", "Type", ":", "int32", "(", "typ", ")", ",", "Creator", ":", "*", "dosa", ".", "GetUsername", "(", ")", ",", "Cluster", ":", "c", ".", "Cluster", ",", "ReadMaxRPS", ":", "c", ".", "ReadRPS", ",", "WriteMaxRPS", ":", "c", ".", "WriteRPS", ",", "}", ")", "\n", "}", ",", "c", ".", "Args", ".", "Scopes", ")", "\n", "}" ]
// Execute executes a scope create command
[ "Execute", "executes", "a", "scope", "create", "command" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/scope.go#L86-L106
4,308
uber-go/dosa
cmd/dosa/scope.go
Execute
func (c *ScopeDrop) Execute(args []string) error { return c.doScopeOp("drop", dosa.AdminClient.DropScope, c.Args.Scopes) }
go
func (c *ScopeDrop) Execute(args []string) error { return c.doScopeOp("drop", dosa.AdminClient.DropScope, c.Args.Scopes) }
[ "func", "(", "c", "*", "ScopeDrop", ")", "Execute", "(", "args", "[", "]", "string", ")", "error", "{", "return", "c", ".", "doScopeOp", "(", "\"", "\"", ",", "dosa", ".", "AdminClient", ".", "DropScope", ",", "c", ".", "Args", ".", "Scopes", ")", "\n", "}" ]
// Execute executes a scope drop command
[ "Execute", "executes", "a", "scope", "drop", "command" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/scope.go#L125-L127
4,309
uber-go/dosa
cmd/dosa/scope.go
Execute
func (c *ScopeTruncate) Execute(args []string) error { return c.doScopeOp("truncate", dosa.AdminClient.TruncateScope, c.Args.Scopes) }
go
func (c *ScopeTruncate) Execute(args []string) error { return c.doScopeOp("truncate", dosa.AdminClient.TruncateScope, c.Args.Scopes) }
[ "func", "(", "c", "*", "ScopeTruncate", ")", "Execute", "(", "args", "[", "]", "string", ")", "error", "{", "return", "c", ".", "doScopeOp", "(", "\"", "\"", ",", "dosa", ".", "AdminClient", ".", "TruncateScope", ",", "c", ".", "Args", ".", "Scopes", ")", "\n", "}" ]
// Execute executes a scope truncate command
[ "Execute", "executes", "a", "scope", "truncate", "command" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/scope.go#L146-L148
4,310
uber-go/dosa
cmd/dosa/scope.go
parseType
func parseType(t string) (dosa.ScopeType, error) { if len(t) == 0 { return dosa.Development, nil } lt := strings.ToLower(t) if strings.HasPrefix("production", lt) { return dosa.Production, nil } if strings.HasPrefix("staging", lt) { return dosa.Staging, nil } if strings.HasPrefix("development", lt) { return dosa.Development, nil } return dosa.Development, fmt.Errorf("unknown scope type %q", t) }
go
func parseType(t string) (dosa.ScopeType, error) { if len(t) == 0 { return dosa.Development, nil } lt := strings.ToLower(t) if strings.HasPrefix("production", lt) { return dosa.Production, nil } if strings.HasPrefix("staging", lt) { return dosa.Staging, nil } if strings.HasPrefix("development", lt) { return dosa.Development, nil } return dosa.Development, fmt.Errorf("unknown scope type %q", t) }
[ "func", "parseType", "(", "t", "string", ")", "(", "dosa", ".", "ScopeType", ",", "error", ")", "{", "if", "len", "(", "t", ")", "==", "0", "{", "return", "dosa", ".", "Development", ",", "nil", "\n", "}", "\n", "lt", ":=", "strings", ".", "ToLower", "(", "t", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "\"", "\"", ",", "lt", ")", "{", "return", "dosa", ".", "Production", ",", "nil", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "\"", "\"", ",", "lt", ")", "{", "return", "dosa", ".", "Staging", ",", "nil", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "\"", "\"", ",", "lt", ")", "{", "return", "dosa", ".", "Development", ",", "nil", "\n", "}", "\n", "return", "dosa", ".", "Development", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "t", ")", "\n", "}" ]
// Parse a string into a scope type.
[ "Parse", "a", "string", "into", "a", "scope", "type", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/scope.go#L151-L166
4,311
uber-go/dosa
finder.go
FindEntityByName
func FindEntityByName(path string, structName string) (*Table, error) { // find all entites in the given path entities, _, err := findEntities([]string{path}, []string{}) if err != nil { return nil, err } // filter entites with the given struct name entitiesFilteredByName := []*Table{} for _, table := range entities { if table.StructName == structName { entitiesFilteredByName = append(entitiesFilteredByName, table) } } // only one entity with given name should be found if len(entitiesFilteredByName) == 0 { return nil, errors.Errorf("no entity named %s found in the path %s", structName, path) } if len(entitiesFilteredByName) > 1 { return nil, errors.Errorf("more than one entities named %s found in the path %s", structName, path) } return entitiesFilteredByName[0], nil }
go
func FindEntityByName(path string, structName string) (*Table, error) { // find all entites in the given path entities, _, err := findEntities([]string{path}, []string{}) if err != nil { return nil, err } // filter entites with the given struct name entitiesFilteredByName := []*Table{} for _, table := range entities { if table.StructName == structName { entitiesFilteredByName = append(entitiesFilteredByName, table) } } // only one entity with given name should be found if len(entitiesFilteredByName) == 0 { return nil, errors.Errorf("no entity named %s found in the path %s", structName, path) } if len(entitiesFilteredByName) > 1 { return nil, errors.Errorf("more than one entities named %s found in the path %s", structName, path) } return entitiesFilteredByName[0], nil }
[ "func", "FindEntityByName", "(", "path", "string", ",", "structName", "string", ")", "(", "*", "Table", ",", "error", ")", "{", "// find all entites in the given path", "entities", ",", "_", ",", "err", ":=", "findEntities", "(", "[", "]", "string", "{", "path", "}", ",", "[", "]", "string", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// filter entites with the given struct name", "entitiesFilteredByName", ":=", "[", "]", "*", "Table", "{", "}", "\n", "for", "_", ",", "table", ":=", "range", "entities", "{", "if", "table", ".", "StructName", "==", "structName", "{", "entitiesFilteredByName", "=", "append", "(", "entitiesFilteredByName", ",", "table", ")", "\n", "}", "\n", "}", "\n\n", "// only one entity with given name should be found", "if", "len", "(", "entitiesFilteredByName", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "structName", ",", "path", ")", "\n", "}", "\n", "if", "len", "(", "entitiesFilteredByName", ")", ">", "1", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "structName", ",", "path", ")", "\n", "}", "\n\n", "return", "entitiesFilteredByName", "[", "0", "]", ",", "nil", "\n", "}" ]
// FindEntityByName returns the entity with given name in the path.
[ "FindEntityByName", "returns", "the", "entity", "with", "given", "name", "in", "the", "path", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/finder.go#L81-L105
4,312
uber-go/dosa
finder.go
Visit
func (f *entityRecordingVisitor) Visit(n ast.Node) ast.Visitor { switch n := n.(type) { case *ast.File, *ast.Package, *ast.BlockStmt, *ast.DeclStmt, *ast.FuncDecl, *ast.GenDecl: return f case *ast.TypeSpec: if structType, ok := n.Type.(*ast.StructType); ok { // look for a Entity with a dosa annotation if isDosaEntity(structType) { table, err := tableFromStructType(n.Name.Name, structType, f.packagePrefix) if err == nil { f.entities = append(f.entities, table) } else { f.warnings = append(f.warnings, err) } } } } return nil }
go
func (f *entityRecordingVisitor) Visit(n ast.Node) ast.Visitor { switch n := n.(type) { case *ast.File, *ast.Package, *ast.BlockStmt, *ast.DeclStmt, *ast.FuncDecl, *ast.GenDecl: return f case *ast.TypeSpec: if structType, ok := n.Type.(*ast.StructType); ok { // look for a Entity with a dosa annotation if isDosaEntity(structType) { table, err := tableFromStructType(n.Name.Name, structType, f.packagePrefix) if err == nil { f.entities = append(f.entities, table) } else { f.warnings = append(f.warnings, err) } } } } return nil }
[ "func", "(", "f", "*", "entityRecordingVisitor", ")", "Visit", "(", "n", "ast", ".", "Node", ")", "ast", ".", "Visitor", "{", "switch", "n", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "File", ",", "*", "ast", ".", "Package", ",", "*", "ast", ".", "BlockStmt", ",", "*", "ast", ".", "DeclStmt", ",", "*", "ast", ".", "FuncDecl", ",", "*", "ast", ".", "GenDecl", ":", "return", "f", "\n", "case", "*", "ast", ".", "TypeSpec", ":", "if", "structType", ",", "ok", ":=", "n", ".", "Type", ".", "(", "*", "ast", ".", "StructType", ")", ";", "ok", "{", "// look for a Entity with a dosa annotation", "if", "isDosaEntity", "(", "structType", ")", "{", "table", ",", "err", ":=", "tableFromStructType", "(", "n", ".", "Name", ".", "Name", ",", "structType", ",", "f", ".", "packagePrefix", ")", "\n", "if", "err", "==", "nil", "{", "f", ".", "entities", "=", "append", "(", "f", ".", "entities", ",", "table", ")", "\n", "}", "else", "{", "f", ".", "warnings", "=", "append", "(", "f", ".", "warnings", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Visit records all the entities seen into the entityRecordingVisitor structure
[ "Visit", "records", "all", "the", "entities", "seen", "into", "the", "entityRecordingVisitor", "structure" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/finder.go#L141-L159
4,313
uber-go/dosa
cmd/dosa/registrar.go
newSimpleRegistrar
func newSimpleRegistrar(scope, namePrefix string, table *dosa.Table) (dosa.Registrar, error) { if err := dosa.IsValidNamePrefix(namePrefix); err != nil { return nil, errors.Wrap(err, "failed to construct Registrar") } re := dosa.NewRegisteredEntity(scope, namePrefix, table) return &simpleRegistrar{ scope: scope, namePrefix: namePrefix, entity: re, }, nil }
go
func newSimpleRegistrar(scope, namePrefix string, table *dosa.Table) (dosa.Registrar, error) { if err := dosa.IsValidNamePrefix(namePrefix); err != nil { return nil, errors.Wrap(err, "failed to construct Registrar") } re := dosa.NewRegisteredEntity(scope, namePrefix, table) return &simpleRegistrar{ scope: scope, namePrefix: namePrefix, entity: re, }, nil }
[ "func", "newSimpleRegistrar", "(", "scope", ",", "namePrefix", "string", ",", "table", "*", "dosa", ".", "Table", ")", "(", "dosa", ".", "Registrar", ",", "error", ")", "{", "if", "err", ":=", "dosa", ".", "IsValidNamePrefix", "(", "namePrefix", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "re", ":=", "dosa", ".", "NewRegisteredEntity", "(", "scope", ",", "namePrefix", ",", "table", ")", "\n\n", "return", "&", "simpleRegistrar", "{", "scope", ":", "scope", ",", "namePrefix", ":", "namePrefix", ",", "entity", ":", "re", ",", "}", ",", "nil", "\n", "}" ]
// newSimpleRegistrar creates a new simpleRegistrar
[ "newSimpleRegistrar", "creates", "a", "new", "simpleRegistrar" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/registrar.go#L36-L48
4,314
uber-go/dosa
cmd/dosa/registrar.go
Find
func (r *simpleRegistrar) Find(entity dosa.DomainObject) (*dosa.RegisteredEntity, error) { if r.entity == nil { return nil, errors.New("no entity found in registrar") } return r.entity, nil }
go
func (r *simpleRegistrar) Find(entity dosa.DomainObject) (*dosa.RegisteredEntity, error) { if r.entity == nil { return nil, errors.New("no entity found in registrar") } return r.entity, nil }
[ "func", "(", "r", "*", "simpleRegistrar", ")", "Find", "(", "entity", "dosa", ".", "DomainObject", ")", "(", "*", "dosa", ".", "RegisteredEntity", ",", "error", ")", "{", "if", "r", ".", "entity", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "r", ".", "entity", ",", "nil", "\n", "}" ]
// Find returns the embedded entity
[ "Find", "returns", "the", "embedded", "entity" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/cmd/dosa/registrar.go#L61-L67
4,315
uber-go/dosa
connectors/routing/config.go
UnmarshalYAML
func (r *Routers) UnmarshalYAML(unmarshal func(interface{}) error) error { routers := make(Routers, 0) scopes := make([]map[string]interface{}, 0) if err := unmarshal(&scopes); err != nil { return err } defaultRouterExist := false for _, scopeMap := range scopes { for scope, namePrefixes := range scopeMap { namePrefixesMap, ok := namePrefixes.(map[interface{}]interface{}) if !ok { return fmt.Errorf("failed to parse the config: %v", namePrefixes) } for namePrefix, connector := range namePrefixesMap { namePrefixStr := namePrefix.(string) connectorName, ok := connector.(string) if !ok { return fmt.Errorf("failed to parse the config: %v", namePrefixesMap) } router, err := NewRule(scope, namePrefixStr, connectorName) if err != nil { return errors.Wrap(err, "failed to parse routing config") } routers = append(routers, router) if scope == DefaultScope { defaultRouterExist = true } } } } if !defaultRouterExist { return errors.New("there should be a default scope defined in routing config yaml file") } sort.Sort(routers) *r = routers return nil }
go
func (r *Routers) UnmarshalYAML(unmarshal func(interface{}) error) error { routers := make(Routers, 0) scopes := make([]map[string]interface{}, 0) if err := unmarshal(&scopes); err != nil { return err } defaultRouterExist := false for _, scopeMap := range scopes { for scope, namePrefixes := range scopeMap { namePrefixesMap, ok := namePrefixes.(map[interface{}]interface{}) if !ok { return fmt.Errorf("failed to parse the config: %v", namePrefixes) } for namePrefix, connector := range namePrefixesMap { namePrefixStr := namePrefix.(string) connectorName, ok := connector.(string) if !ok { return fmt.Errorf("failed to parse the config: %v", namePrefixesMap) } router, err := NewRule(scope, namePrefixStr, connectorName) if err != nil { return errors.Wrap(err, "failed to parse routing config") } routers = append(routers, router) if scope == DefaultScope { defaultRouterExist = true } } } } if !defaultRouterExist { return errors.New("there should be a default scope defined in routing config yaml file") } sort.Sort(routers) *r = routers return nil }
[ "func", "(", "r", "*", "Routers", ")", "UnmarshalYAML", "(", "unmarshal", "func", "(", "interface", "{", "}", ")", "error", ")", "error", "{", "routers", ":=", "make", "(", "Routers", ",", "0", ")", "\n", "scopes", ":=", "make", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ",", "0", ")", "\n", "if", "err", ":=", "unmarshal", "(", "&", "scopes", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defaultRouterExist", ":=", "false", "\n", "for", "_", ",", "scopeMap", ":=", "range", "scopes", "{", "for", "scope", ",", "namePrefixes", ":=", "range", "scopeMap", "{", "namePrefixesMap", ",", "ok", ":=", "namePrefixes", ".", "(", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", ")", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "namePrefixes", ")", "\n", "}", "\n\n", "for", "namePrefix", ",", "connector", ":=", "range", "namePrefixesMap", "{", "namePrefixStr", ":=", "namePrefix", ".", "(", "string", ")", "\n", "connectorName", ",", "ok", ":=", "connector", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "namePrefixesMap", ")", "\n", "}", "\n", "router", ",", "err", ":=", "NewRule", "(", "scope", ",", "namePrefixStr", ",", "connectorName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "routers", "=", "append", "(", "routers", ",", "router", ")", "\n", "if", "scope", "==", "DefaultScope", "{", "defaultRouterExist", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "!", "defaultRouterExist", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "sort", ".", "Sort", "(", "routers", ")", "\n", "*", "r", "=", "routers", "\n", "return", "nil", "\n", "}" ]
// UnmarshalYAML unmarshals the config into gocql cluster config
[ "UnmarshalYAML", "unmarshals", "the", "config", "into", "gocql", "cluster", "config" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/routing/config.go#L51-L90
4,316
uber-go/dosa
connectors/routing/config.go
FindRouter
func (c *Config) FindRouter(scope, namePrefix string) *Rule { for _, router := range c.Routers { if router.RouteTo(scope, namePrefix) { return router } } return c.findDefaultRouter() }
go
func (c *Config) FindRouter(scope, namePrefix string) *Rule { for _, router := range c.Routers { if router.RouteTo(scope, namePrefix) { return router } } return c.findDefaultRouter() }
[ "func", "(", "c", "*", "Config", ")", "FindRouter", "(", "scope", ",", "namePrefix", "string", ")", "*", "Rule", "{", "for", "_", ",", "router", ":=", "range", "c", ".", "Routers", "{", "if", "router", ".", "RouteTo", "(", "scope", ",", "namePrefix", ")", "{", "return", "router", "\n", "}", "\n", "}", "\n\n", "return", "c", ".", "findDefaultRouter", "(", ")", "\n", "}" ]
// FindRouter finds the router information based on scope and namePrefix.
[ "FindRouter", "finds", "the", "router", "information", "based", "on", "scope", "and", "namePrefix", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/routing/config.go#L103-L111
4,317
uber-go/dosa
connectors/routing/config.go
findDefaultRouter
func (c *Config) findDefaultRouter() *Rule { for _, router := range c.Routers { if router.Scope == DefaultScope { return router } } return nil }
go
func (c *Config) findDefaultRouter() *Rule { for _, router := range c.Routers { if router.Scope == DefaultScope { return router } } return nil }
[ "func", "(", "c", "*", "Config", ")", "findDefaultRouter", "(", ")", "*", "Rule", "{", "for", "_", ",", "router", ":=", "range", "c", ".", "Routers", "{", "if", "router", ".", "Scope", "==", "DefaultScope", "{", "return", "router", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// findDefaultRouter finds the default router information.
[ "findDefaultRouter", "finds", "the", "default", "router", "information", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/routing/config.go#L114-L121
4,318
uber-go/dosa
remove_range.go
NewRemoveRangeOp
func NewRemoveRangeOp(object DomainObject) *RemoveRangeOp { rop := &RemoveRangeOp{ conditioner: conditioner{ object: object, conditions: map[string][]*Condition{}, }, } return rop }
go
func NewRemoveRangeOp(object DomainObject) *RemoveRangeOp { rop := &RemoveRangeOp{ conditioner: conditioner{ object: object, conditions: map[string][]*Condition{}, }, } return rop }
[ "func", "NewRemoveRangeOp", "(", "object", "DomainObject", ")", "*", "RemoveRangeOp", "{", "rop", ":=", "&", "RemoveRangeOp", "{", "conditioner", ":", "conditioner", "{", "object", ":", "object", ",", "conditions", ":", "map", "[", "string", "]", "[", "]", "*", "Condition", "{", "}", ",", "}", ",", "}", "\n", "return", "rop", "\n", "}" ]
// NewRemoveRangeOp returns a new RangeOp instance
[ "NewRemoveRangeOp", "returns", "a", "new", "RangeOp", "instance" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/remove_range.go#L29-L37
4,319
uber-go/dosa
remove_range.go
Eq
func (r *RemoveRangeOp) Eq(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(Eq, fieldName, value) return r }
go
func (r *RemoveRangeOp) Eq(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(Eq, fieldName, value) return r }
[ "func", "(", "r", "*", "RemoveRangeOp", ")", "Eq", "(", "fieldName", "string", ",", "value", "interface", "{", "}", ")", "*", "RemoveRangeOp", "{", "r", ".", "appendOp", "(", "Eq", ",", "fieldName", ",", "value", ")", "\n", "return", "r", "\n", "}" ]
// Eq is used to express an equality constraint for a remove range operation
[ "Eq", "is", "used", "to", "express", "an", "equality", "constraint", "for", "a", "remove", "range", "operation" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/remove_range.go#L40-L43
4,320
uber-go/dosa
remove_range.go
Gt
func (r *RemoveRangeOp) Gt(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(Gt, fieldName, value) return r }
go
func (r *RemoveRangeOp) Gt(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(Gt, fieldName, value) return r }
[ "func", "(", "r", "*", "RemoveRangeOp", ")", "Gt", "(", "fieldName", "string", ",", "value", "interface", "{", "}", ")", "*", "RemoveRangeOp", "{", "r", ".", "appendOp", "(", "Gt", ",", "fieldName", ",", "value", ")", "\n", "return", "r", "\n", "}" ]
// Gt is used to express an "greater than" constraint for a remove range operation
[ "Gt", "is", "used", "to", "express", "an", "greater", "than", "constraint", "for", "a", "remove", "range", "operation" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/remove_range.go#L46-L49
4,321
uber-go/dosa
remove_range.go
GtOrEq
func (r *RemoveRangeOp) GtOrEq(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(GtOrEq, fieldName, value) return r }
go
func (r *RemoveRangeOp) GtOrEq(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(GtOrEq, fieldName, value) return r }
[ "func", "(", "r", "*", "RemoveRangeOp", ")", "GtOrEq", "(", "fieldName", "string", ",", "value", "interface", "{", "}", ")", "*", "RemoveRangeOp", "{", "r", ".", "appendOp", "(", "GtOrEq", ",", "fieldName", ",", "value", ")", "\n", "return", "r", "\n", "}" ]
// GtOrEq is used to express an "greater than or equal" constraint for a // remove range operation
[ "GtOrEq", "is", "used", "to", "express", "an", "greater", "than", "or", "equal", "constraint", "for", "a", "remove", "range", "operation" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/remove_range.go#L53-L56
4,322
uber-go/dosa
remove_range.go
Lt
func (r *RemoveRangeOp) Lt(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(Lt, fieldName, value) return r }
go
func (r *RemoveRangeOp) Lt(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(Lt, fieldName, value) return r }
[ "func", "(", "r", "*", "RemoveRangeOp", ")", "Lt", "(", "fieldName", "string", ",", "value", "interface", "{", "}", ")", "*", "RemoveRangeOp", "{", "r", ".", "appendOp", "(", "Lt", ",", "fieldName", ",", "value", ")", "\n", "return", "r", "\n", "}" ]
// Lt is used to express a "less than" constraint for a remove range operation
[ "Lt", "is", "used", "to", "express", "a", "less", "than", "constraint", "for", "a", "remove", "range", "operation" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/remove_range.go#L59-L62
4,323
uber-go/dosa
remove_range.go
LtOrEq
func (r *RemoveRangeOp) LtOrEq(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(LtOrEq, fieldName, value) return r }
go
func (r *RemoveRangeOp) LtOrEq(fieldName string, value interface{}) *RemoveRangeOp { r.appendOp(LtOrEq, fieldName, value) return r }
[ "func", "(", "r", "*", "RemoveRangeOp", ")", "LtOrEq", "(", "fieldName", "string", ",", "value", "interface", "{", "}", ")", "*", "RemoveRangeOp", "{", "r", ".", "appendOp", "(", "LtOrEq", ",", "fieldName", ",", "value", ")", "\n", "return", "r", "\n", "}" ]
// LtOrEq is used to express a "less than or equal" constraint for a // remove range operation
[ "LtOrEq", "is", "used", "to", "express", "a", "less", "than", "or", "equal", "constraint", "for", "a", "remove", "range", "operation" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/remove_range.go#L66-L69
4,324
uber-go/dosa
connectors/yarpc/helpers.go
RawValueAsInterface
func RawValueAsInterface(val dosarpc.RawValue, typ dosa.Type) interface{} { switch typ { case dosa.Blob: return val.BinaryValue case dosa.TUUID: if len(val.BinaryValue) == 0 { return (*dosa.UUID)(nil) } uuid, _ := dosa.BytesToUUID(val.BinaryValue) // TODO: should we handle this error? return &uuid case dosa.String: return val.StringValue case dosa.Int32: return val.Int32Value case dosa.Int64: return val.Int64Value case dosa.Double: return val.DoubleValue case dosa.Timestamp: if val.Int64Value == nil { return (*time.Time)(nil) } t := time.Unix(0, *val.Int64Value) return &t case dosa.Bool: return val.BoolValue } panic("bad type") }
go
func RawValueAsInterface(val dosarpc.RawValue, typ dosa.Type) interface{} { switch typ { case dosa.Blob: return val.BinaryValue case dosa.TUUID: if len(val.BinaryValue) == 0 { return (*dosa.UUID)(nil) } uuid, _ := dosa.BytesToUUID(val.BinaryValue) // TODO: should we handle this error? return &uuid case dosa.String: return val.StringValue case dosa.Int32: return val.Int32Value case dosa.Int64: return val.Int64Value case dosa.Double: return val.DoubleValue case dosa.Timestamp: if val.Int64Value == nil { return (*time.Time)(nil) } t := time.Unix(0, *val.Int64Value) return &t case dosa.Bool: return val.BoolValue } panic("bad type") }
[ "func", "RawValueAsInterface", "(", "val", "dosarpc", ".", "RawValue", ",", "typ", "dosa", ".", "Type", ")", "interface", "{", "}", "{", "switch", "typ", "{", "case", "dosa", ".", "Blob", ":", "return", "val", ".", "BinaryValue", "\n", "case", "dosa", ".", "TUUID", ":", "if", "len", "(", "val", ".", "BinaryValue", ")", "==", "0", "{", "return", "(", "*", "dosa", ".", "UUID", ")", "(", "nil", ")", "\n", "}", "\n", "uuid", ",", "_", ":=", "dosa", ".", "BytesToUUID", "(", "val", ".", "BinaryValue", ")", "// TODO: should we handle this error?", "\n", "return", "&", "uuid", "\n", "case", "dosa", ".", "String", ":", "return", "val", ".", "StringValue", "\n", "case", "dosa", ".", "Int32", ":", "return", "val", ".", "Int32Value", "\n", "case", "dosa", ".", "Int64", ":", "return", "val", ".", "Int64Value", "\n", "case", "dosa", ".", "Double", ":", "return", "val", ".", "DoubleValue", "\n", "case", "dosa", ".", "Timestamp", ":", "if", "val", ".", "Int64Value", "==", "nil", "{", "return", "(", "*", "time", ".", "Time", ")", "(", "nil", ")", "\n", "}", "\n", "t", ":=", "time", ".", "Unix", "(", "0", ",", "*", "val", ".", "Int64Value", ")", "\n", "return", "&", "t", "\n", "case", "dosa", ".", "Bool", ":", "return", "val", ".", "BoolValue", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// RawValueAsInterface converts a value from the wire to an object implementing the interface // based on the dosa type. For example, a TUUID type will get a dosa.UUID object
[ "RawValueAsInterface", "converts", "a", "value", "from", "the", "wire", "to", "an", "object", "implementing", "the", "interface", "based", "on", "the", "dosa", "type", ".", "For", "example", "a", "TUUID", "type", "will", "get", "a", "dosa", ".", "UUID", "object" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L35-L63
4,325
uber-go/dosa
connectors/yarpc/helpers.go
RawValueFromInterface
func RawValueFromInterface(i interface{}) (*dosarpc.RawValue, error) { // TODO: Do we do type compatibility checks here? We should know the schema, // but the callers are all well known and should match the types switch v := i.(type) { case string: return &dosarpc.RawValue{StringValue: &v}, nil case bool: return &dosarpc.RawValue{BoolValue: &v}, nil case int64: return &dosarpc.RawValue{Int64Value: &v}, nil case int32: return &dosarpc.RawValue{Int32Value: &v}, nil case float64: return &dosarpc.RawValue{DoubleValue: &v}, nil case []byte: // If we set nil to BinaryValue, thrift cannot encode it // as it thought we didn't set any field in the union if v == nil { v = []byte{} } return &dosarpc.RawValue{BinaryValue: v}, nil case time.Time: time := v.UnixNano() return &dosarpc.RawValue{Int64Value: &time}, nil case dosa.UUID: bytes, err := v.Bytes() if err != nil { return nil, err } return &dosarpc.RawValue{BinaryValue: bytes}, nil case *dosa.UUID: if v == nil { return nil, nil } bytes, err := v.Bytes() if err != nil { return nil, err } return &dosarpc.RawValue{BinaryValue: bytes}, nil case *string: if v == nil { return nil, nil } return &dosarpc.RawValue{StringValue: v}, nil case *int32: if v == nil { return nil, nil } return &dosarpc.RawValue{Int32Value: v}, nil case *int64: if v == nil { return nil, nil } return &dosarpc.RawValue{Int64Value: v}, nil case *float64: if v == nil { return nil, nil } return &dosarpc.RawValue{DoubleValue: v}, nil case *bool: if v == nil { return nil, nil } return &dosarpc.RawValue{BoolValue: v}, nil case *time.Time: if v == nil { return nil, nil } t := v.UnixNano() return &dosarpc.RawValue{Int64Value: &t}, nil } panic("bad type") }
go
func RawValueFromInterface(i interface{}) (*dosarpc.RawValue, error) { // TODO: Do we do type compatibility checks here? We should know the schema, // but the callers are all well known and should match the types switch v := i.(type) { case string: return &dosarpc.RawValue{StringValue: &v}, nil case bool: return &dosarpc.RawValue{BoolValue: &v}, nil case int64: return &dosarpc.RawValue{Int64Value: &v}, nil case int32: return &dosarpc.RawValue{Int32Value: &v}, nil case float64: return &dosarpc.RawValue{DoubleValue: &v}, nil case []byte: // If we set nil to BinaryValue, thrift cannot encode it // as it thought we didn't set any field in the union if v == nil { v = []byte{} } return &dosarpc.RawValue{BinaryValue: v}, nil case time.Time: time := v.UnixNano() return &dosarpc.RawValue{Int64Value: &time}, nil case dosa.UUID: bytes, err := v.Bytes() if err != nil { return nil, err } return &dosarpc.RawValue{BinaryValue: bytes}, nil case *dosa.UUID: if v == nil { return nil, nil } bytes, err := v.Bytes() if err != nil { return nil, err } return &dosarpc.RawValue{BinaryValue: bytes}, nil case *string: if v == nil { return nil, nil } return &dosarpc.RawValue{StringValue: v}, nil case *int32: if v == nil { return nil, nil } return &dosarpc.RawValue{Int32Value: v}, nil case *int64: if v == nil { return nil, nil } return &dosarpc.RawValue{Int64Value: v}, nil case *float64: if v == nil { return nil, nil } return &dosarpc.RawValue{DoubleValue: v}, nil case *bool: if v == nil { return nil, nil } return &dosarpc.RawValue{BoolValue: v}, nil case *time.Time: if v == nil { return nil, nil } t := v.UnixNano() return &dosarpc.RawValue{Int64Value: &t}, nil } panic("bad type") }
[ "func", "RawValueFromInterface", "(", "i", "interface", "{", "}", ")", "(", "*", "dosarpc", ".", "RawValue", ",", "error", ")", "{", "// TODO: Do we do type compatibility checks here? We should know the schema,", "// but the callers are all well known and should match the types", "switch", "v", ":=", "i", ".", "(", "type", ")", "{", "case", "string", ":", "return", "&", "dosarpc", ".", "RawValue", "{", "StringValue", ":", "&", "v", "}", ",", "nil", "\n", "case", "bool", ":", "return", "&", "dosarpc", ".", "RawValue", "{", "BoolValue", ":", "&", "v", "}", ",", "nil", "\n", "case", "int64", ":", "return", "&", "dosarpc", ".", "RawValue", "{", "Int64Value", ":", "&", "v", "}", ",", "nil", "\n", "case", "int32", ":", "return", "&", "dosarpc", ".", "RawValue", "{", "Int32Value", ":", "&", "v", "}", ",", "nil", "\n", "case", "float64", ":", "return", "&", "dosarpc", ".", "RawValue", "{", "DoubleValue", ":", "&", "v", "}", ",", "nil", "\n", "case", "[", "]", "byte", ":", "// If we set nil to BinaryValue, thrift cannot encode it", "// as it thought we didn't set any field in the union", "if", "v", "==", "nil", "{", "v", "=", "[", "]", "byte", "{", "}", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "BinaryValue", ":", "v", "}", ",", "nil", "\n", "case", "time", ".", "Time", ":", "time", ":=", "v", ".", "UnixNano", "(", ")", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "Int64Value", ":", "&", "time", "}", ",", "nil", "\n", "case", "dosa", ".", "UUID", ":", "bytes", ",", "err", ":=", "v", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "BinaryValue", ":", "bytes", "}", ",", "nil", "\n", "case", "*", "dosa", ".", "UUID", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "bytes", ",", "err", ":=", "v", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "BinaryValue", ":", "bytes", "}", ",", "nil", "\n", "case", "*", "string", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "StringValue", ":", "v", "}", ",", "nil", "\n", "case", "*", "int32", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "Int32Value", ":", "v", "}", ",", "nil", "\n", "case", "*", "int64", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "Int64Value", ":", "v", "}", ",", "nil", "\n", "case", "*", "float64", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "DoubleValue", ":", "v", "}", ",", "nil", "\n", "case", "*", "bool", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "BoolValue", ":", "v", "}", ",", "nil", "\n", "case", "*", "time", ".", "Time", ":", "if", "v", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "t", ":=", "v", ".", "UnixNano", "(", ")", "\n", "return", "&", "dosarpc", ".", "RawValue", "{", "Int64Value", ":", "&", "t", "}", ",", "nil", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// RawValueFromInterface takes an interface, introspects the type, and then // returns a RawValue object that represents this. It panics if the type // is not in the list, which should be a dosa bug
[ "RawValueFromInterface", "takes", "an", "interface", "introspects", "the", "type", "and", "then", "returns", "a", "RawValue", "object", "that", "represents", "this", ".", "It", "panics", "if", "the", "type", "is", "not", "in", "the", "list", "which", "should", "be", "a", "dosa", "bug" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L68-L140
4,326
uber-go/dosa
connectors/yarpc/helpers.go
RPCTypeFromClientType
func RPCTypeFromClientType(t dosa.Type) dosarpc.ElemType { switch t { case dosa.Bool: return dosarpc.ElemTypeBool case dosa.Blob: return dosarpc.ElemTypeBlob case dosa.String: return dosarpc.ElemTypeString case dosa.Int32: return dosarpc.ElemTypeInt32 case dosa.Int64: return dosarpc.ElemTypeInt64 case dosa.Double: return dosarpc.ElemTypeDouble case dosa.Timestamp: return dosarpc.ElemTypeTimestamp case dosa.TUUID: return dosarpc.ElemTypeUUID } panic("bad type") }
go
func RPCTypeFromClientType(t dosa.Type) dosarpc.ElemType { switch t { case dosa.Bool: return dosarpc.ElemTypeBool case dosa.Blob: return dosarpc.ElemTypeBlob case dosa.String: return dosarpc.ElemTypeString case dosa.Int32: return dosarpc.ElemTypeInt32 case dosa.Int64: return dosarpc.ElemTypeInt64 case dosa.Double: return dosarpc.ElemTypeDouble case dosa.Timestamp: return dosarpc.ElemTypeTimestamp case dosa.TUUID: return dosarpc.ElemTypeUUID } panic("bad type") }
[ "func", "RPCTypeFromClientType", "(", "t", "dosa", ".", "Type", ")", "dosarpc", ".", "ElemType", "{", "switch", "t", "{", "case", "dosa", ".", "Bool", ":", "return", "dosarpc", ".", "ElemTypeBool", "\n", "case", "dosa", ".", "Blob", ":", "return", "dosarpc", ".", "ElemTypeBlob", "\n", "case", "dosa", ".", "String", ":", "return", "dosarpc", ".", "ElemTypeString", "\n", "case", "dosa", ".", "Int32", ":", "return", "dosarpc", ".", "ElemTypeInt32", "\n", "case", "dosa", ".", "Int64", ":", "return", "dosarpc", ".", "ElemTypeInt64", "\n", "case", "dosa", ".", "Double", ":", "return", "dosarpc", ".", "ElemTypeDouble", "\n", "case", "dosa", ".", "Timestamp", ":", "return", "dosarpc", ".", "ElemTypeTimestamp", "\n", "case", "dosa", ".", "TUUID", ":", "return", "dosarpc", ".", "ElemTypeUUID", "\n", "}", "\n", "panic", "(", "\"", "\"", ")", "\n", "}" ]
// RPCTypeFromClientType returns the RPC ElemType from a DOSA Type
[ "RPCTypeFromClientType", "returns", "the", "RPC", "ElemType", "from", "a", "DOSA", "Type" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L143-L163
4,327
uber-go/dosa
connectors/yarpc/helpers.go
PrimaryKeyToThrift
func PrimaryKeyToThrift(key *dosa.PrimaryKey) *dosarpc.PrimaryKey { ck := make([]*dosarpc.ClusteringKey, len(key.ClusteringKeys)) for ckinx, clusteringKey := range key.ClusteringKeys { // TODO: The client uses 'descending' but the RPC uses 'ascending'? Fix this insanity! ascending := !clusteringKey.Descending name := clusteringKey.Name ck[ckinx] = &dosarpc.ClusteringKey{Name: &name, Asc: &ascending} } return &dosarpc.PrimaryKey{PartitionKeys: key.PartitionKeys, ClusteringKeys: ck} }
go
func PrimaryKeyToThrift(key *dosa.PrimaryKey) *dosarpc.PrimaryKey { ck := make([]*dosarpc.ClusteringKey, len(key.ClusteringKeys)) for ckinx, clusteringKey := range key.ClusteringKeys { // TODO: The client uses 'descending' but the RPC uses 'ascending'? Fix this insanity! ascending := !clusteringKey.Descending name := clusteringKey.Name ck[ckinx] = &dosarpc.ClusteringKey{Name: &name, Asc: &ascending} } return &dosarpc.PrimaryKey{PartitionKeys: key.PartitionKeys, ClusteringKeys: ck} }
[ "func", "PrimaryKeyToThrift", "(", "key", "*", "dosa", ".", "PrimaryKey", ")", "*", "dosarpc", ".", "PrimaryKey", "{", "ck", ":=", "make", "(", "[", "]", "*", "dosarpc", ".", "ClusteringKey", ",", "len", "(", "key", ".", "ClusteringKeys", ")", ")", "\n", "for", "ckinx", ",", "clusteringKey", ":=", "range", "key", ".", "ClusteringKeys", "{", "// TODO: The client uses 'descending' but the RPC uses 'ascending'? Fix this insanity!", "ascending", ":=", "!", "clusteringKey", ".", "Descending", "\n", "name", ":=", "clusteringKey", ".", "Name", "\n", "ck", "[", "ckinx", "]", "=", "&", "dosarpc", ".", "ClusteringKey", "{", "Name", ":", "&", "name", ",", "Asc", ":", "&", "ascending", "}", "\n", "}", "\n", "return", "&", "dosarpc", ".", "PrimaryKey", "{", "PartitionKeys", ":", "key", ".", "PartitionKeys", ",", "ClusteringKeys", ":", "ck", "}", "\n", "}" ]
// PrimaryKeyToThrift converts the dosa primary key to the thrift primary key type
[ "PrimaryKeyToThrift", "converts", "the", "dosa", "primary", "key", "to", "the", "thrift", "primary", "key", "type" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L189-L198
4,328
uber-go/dosa
connectors/yarpc/helpers.go
ETLStateToThrift
func ETLStateToThrift(etl dosa.ETLState) dosarpc.ETLState { switch etl { case dosa.EtlOn: return dosarpc.ETLStateOn case dosa.EtlOff: return dosarpc.ETLStateOff default: panic(fmt.Sprintf("bad ETL state: %v", etl)) } }
go
func ETLStateToThrift(etl dosa.ETLState) dosarpc.ETLState { switch etl { case dosa.EtlOn: return dosarpc.ETLStateOn case dosa.EtlOff: return dosarpc.ETLStateOff default: panic(fmt.Sprintf("bad ETL state: %v", etl)) } }
[ "func", "ETLStateToThrift", "(", "etl", "dosa", ".", "ETLState", ")", "dosarpc", ".", "ETLState", "{", "switch", "etl", "{", "case", "dosa", ".", "EtlOn", ":", "return", "dosarpc", ".", "ETLStateOn", "\n", "case", "dosa", ".", "EtlOff", ":", "return", "dosarpc", ".", "ETLStateOff", "\n", "default", ":", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "etl", ")", ")", "\n", "}", "\n", "}" ]
// ETLStateToThrift convert the dosa ETLState to the thrift ETLState enum type
[ "ETLStateToThrift", "convert", "the", "dosa", "ETLState", "to", "the", "thrift", "ETLState", "enum", "type" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L201-L210
4,329
uber-go/dosa
connectors/yarpc/helpers.go
EntityDefsToThrift
func EntityDefsToThrift(eds []*dosa.EntityDefinition) []*dosarpc.EntityDefinition { rpcEntityDefs := make([]*dosarpc.EntityDefinition, len(eds)) for i, ed := range eds { rpcEntityDefs[i] = entityDefToThrift(ed) } return rpcEntityDefs }
go
func EntityDefsToThrift(eds []*dosa.EntityDefinition) []*dosarpc.EntityDefinition { rpcEntityDefs := make([]*dosarpc.EntityDefinition, len(eds)) for i, ed := range eds { rpcEntityDefs[i] = entityDefToThrift(ed) } return rpcEntityDefs }
[ "func", "EntityDefsToThrift", "(", "eds", "[", "]", "*", "dosa", ".", "EntityDefinition", ")", "[", "]", "*", "dosarpc", ".", "EntityDefinition", "{", "rpcEntityDefs", ":=", "make", "(", "[", "]", "*", "dosarpc", ".", "EntityDefinition", ",", "len", "(", "eds", ")", ")", "\n", "for", "i", ",", "ed", ":=", "range", "eds", "{", "rpcEntityDefs", "[", "i", "]", "=", "entityDefToThrift", "(", "ed", ")", "\n", "}", "\n", "return", "rpcEntityDefs", "\n", "}" ]
// EntityDefsToThrift coverts a set of client EntityDefinition to the corresponding RPC EntityDefinitions
[ "EntityDefsToThrift", "coverts", "a", "set", "of", "client", "EntityDefinition", "to", "the", "corresponding", "RPC", "EntityDefinitions" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L224-L230
4,330
uber-go/dosa
connectors/yarpc/helpers.go
FromThriftToPrimaryKey
func FromThriftToPrimaryKey(key *dosarpc.PrimaryKey) *dosa.PrimaryKey { pk := key.PartitionKeys ck := make([]*dosa.ClusteringKey, len(key.ClusteringKeys)) for i, v := range key.ClusteringKeys { ck[i] = &dosa.ClusteringKey{ Name: *v.Name, Descending: !*v.Asc, } } return &dosa.PrimaryKey{ PartitionKeys: pk, ClusteringKeys: ck, } }
go
func FromThriftToPrimaryKey(key *dosarpc.PrimaryKey) *dosa.PrimaryKey { pk := key.PartitionKeys ck := make([]*dosa.ClusteringKey, len(key.ClusteringKeys)) for i, v := range key.ClusteringKeys { ck[i] = &dosa.ClusteringKey{ Name: *v.Name, Descending: !*v.Asc, } } return &dosa.PrimaryKey{ PartitionKeys: pk, ClusteringKeys: ck, } }
[ "func", "FromThriftToPrimaryKey", "(", "key", "*", "dosarpc", ".", "PrimaryKey", ")", "*", "dosa", ".", "PrimaryKey", "{", "pk", ":=", "key", ".", "PartitionKeys", "\n", "ck", ":=", "make", "(", "[", "]", "*", "dosa", ".", "ClusteringKey", ",", "len", "(", "key", ".", "ClusteringKeys", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "key", ".", "ClusteringKeys", "{", "ck", "[", "i", "]", "=", "&", "dosa", ".", "ClusteringKey", "{", "Name", ":", "*", "v", ".", "Name", ",", "Descending", ":", "!", "*", "v", ".", "Asc", ",", "}", "\n", "}", "\n\n", "return", "&", "dosa", ".", "PrimaryKey", "{", "PartitionKeys", ":", "pk", ",", "ClusteringKeys", ":", "ck", ",", "}", "\n", "}" ]
// FromThriftToPrimaryKey converts thrift primary key type to dosa primary key type
[ "FromThriftToPrimaryKey", "converts", "thrift", "primary", "key", "type", "to", "dosa", "primary", "key", "type" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L257-L271
4,331
uber-go/dosa
connectors/yarpc/helpers.go
FromThriftToEntityDefinition
func FromThriftToEntityDefinition(ed *dosarpc.EntityDefinition) *dosa.EntityDefinition { fields := make([]*dosa.ColumnDefinition, len(ed.FieldDescs)) i := 0 for k, v := range ed.FieldDescs { fields[i] = &dosa.ColumnDefinition{ Name: k, Type: RPCTypeToClientType(*v.Type), // TODO Tag } i++ } indexes := make(map[string]*dosa.IndexDefinition) for name, index := range ed.Indexes { indexes[name] = &dosa.IndexDefinition{ Key: FromThriftToPrimaryKey(index.Key), } } etlState := dosa.EtlOff if ed.Etl != nil { etlState = fromThriftToETLState(ed.Etl) } return &dosa.EntityDefinition{ Name: *ed.Name, Columns: fields, Key: FromThriftToPrimaryKey(ed.PrimaryKey), Indexes: indexes, ETL: etlState, } }
go
func FromThriftToEntityDefinition(ed *dosarpc.EntityDefinition) *dosa.EntityDefinition { fields := make([]*dosa.ColumnDefinition, len(ed.FieldDescs)) i := 0 for k, v := range ed.FieldDescs { fields[i] = &dosa.ColumnDefinition{ Name: k, Type: RPCTypeToClientType(*v.Type), // TODO Tag } i++ } indexes := make(map[string]*dosa.IndexDefinition) for name, index := range ed.Indexes { indexes[name] = &dosa.IndexDefinition{ Key: FromThriftToPrimaryKey(index.Key), } } etlState := dosa.EtlOff if ed.Etl != nil { etlState = fromThriftToETLState(ed.Etl) } return &dosa.EntityDefinition{ Name: *ed.Name, Columns: fields, Key: FromThriftToPrimaryKey(ed.PrimaryKey), Indexes: indexes, ETL: etlState, } }
[ "func", "FromThriftToEntityDefinition", "(", "ed", "*", "dosarpc", ".", "EntityDefinition", ")", "*", "dosa", ".", "EntityDefinition", "{", "fields", ":=", "make", "(", "[", "]", "*", "dosa", ".", "ColumnDefinition", ",", "len", "(", "ed", ".", "FieldDescs", ")", ")", "\n", "i", ":=", "0", "\n", "for", "k", ",", "v", ":=", "range", "ed", ".", "FieldDescs", "{", "fields", "[", "i", "]", "=", "&", "dosa", ".", "ColumnDefinition", "{", "Name", ":", "k", ",", "Type", ":", "RPCTypeToClientType", "(", "*", "v", ".", "Type", ")", ",", "// TODO Tag", "}", "\n", "i", "++", "\n", "}", "\n\n", "indexes", ":=", "make", "(", "map", "[", "string", "]", "*", "dosa", ".", "IndexDefinition", ")", "\n", "for", "name", ",", "index", ":=", "range", "ed", ".", "Indexes", "{", "indexes", "[", "name", "]", "=", "&", "dosa", ".", "IndexDefinition", "{", "Key", ":", "FromThriftToPrimaryKey", "(", "index", ".", "Key", ")", ",", "}", "\n", "}", "\n\n", "etlState", ":=", "dosa", ".", "EtlOff", "\n", "if", "ed", ".", "Etl", "!=", "nil", "{", "etlState", "=", "fromThriftToETLState", "(", "ed", ".", "Etl", ")", "\n", "}", "\n\n", "return", "&", "dosa", ".", "EntityDefinition", "{", "Name", ":", "*", "ed", ".", "Name", ",", "Columns", ":", "fields", ",", "Key", ":", "FromThriftToPrimaryKey", "(", "ed", ".", "PrimaryKey", ")", ",", "Indexes", ":", "indexes", ",", "ETL", ":", "etlState", ",", "}", "\n", "}" ]
// FromThriftToEntityDefinition converts the RPC EntityDefinition to client EntityDefinition
[ "FromThriftToEntityDefinition", "converts", "the", "RPC", "EntityDefinition", "to", "client", "EntityDefinition" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L274-L305
4,332
uber-go/dosa
connectors/yarpc/helpers.go
getHeaders
func getHeaders(headers map[string]string) []rpc.CallOption { hdrs := make([]rpc.CallOption, 0, len(headers)+1) hdrs = append(hdrs, rpc.WithHeader(_version, dosa.VERSION)) for h, v := range headers { hdrs = append(hdrs, rpc.WithHeader(h, v)) } return hdrs }
go
func getHeaders(headers map[string]string) []rpc.CallOption { hdrs := make([]rpc.CallOption, 0, len(headers)+1) hdrs = append(hdrs, rpc.WithHeader(_version, dosa.VERSION)) for h, v := range headers { hdrs = append(hdrs, rpc.WithHeader(h, v)) } return hdrs }
[ "func", "getHeaders", "(", "headers", "map", "[", "string", "]", "string", ")", "[", "]", "rpc", ".", "CallOption", "{", "hdrs", ":=", "make", "(", "[", "]", "rpc", ".", "CallOption", ",", "0", ",", "len", "(", "headers", ")", "+", "1", ")", "\n", "hdrs", "=", "append", "(", "hdrs", ",", "rpc", ".", "WithHeader", "(", "_version", ",", "dosa", ".", "VERSION", ")", ")", "\n", "for", "h", ",", "v", ":=", "range", "headers", "{", "hdrs", "=", "append", "(", "hdrs", ",", "rpc", ".", "WithHeader", "(", "h", ",", "v", ")", ")", "\n", "}", "\n", "return", "hdrs", "\n", "}" ]
// getHeaders converts the provided headers into rpc.CallOption values. A header for Version is also added.
[ "getHeaders", "converts", "the", "provided", "headers", "into", "rpc", ".", "CallOption", "values", ".", "A", "header", "for", "Version", "is", "also", "added", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/yarpc/helpers.go#L419-L426
4,333
uber-go/dosa
registrar.go
NewRegisteredEntity
func NewRegisteredEntity(scope, namePrefix string, table *Table) *RegisteredEntity { return &RegisteredEntity{ table: table, schemaRef: &SchemaRef{ Scope: scope, NamePrefix: namePrefix, EntityName: table.Name, }, } }
go
func NewRegisteredEntity(scope, namePrefix string, table *Table) *RegisteredEntity { return &RegisteredEntity{ table: table, schemaRef: &SchemaRef{ Scope: scope, NamePrefix: namePrefix, EntityName: table.Name, }, } }
[ "func", "NewRegisteredEntity", "(", "scope", ",", "namePrefix", "string", ",", "table", "*", "Table", ")", "*", "RegisteredEntity", "{", "return", "&", "RegisteredEntity", "{", "table", ":", "table", ",", "schemaRef", ":", "&", "SchemaRef", "{", "Scope", ":", "scope", ",", "NamePrefix", ":", "namePrefix", ",", "EntityName", ":", "table", ".", "Name", ",", "}", ",", "}", "\n", "}" ]
// NewRegisteredEntity is a constructor for creating a RegisteredEntity
[ "NewRegisteredEntity", "is", "a", "constructor", "for", "creating", "a", "RegisteredEntity" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L38-L47
4,334
uber-go/dosa
registrar.go
EntityInfo
func (e *RegisteredEntity) EntityInfo() *EntityInfo { return &EntityInfo{ Ref: e.schemaRef, Def: &e.table.EntityDefinition, TTL: &e.table.TTL, } }
go
func (e *RegisteredEntity) EntityInfo() *EntityInfo { return &EntityInfo{ Ref: e.schemaRef, Def: &e.table.EntityDefinition, TTL: &e.table.TTL, } }
[ "func", "(", "e", "*", "RegisteredEntity", ")", "EntityInfo", "(", ")", "*", "EntityInfo", "{", "return", "&", "EntityInfo", "{", "Ref", ":", "e", ".", "schemaRef", ",", "Def", ":", "&", "e", ".", "table", ".", "EntityDefinition", ",", "TTL", ":", "&", "e", ".", "table", ".", "TTL", ",", "}", "\n", "}" ]
// EntityInfo is a helper for accessing the registered entity's EntityInfo // instance which is required by clients to call connector methods.
[ "EntityInfo", "is", "a", "helper", "for", "accessing", "the", "registered", "entity", "s", "EntityInfo", "instance", "which", "is", "required", "by", "clients", "to", "call", "connector", "methods", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L56-L62
4,335
uber-go/dosa
registrar.go
KeyFieldValues
func (e *RegisteredEntity) KeyFieldValues(entity DomainObject) map[string]FieldValue { v := reflect.ValueOf(entity).Elem() fieldValues := make(map[string]FieldValue) // populate partition key values for _, pk := range e.table.Key.PartitionKeys { fieldName := e.table.ColToField[pk] value := v.FieldByName(fieldName) fieldValues[pk] = value.Interface() } // populate clustering key values for _, ck := range e.table.Key.ClusteringKeys { fieldName := e.table.ColToField[ck.Name] value := v.FieldByName(fieldName) if !value.IsValid() { // this should never happen panic("Field " + fieldName + " is not a valid field for " + e.table.StructName) } fieldValues[ck.Name] = value.Interface() } return fieldValues }
go
func (e *RegisteredEntity) KeyFieldValues(entity DomainObject) map[string]FieldValue { v := reflect.ValueOf(entity).Elem() fieldValues := make(map[string]FieldValue) // populate partition key values for _, pk := range e.table.Key.PartitionKeys { fieldName := e.table.ColToField[pk] value := v.FieldByName(fieldName) fieldValues[pk] = value.Interface() } // populate clustering key values for _, ck := range e.table.Key.ClusteringKeys { fieldName := e.table.ColToField[ck.Name] value := v.FieldByName(fieldName) if !value.IsValid() { // this should never happen panic("Field " + fieldName + " is not a valid field for " + e.table.StructName) } fieldValues[ck.Name] = value.Interface() } return fieldValues }
[ "func", "(", "e", "*", "RegisteredEntity", ")", "KeyFieldValues", "(", "entity", "DomainObject", ")", "map", "[", "string", "]", "FieldValue", "{", "v", ":=", "reflect", ".", "ValueOf", "(", "entity", ")", ".", "Elem", "(", ")", "\n", "fieldValues", ":=", "make", "(", "map", "[", "string", "]", "FieldValue", ")", "\n\n", "// populate partition key values", "for", "_", ",", "pk", ":=", "range", "e", ".", "table", ".", "Key", ".", "PartitionKeys", "{", "fieldName", ":=", "e", ".", "table", ".", "ColToField", "[", "pk", "]", "\n", "value", ":=", "v", ".", "FieldByName", "(", "fieldName", ")", "\n", "fieldValues", "[", "pk", "]", "=", "value", ".", "Interface", "(", ")", "\n", "}", "\n\n", "// populate clustering key values", "for", "_", ",", "ck", ":=", "range", "e", ".", "table", ".", "Key", ".", "ClusteringKeys", "{", "fieldName", ":=", "e", ".", "table", ".", "ColToField", "[", "ck", ".", "Name", "]", "\n", "value", ":=", "v", ".", "FieldByName", "(", "fieldName", ")", "\n", "if", "!", "value", ".", "IsValid", "(", ")", "{", "// this should never happen", "panic", "(", "\"", "\"", "+", "fieldName", "+", "\"", "\"", "+", "e", ".", "table", ".", "StructName", ")", "\n", "}", "\n", "fieldValues", "[", "ck", ".", "Name", "]", "=", "value", ".", "Interface", "(", ")", "\n", "}", "\n\n", "return", "fieldValues", "\n", "}" ]
// KeyFieldValues is a helper for generating a map of field values to be used in a query.
[ "KeyFieldValues", "is", "a", "helper", "for", "generating", "a", "map", "of", "field", "values", "to", "be", "used", "in", "a", "query", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L83-L106
4,336
uber-go/dosa
registrar.go
OnlyFieldValues
func (e *RegisteredEntity) OnlyFieldValues(entity DomainObject, fieldNames []string) (map[string]FieldValue, error) { if fieldNames == nil || len(fieldNames) == 0 { for _, field := range e.table.ColToField { fieldNames = append(fieldNames, field) } } v := reflect.ValueOf(entity).Elem() fieldValues := make(map[string]FieldValue) for _, fieldName := range fieldNames { columnName, ok := e.table.FieldToCol[fieldName] if !ok { return nil, errors.Errorf("%s is not a valid field for %s", fieldName, e.table.StructName) } value := v.FieldByName(fieldName) if !value.IsValid() { // this should never happen panic("Field " + fieldName + " is not a valid field for " + e.table.StructName) } fieldValues[columnName] = value.Interface() } return fieldValues, nil }
go
func (e *RegisteredEntity) OnlyFieldValues(entity DomainObject, fieldNames []string) (map[string]FieldValue, error) { if fieldNames == nil || len(fieldNames) == 0 { for _, field := range e.table.ColToField { fieldNames = append(fieldNames, field) } } v := reflect.ValueOf(entity).Elem() fieldValues := make(map[string]FieldValue) for _, fieldName := range fieldNames { columnName, ok := e.table.FieldToCol[fieldName] if !ok { return nil, errors.Errorf("%s is not a valid field for %s", fieldName, e.table.StructName) } value := v.FieldByName(fieldName) if !value.IsValid() { // this should never happen panic("Field " + fieldName + " is not a valid field for " + e.table.StructName) } fieldValues[columnName] = value.Interface() } return fieldValues, nil }
[ "func", "(", "e", "*", "RegisteredEntity", ")", "OnlyFieldValues", "(", "entity", "DomainObject", ",", "fieldNames", "[", "]", "string", ")", "(", "map", "[", "string", "]", "FieldValue", ",", "error", ")", "{", "if", "fieldNames", "==", "nil", "||", "len", "(", "fieldNames", ")", "==", "0", "{", "for", "_", ",", "field", ":=", "range", "e", ".", "table", ".", "ColToField", "{", "fieldNames", "=", "append", "(", "fieldNames", ",", "field", ")", "\n", "}", "\n", "}", "\n", "v", ":=", "reflect", ".", "ValueOf", "(", "entity", ")", ".", "Elem", "(", ")", "\n", "fieldValues", ":=", "make", "(", "map", "[", "string", "]", "FieldValue", ")", "\n\n", "for", "_", ",", "fieldName", ":=", "range", "fieldNames", "{", "columnName", ",", "ok", ":=", "e", ".", "table", ".", "FieldToCol", "[", "fieldName", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "fieldName", ",", "e", ".", "table", ".", "StructName", ")", "\n", "}", "\n", "value", ":=", "v", ".", "FieldByName", "(", "fieldName", ")", "\n", "if", "!", "value", ".", "IsValid", "(", ")", "{", "// this should never happen", "panic", "(", "\"", "\"", "+", "fieldName", "+", "\"", "\"", "+", "e", ".", "table", ".", "StructName", ")", "\n", "}", "\n", "fieldValues", "[", "columnName", "]", "=", "value", ".", "Interface", "(", ")", "\n", "}", "\n", "return", "fieldValues", ",", "nil", "\n", "}" ]
// OnlyFieldValues is a helper for generating a map of field values for a // a subset of fields. If a field name provided does not map to an entity // field, an error will be returned.
[ "OnlyFieldValues", "is", "a", "helper", "for", "generating", "a", "map", "of", "field", "values", "for", "a", "a", "subset", "of", "fields", ".", "If", "a", "field", "name", "provided", "does", "not", "map", "to", "an", "entity", "field", "an", "error", "will", "be", "returned", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L111-L133
4,337
uber-go/dosa
registrar.go
ColumnNames
func (e *RegisteredEntity) ColumnNames(fieldNames []string) ([]string, error) { if fieldNames == nil || len(fieldNames) == 0 { for _, field := range e.table.ColToField { fieldNames = append(fieldNames, field) } } columnNames := make([]string, len(fieldNames)) for i, fieldName := range fieldNames { columnName, ok := e.table.FieldToCol[fieldName] if !ok { return nil, errors.Errorf("%s is not a valid field for %s", fieldName, e.table.StructName) } columnNames[i] = columnName } return columnNames, nil }
go
func (e *RegisteredEntity) ColumnNames(fieldNames []string) ([]string, error) { if fieldNames == nil || len(fieldNames) == 0 { for _, field := range e.table.ColToField { fieldNames = append(fieldNames, field) } } columnNames := make([]string, len(fieldNames)) for i, fieldName := range fieldNames { columnName, ok := e.table.FieldToCol[fieldName] if !ok { return nil, errors.Errorf("%s is not a valid field for %s", fieldName, e.table.StructName) } columnNames[i] = columnName } return columnNames, nil }
[ "func", "(", "e", "*", "RegisteredEntity", ")", "ColumnNames", "(", "fieldNames", "[", "]", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "fieldNames", "==", "nil", "||", "len", "(", "fieldNames", ")", "==", "0", "{", "for", "_", ",", "field", ":=", "range", "e", ".", "table", ".", "ColToField", "{", "fieldNames", "=", "append", "(", "fieldNames", ",", "field", ")", "\n", "}", "\n", "}", "\n", "columnNames", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "fieldNames", ")", ")", "\n", "for", "i", ",", "fieldName", ":=", "range", "fieldNames", "{", "columnName", ",", "ok", ":=", "e", ".", "table", ".", "FieldToCol", "[", "fieldName", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "fieldName", ",", "e", ".", "table", ".", "StructName", ")", "\n", "}", "\n", "columnNames", "[", "i", "]", "=", "columnName", "\n", "}", "\n", "return", "columnNames", ",", "nil", "\n", "}" ]
// ColumnNames translates field names to column names.
[ "ColumnNames", "translates", "field", "names", "to", "column", "names", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L136-L151
4,338
uber-go/dosa
registrar.go
SetFieldValues
func (e *RegisteredEntity) SetFieldValues(entity DomainObject, fieldValues map[string]FieldValue, fieldsToRead []string) { r := reflect.ValueOf(entity).Elem() if fieldsToRead == nil { for columnName := range fieldValues { fieldsToRead = append(fieldsToRead, columnName) } } //for columnName, fieldValue := range fieldValues { for _, columnName := range fieldsToRead { // column name may be different from the entity's field name, so we // have to look it up along the way. fieldName, ok := e.table.ColToField[columnName] if !ok { continue // we ignore fields that we don't know about } fieldValue := fieldValues[columnName] val := r.FieldByName(fieldName) if !val.IsValid() { panic("Field " + fieldName + " is is not a valid field for " + e.table.StructName) } var fv reflect.Value if fieldValue != nil { fv = reflect.ValueOf(fieldValue) } if !fv.IsValid() || fv.Kind() == reflect.Ptr && fv.IsNil() { val.Set(reflect.Zero(val.Type())) continue } switch val.Type() { case uuidType, boolType, int64Type, stringType, int32Type, doubleType, timestampType, blobType: val.Set(reflect.Indirect(fv)) case nullUUIDType, nullStringType, nullInt32Type, nullInt64Type, nullDoubleType, nullBoolType, nullTimeType: if fv.CanAddr() { val.Set(fv.Addr()) } else { val.Set(fv) } } } }
go
func (e *RegisteredEntity) SetFieldValues(entity DomainObject, fieldValues map[string]FieldValue, fieldsToRead []string) { r := reflect.ValueOf(entity).Elem() if fieldsToRead == nil { for columnName := range fieldValues { fieldsToRead = append(fieldsToRead, columnName) } } //for columnName, fieldValue := range fieldValues { for _, columnName := range fieldsToRead { // column name may be different from the entity's field name, so we // have to look it up along the way. fieldName, ok := e.table.ColToField[columnName] if !ok { continue // we ignore fields that we don't know about } fieldValue := fieldValues[columnName] val := r.FieldByName(fieldName) if !val.IsValid() { panic("Field " + fieldName + " is is not a valid field for " + e.table.StructName) } var fv reflect.Value if fieldValue != nil { fv = reflect.ValueOf(fieldValue) } if !fv.IsValid() || fv.Kind() == reflect.Ptr && fv.IsNil() { val.Set(reflect.Zero(val.Type())) continue } switch val.Type() { case uuidType, boolType, int64Type, stringType, int32Type, doubleType, timestampType, blobType: val.Set(reflect.Indirect(fv)) case nullUUIDType, nullStringType, nullInt32Type, nullInt64Type, nullDoubleType, nullBoolType, nullTimeType: if fv.CanAddr() { val.Set(fv.Addr()) } else { val.Set(fv) } } } }
[ "func", "(", "e", "*", "RegisteredEntity", ")", "SetFieldValues", "(", "entity", "DomainObject", ",", "fieldValues", "map", "[", "string", "]", "FieldValue", ",", "fieldsToRead", "[", "]", "string", ")", "{", "r", ":=", "reflect", ".", "ValueOf", "(", "entity", ")", ".", "Elem", "(", ")", "\n", "if", "fieldsToRead", "==", "nil", "{", "for", "columnName", ":=", "range", "fieldValues", "{", "fieldsToRead", "=", "append", "(", "fieldsToRead", ",", "columnName", ")", "\n", "}", "\n", "}", "\n", "//for columnName, fieldValue := range fieldValues {", "for", "_", ",", "columnName", ":=", "range", "fieldsToRead", "{", "// column name may be different from the entity's field name, so we", "// have to look it up along the way.", "fieldName", ",", "ok", ":=", "e", ".", "table", ".", "ColToField", "[", "columnName", "]", "\n", "if", "!", "ok", "{", "continue", "// we ignore fields that we don't know about", "\n", "}", "\n", "fieldValue", ":=", "fieldValues", "[", "columnName", "]", "\n", "val", ":=", "r", ".", "FieldByName", "(", "fieldName", ")", "\n", "if", "!", "val", ".", "IsValid", "(", ")", "{", "panic", "(", "\"", "\"", "+", "fieldName", "+", "\"", "\"", "+", "e", ".", "table", ".", "StructName", ")", "\n", "}", "\n\n", "var", "fv", "reflect", ".", "Value", "\n", "if", "fieldValue", "!=", "nil", "{", "fv", "=", "reflect", ".", "ValueOf", "(", "fieldValue", ")", "\n", "}", "\n", "if", "!", "fv", ".", "IsValid", "(", ")", "||", "fv", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "&&", "fv", ".", "IsNil", "(", ")", "{", "val", ".", "Set", "(", "reflect", ".", "Zero", "(", "val", ".", "Type", "(", ")", ")", ")", "\n", "continue", "\n", "}", "\n\n", "switch", "val", ".", "Type", "(", ")", "{", "case", "uuidType", ",", "boolType", ",", "int64Type", ",", "stringType", ",", "int32Type", ",", "doubleType", ",", "timestampType", ",", "blobType", ":", "val", ".", "Set", "(", "reflect", ".", "Indirect", "(", "fv", ")", ")", "\n", "case", "nullUUIDType", ",", "nullStringType", ",", "nullInt32Type", ",", "nullInt64Type", ",", "nullDoubleType", ",", "nullBoolType", ",", "nullTimeType", ":", "if", "fv", ".", "CanAddr", "(", ")", "{", "val", ".", "Set", "(", "fv", ".", "Addr", "(", ")", ")", "\n", "}", "else", "{", "val", ".", "Set", "(", "fv", ")", "\n", "}", "\n", "}", "\n\n", "}", "\n", "}" ]
// SetFieldValues is a helper for populating a DOSA entity with the given // fieldName->value map
[ "SetFieldValues", "is", "a", "helper", "for", "populating", "a", "DOSA", "entity", "with", "the", "given", "fieldName", "-", ">", "value", "map" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L155-L197
4,339
uber-go/dosa
registrar.go
NewRegistrar
func NewRegistrar(scope, namePrefix string, entities ...DomainObject) (Registrar, error) { if err := IsValidNamePrefix(namePrefix); err != nil { return nil, errors.Wrap(err, "failed to construct Registrar") } typeIndex := make(map[reflect.Type]*RegisteredEntity) for _, e := range entities { table, err := TableFromInstance(e) if err != nil { return nil, errors.Wrapf(err, "failed to register entity") } // use entity type as internal lookup key typ := reflect.TypeOf(e).Elem() // create instance and index it re := NewRegisteredEntity(scope, namePrefix, table) typeIndex[typ] = re } return &prefixedRegistrar{ scope: scope, namePrefix: namePrefix, typeIndex: typeIndex, }, nil }
go
func NewRegistrar(scope, namePrefix string, entities ...DomainObject) (Registrar, error) { if err := IsValidNamePrefix(namePrefix); err != nil { return nil, errors.Wrap(err, "failed to construct Registrar") } typeIndex := make(map[reflect.Type]*RegisteredEntity) for _, e := range entities { table, err := TableFromInstance(e) if err != nil { return nil, errors.Wrapf(err, "failed to register entity") } // use entity type as internal lookup key typ := reflect.TypeOf(e).Elem() // create instance and index it re := NewRegisteredEntity(scope, namePrefix, table) typeIndex[typ] = re } return &prefixedRegistrar{ scope: scope, namePrefix: namePrefix, typeIndex: typeIndex, }, nil }
[ "func", "NewRegistrar", "(", "scope", ",", "namePrefix", "string", ",", "entities", "...", "DomainObject", ")", "(", "Registrar", ",", "error", ")", "{", "if", "err", ":=", "IsValidNamePrefix", "(", "namePrefix", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "typeIndex", ":=", "make", "(", "map", "[", "reflect", ".", "Type", "]", "*", "RegisteredEntity", ")", "\n\n", "for", "_", ",", "e", ":=", "range", "entities", "{", "table", ",", "err", ":=", "TableFromInstance", "(", "e", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// use entity type as internal lookup key", "typ", ":=", "reflect", ".", "TypeOf", "(", "e", ")", ".", "Elem", "(", ")", "\n\n", "// create instance and index it", "re", ":=", "NewRegisteredEntity", "(", "scope", ",", "namePrefix", ",", "table", ")", "\n", "typeIndex", "[", "typ", "]", "=", "re", "\n", "}", "\n\n", "return", "&", "prefixedRegistrar", "{", "scope", ":", "scope", ",", "namePrefix", ":", "namePrefix", ",", "typeIndex", ":", "typeIndex", ",", "}", ",", "nil", "\n", "}" ]
// NewRegistrar returns a new Registrar for the scope, name prefix and // entities provided. `dosa.Client` implementations are intended to use scope // and prefix to uniquely identify where entities should live but the // registrar itself is only responsible for basic accounting of entities.
[ "NewRegistrar", "returns", "a", "new", "Registrar", "for", "the", "scope", "name", "prefix", "and", "entities", "provided", ".", "dosa", ".", "Client", "implementations", "are", "intended", "to", "use", "scope", "and", "prefix", "to", "uniquely", "identify", "where", "entities", "should", "live", "but", "the", "registrar", "itself", "is", "only", "responsible", "for", "basic", "accounting", "of", "entities", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L221-L246
4,340
uber-go/dosa
registrar.go
Find
func (r *prefixedRegistrar) Find(entity DomainObject) (*RegisteredEntity, error) { t := reflect.TypeOf(entity).Elem() re, ok := r.typeIndex[t] if !ok { return nil, errors.Errorf("failed to find registration for entity %q", t.Name()) } return re, nil }
go
func (r *prefixedRegistrar) Find(entity DomainObject) (*RegisteredEntity, error) { t := reflect.TypeOf(entity).Elem() re, ok := r.typeIndex[t] if !ok { return nil, errors.Errorf("failed to find registration for entity %q", t.Name()) } return re, nil }
[ "func", "(", "r", "*", "prefixedRegistrar", ")", "Find", "(", "entity", "DomainObject", ")", "(", "*", "RegisteredEntity", ",", "error", ")", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "entity", ")", ".", "Elem", "(", ")", "\n", "re", ",", "ok", ":=", "r", ".", "typeIndex", "[", "t", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "t", ".", "Name", "(", ")", ")", "\n", "}", "\n", "return", "re", ",", "nil", "\n", "}" ]
// Find looks at its internal index to find a registration that matches the // entity instance provided. Return an error when not found.
[ "Find", "looks", "at", "its", "internal", "index", "to", "find", "a", "registration", "that", "matches", "the", "entity", "instance", "provided", ".", "Return", "an", "error", "when", "not", "found", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L260-L267
4,341
uber-go/dosa
registrar.go
FindAll
func (r *prefixedRegistrar) FindAll() []*RegisteredEntity { res := []*RegisteredEntity{} for _, re := range r.typeIndex { res = append(res, re) } return res }
go
func (r *prefixedRegistrar) FindAll() []*RegisteredEntity { res := []*RegisteredEntity{} for _, re := range r.typeIndex { res = append(res, re) } return res }
[ "func", "(", "r", "*", "prefixedRegistrar", ")", "FindAll", "(", ")", "[", "]", "*", "RegisteredEntity", "{", "res", ":=", "[", "]", "*", "RegisteredEntity", "{", "}", "\n", "for", "_", ",", "re", ":=", "range", "r", ".", "typeIndex", "{", "res", "=", "append", "(", "res", ",", "re", ")", "\n", "}", "\n", "return", "res", "\n", "}" ]
// FindAll returns all registered entities from its internal index.
[ "FindAll", "returns", "all", "registered", "entities", "from", "its", "internal", "index", "." ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/registrar.go#L270-L276
4,342
uber-go/dosa
connectors/redis/redigo.go
NewRedigoClient
func NewRedigoClient(config ServerConfig, scope metrics.Scope) SimpleRedis { c := &simpleRedis{config: config, stats: metrics.CheckIfNilStats(scope)} c.pool = &redis.Pool{ MaxActive: config.MaxActive, MaxIdle: config.MaxIdle, IdleTimeout: config.IdleTimeout, Dial: func() (redis.Conn, error) { c, err := redis.Dial( "tcp", c.getURL(), redis.DialConnectTimeout(config.ConnectTimeout), redis.DialReadTimeout(config.ReadTimeout), redis.DialWriteTimeout(config.WriteTimeout)) if err != nil { return nil, err } return c, err }, Wait: false, } return c }
go
func NewRedigoClient(config ServerConfig, scope metrics.Scope) SimpleRedis { c := &simpleRedis{config: config, stats: metrics.CheckIfNilStats(scope)} c.pool = &redis.Pool{ MaxActive: config.MaxActive, MaxIdle: config.MaxIdle, IdleTimeout: config.IdleTimeout, Dial: func() (redis.Conn, error) { c, err := redis.Dial( "tcp", c.getURL(), redis.DialConnectTimeout(config.ConnectTimeout), redis.DialReadTimeout(config.ReadTimeout), redis.DialWriteTimeout(config.WriteTimeout)) if err != nil { return nil, err } return c, err }, Wait: false, } return c }
[ "func", "NewRedigoClient", "(", "config", "ServerConfig", ",", "scope", "metrics", ".", "Scope", ")", "SimpleRedis", "{", "c", ":=", "&", "simpleRedis", "{", "config", ":", "config", ",", "stats", ":", "metrics", ".", "CheckIfNilStats", "(", "scope", ")", "}", "\n", "c", ".", "pool", "=", "&", "redis", ".", "Pool", "{", "MaxActive", ":", "config", ".", "MaxActive", ",", "MaxIdle", ":", "config", ".", "MaxIdle", ",", "IdleTimeout", ":", "config", ".", "IdleTimeout", ",", "Dial", ":", "func", "(", ")", "(", "redis", ".", "Conn", ",", "error", ")", "{", "c", ",", "err", ":=", "redis", ".", "Dial", "(", "\"", "\"", ",", "c", ".", "getURL", "(", ")", ",", "redis", ".", "DialConnectTimeout", "(", "config", ".", "ConnectTimeout", ")", ",", "redis", ".", "DialReadTimeout", "(", "config", ".", "ReadTimeout", ")", ",", "redis", ".", "DialWriteTimeout", "(", "config", ".", "WriteTimeout", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "c", ",", "err", "\n", "}", ",", "Wait", ":", "false", ",", "}", "\n", "return", "c", "\n", "}" ]
// NewRedigoClient returns a redigo implementation of SimpleRedis
[ "NewRedigoClient", "returns", "a", "redigo", "implementation", "of", "SimpleRedis" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redigo.go#L33-L54
4,343
uber-go/dosa
connectors/redis/redigo.go
Get
func (c *simpleRedis) Get(key string) ([]byte, error) { bytes, err := redis.Bytes(c.do("GET", key)) if err == redis.ErrNil { err = &dosa.ErrNotFound{} } return bytes, err }
go
func (c *simpleRedis) Get(key string) ([]byte, error) { bytes, err := redis.Bytes(c.do("GET", key)) if err == redis.ErrNil { err = &dosa.ErrNotFound{} } return bytes, err }
[ "func", "(", "c", "*", "simpleRedis", ")", "Get", "(", "key", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "bytes", ",", "err", ":=", "redis", ".", "Bytes", "(", "c", ".", "do", "(", "\"", "\"", ",", "key", ")", ")", "\n", "if", "err", "==", "redis", ".", "ErrNil", "{", "err", "=", "&", "dosa", ".", "ErrNotFound", "{", "}", "\n", "}", "\n", "return", "bytes", ",", "err", "\n", "}" ]
// Get returns an error if the key is not found in cache
[ "Get", "returns", "an", "error", "if", "the", "key", "is", "not", "found", "in", "cache" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redigo.go#L67-L73
4,344
uber-go/dosa
connectors/redis/redigo.go
do
func (c *simpleRedis) do(commandName string, args ...interface{}) (interface{}, error) { t := c.stats.SubScope("redis").SubScope("latency").Timer(commandName) t.Start() defer t.Stop() conn := c.pool.Get() defer func() { _ = conn.Close() }() return conn.Do(commandName, args...) }
go
func (c *simpleRedis) do(commandName string, args ...interface{}) (interface{}, error) { t := c.stats.SubScope("redis").SubScope("latency").Timer(commandName) t.Start() defer t.Stop() conn := c.pool.Get() defer func() { _ = conn.Close() }() return conn.Do(commandName, args...) }
[ "func", "(", "c", "*", "simpleRedis", ")", "do", "(", "commandName", "string", ",", "args", "...", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "t", ":=", "c", ".", "stats", ".", "SubScope", "(", "\"", "\"", ")", ".", "SubScope", "(", "\"", "\"", ")", ".", "Timer", "(", "commandName", ")", "\n", "t", ".", "Start", "(", ")", "\n", "defer", "t", ".", "Stop", "(", ")", "\n\n", "conn", ":=", "c", ".", "pool", ".", "Get", "(", ")", "\n", "defer", "func", "(", ")", "{", "_", "=", "conn", ".", "Close", "(", ")", "}", "(", ")", "\n", "return", "conn", ".", "Do", "(", "commandName", ",", "args", "...", ")", "\n", "}" ]
// Do is a proxy method that calls Redigo's `Do` method and returns its output. It remembers // to close connections taken from the pool
[ "Do", "is", "a", "proxy", "method", "that", "calls", "Redigo", "s", "Do", "method", "and", "returns", "its", "output", ".", "It", "remembers", "to", "close", "connections", "taken", "from", "the", "pool" ]
18f7766015f97d726635fc75b21c93ec270e5ac5
https://github.com/uber-go/dosa/blob/18f7766015f97d726635fc75b21c93ec270e5ac5/connectors/redis/redigo.go#L92-L100
4,345
ligato/cn-infra
messaging/chan.go
ToProtoMsgChan
func ToProtoMsgChan(ch chan ProtoMessage, opts ...interface{}) func(ProtoMessage) { timeout, logger := ParseOpts(opts...) return func(msg ProtoMessage) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
go
func ToProtoMsgChan(ch chan ProtoMessage, opts ...interface{}) func(ProtoMessage) { timeout, logger := ParseOpts(opts...) return func(msg ProtoMessage) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
[ "func", "ToProtoMsgChan", "(", "ch", "chan", "ProtoMessage", ",", "opts", "...", "interface", "{", "}", ")", "func", "(", "ProtoMessage", ")", "{", "timeout", ",", "logger", ":=", "ParseOpts", "(", "opts", "...", ")", "\n\n", "return", "func", "(", "msg", "ProtoMessage", ")", "{", "select", "{", "case", "ch", "<-", "msg", ":", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "logger", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ToProtoMsgChan allows to receive messages through channel instead of callback.
[ "ToProtoMsgChan", "allows", "to", "receive", "messages", "through", "channel", "instead", "of", "callback", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/chan.go#L28-L39
4,346
ligato/cn-infra
messaging/chan.go
ToProtoMsgErrChan
func ToProtoMsgErrChan(ch chan ProtoMessageErr, opts ...interface{}) func(ProtoMessageErr) { timeout, logger := ParseOpts(opts...) return func(msg ProtoMessageErr) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
go
func ToProtoMsgErrChan(ch chan ProtoMessageErr, opts ...interface{}) func(ProtoMessageErr) { timeout, logger := ParseOpts(opts...) return func(msg ProtoMessageErr) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
[ "func", "ToProtoMsgErrChan", "(", "ch", "chan", "ProtoMessageErr", ",", "opts", "...", "interface", "{", "}", ")", "func", "(", "ProtoMessageErr", ")", "{", "timeout", ",", "logger", ":=", "ParseOpts", "(", "opts", "...", ")", "\n\n", "return", "func", "(", "msg", "ProtoMessageErr", ")", "{", "select", "{", "case", "ch", "<-", "msg", ":", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "logger", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ToProtoMsgErrChan allows to receive error messages through channel instead // of callback.
[ "ToProtoMsgErrChan", "allows", "to", "receive", "error", "messages", "through", "channel", "instead", "of", "callback", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/chan.go#L43-L54
4,347
ligato/cn-infra
messaging/chan.go
ParseOpts
func ParseOpts(opts ...interface{}) (time.Duration, logging.Logger) { timeout := DefaultMsgTimeout var logger logging.Logger = logrus.DefaultLogger() for _, opt := range opts { switch opt.(type) { case *WithLoggerOpt: logger = opt.(*WithLoggerOpt).logger case *WithTimeoutOpt: timeout = opt.(*WithTimeoutOpt).timeout } } return timeout, logger }
go
func ParseOpts(opts ...interface{}) (time.Duration, logging.Logger) { timeout := DefaultMsgTimeout var logger logging.Logger = logrus.DefaultLogger() for _, opt := range opts { switch opt.(type) { case *WithLoggerOpt: logger = opt.(*WithLoggerOpt).logger case *WithTimeoutOpt: timeout = opt.(*WithTimeoutOpt).timeout } } return timeout, logger }
[ "func", "ParseOpts", "(", "opts", "...", "interface", "{", "}", ")", "(", "time", ".", "Duration", ",", "logging", ".", "Logger", ")", "{", "timeout", ":=", "DefaultMsgTimeout", "\n", "var", "logger", "logging", ".", "Logger", "=", "logrus", ".", "DefaultLogger", "(", ")", "\n\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "switch", "opt", ".", "(", "type", ")", "{", "case", "*", "WithLoggerOpt", ":", "logger", "=", "opt", ".", "(", "*", "WithLoggerOpt", ")", ".", "logger", "\n", "case", "*", "WithTimeoutOpt", ":", "timeout", "=", "opt", ".", "(", "*", "WithTimeoutOpt", ")", ".", "timeout", "\n", "}", "\n", "}", "\n", "return", "timeout", ",", "logger", "\n\n", "}" ]
// ParseOpts returns timeout and logger to be used based on the given options.
[ "ParseOpts", "returns", "timeout", "and", "logger", "to", "be", "used", "based", "on", "the", "given", "options", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/chan.go#L57-L71
4,348
ligato/cn-infra
processmanager/plugin.go
Init
func (p *Plugin) Init() error { p.Log.Debugf("Initializing process manager plugin") templatePath, err := p.getPMConfig() if err != nil { return err } if templatePath != "" { if p.tReader, err = template.NewTemplateReader(templatePath, p.Log); err != nil { return nil } templates, err := p.tReader.GetAllTemplates() if err != nil { return err } for _, tmp := range templates { pr := p.NewProcessFromTemplate(tmp) if pr == nil { continue } if tmp.POptions != nil && tmp.POptions.RunOnStartup { if err = pr.Start(); err != nil { p.Log.Errorf("failed to start template process %s: %v", tmp.Name, err) continue } } } } return nil }
go
func (p *Plugin) Init() error { p.Log.Debugf("Initializing process manager plugin") templatePath, err := p.getPMConfig() if err != nil { return err } if templatePath != "" { if p.tReader, err = template.NewTemplateReader(templatePath, p.Log); err != nil { return nil } templates, err := p.tReader.GetAllTemplates() if err != nil { return err } for _, tmp := range templates { pr := p.NewProcessFromTemplate(tmp) if pr == nil { continue } if tmp.POptions != nil && tmp.POptions.RunOnStartup { if err = pr.Start(); err != nil { p.Log.Errorf("failed to start template process %s: %v", tmp.Name, err) continue } } } } return nil }
[ "func", "(", "p", "*", "Plugin", ")", "Init", "(", ")", "error", "{", "p", ".", "Log", ".", "Debugf", "(", "\"", "\"", ")", "\n\n", "templatePath", ",", "err", ":=", "p", ".", "getPMConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "templatePath", "!=", "\"", "\"", "{", "if", "p", ".", "tReader", ",", "err", "=", "template", ".", "NewTemplateReader", "(", "templatePath", ",", "p", ".", "Log", ")", ";", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "templates", ",", "err", ":=", "p", ".", "tReader", ".", "GetAllTemplates", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "tmp", ":=", "range", "templates", "{", "pr", ":=", "p", ".", "NewProcessFromTemplate", "(", "tmp", ")", "\n", "if", "pr", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "tmp", ".", "POptions", "!=", "nil", "&&", "tmp", ".", "POptions", ".", "RunOnStartup", "{", "if", "err", "=", "pr", ".", "Start", "(", ")", ";", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "tmp", ".", "Name", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Init reads plugin config file for process template path. If exists, plugin initializes template reader, reads // all existing templates and initializes them. Those marked as 'run on startup' are immediately started
[ "Init", "reads", "plugin", "config", "file", "for", "process", "template", "path", ".", "If", "exists", "plugin", "initializes", "template", "reader", "reads", "all", "existing", "templates", "and", "initializes", "them", ".", "Those", "marked", "as", "run", "on", "startup", "are", "immediately", "started" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L80-L111
4,349
ligato/cn-infra
processmanager/plugin.go
AttachProcess
func (p *Plugin) AttachProcess(name string, cmd string, pid int, options ...POption) (ProcessInstance, error) { pr, err := os.FindProcess(pid) if err != nil { return nil, errors.Errorf("cannot attach to process with PID %d: %v", pid, err) } attachedPr := &Process{ log: p.Log, name: name, cmd: cmd, options: &POptions{}, command: &exec.Cmd{Process: pr}, sh: &status.Reader{Log: p.Log}, cancelChan: make(chan struct{}), } for _, option := range options { option(attachedPr.options) } p.processes = append(p.processes, attachedPr) attachedPr.status, err = attachedPr.sh.ReadStatusFromPID(attachedPr.GetPid()) if err != nil { p.Log.Warnf("failed to read process (PID %d) status: %v", pid, err) } go attachedPr.watch() if attachedPr.options.template { p.writeAsTemplate(attachedPr) } return attachedPr, nil }
go
func (p *Plugin) AttachProcess(name string, cmd string, pid int, options ...POption) (ProcessInstance, error) { pr, err := os.FindProcess(pid) if err != nil { return nil, errors.Errorf("cannot attach to process with PID %d: %v", pid, err) } attachedPr := &Process{ log: p.Log, name: name, cmd: cmd, options: &POptions{}, command: &exec.Cmd{Process: pr}, sh: &status.Reader{Log: p.Log}, cancelChan: make(chan struct{}), } for _, option := range options { option(attachedPr.options) } p.processes = append(p.processes, attachedPr) attachedPr.status, err = attachedPr.sh.ReadStatusFromPID(attachedPr.GetPid()) if err != nil { p.Log.Warnf("failed to read process (PID %d) status: %v", pid, err) } go attachedPr.watch() if attachedPr.options.template { p.writeAsTemplate(attachedPr) } return attachedPr, nil }
[ "func", "(", "p", "*", "Plugin", ")", "AttachProcess", "(", "name", "string", ",", "cmd", "string", ",", "pid", "int", ",", "options", "...", "POption", ")", "(", "ProcessInstance", ",", "error", ")", "{", "pr", ",", "err", ":=", "os", ".", "FindProcess", "(", "pid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "pid", ",", "err", ")", "\n", "}", "\n", "attachedPr", ":=", "&", "Process", "{", "log", ":", "p", ".", "Log", ",", "name", ":", "name", ",", "cmd", ":", "cmd", ",", "options", ":", "&", "POptions", "{", "}", ",", "command", ":", "&", "exec", ".", "Cmd", "{", "Process", ":", "pr", "}", ",", "sh", ":", "&", "status", ".", "Reader", "{", "Log", ":", "p", ".", "Log", "}", ",", "cancelChan", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "for", "_", ",", "option", ":=", "range", "options", "{", "option", "(", "attachedPr", ".", "options", ")", "\n", "}", "\n", "p", ".", "processes", "=", "append", "(", "p", ".", "processes", ",", "attachedPr", ")", "\n\n", "attachedPr", ".", "status", ",", "err", "=", "attachedPr", ".", "sh", ".", "ReadStatusFromPID", "(", "attachedPr", ".", "GetPid", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Warnf", "(", "\"", "\"", ",", "pid", ",", "err", ")", "\n", "}", "\n\n", "go", "attachedPr", ".", "watch", "(", ")", "\n\n", "if", "attachedPr", ".", "options", ".", "template", "{", "p", ".", "writeAsTemplate", "(", "attachedPr", ")", "\n", "}", "\n\n", "return", "attachedPr", ",", "nil", "\n", "}" ]
// AttachProcess attaches to existing process, reads its status and starts process status watcher
[ "AttachProcess", "attaches", "to", "existing", "process", "reads", "its", "status", "and", "starts", "process", "status", "watcher" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L130-L161
4,350
ligato/cn-infra
processmanager/plugin.go
NewProcess
func (p *Plugin) NewProcess(name, cmd string, options ...POption) ProcessInstance { newPr := &Process{ log: p.Log, name: name, cmd: cmd, options: &POptions{}, sh: &status.Reader{Log: p.Log}, status: &status.File{ State: status.Initial, }, cancelChan: make(chan struct{}), } for _, option := range options { option(newPr.options) } p.processes = append(p.processes, newPr) if newPr.options.template { p.writeAsTemplate(newPr) } return newPr }
go
func (p *Plugin) NewProcess(name, cmd string, options ...POption) ProcessInstance { newPr := &Process{ log: p.Log, name: name, cmd: cmd, options: &POptions{}, sh: &status.Reader{Log: p.Log}, status: &status.File{ State: status.Initial, }, cancelChan: make(chan struct{}), } for _, option := range options { option(newPr.options) } p.processes = append(p.processes, newPr) if newPr.options.template { p.writeAsTemplate(newPr) } return newPr }
[ "func", "(", "p", "*", "Plugin", ")", "NewProcess", "(", "name", ",", "cmd", "string", ",", "options", "...", "POption", ")", "ProcessInstance", "{", "newPr", ":=", "&", "Process", "{", "log", ":", "p", ".", "Log", ",", "name", ":", "name", ",", "cmd", ":", "cmd", ",", "options", ":", "&", "POptions", "{", "}", ",", "sh", ":", "&", "status", ".", "Reader", "{", "Log", ":", "p", ".", "Log", "}", ",", "status", ":", "&", "status", ".", "File", "{", "State", ":", "status", ".", "Initial", ",", "}", ",", "cancelChan", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "for", "_", ",", "option", ":=", "range", "options", "{", "option", "(", "newPr", ".", "options", ")", "\n", "}", "\n", "p", ".", "processes", "=", "append", "(", "p", ".", "processes", ",", "newPr", ")", "\n\n", "if", "newPr", ".", "options", ".", "template", "{", "p", ".", "writeAsTemplate", "(", "newPr", ")", "\n", "}", "\n\n", "return", "newPr", "\n", "}" ]
// NewProcess creates a new process and saves its template if required
[ "NewProcess", "creates", "a", "new", "process", "and", "saves", "its", "template", "if", "required" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L164-L186
4,351
ligato/cn-infra
processmanager/plugin.go
NewProcessFromTemplate
func (p *Plugin) NewProcessFromTemplate(tmp *process.Template) ProcessInstance { newTmpPr, err := p.templateToProcess(tmp) if err != nil { p.Log.Errorf("cannot create a process from template: %v", err) return nil } p.processes = append(p.processes, newTmpPr) go newTmpPr.watch() return newTmpPr }
go
func (p *Plugin) NewProcessFromTemplate(tmp *process.Template) ProcessInstance { newTmpPr, err := p.templateToProcess(tmp) if err != nil { p.Log.Errorf("cannot create a process from template: %v", err) return nil } p.processes = append(p.processes, newTmpPr) go newTmpPr.watch() return newTmpPr }
[ "func", "(", "p", "*", "Plugin", ")", "NewProcessFromTemplate", "(", "tmp", "*", "process", ".", "Template", ")", "ProcessInstance", "{", "newTmpPr", ",", "err", ":=", "p", ".", "templateToProcess", "(", "tmp", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "p", ".", "processes", "=", "append", "(", "p", ".", "processes", ",", "newTmpPr", ")", "\n\n", "go", "newTmpPr", ".", "watch", "(", ")", "\n\n", "return", "newTmpPr", "\n", "}" ]
// NewProcessFromTemplate creates a new process from template file
[ "NewProcessFromTemplate", "creates", "a", "new", "process", "from", "template", "file" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L189-L200
4,352
ligato/cn-infra
processmanager/plugin.go
GetProcessByName
func (p *Plugin) GetProcessByName(name string) ProcessInstance { for _, pr := range p.processes { if pr.name == name { return pr } } return nil }
go
func (p *Plugin) GetProcessByName(name string) ProcessInstance { for _, pr := range p.processes { if pr.name == name { return pr } } return nil }
[ "func", "(", "p", "*", "Plugin", ")", "GetProcessByName", "(", "name", "string", ")", "ProcessInstance", "{", "for", "_", ",", "pr", ":=", "range", "p", ".", "processes", "{", "if", "pr", ".", "name", "==", "name", "{", "return", "pr", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetProcessByName uses process name to find a desired instance
[ "GetProcessByName", "uses", "process", "name", "to", "find", "a", "desired", "instance" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L203-L210
4,353
ligato/cn-infra
processmanager/plugin.go
GetProcessByPID
func (p *Plugin) GetProcessByPID(pid int) ProcessInstance { for _, pr := range p.processes { if pr.status.Pid == pid { return pr } } return nil }
go
func (p *Plugin) GetProcessByPID(pid int) ProcessInstance { for _, pr := range p.processes { if pr.status.Pid == pid { return pr } } return nil }
[ "func", "(", "p", "*", "Plugin", ")", "GetProcessByPID", "(", "pid", "int", ")", "ProcessInstance", "{", "for", "_", ",", "pr", ":=", "range", "p", ".", "processes", "{", "if", "pr", ".", "status", ".", "Pid", "==", "pid", "{", "return", "pr", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetProcessByPID uses process ID to find a desired instance
[ "GetProcessByPID", "uses", "process", "ID", "to", "find", "a", "desired", "instance" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L213-L220
4,354
ligato/cn-infra
processmanager/plugin.go
GetAllProcesses
func (p *Plugin) GetAllProcesses() []ProcessInstance { var processes []ProcessInstance for _, pr := range p.processes { processes = append(processes, pr) } return processes }
go
func (p *Plugin) GetAllProcesses() []ProcessInstance { var processes []ProcessInstance for _, pr := range p.processes { processes = append(processes, pr) } return processes }
[ "func", "(", "p", "*", "Plugin", ")", "GetAllProcesses", "(", ")", "[", "]", "ProcessInstance", "{", "var", "processes", "[", "]", "ProcessInstance", "\n", "for", "_", ",", "pr", ":=", "range", "p", ".", "processes", "{", "processes", "=", "append", "(", "processes", ",", "pr", ")", "\n", "}", "\n", "return", "processes", "\n", "}" ]
// GetAllProcesses returns all processes known to plugin
[ "GetAllProcesses", "returns", "all", "processes", "known", "to", "plugin" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L223-L229
4,355
ligato/cn-infra
processmanager/plugin.go
Delete
func (p *Plugin) Delete(name string) error { var updated []*Process for _, pr := range p.processes { if pr.name == name { if err := pr.deleteProcess(); err != nil { return err } } else { updated = append(updated, pr) } } p.processes = updated return nil }
go
func (p *Plugin) Delete(name string) error { var updated []*Process for _, pr := range p.processes { if pr.name == name { if err := pr.deleteProcess(); err != nil { return err } } else { updated = append(updated, pr) } } p.processes = updated return nil }
[ "func", "(", "p", "*", "Plugin", ")", "Delete", "(", "name", "string", ")", "error", "{", "var", "updated", "[", "]", "*", "Process", "\n", "for", "_", ",", "pr", ":=", "range", "p", ".", "processes", "{", "if", "pr", ".", "name", "==", "name", "{", "if", "err", ":=", "pr", ".", "deleteProcess", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "updated", "=", "append", "(", "updated", ",", "pr", ")", "\n", "}", "\n", "}", "\n\n", "p", ".", "processes", "=", "updated", "\n\n", "return", "nil", "\n", "}" ]
// Delete releases the process resources and removes it from the plugin cache
[ "Delete", "releases", "the", "process", "resources", "and", "removes", "it", "from", "the", "plugin", "cache" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L232-L247
4,356
ligato/cn-infra
processmanager/plugin.go
GetTemplate
func (p *Plugin) GetTemplate(name string) (*process.Template, error) { if p.tReader == nil { return nil, errors.Errorf("cannot read process template %s: reader is nil (no path was defined)", name) } templates, err := p.tReader.GetAllTemplates() if err != nil { return nil, err } for _, tmp := range templates { if tmp.Name == name { return tmp, nil } } return nil, nil }
go
func (p *Plugin) GetTemplate(name string) (*process.Template, error) { if p.tReader == nil { return nil, errors.Errorf("cannot read process template %s: reader is nil (no path was defined)", name) } templates, err := p.tReader.GetAllTemplates() if err != nil { return nil, err } for _, tmp := range templates { if tmp.Name == name { return tmp, nil } } return nil, nil }
[ "func", "(", "p", "*", "Plugin", ")", "GetTemplate", "(", "name", "string", ")", "(", "*", "process", ".", "Template", ",", "error", ")", "{", "if", "p", ".", "tReader", "==", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "templates", ",", "err", ":=", "p", ".", "tReader", ".", "GetAllTemplates", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "tmp", ":=", "range", "templates", "{", "if", "tmp", ".", "Name", "==", "name", "{", "return", "tmp", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// GetTemplate returns template with given name
[ "GetTemplate", "returns", "template", "with", "given", "name" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L250-L264
4,357
ligato/cn-infra
processmanager/plugin.go
GetAllTemplates
func (p *Plugin) GetAllTemplates() ([]*process.Template, error) { if p.tReader == nil { return nil, errors.Errorf("cannot read process templates: reader is nil (no path was defined)") } return p.tReader.GetAllTemplates() }
go
func (p *Plugin) GetAllTemplates() ([]*process.Template, error) { if p.tReader == nil { return nil, errors.Errorf("cannot read process templates: reader is nil (no path was defined)") } return p.tReader.GetAllTemplates() }
[ "func", "(", "p", "*", "Plugin", ")", "GetAllTemplates", "(", ")", "(", "[", "]", "*", "process", ".", "Template", ",", "error", ")", "{", "if", "p", ".", "tReader", "==", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "p", ".", "tReader", ".", "GetAllTemplates", "(", ")", "\n", "}" ]
// GetAllTemplates returns all templates
[ "GetAllTemplates", "returns", "all", "templates" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L267-L272
4,358
ligato/cn-infra
processmanager/plugin.go
getPMConfig
func (p *Plugin) getPMConfig() (path string, err error) { var pmConfig Config found, err := p.Cfg.LoadValue(&pmConfig) if err != nil { return path, errors.Errorf("failed to read process manager config file: %v", err) } if found { return pmConfig.TemplatePath, nil } return path, nil }
go
func (p *Plugin) getPMConfig() (path string, err error) { var pmConfig Config found, err := p.Cfg.LoadValue(&pmConfig) if err != nil { return path, errors.Errorf("failed to read process manager config file: %v", err) } if found { return pmConfig.TemplatePath, nil } return path, nil }
[ "func", "(", "p", "*", "Plugin", ")", "getPMConfig", "(", ")", "(", "path", "string", ",", "err", "error", ")", "{", "var", "pmConfig", "Config", "\n", "found", ",", "err", ":=", "p", ".", "Cfg", ".", "LoadValue", "(", "&", "pmConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "path", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "found", "{", "return", "pmConfig", ".", "TemplatePath", ",", "nil", "\n", "}", "\n", "return", "path", ",", "nil", "\n", "}" ]
// Reads plugin config file
[ "Reads", "plugin", "config", "file" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L275-L285
4,359
ligato/cn-infra
processmanager/plugin.go
writeAsTemplate
func (p *Plugin) writeAsTemplate(pr *Process) { tmp, err := p.processToTemplate(pr) if err != nil { p.Log.Errorf("cannot create a template from process: %v", err) return } if p.tReader == nil { p.Log.Warnf("process %s should write a new template, but reader (template path) is not defined", pr.name) return } if err = p.tReader.WriteTemplate(tmp, template.DefaultMode); err != nil { p.Log.Warnf("failed to write template %s: %v", tmp.Name, err) return } }
go
func (p *Plugin) writeAsTemplate(pr *Process) { tmp, err := p.processToTemplate(pr) if err != nil { p.Log.Errorf("cannot create a template from process: %v", err) return } if p.tReader == nil { p.Log.Warnf("process %s should write a new template, but reader (template path) is not defined", pr.name) return } if err = p.tReader.WriteTemplate(tmp, template.DefaultMode); err != nil { p.Log.Warnf("failed to write template %s: %v", tmp.Name, err) return } }
[ "func", "(", "p", "*", "Plugin", ")", "writeAsTemplate", "(", "pr", "*", "Process", ")", "{", "tmp", ",", "err", ":=", "p", ".", "processToTemplate", "(", "pr", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "if", "p", ".", "tReader", "==", "nil", "{", "p", ".", "Log", ".", "Warnf", "(", "\"", "\"", ",", "pr", ".", "name", ")", "\n", "return", "\n", "}", "\n", "if", "err", "=", "p", ".", "tReader", ".", "WriteTemplate", "(", "tmp", ",", "template", ".", "DefaultMode", ")", ";", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Warnf", "(", "\"", "\"", ",", "tmp", ".", "Name", ",", "err", ")", "\n", "return", "\n", "}", "\n", "}" ]
// Writes process as template to the filesystem. Errors are logged but not returned
[ "Writes", "process", "as", "template", "to", "the", "filesystem", ".", "Errors", "are", "logged", "but", "not", "returned" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L288-L303
4,360
ligato/cn-infra
processmanager/plugin.go
processToTemplate
func (p *Plugin) processToTemplate(pr *Process) (*process.Template, error) { if pr.name == "" { return nil, errors.Errorf("cannot create template from process, missing name") } if pr.cmd == "" { return nil, errors.Errorf("cannot create template from process, missing command") } pOptions := &process.TemplatePOptions{ Args: pr.options.args, Restart: pr.options.restart, OutWriter: func(w io.Writer) bool { return w != nil }(pr.options.outWriter), ErrWriter: func(w io.Writer) bool { return w != nil }(pr.options.errWriter), Detach: pr.options.detach, RunOnStartup: pr.options.runOnStartup, Notify: func(notifyChan chan status.ProcessStatus) bool { if notifyChan == nil { return false } return true }(pr.options.notifyChan), AutoTerminate: pr.options.autoTerm, } return &process.Template{ Name: pr.name, Cmd: pr.cmd, POptions: pOptions, }, nil }
go
func (p *Plugin) processToTemplate(pr *Process) (*process.Template, error) { if pr.name == "" { return nil, errors.Errorf("cannot create template from process, missing name") } if pr.cmd == "" { return nil, errors.Errorf("cannot create template from process, missing command") } pOptions := &process.TemplatePOptions{ Args: pr.options.args, Restart: pr.options.restart, OutWriter: func(w io.Writer) bool { return w != nil }(pr.options.outWriter), ErrWriter: func(w io.Writer) bool { return w != nil }(pr.options.errWriter), Detach: pr.options.detach, RunOnStartup: pr.options.runOnStartup, Notify: func(notifyChan chan status.ProcessStatus) bool { if notifyChan == nil { return false } return true }(pr.options.notifyChan), AutoTerminate: pr.options.autoTerm, } return &process.Template{ Name: pr.name, Cmd: pr.cmd, POptions: pOptions, }, nil }
[ "func", "(", "p", "*", "Plugin", ")", "processToTemplate", "(", "pr", "*", "Process", ")", "(", "*", "process", ".", "Template", ",", "error", ")", "{", "if", "pr", ".", "name", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "pr", ".", "cmd", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "pOptions", ":=", "&", "process", ".", "TemplatePOptions", "{", "Args", ":", "pr", ".", "options", ".", "args", ",", "Restart", ":", "pr", ".", "options", ".", "restart", ",", "OutWriter", ":", "func", "(", "w", "io", ".", "Writer", ")", "bool", "{", "return", "w", "!=", "nil", "\n", "}", "(", "pr", ".", "options", ".", "outWriter", ")", ",", "ErrWriter", ":", "func", "(", "w", "io", ".", "Writer", ")", "bool", "{", "return", "w", "!=", "nil", "\n", "}", "(", "pr", ".", "options", ".", "errWriter", ")", ",", "Detach", ":", "pr", ".", "options", ".", "detach", ",", "RunOnStartup", ":", "pr", ".", "options", ".", "runOnStartup", ",", "Notify", ":", "func", "(", "notifyChan", "chan", "status", ".", "ProcessStatus", ")", "bool", "{", "if", "notifyChan", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}", "(", "pr", ".", "options", ".", "notifyChan", ")", ",", "AutoTerminate", ":", "pr", ".", "options", ".", "autoTerm", ",", "}", "\n\n", "return", "&", "process", ".", "Template", "{", "Name", ":", "pr", ".", "name", ",", "Cmd", ":", "pr", ".", "cmd", ",", "POptions", ":", "pOptions", ",", "}", ",", "nil", "\n", "}" ]
// Create a template object from process. A name and a command are mandatory
[ "Create", "a", "template", "object", "from", "process", ".", "A", "name", "and", "a", "command", "are", "mandatory" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L306-L339
4,361
ligato/cn-infra
processmanager/plugin.go
templateToProcess
func (p *Plugin) templateToProcess(tmp *process.Template) (*Process, error) { if tmp.Name == "" { return nil, errors.Errorf("cannot create process from template, missing name") } if tmp.Cmd == "" { return nil, errors.Errorf("cannot create process from template, missing command") } pOptions := &POptions{} if tmp.POptions != nil { pOptions.args = tmp.POptions.Args pOptions.outWriter = func(isSet bool) io.Writer { if isSet { return os.Stdout } return nil }(tmp.POptions.OutWriter) pOptions.errWriter = func(isSet bool) io.Writer { if isSet { return os.Stderr } return nil }(tmp.POptions.ErrWriter) pOptions.detach = tmp.POptions.Detach pOptions.restart = tmp.POptions.Restart pOptions.runOnStartup = tmp.POptions.RunOnStartup pOptions.notifyChan = func(notify bool) chan status.ProcessStatus { if notify { return make(chan status.ProcessStatus) } return nil }(tmp.POptions.Notify) pOptions.autoTerm = tmp.POptions.AutoTerminate } return &Process{ log: p.Log, name: tmp.Name, cmd: tmp.Cmd, options: pOptions, sh: &status.Reader{Log: p.Log}, status: &status.File{ State: status.Initial, }, cancelChan: make(chan struct{}), }, nil }
go
func (p *Plugin) templateToProcess(tmp *process.Template) (*Process, error) { if tmp.Name == "" { return nil, errors.Errorf("cannot create process from template, missing name") } if tmp.Cmd == "" { return nil, errors.Errorf("cannot create process from template, missing command") } pOptions := &POptions{} if tmp.POptions != nil { pOptions.args = tmp.POptions.Args pOptions.outWriter = func(isSet bool) io.Writer { if isSet { return os.Stdout } return nil }(tmp.POptions.OutWriter) pOptions.errWriter = func(isSet bool) io.Writer { if isSet { return os.Stderr } return nil }(tmp.POptions.ErrWriter) pOptions.detach = tmp.POptions.Detach pOptions.restart = tmp.POptions.Restart pOptions.runOnStartup = tmp.POptions.RunOnStartup pOptions.notifyChan = func(notify bool) chan status.ProcessStatus { if notify { return make(chan status.ProcessStatus) } return nil }(tmp.POptions.Notify) pOptions.autoTerm = tmp.POptions.AutoTerminate } return &Process{ log: p.Log, name: tmp.Name, cmd: tmp.Cmd, options: pOptions, sh: &status.Reader{Log: p.Log}, status: &status.File{ State: status.Initial, }, cancelChan: make(chan struct{}), }, nil }
[ "func", "(", "p", "*", "Plugin", ")", "templateToProcess", "(", "tmp", "*", "process", ".", "Template", ")", "(", "*", "Process", ",", "error", ")", "{", "if", "tmp", ".", "Name", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "tmp", ".", "Cmd", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "pOptions", ":=", "&", "POptions", "{", "}", "\n", "if", "tmp", ".", "POptions", "!=", "nil", "{", "pOptions", ".", "args", "=", "tmp", ".", "POptions", ".", "Args", "\n", "pOptions", ".", "outWriter", "=", "func", "(", "isSet", "bool", ")", "io", ".", "Writer", "{", "if", "isSet", "{", "return", "os", ".", "Stdout", "\n", "}", "\n", "return", "nil", "\n", "}", "(", "tmp", ".", "POptions", ".", "OutWriter", ")", "\n", "pOptions", ".", "errWriter", "=", "func", "(", "isSet", "bool", ")", "io", ".", "Writer", "{", "if", "isSet", "{", "return", "os", ".", "Stderr", "\n", "}", "\n", "return", "nil", "\n", "}", "(", "tmp", ".", "POptions", ".", "ErrWriter", ")", "\n", "pOptions", ".", "detach", "=", "tmp", ".", "POptions", ".", "Detach", "\n", "pOptions", ".", "restart", "=", "tmp", ".", "POptions", ".", "Restart", "\n", "pOptions", ".", "runOnStartup", "=", "tmp", ".", "POptions", ".", "RunOnStartup", "\n", "pOptions", ".", "notifyChan", "=", "func", "(", "notify", "bool", ")", "chan", "status", ".", "ProcessStatus", "{", "if", "notify", "{", "return", "make", "(", "chan", "status", ".", "ProcessStatus", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "(", "tmp", ".", "POptions", ".", "Notify", ")", "\n", "pOptions", ".", "autoTerm", "=", "tmp", ".", "POptions", ".", "AutoTerminate", "\n", "}", "\n\n", "return", "&", "Process", "{", "log", ":", "p", ".", "Log", ",", "name", ":", "tmp", ".", "Name", ",", "cmd", ":", "tmp", ".", "Cmd", ",", "options", ":", "pOptions", ",", "sh", ":", "&", "status", ".", "Reader", "{", "Log", ":", "p", ".", "Log", "}", ",", "status", ":", "&", "status", ".", "File", "{", "State", ":", "status", ".", "Initial", ",", "}", ",", "cancelChan", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", ",", "nil", "\n", "}" ]
// Create a process object from template. A name and a command are mandatory
[ "Create", "a", "process", "object", "from", "template", ".", "A", "name", "and", "a", "command", "are", "mandatory" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/processmanager/plugin.go#L342-L388
4,362
ligato/cn-infra
db/keyval/bolt/plugin.go
OnConnect
func (p *Plugin) OnConnect(callback func() error) { if err := callback(); err != nil { p.Log.Error(err) } }
go
func (p *Plugin) OnConnect(callback func() error) { if err := callback(); err != nil { p.Log.Error(err) } }
[ "func", "(", "p", "*", "Plugin", ")", "OnConnect", "(", "callback", "func", "(", ")", "error", ")", "{", "if", "err", ":=", "callback", "(", ")", ";", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Error", "(", "err", ")", "\n", "}", "\n", "}" ]
// OnConnect executes callback from datasync
[ "OnConnect", "executes", "callback", "from", "datasync" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/bolt/plugin.go#L59-L63
4,363
ligato/cn-infra
db/keyval/bolt/plugin.go
Init
func (p *Plugin) Init() (err error) { if p.Config == nil { p.Config, err = p.getConfig() if err != nil || p.disabled { return err } } p.boltClient, err = NewClient(p.Config) if err != nil { p.Log.Errorf("Err: %v", err) return err } p.protoWrapper = kvproto.NewProtoWrapper(p.boltClient, &keyval.SerializerJSON{}) p.Log.Infof("BoltDB started with: %v", p.Config.DbPath) return nil }
go
func (p *Plugin) Init() (err error) { if p.Config == nil { p.Config, err = p.getConfig() if err != nil || p.disabled { return err } } p.boltClient, err = NewClient(p.Config) if err != nil { p.Log.Errorf("Err: %v", err) return err } p.protoWrapper = kvproto.NewProtoWrapper(p.boltClient, &keyval.SerializerJSON{}) p.Log.Infof("BoltDB started with: %v", p.Config.DbPath) return nil }
[ "func", "(", "p", "*", "Plugin", ")", "Init", "(", ")", "(", "err", "error", ")", "{", "if", "p", ".", "Config", "==", "nil", "{", "p", ".", "Config", ",", "err", "=", "p", ".", "getConfig", "(", ")", "\n", "if", "err", "!=", "nil", "||", "p", ".", "disabled", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "p", ".", "boltClient", ",", "err", "=", "NewClient", "(", "p", ".", "Config", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "p", ".", "protoWrapper", "=", "kvproto", ".", "NewProtoWrapper", "(", "p", ".", "boltClient", ",", "&", "keyval", ".", "SerializerJSON", "{", "}", ")", "\n\n", "p", ".", "Log", ".", "Infof", "(", "\"", "\"", ",", "p", ".", "Config", ".", "DbPath", ")", "\n\n", "return", "nil", "\n", "}" ]
// Init initializes Bolt plugin.
[ "Init", "initializes", "Bolt", "plugin", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/bolt/plugin.go#L66-L85
4,364
ligato/cn-infra
db/keyval/bolt/plugin.go
Close
func (p *Plugin) Close() error { if p.boltClient != nil { return p.boltClient.Close() } return nil }
go
func (p *Plugin) Close() error { if p.boltClient != nil { return p.boltClient.Close() } return nil }
[ "func", "(", "p", "*", "Plugin", ")", "Close", "(", ")", "error", "{", "if", "p", ".", "boltClient", "!=", "nil", "{", "return", "p", ".", "boltClient", ".", "Close", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close closes the Bolt client.
[ "Close", "closes", "the", "Bolt", "client", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/bolt/plugin.go#L88-L93
4,365
ligato/cn-infra
db/keyval/bolt/plugin.go
NewBroker
func (p *Plugin) NewBroker(keyPrefix string) keyval.ProtoBroker { return p.protoWrapper.NewBroker(keyPrefix) }
go
func (p *Plugin) NewBroker(keyPrefix string) keyval.ProtoBroker { return p.protoWrapper.NewBroker(keyPrefix) }
[ "func", "(", "p", "*", "Plugin", ")", "NewBroker", "(", "keyPrefix", "string", ")", "keyval", ".", "ProtoBroker", "{", "return", "p", ".", "protoWrapper", ".", "NewBroker", "(", "keyPrefix", ")", "\n", "}" ]
// NewBroker creates new instance of prefixed broker that provides API with arguments of type proto.Message.
[ "NewBroker", "creates", "new", "instance", "of", "prefixed", "broker", "that", "provides", "API", "with", "arguments", "of", "type", "proto", ".", "Message", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/bolt/plugin.go#L96-L98
4,366
ligato/cn-infra
db/keyval/bolt/plugin.go
NewWatcher
func (p *Plugin) NewWatcher(keyPrefix string) keyval.ProtoWatcher { return p.protoWrapper.NewWatcher(keyPrefix) }
go
func (p *Plugin) NewWatcher(keyPrefix string) keyval.ProtoWatcher { return p.protoWrapper.NewWatcher(keyPrefix) }
[ "func", "(", "p", "*", "Plugin", ")", "NewWatcher", "(", "keyPrefix", "string", ")", "keyval", ".", "ProtoWatcher", "{", "return", "p", ".", "protoWrapper", ".", "NewWatcher", "(", "keyPrefix", ")", "\n", "}" ]
// NewWatcher creates new instance of prefixed broker that provides API with arguments of type proto.Message.
[ "NewWatcher", "creates", "new", "instance", "of", "prefixed", "broker", "that", "provides", "API", "with", "arguments", "of", "type", "proto", ".", "Message", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/bolt/plugin.go#L101-L103
4,367
ligato/cn-infra
examples/etcd-lib/editor/editor.go
processArgs
func processArgs() (cfg *etcd.ClientConfig, op int, data []string, err error) { var task []string // default args fileConfig := &etcd.Config{} op = Put if len(os.Args) > 2 { if os.Args[1] == "--cfg" { err = config.ParseConfigFromYamlFile(os.Args[2], fileConfig) if err != nil { return } cfg, err = etcd.ConfigToClient(fileConfig) if err != nil { return } task = os.Args[3:] } else { task = os.Args[1:] } } else { return cfg, 0, nil, fmt.Errorf("incorrect arguments") } if len(task) < 2 || (task[0] == "put" && len(task) < 4) { return cfg, 0, nil, fmt.Errorf("incorrect arguments") } if task[0] == "delete" { op = Delete } else if task[0] == "puttxn" { op = PutTxn } return cfg, op, task[1:], nil }
go
func processArgs() (cfg *etcd.ClientConfig, op int, data []string, err error) { var task []string // default args fileConfig := &etcd.Config{} op = Put if len(os.Args) > 2 { if os.Args[1] == "--cfg" { err = config.ParseConfigFromYamlFile(os.Args[2], fileConfig) if err != nil { return } cfg, err = etcd.ConfigToClient(fileConfig) if err != nil { return } task = os.Args[3:] } else { task = os.Args[1:] } } else { return cfg, 0, nil, fmt.Errorf("incorrect arguments") } if len(task) < 2 || (task[0] == "put" && len(task) < 4) { return cfg, 0, nil, fmt.Errorf("incorrect arguments") } if task[0] == "delete" { op = Delete } else if task[0] == "puttxn" { op = PutTxn } return cfg, op, task[1:], nil }
[ "func", "processArgs", "(", ")", "(", "cfg", "*", "etcd", ".", "ClientConfig", ",", "op", "int", ",", "data", "[", "]", "string", ",", "err", "error", ")", "{", "var", "task", "[", "]", "string", "\n\n", "// default args", "fileConfig", ":=", "&", "etcd", ".", "Config", "{", "}", "\n", "op", "=", "Put", "\n\n", "if", "len", "(", "os", ".", "Args", ")", ">", "2", "{", "if", "os", ".", "Args", "[", "1", "]", "==", "\"", "\"", "{", "err", "=", "config", ".", "ParseConfigFromYamlFile", "(", "os", ".", "Args", "[", "2", "]", ",", "fileConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "cfg", ",", "err", "=", "etcd", ".", "ConfigToClient", "(", "fileConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "task", "=", "os", ".", "Args", "[", "3", ":", "]", "\n", "}", "else", "{", "task", "=", "os", ".", "Args", "[", "1", ":", "]", "\n", "}", "\n", "}", "else", "{", "return", "cfg", ",", "0", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "task", ")", "<", "2", "||", "(", "task", "[", "0", "]", "==", "\"", "\"", "&&", "len", "(", "task", ")", "<", "4", ")", "{", "return", "cfg", ",", "0", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "task", "[", "0", "]", "==", "\"", "\"", "{", "op", "=", "Delete", "\n", "}", "else", "if", "task", "[", "0", "]", "==", "\"", "\"", "{", "op", "=", "PutTxn", "\n", "}", "\n\n", "return", "cfg", ",", "op", ",", "task", "[", "1", ":", "]", ",", "nil", "\n", "}" ]
// processArgs processes input arguments.
[ "processArgs", "processes", "input", "arguments", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/etcd-lib/editor/editor.go#L27-L64
4,368
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
Close
func (db *BytesConnectionRedis) Close() error { if db.closed { db.Debug("Close() called on a closed connection") return nil } db.Debug("Close()") db.closed = true safeclose.Close(db.closeCh) if db.client != nil { err := safeclose.Close(db.client) if err != nil { return fmt.Errorf("Close() encountered error: %s", err) } } return nil }
go
func (db *BytesConnectionRedis) Close() error { if db.closed { db.Debug("Close() called on a closed connection") return nil } db.Debug("Close()") db.closed = true safeclose.Close(db.closeCh) if db.client != nil { err := safeclose.Close(db.client) if err != nil { return fmt.Errorf("Close() encountered error: %s", err) } } return nil }
[ "func", "(", "db", "*", "BytesConnectionRedis", ")", "Close", "(", ")", "error", "{", "if", "db", ".", "closed", "{", "db", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "db", ".", "Debug", "(", "\"", "\"", ")", "\n", "db", ".", "closed", "=", "true", "\n", "safeclose", ".", "Close", "(", "db", ".", "closeCh", ")", "\n", "if", "db", ".", "client", "!=", "nil", "{", "err", ":=", "safeclose", ".", "Close", "(", "db", ".", "client", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Close closes the connection to redis.
[ "Close", "closes", "the", "connection", "to", "redis", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L72-L87
4,369
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
GetValue
func (db *BytesConnectionRedis) GetValue(key string) (data []byte, found bool, revision int64, err error) { if db.closed { return nil, false, 0, fmt.Errorf("GetValue(%s) called on a closed connection", key) } db.Debugf("GetValue(%s)", key) statusCmd := db.client.Get(key) data, err = statusCmd.Bytes() if err != nil { if err == GoRedisNil { return data, false, 0, nil } return nil, false, 0, fmt.Errorf("Get(%s) failed: %s", key, err) } return data, true, 0, nil }
go
func (db *BytesConnectionRedis) GetValue(key string) (data []byte, found bool, revision int64, err error) { if db.closed { return nil, false, 0, fmt.Errorf("GetValue(%s) called on a closed connection", key) } db.Debugf("GetValue(%s)", key) statusCmd := db.client.Get(key) data, err = statusCmd.Bytes() if err != nil { if err == GoRedisNil { return data, false, 0, nil } return nil, false, 0, fmt.Errorf("Get(%s) failed: %s", key, err) } return data, true, 0, nil }
[ "func", "(", "db", "*", "BytesConnectionRedis", ")", "GetValue", "(", "key", "string", ")", "(", "data", "[", "]", "byte", ",", "found", "bool", ",", "revision", "int64", ",", "err", "error", ")", "{", "if", "db", ".", "closed", "{", "return", "nil", ",", "false", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n", "db", ".", "Debugf", "(", "\"", "\"", ",", "key", ")", "\n\n", "statusCmd", ":=", "db", ".", "client", ".", "Get", "(", "key", ")", "\n", "data", ",", "err", "=", "statusCmd", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "GoRedisNil", "{", "return", "data", ",", "false", ",", "0", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "false", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ",", "err", ")", "\n", "}", "\n", "return", "data", ",", "true", ",", "0", ",", "nil", "\n", "}" ]
// GetValue retrieves the value of the key from Redis.
[ "GetValue", "retrieves", "the", "value", "of", "the", "key", "from", "Redis", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L121-L136
4,370
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
Delete
func (db *BytesConnectionRedis) Delete(key string, opts ...datasync.DelOption) (found bool, err error) { if db.closed { return false, fmt.Errorf("Delete(%s) called on a closed connection", key) } db.Debugf("Delete(%s)", key) keysToDelete := []string{} var keyIsPrefix bool for _, o := range opts { if _, ok := o.(*datasync.WithPrefixOpt); ok { keyIsPrefix = true } } if keyIsPrefix { iterator, err := db.ListKeys(key) if err != nil { return false, err } for { k, _, last := iterator.GetNext() if last { break } keysToDelete = append(keysToDelete, k) } if len(keysToDelete) == 0 { return false, nil } db.Debugf("Delete(%s): deleting %v", key, keysToDelete) } else { keysToDelete = append(keysToDelete, key) } intCmd := db.client.Del(keysToDelete...) if intCmd.Err() != nil { return false, fmt.Errorf("Delete(%s) failed: %s", key, intCmd.Err()) } return (intCmd.Val() != 0), nil }
go
func (db *BytesConnectionRedis) Delete(key string, opts ...datasync.DelOption) (found bool, err error) { if db.closed { return false, fmt.Errorf("Delete(%s) called on a closed connection", key) } db.Debugf("Delete(%s)", key) keysToDelete := []string{} var keyIsPrefix bool for _, o := range opts { if _, ok := o.(*datasync.WithPrefixOpt); ok { keyIsPrefix = true } } if keyIsPrefix { iterator, err := db.ListKeys(key) if err != nil { return false, err } for { k, _, last := iterator.GetNext() if last { break } keysToDelete = append(keysToDelete, k) } if len(keysToDelete) == 0 { return false, nil } db.Debugf("Delete(%s): deleting %v", key, keysToDelete) } else { keysToDelete = append(keysToDelete, key) } intCmd := db.client.Del(keysToDelete...) if intCmd.Err() != nil { return false, fmt.Errorf("Delete(%s) failed: %s", key, intCmd.Err()) } return (intCmd.Val() != 0), nil }
[ "func", "(", "db", "*", "BytesConnectionRedis", ")", "Delete", "(", "key", "string", ",", "opts", "...", "datasync", ".", "DelOption", ")", "(", "found", "bool", ",", "err", "error", ")", "{", "if", "db", ".", "closed", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n", "db", ".", "Debugf", "(", "\"", "\"", ",", "key", ")", "\n\n", "keysToDelete", ":=", "[", "]", "string", "{", "}", "\n\n", "var", "keyIsPrefix", "bool", "\n", "for", "_", ",", "o", ":=", "range", "opts", "{", "if", "_", ",", "ok", ":=", "o", ".", "(", "*", "datasync", ".", "WithPrefixOpt", ")", ";", "ok", "{", "keyIsPrefix", "=", "true", "\n", "}", "\n", "}", "\n", "if", "keyIsPrefix", "{", "iterator", ",", "err", ":=", "db", ".", "ListKeys", "(", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "for", "{", "k", ",", "_", ",", "last", ":=", "iterator", ".", "GetNext", "(", ")", "\n", "if", "last", "{", "break", "\n", "}", "\n", "keysToDelete", "=", "append", "(", "keysToDelete", ",", "k", ")", "\n", "}", "\n", "if", "len", "(", "keysToDelete", ")", "==", "0", "{", "return", "false", ",", "nil", "\n", "}", "\n", "db", ".", "Debugf", "(", "\"", "\"", ",", "key", ",", "keysToDelete", ")", "\n", "}", "else", "{", "keysToDelete", "=", "append", "(", "keysToDelete", ",", "key", ")", "\n", "}", "\n\n", "intCmd", ":=", "db", ".", "client", ".", "Del", "(", "keysToDelete", "...", ")", "\n", "if", "intCmd", ".", "Err", "(", ")", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ",", "intCmd", ".", "Err", "(", ")", ")", "\n", "}", "\n", "return", "(", "intCmd", ".", "Val", "(", ")", "!=", "0", ")", ",", "nil", "\n", "}" ]
// Delete deletes all the keys that start with the given match string.
[ "Delete", "deletes", "all", "the", "keys", "that", "start", "with", "the", "given", "match", "string", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L157-L196
4,371
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
NewTxn
func (pdb *BytesBrokerWatcherRedis) NewTxn() keyval.BytesTxn { if pdb.delegate.closed { pdb.Error("NewTxn() called on a closed connection") return nil } pdb.Debug("NewTxn()") return &Txn{db: pdb.delegate, ops: []op{}, addPrefix: pdb.addPrefix} }
go
func (pdb *BytesBrokerWatcherRedis) NewTxn() keyval.BytesTxn { if pdb.delegate.closed { pdb.Error("NewTxn() called on a closed connection") return nil } pdb.Debug("NewTxn()") return &Txn{db: pdb.delegate, ops: []op{}, addPrefix: pdb.addPrefix} }
[ "func", "(", "pdb", "*", "BytesBrokerWatcherRedis", ")", "NewTxn", "(", ")", "keyval", ".", "BytesTxn", "{", "if", "pdb", ".", "delegate", ".", "closed", "{", "pdb", ".", "Error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "pdb", ".", "Debug", "(", "\"", "\"", ")", "\n\n", "return", "&", "Txn", "{", "db", ":", "pdb", ".", "delegate", ",", "ops", ":", "[", "]", "op", "{", "}", ",", "addPrefix", ":", "pdb", ".", "addPrefix", "}", "\n", "}" ]
// NewTxn creates new transaction. Prefix will be prepended to the key argument.
[ "NewTxn", "creates", "new", "transaction", ".", "Prefix", "will", "be", "prepended", "to", "the", "key", "argument", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L450-L458
4,372
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
Put
func (pdb *BytesBrokerWatcherRedis) Put(key string, data []byte, opts ...datasync.PutOption) error { if pdb.delegate.closed { return fmt.Errorf("Put(%s) called on a closed connection", key) } pdb.Debugf("Put(%s)", key) return pdb.delegate.Put(pdb.addPrefix(key), data, opts...) }
go
func (pdb *BytesBrokerWatcherRedis) Put(key string, data []byte, opts ...datasync.PutOption) error { if pdb.delegate.closed { return fmt.Errorf("Put(%s) called on a closed connection", key) } pdb.Debugf("Put(%s)", key) return pdb.delegate.Put(pdb.addPrefix(key), data, opts...) }
[ "func", "(", "pdb", "*", "BytesBrokerWatcherRedis", ")", "Put", "(", "key", "string", ",", "data", "[", "]", "byte", ",", "opts", "...", "datasync", ".", "PutOption", ")", "error", "{", "if", "pdb", ".", "delegate", ".", "closed", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n", "pdb", ".", "Debugf", "(", "\"", "\"", ",", "key", ")", "\n\n", "return", "pdb", ".", "delegate", ".", "Put", "(", "pdb", ".", "addPrefix", "(", "key", ")", ",", "data", ",", "opts", "...", ")", "\n", "}" ]
// Put calls Put function of BytesConnectionRedis. Prefix will be prepended to the key argument.
[ "Put", "calls", "Put", "function", "of", "BytesConnectionRedis", ".", "Prefix", "will", "be", "prepended", "to", "the", "key", "argument", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L461-L468
4,373
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
GetValue
func (pdb *BytesBrokerWatcherRedis) GetValue(key string) (data []byte, found bool, revision int64, err error) { if pdb.delegate.closed { return nil, false, 0, fmt.Errorf("GetValue(%s) called on a closed connection", key) } pdb.Debugf("GetValue(%s)", key) return pdb.delegate.GetValue(pdb.addPrefix(key)) }
go
func (pdb *BytesBrokerWatcherRedis) GetValue(key string) (data []byte, found bool, revision int64, err error) { if pdb.delegate.closed { return nil, false, 0, fmt.Errorf("GetValue(%s) called on a closed connection", key) } pdb.Debugf("GetValue(%s)", key) return pdb.delegate.GetValue(pdb.addPrefix(key)) }
[ "func", "(", "pdb", "*", "BytesBrokerWatcherRedis", ")", "GetValue", "(", "key", "string", ")", "(", "data", "[", "]", "byte", ",", "found", "bool", ",", "revision", "int64", ",", "err", "error", ")", "{", "if", "pdb", ".", "delegate", ".", "closed", "{", "return", "nil", ",", "false", ",", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "\n", "pdb", ".", "Debugf", "(", "\"", "\"", ",", "key", ")", "\n\n", "return", "pdb", ".", "delegate", ".", "GetValue", "(", "pdb", ".", "addPrefix", "(", "key", ")", ")", "\n", "}" ]
// GetValue calls GetValue function of BytesConnectionRedis. // Prefix will be prepended to the key argument when searching.
[ "GetValue", "calls", "GetValue", "function", "of", "BytesConnectionRedis", ".", "Prefix", "will", "be", "prepended", "to", "the", "key", "argument", "when", "searching", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L472-L479
4,374
ligato/cn-infra
db/keyval/redis/bytes_broker_impl.go
Delete
func (pdb *BytesBrokerWatcherRedis) Delete(match string, opts ...datasync.DelOption) (found bool, err error) { if pdb.delegate.closed { return false, fmt.Errorf("Delete(%s) called on a closed connection", match) } pdb.Debugf("Delete(%s)", match) return pdb.delegate.Delete(pdb.addPrefix(match), opts...) }
go
func (pdb *BytesBrokerWatcherRedis) Delete(match string, opts ...datasync.DelOption) (found bool, err error) { if pdb.delegate.closed { return false, fmt.Errorf("Delete(%s) called on a closed connection", match) } pdb.Debugf("Delete(%s)", match) return pdb.delegate.Delete(pdb.addPrefix(match), opts...) }
[ "func", "(", "pdb", "*", "BytesBrokerWatcherRedis", ")", "Delete", "(", "match", "string", ",", "opts", "...", "datasync", ".", "DelOption", ")", "(", "found", "bool", ",", "err", "error", ")", "{", "if", "pdb", ".", "delegate", ".", "closed", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "match", ")", "\n", "}", "\n", "pdb", ".", "Debugf", "(", "\"", "\"", ",", "match", ")", "\n\n", "return", "pdb", ".", "delegate", ".", "Delete", "(", "pdb", ".", "addPrefix", "(", "match", ")", ",", "opts", "...", ")", "\n", "}" ]
// Delete calls Delete function of BytesConnectionRedis. // Prefix will be prepended to key argument when searching.
[ "Delete", "calls", "Delete", "function", "of", "BytesConnectionRedis", ".", "Prefix", "will", "be", "prepended", "to", "key", "argument", "when", "searching", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/redis/bytes_broker_impl.go#L505-L512
4,375
ligato/cn-infra
datasync/resync/plugin_impl_resync.go
Init
func (p *Plugin) Init() error { p.registrations = make(map[string]*registration) return nil }
go
func (p *Plugin) Init() error { p.registrations = make(map[string]*registration) return nil }
[ "func", "(", "p", "*", "Plugin", ")", "Init", "(", ")", "error", "{", "p", ".", "registrations", "=", "make", "(", "map", "[", "string", "]", "*", "registration", ")", "\n", "return", "nil", "\n", "}" ]
// Init initializes variables.
[ "Init", "initializes", "variables", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/resync/plugin_impl_resync.go#L50-L53
4,376
ligato/cn-infra
examples/redis-plugin/main.go
AfterInit
func (plugin *ExamplePlugin) AfterInit() (err error) { db := plugin.DB.NewBroker(keyval.Root) db.ListKeys(keyval.Root) return nil }
go
func (plugin *ExamplePlugin) AfterInit() (err error) { db := plugin.DB.NewBroker(keyval.Root) db.ListKeys(keyval.Root) return nil }
[ "func", "(", "plugin", "*", "ExamplePlugin", ")", "AfterInit", "(", ")", "(", "err", "error", ")", "{", "db", ":=", "plugin", ".", "DB", ".", "NewBroker", "(", "keyval", ".", "Root", ")", "\n", "db", ".", "ListKeys", "(", "keyval", ".", "Root", ")", "\n\n", "return", "nil", "\n", "}" ]
// AfterInit is meant to use DB if needed
[ "AfterInit", "is", "meant", "to", "use", "DB", "if", "needed" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/redis-plugin/main.go#L75-L80
4,377
ligato/cn-infra
messaging/kafka/mux/chan.go
ToBytesMsgChan
func ToBytesMsgChan(ch chan *client.ConsumerMessage, opts ...interface{}) func(*client.ConsumerMessage) { timeout, logger := messaging.ParseOpts(opts...) return func(msg *client.ConsumerMessage) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
go
func ToBytesMsgChan(ch chan *client.ConsumerMessage, opts ...interface{}) func(*client.ConsumerMessage) { timeout, logger := messaging.ParseOpts(opts...) return func(msg *client.ConsumerMessage) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
[ "func", "ToBytesMsgChan", "(", "ch", "chan", "*", "client", ".", "ConsumerMessage", ",", "opts", "...", "interface", "{", "}", ")", "func", "(", "*", "client", ".", "ConsumerMessage", ")", "{", "timeout", ",", "logger", ":=", "messaging", ".", "ParseOpts", "(", "opts", "...", ")", "\n\n", "return", "func", "(", "msg", "*", "client", ".", "ConsumerMessage", ")", "{", "select", "{", "case", "ch", "<-", "msg", ":", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "logger", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ToBytesMsgChan allows to receive ConsumerMessage through channel. This function can be used as an argument for // ConsumeTopic call.
[ "ToBytesMsgChan", "allows", "to", "receive", "ConsumerMessage", "through", "channel", ".", "This", "function", "can", "be", "used", "as", "an", "argument", "for", "ConsumeTopic", "call", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/chan.go#L25-L36
4,378
ligato/cn-infra
messaging/kafka/mux/chan.go
ToBytesProducerChan
func ToBytesProducerChan(ch chan *client.ProducerMessage, opts ...interface{}) func(*client.ProducerMessage) { timeout, logger := messaging.ParseOpts(opts...) return func(msg *client.ProducerMessage) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
go
func ToBytesProducerChan(ch chan *client.ProducerMessage, opts ...interface{}) func(*client.ProducerMessage) { timeout, logger := messaging.ParseOpts(opts...) return func(msg *client.ProducerMessage) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
[ "func", "ToBytesProducerChan", "(", "ch", "chan", "*", "client", ".", "ProducerMessage", ",", "opts", "...", "interface", "{", "}", ")", "func", "(", "*", "client", ".", "ProducerMessage", ")", "{", "timeout", ",", "logger", ":=", "messaging", ".", "ParseOpts", "(", "opts", "...", ")", "\n\n", "return", "func", "(", "msg", "*", "client", ".", "ProducerMessage", ")", "{", "select", "{", "case", "ch", "<-", "msg", ":", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "logger", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ToBytesProducerChan allows to receive ProducerMessage through channel. This function can be used as an argument for // methods publishing using async API.
[ "ToBytesProducerChan", "allows", "to", "receive", "ProducerMessage", "through", "channel", ".", "This", "function", "can", "be", "used", "as", "an", "argument", "for", "methods", "publishing", "using", "async", "API", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/chan.go#L40-L51
4,379
ligato/cn-infra
messaging/kafka/mux/chan.go
ToBytesProducerErrChan
func ToBytesProducerErrChan(ch chan *client.ProducerError, opts ...interface{}) func(*client.ProducerError) { timeout, logger := messaging.ParseOpts(opts...) return func(msg *client.ProducerError) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
go
func ToBytesProducerErrChan(ch chan *client.ProducerError, opts ...interface{}) func(*client.ProducerError) { timeout, logger := messaging.ParseOpts(opts...) return func(msg *client.ProducerError) { select { case ch <- msg: case <-time.After(timeout): logger.Warn("Unable to deliver message") } } }
[ "func", "ToBytesProducerErrChan", "(", "ch", "chan", "*", "client", ".", "ProducerError", ",", "opts", "...", "interface", "{", "}", ")", "func", "(", "*", "client", ".", "ProducerError", ")", "{", "timeout", ",", "logger", ":=", "messaging", ".", "ParseOpts", "(", "opts", "...", ")", "\n\n", "return", "func", "(", "msg", "*", "client", ".", "ProducerError", ")", "{", "select", "{", "case", "ch", "<-", "msg", ":", "case", "<-", "time", ".", "After", "(", "timeout", ")", ":", "logger", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ToBytesProducerErrChan allows to receive ProducerMessage through channel. This function can be used as an argument for // methods publishing using async API.
[ "ToBytesProducerErrChan", "allows", "to", "receive", "ProducerMessage", "through", "channel", ".", "This", "function", "can", "be", "used", "as", "an", "argument", "for", "methods", "publishing", "using", "async", "API", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/messaging/kafka/mux/chan.go#L55-L66
4,380
ligato/cn-infra
rpc/rest/security/password-hasher/main.go
main
func main() { // Read args args := os.Args if len(args) != 3 { usage() return } pass := args[1] cost, err := strconv.Atoi(args[2]) if err != nil { logrus.DefaultLogger().Errorf("invalid cost format: %v", err) os.Exit(1) } if cost < 4 || cost > 31 { logrus.DefaultLogger().Errorf("invalid cost value %d, set it in interval 4-31", cost) os.Exit(1) } hash, err := bcrypt.GenerateFromPassword([]byte(pass), cost) if err != nil { logrus.DefaultLogger().Errorf("failed to hash password: %v", err) os.Exit(1) } logrus.DefaultLogger().Print(string(hash)) }
go
func main() { // Read args args := os.Args if len(args) != 3 { usage() return } pass := args[1] cost, err := strconv.Atoi(args[2]) if err != nil { logrus.DefaultLogger().Errorf("invalid cost format: %v", err) os.Exit(1) } if cost < 4 || cost > 31 { logrus.DefaultLogger().Errorf("invalid cost value %d, set it in interval 4-31", cost) os.Exit(1) } hash, err := bcrypt.GenerateFromPassword([]byte(pass), cost) if err != nil { logrus.DefaultLogger().Errorf("failed to hash password: %v", err) os.Exit(1) } logrus.DefaultLogger().Print(string(hash)) }
[ "func", "main", "(", ")", "{", "// Read args", "args", ":=", "os", ".", "Args", "\n", "if", "len", "(", "args", ")", "!=", "3", "{", "usage", "(", ")", "\n", "return", "\n", "}", "\n\n", "pass", ":=", "args", "[", "1", "]", "\n", "cost", ",", "err", ":=", "strconv", ".", "Atoi", "(", "args", "[", "2", "]", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "DefaultLogger", "(", ")", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "if", "cost", "<", "4", "||", "cost", ">", "31", "{", "logrus", ".", "DefaultLogger", "(", ")", ".", "Errorf", "(", "\"", "\"", ",", "cost", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "hash", ",", "err", ":=", "bcrypt", ".", "GenerateFromPassword", "(", "[", "]", "byte", "(", "pass", ")", ",", "cost", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "DefaultLogger", "(", ")", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n\n", "logrus", ".", "DefaultLogger", "(", ")", ".", "Print", "(", "string", "(", "hash", ")", ")", "\n", "}" ]
// A simple utility to help with password hashing. Hashed password can be stored as // user password in config file. Always provide two parameters; password and cost.
[ "A", "simple", "utility", "to", "help", "with", "password", "hashing", ".", "Hashed", "password", "can", "be", "stored", "as", "user", "password", "in", "config", "file", ".", "Always", "provide", "two", "parameters", ";", "password", "and", "cost", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/rpc/rest/security/password-hasher/main.go#L32-L57
4,381
ligato/cn-infra
db/keyval/bytes_watcher_api.go
ToChan
func ToChan(respCh chan BytesWatchResp, opts ...interface{}) func(dto BytesWatchResp) { return func(dto BytesWatchResp) { select { case respCh <- dto: // success case <-time.After(datasync.DefaultNotifTimeout): logging.DefaultLogger.Warn("Unable to deliver notification") } } }
go
func ToChan(respCh chan BytesWatchResp, opts ...interface{}) func(dto BytesWatchResp) { return func(dto BytesWatchResp) { select { case respCh <- dto: // success case <-time.After(datasync.DefaultNotifTimeout): logging.DefaultLogger.Warn("Unable to deliver notification") } } }
[ "func", "ToChan", "(", "respCh", "chan", "BytesWatchResp", ",", "opts", "...", "interface", "{", "}", ")", "func", "(", "dto", "BytesWatchResp", ")", "{", "return", "func", "(", "dto", "BytesWatchResp", ")", "{", "select", "{", "case", "respCh", "<-", "dto", ":", "// success", "case", "<-", "time", ".", "After", "(", "datasync", ".", "DefaultNotifTimeout", ")", ":", "logging", ".", "DefaultLogger", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ToChan creates a callback that can be passed to the Watch function in order // to receive notifications through a channel. If the notification cannot be // delivered until timeout, it is dropped.
[ "ToChan", "creates", "a", "callback", "that", "can", "be", "passed", "to", "the", "Watch", "function", "in", "order", "to", "receive", "notifications", "through", "a", "channel", ".", "If", "the", "notification", "cannot", "be", "delivered", "until", "timeout", "it", "is", "dropped", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/bytes_watcher_api.go#L43-L52
4,382
ligato/cn-infra
examples/kafka-lib/asyncproducer/asyncproducer.go
sendMessage
func sendMessage(producer *client.AsyncProducer, msg utils.Message) error { var ( msgKey []byte msgMeta []byte msgValue []byte ) // init message if msg.Key != "" { msgKey = []byte(msg.Key) } if msg.Metadata != "" { msgMeta = []byte(msg.Metadata) } msgValue = []byte(msg.Text) // send message producer.SendMsgByte(msg.Topic, msgKey, msgValue, msgMeta) fmt.Println("message sent") return nil }
go
func sendMessage(producer *client.AsyncProducer, msg utils.Message) error { var ( msgKey []byte msgMeta []byte msgValue []byte ) // init message if msg.Key != "" { msgKey = []byte(msg.Key) } if msg.Metadata != "" { msgMeta = []byte(msg.Metadata) } msgValue = []byte(msg.Text) // send message producer.SendMsgByte(msg.Topic, msgKey, msgValue, msgMeta) fmt.Println("message sent") return nil }
[ "func", "sendMessage", "(", "producer", "*", "client", ".", "AsyncProducer", ",", "msg", "utils", ".", "Message", ")", "error", "{", "var", "(", "msgKey", "[", "]", "byte", "\n", "msgMeta", "[", "]", "byte", "\n", "msgValue", "[", "]", "byte", "\n", ")", "\n\n", "// init message", "if", "msg", ".", "Key", "!=", "\"", "\"", "{", "msgKey", "=", "[", "]", "byte", "(", "msg", ".", "Key", ")", "\n", "}", "\n", "if", "msg", ".", "Metadata", "!=", "\"", "\"", "{", "msgMeta", "=", "[", "]", "byte", "(", "msg", ".", "Metadata", ")", "\n", "}", "\n", "msgValue", "=", "[", "]", "byte", "(", "msg", ".", "Text", ")", "\n\n", "// send message", "producer", ".", "SendMsgByte", "(", "msg", ".", "Topic", ",", "msgKey", ",", "msgValue", ",", "msgMeta", ")", "\n\n", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// sendMessage demonstrates AsyncProducer.SendMsgByte API to publish a single // message to a Kafka topic.
[ "sendMessage", "demonstrates", "AsyncProducer", ".", "SendMsgByte", "API", "to", "publish", "a", "single", "message", "to", "a", "Kafka", "topic", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/examples/kafka-lib/asyncproducer/asyncproducer.go#L134-L155
4,383
ligato/cn-infra
datasync/syncbase/events.go
NewResyncEventDB
func NewResyncEventDB(ctx context.Context, its map[string]datasync.KeyValIterator) *ResyncEventDB { return &ResyncEventDB{ ctx: ctx, its: its, DoneChannel: &DoneChannel{make(chan error, 1)}, } }
go
func NewResyncEventDB(ctx context.Context, its map[string]datasync.KeyValIterator) *ResyncEventDB { return &ResyncEventDB{ ctx: ctx, its: its, DoneChannel: &DoneChannel{make(chan error, 1)}, } }
[ "func", "NewResyncEventDB", "(", "ctx", "context", ".", "Context", ",", "its", "map", "[", "string", "]", "datasync", ".", "KeyValIterator", ")", "*", "ResyncEventDB", "{", "return", "&", "ResyncEventDB", "{", "ctx", ":", "ctx", ",", "its", ":", "its", ",", "DoneChannel", ":", "&", "DoneChannel", "{", "make", "(", "chan", "error", ",", "1", ")", "}", ",", "}", "\n", "}" ]
// NewResyncEventDB creates a new instance of ResyncEventDB using the given map of iterators.
[ "NewResyncEventDB", "creates", "a", "new", "instance", "of", "ResyncEventDB", "using", "the", "given", "map", "of", "iterators", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/syncbase/events.go#L26-L32
4,384
ligato/cn-infra
datasync/syncbase/events.go
GetValue
func (ev *ChangeResp) GetValue(val proto.Message) (err error) { return ev.CurrVal.GetValue(val) }
go
func (ev *ChangeResp) GetValue(val proto.Message) (err error) { return ev.CurrVal.GetValue(val) }
[ "func", "(", "ev", "*", "ChangeResp", ")", "GetValue", "(", "val", "proto", ".", "Message", ")", "(", "err", "error", ")", "{", "return", "ev", ".", "CurrVal", ".", "GetValue", "(", "val", ")", "\n", "}" ]
// GetValue - see the comments in the interface datasync.ChangeEvent
[ "GetValue", "-", "see", "the", "comments", "in", "the", "interface", "datasync", ".", "ChangeEvent" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/syncbase/events.go#L97-L99
4,385
ligato/cn-infra
db/keyval/filedb/decoder/decoder_api.go
CompareTo
func (f1 *File) CompareTo(f2 *File) (changed, removed []*FileDataEntry) { if f1.Path != f2.Path { return f1.Data, f2.Data } for _, f2Data := range f2.Data { var found bool for _, f1Data := range f1.Data { if f1Data.Key == f2Data.Key { found = true if !bytes.Equal(f1Data.Value, f2Data.Value) { changed = append(changed, f1Data) break } } } if !found { removed = append(removed, f2Data) } } for _, f1Data := range f1.Data { var found bool for _, f2Data := range f2.Data { if f1Data.Key == f2Data.Key { found = true break } } if !found { changed = append(changed, f1Data) } } return }
go
func (f1 *File) CompareTo(f2 *File) (changed, removed []*FileDataEntry) { if f1.Path != f2.Path { return f1.Data, f2.Data } for _, f2Data := range f2.Data { var found bool for _, f1Data := range f1.Data { if f1Data.Key == f2Data.Key { found = true if !bytes.Equal(f1Data.Value, f2Data.Value) { changed = append(changed, f1Data) break } } } if !found { removed = append(removed, f2Data) } } for _, f1Data := range f1.Data { var found bool for _, f2Data := range f2.Data { if f1Data.Key == f2Data.Key { found = true break } } if !found { changed = append(changed, f1Data) } } return }
[ "func", "(", "f1", "*", "File", ")", "CompareTo", "(", "f2", "*", "File", ")", "(", "changed", ",", "removed", "[", "]", "*", "FileDataEntry", ")", "{", "if", "f1", ".", "Path", "!=", "f2", ".", "Path", "{", "return", "f1", ".", "Data", ",", "f2", ".", "Data", "\n", "}", "\n", "for", "_", ",", "f2Data", ":=", "range", "f2", ".", "Data", "{", "var", "found", "bool", "\n", "for", "_", ",", "f1Data", ":=", "range", "f1", ".", "Data", "{", "if", "f1Data", ".", "Key", "==", "f2Data", ".", "Key", "{", "found", "=", "true", "\n", "if", "!", "bytes", ".", "Equal", "(", "f1Data", ".", "Value", ",", "f2Data", ".", "Value", ")", "{", "changed", "=", "append", "(", "changed", ",", "f1Data", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "removed", "=", "append", "(", "removed", ",", "f2Data", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "f1Data", ":=", "range", "f1", ".", "Data", "{", "var", "found", "bool", "\n", "for", "_", ",", "f2Data", ":=", "range", "f2", ".", "Data", "{", "if", "f1Data", ".", "Key", "==", "f2Data", ".", "Key", "{", "found", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "!", "found", "{", "changed", "=", "append", "(", "changed", ",", "f1Data", ")", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// CompareTo compares two files - new, modified and deleted entries. Result is against the parameter.
[ "CompareTo", "compares", "two", "files", "-", "new", "modified", "and", "deleted", "entries", ".", "Result", "is", "against", "the", "parameter", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/keyval/filedb/decoder/decoder_api.go#L42-L75
4,386
ligato/cn-infra
datasync/grpcsync/msgservice.go
DataChanges
func (s *DataMsgServiceServer) DataChanges(stream msg.DataMsgService_DataChangesServer) error { for { chng, err := stream.Recv() if err == io.EOF { return nil } if err != nil { return err } for _, sub := range s.adapter.base.Subscriptions() { for _, keyPrefix := range sub.KeyPrefixes { if strings.HasPrefix(chng.Key, keyPrefix) { sub.ChangeChan <- msg.NewChangeWatchResp(context.Background(), chng, func(err2 error) { err = stream.Send(&msg.DataChangeReply{Key: chng.Key, OperationType: chng.OperationType, Result: 0 /*TODO VPP Result*/}) if err != nil { logrus.DefaultLogger().Error(err) //Not able to propagate it somewhere else } }) } } } } }
go
func (s *DataMsgServiceServer) DataChanges(stream msg.DataMsgService_DataChangesServer) error { for { chng, err := stream.Recv() if err == io.EOF { return nil } if err != nil { return err } for _, sub := range s.adapter.base.Subscriptions() { for _, keyPrefix := range sub.KeyPrefixes { if strings.HasPrefix(chng.Key, keyPrefix) { sub.ChangeChan <- msg.NewChangeWatchResp(context.Background(), chng, func(err2 error) { err = stream.Send(&msg.DataChangeReply{Key: chng.Key, OperationType: chng.OperationType, Result: 0 /*TODO VPP Result*/}) if err != nil { logrus.DefaultLogger().Error(err) //Not able to propagate it somewhere else } }) } } } } }
[ "func", "(", "s", "*", "DataMsgServiceServer", ")", "DataChanges", "(", "stream", "msg", ".", "DataMsgService_DataChangesServer", ")", "error", "{", "for", "{", "chng", ",", "err", ":=", "stream", ".", "Recv", "(", ")", "\n\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "_", ",", "sub", ":=", "range", "s", ".", "adapter", ".", "base", ".", "Subscriptions", "(", ")", "{", "for", "_", ",", "keyPrefix", ":=", "range", "sub", ".", "KeyPrefixes", "{", "if", "strings", ".", "HasPrefix", "(", "chng", ".", "Key", ",", "keyPrefix", ")", "{", "sub", ".", "ChangeChan", "<-", "msg", ".", "NewChangeWatchResp", "(", "context", ".", "Background", "(", ")", ",", "chng", ",", "func", "(", "err2", "error", ")", "{", "err", "=", "stream", ".", "Send", "(", "&", "msg", ".", "DataChangeReply", "{", "Key", ":", "chng", ".", "Key", ",", "OperationType", ":", "chng", ".", "OperationType", ",", "Result", ":", "0", "/*TODO VPP Result*/", "}", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "DefaultLogger", "(", ")", ".", "Error", "(", "err", ")", "//Not able to propagate it somewhere else", "\n", "}", "\n", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// DataChanges propagates the events in the stream to go channels of registered plugins.
[ "DataChanges", "propagates", "the", "events", "in", "the", "stream", "to", "go", "channels", "of", "registered", "plugins", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/grpcsync/msgservice.go#L38-L63
4,387
ligato/cn-infra
datasync/grpcsync/msgservice.go
DataResyncs
func (s *DataMsgServiceServer) DataResyncs(ctx context.Context, req *msg.DataResyncRequests) ( *msg.DataResyncReplies, error) { resyncs := req.GetDataResyncs() if resyncs != nil { //TODO propagate event like in Kafka transport /*localtxn := syncbase.NewLocalBytesTxn(s.adapter.localtransp.PropagateBytesResync) if len(resyncs) == 0 { log.Debug("received empty resync => DELETE ALL") } for _, chReq := range resyncs { //TODO chReq.ContentType localtxn.Put(chReq.Key, chReq.Content) } err := localtxn.Commit()*/ var err error if err != nil { return &msg.DataResyncReplies{MsgId: replySeq(), Error: &msg.Error{Message: err.Error()} /*TODO all other fields*/}, err } return &msg.DataResyncReplies{MsgId: replySeq() /*TODO all other fields*/}, nil } err := errors.New("unexpected place - nil resyncs") return &msg.DataResyncReplies{MsgId: replySeq(), Error: &msg.Error{Message: err.Error()} /*TODO all other fields*/}, err }
go
func (s *DataMsgServiceServer) DataResyncs(ctx context.Context, req *msg.DataResyncRequests) ( *msg.DataResyncReplies, error) { resyncs := req.GetDataResyncs() if resyncs != nil { //TODO propagate event like in Kafka transport /*localtxn := syncbase.NewLocalBytesTxn(s.adapter.localtransp.PropagateBytesResync) if len(resyncs) == 0 { log.Debug("received empty resync => DELETE ALL") } for _, chReq := range resyncs { //TODO chReq.ContentType localtxn.Put(chReq.Key, chReq.Content) } err := localtxn.Commit()*/ var err error if err != nil { return &msg.DataResyncReplies{MsgId: replySeq(), Error: &msg.Error{Message: err.Error()} /*TODO all other fields*/}, err } return &msg.DataResyncReplies{MsgId: replySeq() /*TODO all other fields*/}, nil } err := errors.New("unexpected place - nil resyncs") return &msg.DataResyncReplies{MsgId: replySeq(), Error: &msg.Error{Message: err.Error()} /*TODO all other fields*/}, err }
[ "func", "(", "s", "*", "DataMsgServiceServer", ")", "DataResyncs", "(", "ctx", "context", ".", "Context", ",", "req", "*", "msg", ".", "DataResyncRequests", ")", "(", "*", "msg", ".", "DataResyncReplies", ",", "error", ")", "{", "resyncs", ":=", "req", ".", "GetDataResyncs", "(", ")", "\n", "if", "resyncs", "!=", "nil", "{", "//TODO propagate event like in Kafka transport", "/*localtxn := syncbase.NewLocalBytesTxn(s.adapter.localtransp.PropagateBytesResync)\n\t\tif len(resyncs) == 0 {\n\t\t\tlog.Debug(\"received empty resync => DELETE ALL\")\n\t\t}\n\t\tfor _, chReq := range resyncs {\n\t\t\t//TODO chReq.ContentType\n\t\t\tlocaltxn.Put(chReq.Key, chReq.Content)\n\t\t}\n\t\terr := localtxn.Commit()*/", "var", "err", "error", "\n", "if", "err", "!=", "nil", "{", "return", "&", "msg", ".", "DataResyncReplies", "{", "MsgId", ":", "replySeq", "(", ")", ",", "Error", ":", "&", "msg", ".", "Error", "{", "Message", ":", "err", ".", "Error", "(", ")", "}", "/*TODO all other fields*/", "}", ",", "err", "\n", "}", "\n\n", "return", "&", "msg", ".", "DataResyncReplies", "{", "MsgId", ":", "replySeq", "(", ")", "/*TODO all other fields*/", "}", ",", "nil", "\n", "}", "\n\n", "err", ":=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "return", "&", "msg", ".", "DataResyncReplies", "{", "MsgId", ":", "replySeq", "(", ")", ",", "Error", ":", "&", "msg", ".", "Error", "{", "Message", ":", "err", ".", "Error", "(", ")", "}", "/*TODO all other fields*/", "}", ",", "err", "\n", "}" ]
// DataResyncs propagates the events in the stream to go channels of registered plugins.
[ "DataResyncs", "propagates", "the", "events", "in", "the", "stream", "to", "go", "channels", "of", "registered", "plugins", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/datasync/grpcsync/msgservice.go#L66-L91
4,388
ligato/cn-infra
logging/logrus/entry.go
NewEntry
func NewEntry(logger *Logger) *Entry { //todo lgEntry := lg.NewEntry(logger.std) return &Entry{ logger: logger, lgEntry: lgEntry, } }
go
func NewEntry(logger *Logger) *Entry { //todo lgEntry := lg.NewEntry(logger.std) return &Entry{ logger: logger, lgEntry: lgEntry, } }
[ "func", "NewEntry", "(", "logger", "*", "Logger", ")", "*", "Entry", "{", "//todo", "lgEntry", ":=", "lg", ".", "NewEntry", "(", "logger", ".", "std", ")", "\n", "return", "&", "Entry", "{", "logger", ":", "logger", ",", "lgEntry", ":", "lgEntry", ",", "}", "\n", "}" ]
// NewEntry creates net entry object which stores provided logger and logrus' entry
[ "NewEntry", "creates", "net", "entry", "object", "which", "stores", "provided", "logger", "and", "logrus", "entry" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L37-L43
4,389
ligato/cn-infra
logging/logrus/entry.go
Panic
func (entry *Entry) Panic(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.PanicLevel { entry.lgEntry.WithFields(entry.fields).Panic(args...) } }
go
func (entry *Entry) Panic(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.PanicLevel { entry.lgEntry.WithFields(entry.fields).Panic(args...) } }
[ "func", "(", "entry", "*", "Entry", ")", "Panic", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "PanicLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Panic", "(", "args", "...", ")", "\n", "}", "\n", "}" ]
// Panic logs a message at level Panic on the standard logger.
[ "Panic", "logs", "a", "message", "at", "level", "Panic", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L125-L129
4,390
ligato/cn-infra
logging/logrus/entry.go
Fatalf
func (entry *Entry) Fatalf(format string, args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.FatalLevel { entry.lgEntry.WithFields(entry.fields).Fatalf(format, args...) } }
go
func (entry *Entry) Fatalf(format string, args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.FatalLevel { entry.lgEntry.WithFields(entry.fields).Fatalf(format, args...) } }
[ "func", "(", "entry", "*", "Entry", ")", "Fatalf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "FatalLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Fatalf", "(", "format", ",", "args", "...", ")", "\n", "}", "\n", "}" ]
// Fatalf logs a message at level Debug on the standard logger.
[ "Fatalf", "logs", "a", "message", "at", "level", "Debug", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L174-L178
4,391
ligato/cn-infra
logging/logrus/entry.go
Debugln
func (entry *Entry) Debugln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.DebugLevel { entry.lgEntry.WithFields(entry.fields).Debugln(entry.sprintlnn(args...)) } }
go
func (entry *Entry) Debugln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.DebugLevel { entry.lgEntry.WithFields(entry.fields).Debugln(entry.sprintlnn(args...)) } }
[ "func", "(", "entry", "*", "Entry", ")", "Debugln", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "DebugLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Debugln", "(", "entry", ".", "sprintlnn", "(", "args", "...", ")", ")", "\n", "}", "\n", "}" ]
// Debugln logs a message at level Debug on the standard logger.
[ "Debugln", "logs", "a", "message", "at", "level", "Debug", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L188-L192
4,392
ligato/cn-infra
logging/logrus/entry.go
Println
func (entry *Entry) Println(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.InfoLevel { entry.lgEntry.WithFields(entry.fields).Println(entry.sprintlnn(args...)) } }
go
func (entry *Entry) Println(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.InfoLevel { entry.lgEntry.WithFields(entry.fields).Println(entry.sprintlnn(args...)) } }
[ "func", "(", "entry", "*", "Entry", ")", "Println", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "InfoLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Println", "(", "entry", ".", "sprintlnn", "(", "args", "...", ")", ")", "\n", "}", "\n", "}" ]
// Println logs a message at level Info on the standard logger.
[ "Println", "logs", "a", "message", "at", "level", "Info", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L202-L206
4,393
ligato/cn-infra
logging/logrus/entry.go
Warnln
func (entry *Entry) Warnln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.WarnLevel { entry.lgEntry.WithFields(entry.fields).Warnln(entry.sprintlnn(args...)) } }
go
func (entry *Entry) Warnln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.WarnLevel { entry.lgEntry.WithFields(entry.fields).Warnln(entry.sprintlnn(args...)) } }
[ "func", "(", "entry", "*", "Entry", ")", "Warnln", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "WarnLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Warnln", "(", "entry", ".", "sprintlnn", "(", "args", "...", ")", ")", "\n", "}", "\n", "}" ]
// Warnln logs a message at level Warn on the standard logger.
[ "Warnln", "logs", "a", "message", "at", "level", "Warn", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L209-L213
4,394
ligato/cn-infra
logging/logrus/entry.go
Errorln
func (entry *Entry) Errorln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.ErrorLevel { entry.lgEntry.WithFields(entry.fields).Errorln(entry.sprintlnn(args...)) } }
go
func (entry *Entry) Errorln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.ErrorLevel { entry.lgEntry.WithFields(entry.fields).Errorln(entry.sprintlnn(args...)) } }
[ "func", "(", "entry", "*", "Entry", ")", "Errorln", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "ErrorLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Errorln", "(", "entry", ".", "sprintlnn", "(", "args", "...", ")", ")", "\n", "}", "\n", "}" ]
// Errorln logs a message at level Error on the standard logger.
[ "Errorln", "logs", "a", "message", "at", "level", "Error", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L223-L227
4,395
ligato/cn-infra
logging/logrus/entry.go
Fatalln
func (entry *Entry) Fatalln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.FatalLevel { entry.lgEntry.WithFields(entry.fields).Fatalln(entry.sprintlnn(args...)) } }
go
func (entry *Entry) Fatalln(args ...interface{}) { if entry.lgEntry.Logger.Level >= lg.FatalLevel { entry.lgEntry.WithFields(entry.fields).Fatalln(entry.sprintlnn(args...)) } }
[ "func", "(", "entry", "*", "Entry", ")", "Fatalln", "(", "args", "...", "interface", "{", "}", ")", "{", "if", "entry", ".", "lgEntry", ".", "Logger", ".", "Level", ">=", "lg", ".", "FatalLevel", "{", "entry", ".", "lgEntry", ".", "WithFields", "(", "entry", ".", "fields", ")", ".", "Fatalln", "(", "entry", ".", "sprintlnn", "(", "args", "...", ")", ")", "\n", "}", "\n", "}" ]
// Fatalln logs a message at level Fatal on the standard logger.
[ "Fatalln", "logs", "a", "message", "at", "level", "Fatal", "on", "the", "standard", "logger", "." ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/logging/logrus/entry.go#L230-L234
4,396
ligato/cn-infra
db/sql/cassandra/query.go
PutExpToString
func PutExpToString(whereCondition sql.Expression, entity interface{}) (sqlStr string, bindings []interface{}, err error) { whereCondtionStr := &toStringVisitor{entity: entity} whereCondition.Accept(whereCondtionStr) statement, _, err := updateSetExpToString(sql.EntityTableName(entity), /*TODO extract method / make customizable*/ entity /*, TODO TTL*/) if err != nil { return "", nil, err } _, bindings = structs.ListExportedFieldsPtrs(entity, cqlExported, filterOutPK) whereBinding := whereCondtionStr.Binding() if whereBinding != nil { bindings = append(bindings, whereBinding...) } return strings.Trim(statement+" WHERE "+whereCondtionStr.String(), " "), bindings, nil }
go
func PutExpToString(whereCondition sql.Expression, entity interface{}) (sqlStr string, bindings []interface{}, err error) { whereCondtionStr := &toStringVisitor{entity: entity} whereCondition.Accept(whereCondtionStr) statement, _, err := updateSetExpToString(sql.EntityTableName(entity), /*TODO extract method / make customizable*/ entity /*, TODO TTL*/) if err != nil { return "", nil, err } _, bindings = structs.ListExportedFieldsPtrs(entity, cqlExported, filterOutPK) whereBinding := whereCondtionStr.Binding() if whereBinding != nil { bindings = append(bindings, whereBinding...) } return strings.Trim(statement+" WHERE "+whereCondtionStr.String(), " "), bindings, nil }
[ "func", "PutExpToString", "(", "whereCondition", "sql", ".", "Expression", ",", "entity", "interface", "{", "}", ")", "(", "sqlStr", "string", ",", "bindings", "[", "]", "interface", "{", "}", ",", "err", "error", ")", "{", "whereCondtionStr", ":=", "&", "toStringVisitor", "{", "entity", ":", "entity", "}", "\n", "whereCondition", ".", "Accept", "(", "whereCondtionStr", ")", "\n\n", "statement", ",", "_", ",", "err", ":=", "updateSetExpToString", "(", "sql", ".", "EntityTableName", "(", "entity", ")", ",", "/*TODO extract method / make customizable*/", "entity", "/*, TODO TTL*/", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "err", "\n", "}", "\n\n", "_", ",", "bindings", "=", "structs", ".", "ListExportedFieldsPtrs", "(", "entity", ",", "cqlExported", ",", "filterOutPK", ")", "\n", "whereBinding", ":=", "whereCondtionStr", ".", "Binding", "(", ")", "\n", "if", "whereBinding", "!=", "nil", "{", "bindings", "=", "append", "(", "bindings", ",", "whereBinding", "...", ")", "\n", "}", "\n\n", "return", "strings", ".", "Trim", "(", "statement", "+", "\"", "\"", "+", "whereCondtionStr", ".", "String", "(", ")", ",", "\"", "\"", ")", ",", "bindings", ",", "nil", "\n", "}" ]
// PutExpToString converts expression to string & slice of bindings
[ "PutExpToString", "converts", "expression", "to", "string", "&", "slice", "of", "bindings" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/sql/cassandra/query.go#L28-L47
4,397
ligato/cn-infra
db/sql/cassandra/query.go
SelectExpToString
func SelectExpToString(fromWhere sql.Expression) (sqlStr string, bindings []interface{}, err error) { findEntity := &findEntityVisitor{} fromWhere.Accept(findEntity) fromWhereStr := &toStringVisitor{entity: findEntity.entity} fromWhere.Accept(fromWhereStr) fieldsStr := selectFields(findEntity.entity) if err != nil { return "", nil, err } fromWhereBindings := fromWhereStr.Binding() whereStr := fromWhereStr.String() if strings.Contains(whereStr, "AND") { whereStr = whereStr + " ALLOW FILTERING" } return "SELECT " + fieldsStr + whereStr, fromWhereBindings, nil }
go
func SelectExpToString(fromWhere sql.Expression) (sqlStr string, bindings []interface{}, err error) { findEntity := &findEntityVisitor{} fromWhere.Accept(findEntity) fromWhereStr := &toStringVisitor{entity: findEntity.entity} fromWhere.Accept(fromWhereStr) fieldsStr := selectFields(findEntity.entity) if err != nil { return "", nil, err } fromWhereBindings := fromWhereStr.Binding() whereStr := fromWhereStr.String() if strings.Contains(whereStr, "AND") { whereStr = whereStr + " ALLOW FILTERING" } return "SELECT " + fieldsStr + whereStr, fromWhereBindings, nil }
[ "func", "SelectExpToString", "(", "fromWhere", "sql", ".", "Expression", ")", "(", "sqlStr", "string", ",", "bindings", "[", "]", "interface", "{", "}", ",", "err", "error", ")", "{", "findEntity", ":=", "&", "findEntityVisitor", "{", "}", "\n", "fromWhere", ".", "Accept", "(", "findEntity", ")", "\n\n", "fromWhereStr", ":=", "&", "toStringVisitor", "{", "entity", ":", "findEntity", ".", "entity", "}", "\n", "fromWhere", ".", "Accept", "(", "fromWhereStr", ")", "\n\n", "fieldsStr", ":=", "selectFields", "(", "findEntity", ".", "entity", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "nil", ",", "err", "\n", "}", "\n", "fromWhereBindings", ":=", "fromWhereStr", ".", "Binding", "(", ")", "\n\n", "whereStr", ":=", "fromWhereStr", ".", "String", "(", ")", "\n", "if", "strings", ".", "Contains", "(", "whereStr", ",", "\"", "\"", ")", "{", "whereStr", "=", "whereStr", "+", "\"", "\"", "\n", "}", "\n", "return", "\"", "\"", "+", "fieldsStr", "+", "whereStr", ",", "fromWhereBindings", ",", "nil", "\n", "}" ]
// SelectExpToString converts expression to string & slice of bindings
[ "SelectExpToString", "converts", "expression", "to", "string", "&", "slice", "of", "bindings" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/sql/cassandra/query.go#L50-L70
4,398
ligato/cn-infra
db/sql/cassandra/query.go
ExpToString
func ExpToString(exp sql.Expression) (sql string, bindings []interface{}, err error) { findEntity := &findEntityVisitor{} exp.Accept(findEntity) stringer := &toStringVisitor{entity: findEntity.entity} exp.Accept(stringer) return stringer.String(), stringer.Binding(), stringer.lastError }
go
func ExpToString(exp sql.Expression) (sql string, bindings []interface{}, err error) { findEntity := &findEntityVisitor{} exp.Accept(findEntity) stringer := &toStringVisitor{entity: findEntity.entity} exp.Accept(stringer) return stringer.String(), stringer.Binding(), stringer.lastError }
[ "func", "ExpToString", "(", "exp", "sql", ".", "Expression", ")", "(", "sql", "string", ",", "bindings", "[", "]", "interface", "{", "}", ",", "err", "error", ")", "{", "findEntity", ":=", "&", "findEntityVisitor", "{", "}", "\n", "exp", ".", "Accept", "(", "findEntity", ")", "\n\n", "stringer", ":=", "&", "toStringVisitor", "{", "entity", ":", "findEntity", ".", "entity", "}", "\n", "exp", ".", "Accept", "(", "stringer", ")", "\n\n", "return", "stringer", ".", "String", "(", ")", ",", "stringer", ".", "Binding", "(", ")", ",", "stringer", ".", "lastError", "\n", "}" ]
// ExpToString converts expression to string & slice of bindings
[ "ExpToString", "converts", "expression", "to", "string", "&", "slice", "of", "bindings" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/sql/cassandra/query.go#L73-L81
4,399
ligato/cn-infra
db/sql/cassandra/query.go
cqlExported
func cqlExported(field *r.StructField) (exported bool) { cql := field.Tag.Get("cql") if len(cql) > 0 { if cql == "-" { return false } return true } return true }
go
func cqlExported(field *r.StructField) (exported bool) { cql := field.Tag.Get("cql") if len(cql) > 0 { if cql == "-" { return false } return true } return true }
[ "func", "cqlExported", "(", "field", "*", "r", ".", "StructField", ")", "(", "exported", "bool", ")", "{", "cql", ":=", "field", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "len", "(", "cql", ")", ">", "0", "{", "if", "cql", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}", "\n", "return", "true", "\n", "}" ]
// cqlExported checks the cql tag in StructField and parses the field name
[ "cqlExported", "checks", "the", "cql", "tag", "in", "StructField", "and", "parses", "the", "field", "name" ]
6552f4407e293b0986ec353eb0f01968cbecb928
https://github.com/ligato/cn-infra/blob/6552f4407e293b0986ec353eb0f01968cbecb928/db/sql/cassandra/query.go#L149-L158