id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
14,000
go-ozzo/ozzo-dbx
struct.go
pk
func (s *structValue) pk() map[string]interface{} { if len(s.pkNames) == 0 { return nil } return s.columns(s.pkNames, nil) }
go
func (s *structValue) pk() map[string]interface{} { if len(s.pkNames) == 0 { return nil } return s.columns(s.pkNames, nil) }
[ "func", "(", "s", "*", "structValue", ")", "pk", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "if", "len", "(", "s", ".", "pkNames", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "return", "s", ".", "columns", "(", "s", ".", "pkNames", ",", "nil", ")", "\n", "}" ]
// pk returns the primary key values indexed by the corresponding primary key column names.
[ "pk", "returns", "the", "primary", "key", "values", "indexed", "by", "the", "corresponding", "primary", "key", "column", "names", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/struct.go#L94-L99
14,001
go-ozzo/ozzo-dbx
struct.go
columns
func (s *structValue) columns(include, exclude []string) map[string]interface{} { v := make(map[string]interface{}, len(s.nameMap)) if len(include) == 0 { for _, fi := range s.nameMap { v[fi.dbName] = fi.getValue(s.value) } } else { for _, attr := range include { if fi, ok := s.nameMap[attr]; ok { v[fi.dbName] = fi.getValue(s.value) } } } if len(exclude) > 0 { for _, name := range exclude { if fi, ok := s.nameMap[name]; ok { delete(v, fi.dbName) } } } return v }
go
func (s *structValue) columns(include, exclude []string) map[string]interface{} { v := make(map[string]interface{}, len(s.nameMap)) if len(include) == 0 { for _, fi := range s.nameMap { v[fi.dbName] = fi.getValue(s.value) } } else { for _, attr := range include { if fi, ok := s.nameMap[attr]; ok { v[fi.dbName] = fi.getValue(s.value) } } } if len(exclude) > 0 { for _, name := range exclude { if fi, ok := s.nameMap[name]; ok { delete(v, fi.dbName) } } } return v }
[ "func", "(", "s", "*", "structValue", ")", "columns", "(", "include", ",", "exclude", "[", "]", "string", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "v", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "len", "(", "s", ".", "nameMap", ")", ")", "\n", "if", "len", "(", "include", ")", "==", "0", "{", "for", "_", ",", "fi", ":=", "range", "s", ".", "nameMap", "{", "v", "[", "fi", ".", "dbName", "]", "=", "fi", ".", "getValue", "(", "s", ".", "value", ")", "\n", "}", "\n", "}", "else", "{", "for", "_", ",", "attr", ":=", "range", "include", "{", "if", "fi", ",", "ok", ":=", "s", ".", "nameMap", "[", "attr", "]", ";", "ok", "{", "v", "[", "fi", ".", "dbName", "]", "=", "fi", ".", "getValue", "(", "s", ".", "value", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "exclude", ")", ">", "0", "{", "for", "_", ",", "name", ":=", "range", "exclude", "{", "if", "fi", ",", "ok", ":=", "s", ".", "nameMap", "[", "name", "]", ";", "ok", "{", "delete", "(", "v", ",", "fi", ".", "dbName", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "v", "\n", "}" ]
// columns returns the struct field values indexed by their corresponding DB column names.
[ "columns", "returns", "the", "struct", "field", "values", "indexed", "by", "their", "corresponding", "DB", "column", "names", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/struct.go#L102-L123
14,002
go-ozzo/ozzo-dbx
struct.go
getValue
func (fi *fieldInfo) getValue(a reflect.Value) interface{} { for _, i := range fi.path { a = a.Field(i) if a.Kind() == reflect.Ptr { if a.IsNil() { return nil } a = a.Elem() } } return a.Interface() }
go
func (fi *fieldInfo) getValue(a reflect.Value) interface{} { for _, i := range fi.path { a = a.Field(i) if a.Kind() == reflect.Ptr { if a.IsNil() { return nil } a = a.Elem() } } return a.Interface() }
[ "func", "(", "fi", "*", "fieldInfo", ")", "getValue", "(", "a", "reflect", ".", "Value", ")", "interface", "{", "}", "{", "for", "_", ",", "i", ":=", "range", "fi", ".", "path", "{", "a", "=", "a", ".", "Field", "(", "i", ")", "\n", "if", "a", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "if", "a", ".", "IsNil", "(", ")", "{", "return", "nil", "\n", "}", "\n", "a", "=", "a", ".", "Elem", "(", ")", "\n", "}", "\n", "}", "\n", "return", "a", ".", "Interface", "(", ")", "\n", "}" ]
// getValue returns the field value for the given struct value.
[ "getValue", "returns", "the", "field", "value", "for", "the", "given", "struct", "value", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/struct.go#L126-L137
14,003
go-ozzo/ozzo-dbx
struct.go
getField
func (fi *fieldInfo) getField(a reflect.Value) reflect.Value { i := 0 for ; i < len(fi.path)-1; i++ { a = indirect(a.Field(fi.path[i])) } return a.Field(fi.path[i]) }
go
func (fi *fieldInfo) getField(a reflect.Value) reflect.Value { i := 0 for ; i < len(fi.path)-1; i++ { a = indirect(a.Field(fi.path[i])) } return a.Field(fi.path[i]) }
[ "func", "(", "fi", "*", "fieldInfo", ")", "getField", "(", "a", "reflect", ".", "Value", ")", "reflect", ".", "Value", "{", "i", ":=", "0", "\n", "for", ";", "i", "<", "len", "(", "fi", ".", "path", ")", "-", "1", ";", "i", "++", "{", "a", "=", "indirect", "(", "a", ".", "Field", "(", "fi", ".", "path", "[", "i", "]", ")", ")", "\n", "}", "\n", "return", "a", ".", "Field", "(", "fi", ".", "path", "[", "i", "]", ")", "\n", "}" ]
// getField returns the reflection value of the field for the given struct value.
[ "getField", "returns", "the", "reflection", "value", "of", "the", "field", "for", "the", "given", "struct", "value", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/struct.go#L140-L146
14,004
go-ozzo/ozzo-dbx
struct.go
indirect
func indirect(v reflect.Value) reflect.Value { for v.Kind() == reflect.Ptr { if v.IsNil() { v.Set(reflect.New(v.Type().Elem())) } v = v.Elem() } return v }
go
func indirect(v reflect.Value) reflect.Value { for v.Kind() == reflect.Ptr { if v.IsNil() { v.Set(reflect.New(v.Type().Elem())) } v = v.Elem() } return v }
[ "func", "indirect", "(", "v", "reflect", ".", "Value", ")", "reflect", ".", "Value", "{", "for", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "if", "v", ".", "IsNil", "(", ")", "{", "v", ".", "Set", "(", "reflect", ".", "New", "(", "v", ".", "Type", "(", ")", ".", "Elem", "(", ")", ")", ")", "\n", "}", "\n", "v", "=", "v", ".", "Elem", "(", ")", "\n", "}", "\n", "return", "v", "\n", "}" ]
// indirect dereferences pointers and returns the actual value it points to. // If a pointer is nil, it will be initialized with a new value.
[ "indirect", "dereferences", "pointers", "and", "returns", "the", "actual", "value", "it", "points", "to", ".", "If", "a", "pointer", "is", "nil", "it", "will", "be", "initialized", "with", "a", "new", "value", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/struct.go#L239-L247
14,005
go-ozzo/ozzo-dbx
expression.go
NewExp
func NewExp(e string, params ...Params) Expression { if len(params) > 0 { return &Exp{e, params[0]} } return &Exp{e, nil} }
go
func NewExp(e string, params ...Params) Expression { if len(params) > 0 { return &Exp{e, params[0]} } return &Exp{e, nil} }
[ "func", "NewExp", "(", "e", "string", ",", "params", "...", "Params", ")", "Expression", "{", "if", "len", "(", "params", ")", ">", "0", "{", "return", "&", "Exp", "{", "e", ",", "params", "[", "0", "]", "}", "\n", "}", "\n", "return", "&", "Exp", "{", "e", ",", "nil", "}", "\n", "}" ]
// NewExp generates an expression with the specified SQL fragment and the optional binding parameters.
[ "NewExp", "generates", "an", "expression", "with", "the", "specified", "SQL", "fragment", "and", "the", "optional", "binding", "parameters", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/expression.go#L31-L36
14,006
go-ozzo/ozzo-dbx
expression.go
Escape
func (e *LikeExp) Escape(chars ...string) *LikeExp { e.escape = chars return e }
go
func (e *LikeExp) Escape(chars ...string) *LikeExp { e.escape = chars return e }
[ "func", "(", "e", "*", "LikeExp", ")", "Escape", "(", "chars", "...", "string", ")", "*", "LikeExp", "{", "e", ".", "escape", "=", "chars", "\n", "return", "e", "\n", "}" ]
// Escape specifies how a LIKE expression should be escaped. // Each string at position 2i represents a special character and the string at position 2i+1 is // the corresponding escaped version.
[ "Escape", "specifies", "how", "a", "LIKE", "expression", "should", "be", "escaped", ".", "Each", "string", "at", "position", "2i", "represents", "a", "special", "character", "and", "the", "string", "at", "position", "2i", "+", "1", "is", "the", "corresponding", "escaped", "version", "." ]
e984ee904f1b2df904d0b2e6b2ca5064c87c0409
https://github.com/go-ozzo/ozzo-dbx/blob/e984ee904f1b2df904d0b2e6b2ca5064c87c0409/expression.go#L316-L319
14,007
compose/transporter
message/ops/ops.go
String
func (o Op) String() string { switch o { case Insert: return "insert" case Update: return "update" case Delete: return "delete" case Command: return "command" case Noop: return "noop" case Skip: return "skip" default: return "unknown" } }
go
func (o Op) String() string { switch o { case Insert: return "insert" case Update: return "update" case Delete: return "delete" case Command: return "command" case Noop: return "noop" case Skip: return "skip" default: return "unknown" } }
[ "func", "(", "o", "Op", ")", "String", "(", ")", "string", "{", "switch", "o", "{", "case", "Insert", ":", "return", "\"", "\"", "\n", "case", "Update", ":", "return", "\"", "\"", "\n", "case", "Delete", ":", "return", "\"", "\"", "\n", "case", "Command", ":", "return", "\"", "\"", "\n", "case", "Noop", ":", "return", "\"", "\"", "\n", "case", "Skip", ":", "return", "\"", "\"", "\n", "default", ":", "return", "\"", "\"", "\n", "}", "\n", "}" ]
// String returns the constant of the // string representation of the OpType object.
[ "String", "returns", "the", "constant", "of", "the", "string", "representation", "of", "the", "OpType", "object", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/message/ops/ops.go#L24-L41
14,008
compose/transporter
message/ops/ops.go
OpTypeFromString
func OpTypeFromString(s string) Op { switch s[0] { case 'i': return Insert case 'u': return Update case 'd': return Delete case 'c': return Command case 'n': return Noop case 's': return Skip default: return Unknown } }
go
func OpTypeFromString(s string) Op { switch s[0] { case 'i': return Insert case 'u': return Update case 'd': return Delete case 'c': return Command case 'n': return Noop case 's': return Skip default: return Unknown } }
[ "func", "OpTypeFromString", "(", "s", "string", ")", "Op", "{", "switch", "s", "[", "0", "]", "{", "case", "'i'", ":", "return", "Insert", "\n", "case", "'u'", ":", "return", "Update", "\n", "case", "'d'", ":", "return", "Delete", "\n", "case", "'c'", ":", "return", "Command", "\n", "case", "'n'", ":", "return", "Noop", "\n", "case", "'s'", ":", "return", "Skip", "\n", "default", ":", "return", "Unknown", "\n", "}", "\n", "}" ]
// OpTypeFromString returns the constant // representing the passed in string
[ "OpTypeFromString", "returns", "the", "constant", "representing", "the", "passed", "in", "string" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/message/ops/ops.go#L45-L62
14,009
compose/transporter
function/registry.go
GetFunction
func GetFunction(name string, conf map[string]interface{}) (Function, error) { creator, ok := functions[name] if ok { a := creator() b, err := json.Marshal(conf) if err != nil { return nil, err } err = json.Unmarshal(b, a) if err != nil { return nil, err } return a, nil } return nil, ErrNotFound{name} }
go
func GetFunction(name string, conf map[string]interface{}) (Function, error) { creator, ok := functions[name] if ok { a := creator() b, err := json.Marshal(conf) if err != nil { return nil, err } err = json.Unmarshal(b, a) if err != nil { return nil, err } return a, nil } return nil, ErrNotFound{name} }
[ "func", "GetFunction", "(", "name", "string", ",", "conf", "map", "[", "string", "]", "interface", "{", "}", ")", "(", "Function", ",", "error", ")", "{", "creator", ",", "ok", ":=", "functions", "[", "name", "]", "\n", "if", "ok", "{", "a", ":=", "creator", "(", ")", "\n", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "conf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "a", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "ErrNotFound", "{", "name", "}", "\n", "}" ]
// GetFunction looks up a function by name and then init's it with the provided map. // returns ErrNotFound if the provided name was not registered.
[ "GetFunction", "looks", "up", "a", "function", "by", "name", "and", "then", "init", "s", "it", "with", "the", "provided", "map", ".", "returns", "ErrNotFound", "if", "the", "provided", "name", "was", "not", "registered", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/function/registry.go#L29-L44
14,010
compose/transporter
function/registry.go
RegisteredFunctions
func RegisteredFunctions() []string { all := make([]string, 0) for i := range functions { all = append(all, i) } return all }
go
func RegisteredFunctions() []string { all := make([]string, 0) for i := range functions { all = append(all, i) } return all }
[ "func", "RegisteredFunctions", "(", ")", "[", "]", "string", "{", "all", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "i", ":=", "range", "functions", "{", "all", "=", "append", "(", "all", ",", "i", ")", "\n", "}", "\n", "return", "all", "\n", "}" ]
// RegisteredFunctions returns a slice of the names of every function registered.
[ "RegisteredFunctions", "returns", "a", "slice", "of", "the", "names", "of", "every", "function", "registered", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/function/registry.go#L47-L53
14,011
compose/transporter
adaptor/postgres/tailer.go
Read
func (t *Tailer) Read(resumeMap map[string]client.MessageSet, filterFn client.NsFilterFunc) client.MessageChanFunc { return func(s client.Session, done chan struct{}) (chan client.MessageSet, error) { readFunc := t.reader.Read(resumeMap, filterFn) msgChan, err := readFunc(s, done) if err != nil { return nil, err } session := s.(*Session) out := make(chan client.MessageSet) go func() { defer close(out) // read until reader done for msg := range msgChan { out <- msg } // start tailing log.With("db", session.db).With("logical_decoding_slot", t.replicationSlot).Infoln("Listening for changes...") for { select { case <-done: log.With("db", session.db).Infoln("tailing stopping...") return case <-time.After(time.Second): msgSlice, err := t.pluckFromLogicalDecoding(s.(*Session), filterFn) if err != nil { log.With("db", session.db).Errorf("error plucking from logical decoding %v", err) continue } for _, msg := range msgSlice { out <- msg } } } }() return out, nil } }
go
func (t *Tailer) Read(resumeMap map[string]client.MessageSet, filterFn client.NsFilterFunc) client.MessageChanFunc { return func(s client.Session, done chan struct{}) (chan client.MessageSet, error) { readFunc := t.reader.Read(resumeMap, filterFn) msgChan, err := readFunc(s, done) if err != nil { return nil, err } session := s.(*Session) out := make(chan client.MessageSet) go func() { defer close(out) // read until reader done for msg := range msgChan { out <- msg } // start tailing log.With("db", session.db).With("logical_decoding_slot", t.replicationSlot).Infoln("Listening for changes...") for { select { case <-done: log.With("db", session.db).Infoln("tailing stopping...") return case <-time.After(time.Second): msgSlice, err := t.pluckFromLogicalDecoding(s.(*Session), filterFn) if err != nil { log.With("db", session.db).Errorf("error plucking from logical decoding %v", err) continue } for _, msg := range msgSlice { out <- msg } } } }() return out, nil } }
[ "func", "(", "t", "*", "Tailer", ")", "Read", "(", "resumeMap", "map", "[", "string", "]", "client", ".", "MessageSet", ",", "filterFn", "client", ".", "NsFilterFunc", ")", "client", ".", "MessageChanFunc", "{", "return", "func", "(", "s", "client", ".", "Session", ",", "done", "chan", "struct", "{", "}", ")", "(", "chan", "client", ".", "MessageSet", ",", "error", ")", "{", "readFunc", ":=", "t", ".", "reader", ".", "Read", "(", "resumeMap", ",", "filterFn", ")", "\n", "msgChan", ",", "err", ":=", "readFunc", "(", "s", ",", "done", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "session", ":=", "s", ".", "(", "*", "Session", ")", "\n", "out", ":=", "make", "(", "chan", "client", ".", "MessageSet", ")", "\n", "go", "func", "(", ")", "{", "defer", "close", "(", "out", ")", "\n", "// read until reader done", "for", "msg", ":=", "range", "msgChan", "{", "out", "<-", "msg", "\n", "}", "\n", "// start tailing", "log", ".", "With", "(", "\"", "\"", ",", "session", ".", "db", ")", ".", "With", "(", "\"", "\"", ",", "t", ".", "replicationSlot", ")", ".", "Infoln", "(", "\"", "\"", ")", "\n", "for", "{", "select", "{", "case", "<-", "done", ":", "log", ".", "With", "(", "\"", "\"", ",", "session", ".", "db", ")", ".", "Infoln", "(", "\"", "\"", ")", "\n", "return", "\n", "case", "<-", "time", ".", "After", "(", "time", ".", "Second", ")", ":", "msgSlice", ",", "err", ":=", "t", ".", "pluckFromLogicalDecoding", "(", "s", ".", "(", "*", "Session", ")", ",", "filterFn", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "With", "(", "\"", "\"", ",", "session", ".", "db", ")", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "for", "_", ",", "msg", ":=", "range", "msgSlice", "{", "out", "<-", "msg", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "out", ",", "nil", "\n", "}", "\n", "}" ]
// Tail does the things
[ "Tail", "does", "the", "things" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/postgres/tailer.go#L35-L72
14,012
compose/transporter
adaptor/postgres/tailer.go
pluckFromLogicalDecoding
func (t *Tailer) pluckFromLogicalDecoding(s *Session, filterFn client.NsFilterFunc) ([]client.MessageSet, error) { var result []client.MessageSet dataMatcher := regexp.MustCompile("(?s)^table ([^\\.]+)\\.([^:]+): (INSERT|DELETE|UPDATE): (.+)$") // 1 - schema, 2 - table, 3 - action, 4 - remaining changesResult, err := s.pqSession.Query(fmt.Sprintf("SELECT * FROM pg_logical_slot_get_changes('%v', NULL, NULL);", t.replicationSlot)) if err != nil { return result, err } for changesResult.Next() { var ( location string xid string d string ) err = changesResult.Scan(&location, &xid, &d) if err != nil { return result, err } // Ensure we are getting a data change row dataMatches := dataMatcher.FindStringSubmatch(d) if len(dataMatches) == 0 { continue } // Skippable because no primary key on record // Make sure we are getting changes on valid tables schemaAndTable := fmt.Sprintf("%v.%v", dataMatches[1], dataMatches[2]) if !filterFn(schemaAndTable) { continue } if dataMatches[4] == "(no-tuple-data)" { log.With("op", dataMatches[3]).With("schema", schemaAndTable).Infoln("no tuple data") continue } // normalize the action var action ops.Op switch dataMatches[3] { case "INSERT": action = ops.Insert case "DELETE": action = ops.Delete case "UPDATE": action = ops.Update default: return result, fmt.Errorf("Error processing action from string: %v", d) } log.With("op", action).With("table", schemaAndTable).Debugln("received") docMap := parseLogicalDecodingData(dataMatches[4]) result = append(result, client.MessageSet{ Msg: message.From(action, schemaAndTable, docMap), Mode: commitlog.Sync, }) } return result, err }
go
func (t *Tailer) pluckFromLogicalDecoding(s *Session, filterFn client.NsFilterFunc) ([]client.MessageSet, error) { var result []client.MessageSet dataMatcher := regexp.MustCompile("(?s)^table ([^\\.]+)\\.([^:]+): (INSERT|DELETE|UPDATE): (.+)$") // 1 - schema, 2 - table, 3 - action, 4 - remaining changesResult, err := s.pqSession.Query(fmt.Sprintf("SELECT * FROM pg_logical_slot_get_changes('%v', NULL, NULL);", t.replicationSlot)) if err != nil { return result, err } for changesResult.Next() { var ( location string xid string d string ) err = changesResult.Scan(&location, &xid, &d) if err != nil { return result, err } // Ensure we are getting a data change row dataMatches := dataMatcher.FindStringSubmatch(d) if len(dataMatches) == 0 { continue } // Skippable because no primary key on record // Make sure we are getting changes on valid tables schemaAndTable := fmt.Sprintf("%v.%v", dataMatches[1], dataMatches[2]) if !filterFn(schemaAndTable) { continue } if dataMatches[4] == "(no-tuple-data)" { log.With("op", dataMatches[3]).With("schema", schemaAndTable).Infoln("no tuple data") continue } // normalize the action var action ops.Op switch dataMatches[3] { case "INSERT": action = ops.Insert case "DELETE": action = ops.Delete case "UPDATE": action = ops.Update default: return result, fmt.Errorf("Error processing action from string: %v", d) } log.With("op", action).With("table", schemaAndTable).Debugln("received") docMap := parseLogicalDecodingData(dataMatches[4]) result = append(result, client.MessageSet{ Msg: message.From(action, schemaAndTable, docMap), Mode: commitlog.Sync, }) } return result, err }
[ "func", "(", "t", "*", "Tailer", ")", "pluckFromLogicalDecoding", "(", "s", "*", "Session", ",", "filterFn", "client", ".", "NsFilterFunc", ")", "(", "[", "]", "client", ".", "MessageSet", ",", "error", ")", "{", "var", "result", "[", "]", "client", ".", "MessageSet", "\n", "dataMatcher", ":=", "regexp", ".", "MustCompile", "(", "\"", "\\\\", "\\\\", "\"", ")", "// 1 - schema, 2 - table, 3 - action, 4 - remaining", "\n\n", "changesResult", ",", "err", ":=", "s", ".", "pqSession", ".", "Query", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "replicationSlot", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "err", "\n", "}", "\n\n", "for", "changesResult", ".", "Next", "(", ")", "{", "var", "(", "location", "string", "\n", "xid", "string", "\n", "d", "string", "\n", ")", "\n\n", "err", "=", "changesResult", ".", "Scan", "(", "&", "location", ",", "&", "xid", ",", "&", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "err", "\n", "}", "\n\n", "// Ensure we are getting a data change row", "dataMatches", ":=", "dataMatcher", ".", "FindStringSubmatch", "(", "d", ")", "\n", "if", "len", "(", "dataMatches", ")", "==", "0", "{", "continue", "\n", "}", "\n\n", "// Skippable because no primary key on record", "// Make sure we are getting changes on valid tables", "schemaAndTable", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dataMatches", "[", "1", "]", ",", "dataMatches", "[", "2", "]", ")", "\n", "if", "!", "filterFn", "(", "schemaAndTable", ")", "{", "continue", "\n", "}", "\n\n", "if", "dataMatches", "[", "4", "]", "==", "\"", "\"", "{", "log", ".", "With", "(", "\"", "\"", ",", "dataMatches", "[", "3", "]", ")", ".", "With", "(", "\"", "\"", ",", "schemaAndTable", ")", ".", "Infoln", "(", "\"", "\"", ")", "\n", "continue", "\n", "}", "\n\n", "// normalize the action", "var", "action", "ops", ".", "Op", "\n", "switch", "dataMatches", "[", "3", "]", "{", "case", "\"", "\"", ":", "action", "=", "ops", ".", "Insert", "\n", "case", "\"", "\"", ":", "action", "=", "ops", ".", "Delete", "\n", "case", "\"", "\"", ":", "action", "=", "ops", ".", "Update", "\n", "default", ":", "return", "result", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "d", ")", "\n", "}", "\n\n", "log", ".", "With", "(", "\"", "\"", ",", "action", ")", ".", "With", "(", "\"", "\"", ",", "schemaAndTable", ")", ".", "Debugln", "(", "\"", "\"", ")", "\n\n", "docMap", ":=", "parseLogicalDecodingData", "(", "dataMatches", "[", "4", "]", ")", "\n", "result", "=", "append", "(", "result", ",", "client", ".", "MessageSet", "{", "Msg", ":", "message", ".", "From", "(", "action", ",", "schemaAndTable", ",", "docMap", ")", ",", "Mode", ":", "commitlog", ".", "Sync", ",", "}", ")", "\n", "}", "\n\n", "return", "result", ",", "err", "\n", "}" ]
// Use Postgres logical decoding to retrieve the latest changes
[ "Use", "Postgres", "logical", "decoding", "to", "retrieve", "the", "latest", "changes" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/postgres/tailer.go#L75-L137
14,013
compose/transporter
pipeline/pipeline.go
Stop
func (pipeline *Pipeline) Stop() { endpoints := pipeline.source.Endpoints() pipeline.source.Stop() // pipeline has stopped, emit one last round of metrics and send the exit event close(pipeline.done) pipeline.emitMetrics() pipeline.source.pipe.Event <- events.NewExitEvent(time.Now().UnixNano(), pipeline.version, endpoints) pipeline.emitter.Stop() }
go
func (pipeline *Pipeline) Stop() { endpoints := pipeline.source.Endpoints() pipeline.source.Stop() // pipeline has stopped, emit one last round of metrics and send the exit event close(pipeline.done) pipeline.emitMetrics() pipeline.source.pipe.Event <- events.NewExitEvent(time.Now().UnixNano(), pipeline.version, endpoints) pipeline.emitter.Stop() }
[ "func", "(", "pipeline", "*", "Pipeline", ")", "Stop", "(", ")", "{", "endpoints", ":=", "pipeline", ".", "source", ".", "Endpoints", "(", ")", "\n", "pipeline", ".", "source", ".", "Stop", "(", ")", "\n\n", "// pipeline has stopped, emit one last round of metrics and send the exit event", "close", "(", "pipeline", ".", "done", ")", "\n", "pipeline", ".", "emitMetrics", "(", ")", "\n", "pipeline", ".", "source", ".", "pipe", ".", "Event", "<-", "events", ".", "NewExitEvent", "(", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ",", "pipeline", ".", "version", ",", "endpoints", ")", "\n", "pipeline", ".", "emitter", ".", "Stop", "(", ")", "\n", "}" ]
// Stop sends a stop signal to the emitter and all the nodes, whether they are running or not. // the node's database adaptors are expected to clean up after themselves, and stop will block until // all nodes have stopped successfully
[ "Stop", "sends", "a", "stop", "signal", "to", "the", "emitter", "and", "all", "the", "nodes", "whether", "they", "are", "running", "or", "not", ".", "the", "node", "s", "database", "adaptors", "are", "expected", "to", "clean", "up", "after", "themselves", "and", "stop", "will", "block", "until", "all", "nodes", "have", "stopped", "successfully" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/pipeline.go#L105-L114
14,014
compose/transporter
pipeline/pipeline.go
Run
func (pipeline *Pipeline) Run() error { endpoints := pipeline.source.Endpoints() // send a boot event pipeline.source.pipe.Event <- events.NewBootEvent(time.Now().UnixNano(), pipeline.version, endpoints) errors := make(chan error, 2) go func() { errors <- pipeline.startErrorListener() }() go func() { errors <- pipeline.source.Start() }() return <-errors }
go
func (pipeline *Pipeline) Run() error { endpoints := pipeline.source.Endpoints() // send a boot event pipeline.source.pipe.Event <- events.NewBootEvent(time.Now().UnixNano(), pipeline.version, endpoints) errors := make(chan error, 2) go func() { errors <- pipeline.startErrorListener() }() go func() { errors <- pipeline.source.Start() }() return <-errors }
[ "func", "(", "pipeline", "*", "Pipeline", ")", "Run", "(", ")", "error", "{", "endpoints", ":=", "pipeline", ".", "source", ".", "Endpoints", "(", ")", "\n", "// send a boot event", "pipeline", ".", "source", ".", "pipe", ".", "Event", "<-", "events", ".", "NewBootEvent", "(", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ",", "pipeline", ".", "version", ",", "endpoints", ")", "\n\n", "errors", ":=", "make", "(", "chan", "error", ",", "2", ")", "\n", "go", "func", "(", ")", "{", "errors", "<-", "pipeline", ".", "startErrorListener", "(", ")", "\n", "}", "(", ")", "\n", "go", "func", "(", ")", "{", "errors", "<-", "pipeline", ".", "source", ".", "Start", "(", ")", "\n", "}", "(", ")", "\n\n", "return", "<-", "errors", "\n", "}" ]
// Run the pipeline
[ "Run", "the", "pipeline" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/pipeline.go#L117-L131
14,015
compose/transporter
pipeline/pipeline.go
startErrorListener
func (pipeline *Pipeline) startErrorListener() error { for { select { case err := <-pipeline.source.pipe.Err: return err case <-pipeline.done: return nil } } }
go
func (pipeline *Pipeline) startErrorListener() error { for { select { case err := <-pipeline.source.pipe.Err: return err case <-pipeline.done: return nil } } }
[ "func", "(", "pipeline", "*", "Pipeline", ")", "startErrorListener", "(", ")", "error", "{", "for", "{", "select", "{", "case", "err", ":=", "<-", "pipeline", ".", "source", ".", "pipe", ".", "Err", ":", "return", "err", "\n", "case", "<-", "pipeline", ".", "done", ":", "return", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// start error listener consumes all the events on the pipe's Err channel, and stops the pipeline // when it receives one
[ "start", "error", "listener", "consumes", "all", "the", "events", "on", "the", "pipe", "s", "Err", "channel", "and", "stops", "the", "pipeline", "when", "it", "receives", "one" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/pipeline.go#L135-L144
14,016
compose/transporter
pipeline/pipeline.go
emitMetrics
func (pipeline *Pipeline) emitMetrics() { pipeline.apply(func(node *Node) { pipeline.source.pipe.Event <- events.NewMetricsEvent(time.Now().UnixNano(), node.path, node.pipe.MessageCount) }) }
go
func (pipeline *Pipeline) emitMetrics() { pipeline.apply(func(node *Node) { pipeline.source.pipe.Event <- events.NewMetricsEvent(time.Now().UnixNano(), node.path, node.pipe.MessageCount) }) }
[ "func", "(", "pipeline", "*", "Pipeline", ")", "emitMetrics", "(", ")", "{", "pipeline", ".", "apply", "(", "func", "(", "node", "*", "Node", ")", "{", "pipeline", ".", "source", ".", "pipe", ".", "Event", "<-", "events", ".", "NewMetricsEvent", "(", "time", ".", "Now", "(", ")", ".", "UnixNano", "(", ")", ",", "node", ".", "path", ",", "node", ".", "pipe", ".", "MessageCount", ")", "\n", "}", ")", "\n", "}" ]
// emit the metrics
[ "emit", "the", "metrics" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/pipeline.go#L158-L162
14,017
compose/transporter
pipeline/pipeline.go
apply
func (pipeline *Pipeline) apply(f func(*Node)) { head := pipeline.source nodes := []*Node{head} for len(nodes) > 0 { head, nodes = nodes[0], nodes[1:] f(head) nodes = append(nodes, head.children...) } }
go
func (pipeline *Pipeline) apply(f func(*Node)) { head := pipeline.source nodes := []*Node{head} for len(nodes) > 0 { head, nodes = nodes[0], nodes[1:] f(head) nodes = append(nodes, head.children...) } }
[ "func", "(", "pipeline", "*", "Pipeline", ")", "apply", "(", "f", "func", "(", "*", "Node", ")", ")", "{", "head", ":=", "pipeline", ".", "source", "\n", "nodes", ":=", "[", "]", "*", "Node", "{", "head", "}", "\n", "for", "len", "(", "nodes", ")", ">", "0", "{", "head", ",", "nodes", "=", "nodes", "[", "0", "]", ",", "nodes", "[", "1", ":", "]", "\n", "f", "(", "head", ")", "\n", "nodes", "=", "append", "(", "nodes", ",", "head", ".", "children", "...", ")", "\n", "}", "\n", "}" ]
// apply maps a function f across all nodes of a pipeline
[ "apply", "maps", "a", "function", "f", "across", "all", "nodes", "of", "a", "pipeline" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/pipeline.go#L165-L173
14,018
compose/transporter
adaptor/file/file.go
Writer
func (f *File) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) { return newWriter(), nil }
go
func (f *File) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) { return newWriter(), nil }
[ "func", "(", "f", "*", "File", ")", "Writer", "(", "done", "chan", "struct", "{", "}", ",", "wg", "*", "sync", ".", "WaitGroup", ")", "(", "client", ".", "Writer", ",", "error", ")", "{", "return", "newWriter", "(", ")", ",", "nil", "\n", "}" ]
// Writer instantiates a Writer for use with working with the file.
[ "Writer", "instantiates", "a", "Writer", "for", "use", "with", "working", "with", "the", "file", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/file/file.go#L44-L46
14,019
compose/transporter
adaptor/adaptor.go
Construct
func (c *Config) Construct(conf interface{}) error { b, err := json.Marshal(c) if err != nil { return err } err = json.Unmarshal(b, conf) if err != nil { return err } return nil }
go
func (c *Config) Construct(conf interface{}) error { b, err := json.Marshal(c) if err != nil { return err } err = json.Unmarshal(b, conf) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "Config", ")", "Construct", "(", "conf", "interface", "{", "}", ")", "error", "{", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "conf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Construct will Marshal the Config and then Unmarshal it into a // named struct the generic map into a proper struct
[ "Construct", "will", "Marshal", "the", "Config", "and", "then", "Unmarshal", "it", "into", "a", "named", "struct", "the", "generic", "map", "into", "a", "proper", "struct" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/adaptor.go#L64-L75
14,020
compose/transporter
adaptor/adaptor.go
GetString
func (c Config) GetString(key string) string { i, ok := c[key] if !ok { return "" } s, ok := i.(string) if !ok { return "" } return s }
go
func (c Config) GetString(key string) string { i, ok := c[key] if !ok { return "" } s, ok := i.(string) if !ok { return "" } return s }
[ "func", "(", "c", "Config", ")", "GetString", "(", "key", "string", ")", "string", "{", "i", ",", "ok", ":=", "c", "[", "key", "]", "\n", "if", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n", "s", ",", "ok", ":=", "i", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "s", "\n", "}" ]
// GetString returns value stored in the config under the given key, or // an empty string if the key doesn't exist, or isn't a string value
[ "GetString", "returns", "value", "stored", "in", "the", "config", "under", "the", "given", "key", "or", "an", "empty", "string", "if", "the", "key", "doesn", "t", "exist", "or", "isn", "t", "a", "string", "value" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/adaptor.go#L79-L89
14,021
compose/transporter
adaptor/elasticsearch/clients/registry.go
Add
func Add(v string, constraint version.Constraints, creator Creator) { Clients[v] = &VersionedClient{constraint, creator} }
go
func Add(v string, constraint version.Constraints, creator Creator) { Clients[v] = &VersionedClient{constraint, creator} }
[ "func", "Add", "(", "v", "string", ",", "constraint", "version", ".", "Constraints", ",", "creator", "Creator", ")", "{", "Clients", "[", "v", "]", "=", "&", "VersionedClient", "{", "constraint", ",", "creator", "}", "\n", "}" ]
// Add exposes the ability for each versioned client to register itself for use
[ "Add", "exposes", "the", "ability", "for", "each", "versioned", "client", "to", "register", "itself", "for", "use" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/elasticsearch/clients/registry.go#L25-L27
14,022
compose/transporter
offset/logmanager.go
NewLogManager
func NewLogManager(path, name string) (*LogManager, error) { m := &LogManager{ name: name, nsMap: make(map[string]uint64), } l, err := commitlog.New( commitlog.WithPath(filepath.Join(path, fmt.Sprintf("%s-%s", offsetPrefixDir, name))), commitlog.WithMaxSegmentBytes(1024*1024*1024), ) if err != nil { return nil, err } m.log = l err = m.buildMap() if err == io.EOF { return m, nil } return m, err }
go
func NewLogManager(path, name string) (*LogManager, error) { m := &LogManager{ name: name, nsMap: make(map[string]uint64), } l, err := commitlog.New( commitlog.WithPath(filepath.Join(path, fmt.Sprintf("%s-%s", offsetPrefixDir, name))), commitlog.WithMaxSegmentBytes(1024*1024*1024), ) if err != nil { return nil, err } m.log = l err = m.buildMap() if err == io.EOF { return m, nil } return m, err }
[ "func", "NewLogManager", "(", "path", ",", "name", "string", ")", "(", "*", "LogManager", ",", "error", ")", "{", "m", ":=", "&", "LogManager", "{", "name", ":", "name", ",", "nsMap", ":", "make", "(", "map", "[", "string", "]", "uint64", ")", ",", "}", "\n\n", "l", ",", "err", ":=", "commitlog", ".", "New", "(", "commitlog", ".", "WithPath", "(", "filepath", ".", "Join", "(", "path", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "offsetPrefixDir", ",", "name", ")", ")", ")", ",", "commitlog", ".", "WithMaxSegmentBytes", "(", "1024", "*", "1024", "*", "1024", ")", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "m", ".", "log", "=", "l", "\n\n", "err", "=", "m", ".", "buildMap", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "m", ",", "nil", "\n", "}", "\n\n", "return", "m", ",", "err", "\n", "}" ]
// NewLogManager creates a new instance of LogManager and initializes its namespace map by reading any // existing log files.
[ "NewLogManager", "creates", "a", "new", "instance", "of", "LogManager", "and", "initializes", "its", "namespace", "map", "by", "reading", "any", "existing", "log", "files", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/offset/logmanager.go#L31-L52
14,023
compose/transporter
offset/logmanager.go
CommitOffset
func (m *LogManager) CommitOffset(o Offset, override bool) error { m.Lock() defer m.Unlock() if currentOffset, ok := m.nsMap[o.Namespace]; !override && ok && currentOffset >= o.LogOffset { log.With("currentOffest", currentOffset). With("providedOffset", o.LogOffset). Debugln("refusing to commit offset") return nil } _, err := m.log.Append(o.Bytes()) if err != nil { return err } m.nsMap[o.Namespace] = o.LogOffset return nil }
go
func (m *LogManager) CommitOffset(o Offset, override bool) error { m.Lock() defer m.Unlock() if currentOffset, ok := m.nsMap[o.Namespace]; !override && ok && currentOffset >= o.LogOffset { log.With("currentOffest", currentOffset). With("providedOffset", o.LogOffset). Debugln("refusing to commit offset") return nil } _, err := m.log.Append(o.Bytes()) if err != nil { return err } m.nsMap[o.Namespace] = o.LogOffset return nil }
[ "func", "(", "m", "*", "LogManager", ")", "CommitOffset", "(", "o", "Offset", ",", "override", "bool", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n", "if", "currentOffset", ",", "ok", ":=", "m", ".", "nsMap", "[", "o", ".", "Namespace", "]", ";", "!", "override", "&&", "ok", "&&", "currentOffset", ">=", "o", ".", "LogOffset", "{", "log", ".", "With", "(", "\"", "\"", ",", "currentOffset", ")", ".", "With", "(", "\"", "\"", ",", "o", ".", "LogOffset", ")", ".", "Debugln", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "_", ",", "err", ":=", "m", ".", "log", ".", "Append", "(", "o", ".", "Bytes", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "m", ".", "nsMap", "[", "o", ".", "Namespace", "]", "=", "o", ".", "LogOffset", "\n", "return", "nil", "\n", "}" ]
// CommitOffset verifies it does not contain an offset older than the current offset // and persists to the log.
[ "CommitOffset", "verifies", "it", "does", "not", "contain", "an", "offset", "older", "than", "the", "current", "offset", "and", "persists", "to", "the", "log", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/offset/logmanager.go#L96-L111
14,024
compose/transporter
offset/logmanager.go
OffsetMap
func (m *LogManager) OffsetMap() map[string]uint64 { m.Lock() defer m.Unlock() return m.nsMap }
go
func (m *LogManager) OffsetMap() map[string]uint64 { m.Lock() defer m.Unlock() return m.nsMap }
[ "func", "(", "m", "*", "LogManager", ")", "OffsetMap", "(", ")", "map", "[", "string", "]", "uint64", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n", "return", "m", ".", "nsMap", "\n", "}" ]
// OffsetMap provides access to the underlying map containing the newest offset for every // namespace.
[ "OffsetMap", "provides", "access", "to", "the", "underlying", "map", "containing", "the", "newest", "offset", "for", "every", "namespace", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/offset/logmanager.go#L115-L119
14,025
compose/transporter
offset/logmanager.go
NewestOffset
func (m *LogManager) NewestOffset() int64 { m.Lock() defer m.Unlock() if len(m.nsMap) == 0 { return -1 } var newestOffset uint64 for _, v := range m.nsMap { if newestOffset < v { newestOffset = v } } return int64(newestOffset) }
go
func (m *LogManager) NewestOffset() int64 { m.Lock() defer m.Unlock() if len(m.nsMap) == 0 { return -1 } var newestOffset uint64 for _, v := range m.nsMap { if newestOffset < v { newestOffset = v } } return int64(newestOffset) }
[ "func", "(", "m", "*", "LogManager", ")", "NewestOffset", "(", ")", "int64", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n", "if", "len", "(", "m", ".", "nsMap", ")", "==", "0", "{", "return", "-", "1", "\n", "}", "\n", "var", "newestOffset", "uint64", "\n", "for", "_", ",", "v", ":=", "range", "m", ".", "nsMap", "{", "if", "newestOffset", "<", "v", "{", "newestOffset", "=", "v", "\n", "}", "\n", "}", "\n", "return", "int64", "(", "newestOffset", ")", "\n", "}" ]
// NewestOffset loops over every offset and returns the highest one.
[ "NewestOffset", "loops", "over", "every", "offset", "and", "returns", "the", "highest", "one", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/offset/logmanager.go#L122-L135
14,026
compose/transporter
adaptor/rabbitmq/client.go
WithURI
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { if _, err := amqp.ParseURI(uri); err != nil { return client.InvalidURIError{URI: uri, Err: err.Error()} } c.uri = uri return nil } }
go
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { if _, err := amqp.ParseURI(uri); err != nil { return client.InvalidURIError{URI: uri, Err: err.Error()} } c.uri = uri return nil } }
[ "func", "WithURI", "(", "uri", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "_", ",", "err", ":=", "amqp", ".", "ParseURI", "(", "uri", ")", ";", "err", "!=", "nil", "{", "return", "client", ".", "InvalidURIError", "{", "URI", ":", "uri", ",", "Err", ":", "err", ".", "Error", "(", ")", "}", "\n", "}", "\n", "c", ".", "uri", "=", "uri", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithURI defines the full connection string for the RabbitMQ connection
[ "WithURI", "defines", "the", "full", "connection", "string", "for", "the", "RabbitMQ", "connection" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rabbitmq/client.go#L67-L75
14,027
compose/transporter
adaptor/rabbitmq/client.go
WithSSL
func WithSSL(ssl bool) ClientOptionFunc { return func(c *Client) error { if ssl { tlsConfig := &tls.Config{InsecureSkipVerify: true} tlsConfig.RootCAs = x509.NewCertPool() c.tlsConfig = tlsConfig } return nil } }
go
func WithSSL(ssl bool) ClientOptionFunc { return func(c *Client) error { if ssl { tlsConfig := &tls.Config{InsecureSkipVerify: true} tlsConfig.RootCAs = x509.NewCertPool() c.tlsConfig = tlsConfig } return nil } }
[ "func", "WithSSL", "(", "ssl", "bool", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "ssl", "{", "tlsConfig", ":=", "&", "tls", ".", "Config", "{", "InsecureSkipVerify", ":", "true", "}", "\n", "tlsConfig", ".", "RootCAs", "=", "x509", ".", "NewCertPool", "(", ")", "\n", "c", ".", "tlsConfig", "=", "tlsConfig", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithSSL configures the database connection to connect via TLS.
[ "WithSSL", "configures", "the", "database", "connection", "to", "connect", "via", "TLS", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rabbitmq/client.go#L78-L87
14,028
compose/transporter
adaptor/rabbitmq/client.go
WithCACerts
func WithCACerts(certs []string) ClientOptionFunc { return func(c *Client) error { if len(certs) > 0 { roots := x509.NewCertPool() for _, cert := range certs { if _, err := os.Stat(cert); err == nil { filepath.Abs(cert) c, err := ioutil.ReadFile(cert) if err != nil { return err } cert = string(c) } if ok := roots.AppendCertsFromPEM([]byte(cert)); !ok { return client.ErrInvalidCert } } if c.tlsConfig != nil { c.tlsConfig.RootCAs = roots } else { c.tlsConfig = &tls.Config{RootCAs: roots} } c.tlsConfig.InsecureSkipVerify = false } return nil } }
go
func WithCACerts(certs []string) ClientOptionFunc { return func(c *Client) error { if len(certs) > 0 { roots := x509.NewCertPool() for _, cert := range certs { if _, err := os.Stat(cert); err == nil { filepath.Abs(cert) c, err := ioutil.ReadFile(cert) if err != nil { return err } cert = string(c) } if ok := roots.AppendCertsFromPEM([]byte(cert)); !ok { return client.ErrInvalidCert } } if c.tlsConfig != nil { c.tlsConfig.RootCAs = roots } else { c.tlsConfig = &tls.Config{RootCAs: roots} } c.tlsConfig.InsecureSkipVerify = false } return nil } }
[ "func", "WithCACerts", "(", "certs", "[", "]", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "len", "(", "certs", ")", ">", "0", "{", "roots", ":=", "x509", ".", "NewCertPool", "(", ")", "\n", "for", "_", ",", "cert", ":=", "range", "certs", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "cert", ")", ";", "err", "==", "nil", "{", "filepath", ".", "Abs", "(", "cert", ")", "\n", "c", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "cert", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "cert", "=", "string", "(", "c", ")", "\n", "}", "\n", "if", "ok", ":=", "roots", ".", "AppendCertsFromPEM", "(", "[", "]", "byte", "(", "cert", ")", ")", ";", "!", "ok", "{", "return", "client", ".", "ErrInvalidCert", "\n", "}", "\n", "}", "\n", "if", "c", ".", "tlsConfig", "!=", "nil", "{", "c", ".", "tlsConfig", ".", "RootCAs", "=", "roots", "\n", "}", "else", "{", "c", ".", "tlsConfig", "=", "&", "tls", ".", "Config", "{", "RootCAs", ":", "roots", "}", "\n", "}", "\n", "c", ".", "tlsConfig", ".", "InsecureSkipVerify", "=", "false", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithCACerts configures the RootCAs for the underlying TLS connection
[ "WithCACerts", "configures", "the", "RootCAs", "for", "the", "underlying", "TLS", "connection" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rabbitmq/client.go#L90-L116
14,029
compose/transporter
adaptor/rabbitmq/client.go
Connect
func (c *Client) Connect() (client.Session, error) { if c.conn == nil { if err := c.initConnection(); err != nil { return nil, err } } return &Session{c.conn, c.ch}, nil }
go
func (c *Client) Connect() (client.Session, error) { if c.conn == nil { if err := c.initConnection(); err != nil { return nil, err } } return &Session{c.conn, c.ch}, nil }
[ "func", "(", "c", "*", "Client", ")", "Connect", "(", ")", "(", "client", ".", "Session", ",", "error", ")", "{", "if", "c", ".", "conn", "==", "nil", "{", "if", "err", ":=", "c", ".", "initConnection", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "Session", "{", "c", ".", "conn", ",", "c", ".", "ch", "}", ",", "nil", "\n", "}" ]
// Connect satisfies the client.Client interface.
[ "Connect", "satisfies", "the", "client", ".", "Client", "interface", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rabbitmq/client.go#L119-L126
14,030
compose/transporter
cmd/transporter/goja_builder.go
String
func (t *Transporter) String() string { out := "Transporter:\n" out += fmt.Sprintf("%s", t.sourceNode.String()) return out }
go
func (t *Transporter) String() string { out := "Transporter:\n" out += fmt.Sprintf("%s", t.sourceNode.String()) return out }
[ "func", "(", "t", "*", "Transporter", ")", "String", "(", ")", "string", "{", "out", ":=", "\"", "\\n", "\"", "\n", "out", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "t", ".", "sourceNode", ".", "String", "(", ")", ")", "\n", "return", "out", "\n", "}" ]
// String represents the pipelines as a string
[ "String", "represents", "the", "pipelines", "as", "a", "string" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/cmd/transporter/goja_builder.go#L148-L152
14,031
compose/transporter
cmd/transporter/goja_builder.go
Config
func (t *Transporter) Config(call goja.FunctionCall) goja.Value { if cfg, ok := call.Argument(0).Export().(map[string]interface{}); ok { b, err := json.Marshal(cfg) if err != nil { panic(err) } var c config if err = json.Unmarshal(b, &c); err != nil { panic(err) } t.config = &c } return t.vm.ToValue(t) }
go
func (t *Transporter) Config(call goja.FunctionCall) goja.Value { if cfg, ok := call.Argument(0).Export().(map[string]interface{}); ok { b, err := json.Marshal(cfg) if err != nil { panic(err) } var c config if err = json.Unmarshal(b, &c); err != nil { panic(err) } t.config = &c } return t.vm.ToValue(t) }
[ "func", "(", "t", "*", "Transporter", ")", "Config", "(", "call", "goja", ".", "FunctionCall", ")", "goja", ".", "Value", "{", "if", "cfg", ",", "ok", ":=", "call", ".", "Argument", "(", "0", ")", ".", "Export", "(", ")", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", ";", "ok", "{", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "var", "c", "config", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "b", ",", "&", "c", ")", ";", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "t", ".", "config", "=", "&", "c", "\n", "}", "\n", "return", "t", ".", "vm", ".", "ToValue", "(", "t", ")", "\n", "}" ]
// Config parses the provided configuration object and associates it with the // JS VM.
[ "Config", "parses", "the", "provided", "configuration", "object", "and", "associates", "it", "with", "the", "JS", "VM", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/cmd/transporter/goja_builder.go#L176-L190
14,032
compose/transporter
adaptor/elasticsearch/elasticsearch.go
Reader
func (e *Elasticsearch) Reader() (client.Reader, error) { return nil, adaptor.ErrFuncNotSupported{Name: "Reader()", Func: "elasticsearch"} }
go
func (e *Elasticsearch) Reader() (client.Reader, error) { return nil, adaptor.ErrFuncNotSupported{Name: "Reader()", Func: "elasticsearch"} }
[ "func", "(", "e", "*", "Elasticsearch", ")", "Reader", "(", ")", "(", "client", ".", "Reader", ",", "error", ")", "{", "return", "nil", ",", "adaptor", ".", "ErrFuncNotSupported", "{", "Name", ":", "\"", "\"", ",", "Func", ":", "\"", "\"", "}", "\n", "}" ]
// Reader returns an error because this adaptor is currently not supported as a Source.
[ "Reader", "returns", "an", "error", "because", "this", "adaptor", "is", "currently", "not", "supported", "as", "a", "Source", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/elasticsearch/elasticsearch.go#L75-L77
14,033
compose/transporter
adaptor/elasticsearch/elasticsearch.go
Writer
func (e *Elasticsearch) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) { return setupWriter(e) }
go
func (e *Elasticsearch) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) { return setupWriter(e) }
[ "func", "(", "e", "*", "Elasticsearch", ")", "Writer", "(", "done", "chan", "struct", "{", "}", ",", "wg", "*", "sync", ".", "WaitGroup", ")", "(", "client", ".", "Writer", ",", "error", ")", "{", "return", "setupWriter", "(", "e", ")", "\n", "}" ]
// Writer determines the which underlying writer to used based on the cluster's version.
[ "Writer", "determines", "the", "which", "underlying", "writer", "to", "used", "based", "on", "the", "cluster", "s", "version", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/elasticsearch/elasticsearch.go#L80-L82
14,034
compose/transporter
message/data/data.go
Has
func (d Data) Has(key string) (interface{}, bool) { val, ok := d[key] return val, ok }
go
func (d Data) Has(key string) (interface{}, bool) { val, ok := d[key] return val, ok }
[ "func", "(", "d", "Data", ")", "Has", "(", "key", "string", ")", "(", "interface", "{", "}", ",", "bool", ")", "{", "val", ",", "ok", ":=", "d", "[", "key", "]", "\n", "return", "val", ",", "ok", "\n", "}" ]
// Has returns to two value from of the key lookup on a map.
[ "Has", "returns", "to", "two", "value", "from", "of", "the", "key", "lookup", "on", "a", "map", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/message/data/data.go#L17-L20
14,035
compose/transporter
commitlog/log.go
PutOffset
func (l Log) PutOffset(offset int64) { encoding.PutUint64(l[offsetPos:sizePos], uint64(offset)) }
go
func (l Log) PutOffset(offset int64) { encoding.PutUint64(l[offsetPos:sizePos], uint64(offset)) }
[ "func", "(", "l", "Log", ")", "PutOffset", "(", "offset", "int64", ")", "{", "encoding", ".", "PutUint64", "(", "l", "[", "offsetPos", ":", "sizePos", "]", ",", "uint64", "(", "offset", ")", ")", "\n", "}" ]
// PutOffset sets the provided offset for the given Log.
[ "PutOffset", "sets", "the", "provided", "offset", "for", "the", "given", "Log", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/log.go#L7-L9
14,036
compose/transporter
commitlog/commitlog.go
WithPath
func WithPath(path string) OptionFunc { return func(c *CommitLog) error { if path == "" { return ErrEmptyPath } c.path = path return nil } }
go
func WithPath(path string) OptionFunc { return func(c *CommitLog) error { if path == "" { return ErrEmptyPath } c.path = path return nil } }
[ "func", "WithPath", "(", "path", "string", ")", "OptionFunc", "{", "return", "func", "(", "c", "*", "CommitLog", ")", "error", "{", "if", "path", "==", "\"", "\"", "{", "return", "ErrEmptyPath", "\n", "}", "\n", "c", ".", "path", "=", "path", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithPath defines the directory where all data will be stored.
[ "WithPath", "defines", "the", "directory", "where", "all", "data", "will", "be", "stored", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/commitlog.go#L92-L100
14,037
compose/transporter
commitlog/commitlog.go
WithMaxSegmentBytes
func WithMaxSegmentBytes(max int64) OptionFunc { return func(c *CommitLog) error { if max > 0 { c.maxSegmentBytes = max } return nil } }
go
func WithMaxSegmentBytes(max int64) OptionFunc { return func(c *CommitLog) error { if max > 0 { c.maxSegmentBytes = max } return nil } }
[ "func", "WithMaxSegmentBytes", "(", "max", "int64", ")", "OptionFunc", "{", "return", "func", "(", "c", "*", "CommitLog", ")", "error", "{", "if", "max", ">", "0", "{", "c", ".", "maxSegmentBytes", "=", "max", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithMaxSegmentBytes defines the maximum limit a log segment can reach before needing // to create a new one.
[ "WithMaxSegmentBytes", "defines", "the", "maximum", "limit", "a", "log", "segment", "can", "reach", "before", "needing", "to", "create", "a", "new", "one", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/commitlog.go#L104-L111
14,038
compose/transporter
commitlog/commitlog.go
OldestOffset
func (c *CommitLog) OldestOffset() int64 { c.mu.RLock() defer c.mu.RUnlock() return c.segments[0].BaseOffset }
go
func (c *CommitLog) OldestOffset() int64 { c.mu.RLock() defer c.mu.RUnlock() return c.segments[0].BaseOffset }
[ "func", "(", "c", "*", "CommitLog", ")", "OldestOffset", "(", ")", "int64", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "c", ".", "segments", "[", "0", "]", ".", "BaseOffset", "\n", "}" ]
// OldestOffset obtains the BaseOffset from the oldest segment on disk.
[ "OldestOffset", "obtains", "the", "BaseOffset", "from", "the", "oldest", "segment", "on", "disk", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/commitlog.go#L203-L207
14,039
compose/transporter
commitlog/commitlog.go
Segments
func (c *CommitLog) Segments() []*Segment { c.mu.Lock() defer c.mu.Unlock() return c.segments }
go
func (c *CommitLog) Segments() []*Segment { c.mu.Lock() defer c.mu.Unlock() return c.segments }
[ "func", "(", "c", "*", "CommitLog", ")", "Segments", "(", ")", "[", "]", "*", "Segment", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "segments", "\n", "}" ]
// Segments provides access to the underlying segments stored on disk.
[ "Segments", "provides", "access", "to", "the", "underlying", "segments", "stored", "on", "disk", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/commitlog.go#L210-L214
14,040
compose/transporter
commitlog/commitlog.go
DeleteAll
func (c *CommitLog) DeleteAll() error { if err := c.Close(); err != nil { return err } return os.RemoveAll(c.path) }
go
func (c *CommitLog) DeleteAll() error { if err := c.Close(); err != nil { return err } return os.RemoveAll(c.path) }
[ "func", "(", "c", "*", "CommitLog", ")", "DeleteAll", "(", ")", "error", "{", "if", "err", ":=", "c", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "os", ".", "RemoveAll", "(", "c", ".", "path", ")", "\n", "}" ]
// DeleteAll cleans out all data in the path.
[ "DeleteAll", "cleans", "out", "all", "data", "in", "the", "path", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/commitlog.go#L217-L222
14,041
compose/transporter
commitlog/commitlog.go
NewReader
func (c *CommitLog) NewReader(offset int64) (io.Reader, error) { c.mu.RLock() defer c.mu.RUnlock() log.With("num_segments", len(c.segments)). With("offset", offset). Infoln("searching segments") // in the event there has been data committed to the segment but no offset for a path, // then we need to create a reader that starts from the very beginning if offset < 0 && len(c.segments) > 0 { // if err := c.segments[0].Open(); err != nil { // log.Errorf("unable to open segment, %s", err) // } return &Reader{commitlog: c, idx: 0, position: 0}, nil } var idx int for i := 0; i < len(c.segments); i++ { idx = i if (i + 1) != len(c.segments) { lowerOffset := c.segments[i].BaseOffset upperOffset := c.segments[i+1].BaseOffset log.With("lower_offset", lowerOffset). With("upper_offset", upperOffset). With("offset", offset). With("segment", idx). Debugln("checking if offset in segment") if offset >= lowerOffset && offset < upperOffset { break } } } log.With("offset", offset).With("segment_index", idx).Debugln("finding offset in segment") // if err := c.segments[idx].Open(); err != nil { // log.Errorf("unable to open segment, %s", err) // } position, err := c.segments[idx].FindOffsetPosition(uint64(offset)) if err != nil { return nil, err } return &Reader{ commitlog: c, idx: idx, position: position, }, nil }
go
func (c *CommitLog) NewReader(offset int64) (io.Reader, error) { c.mu.RLock() defer c.mu.RUnlock() log.With("num_segments", len(c.segments)). With("offset", offset). Infoln("searching segments") // in the event there has been data committed to the segment but no offset for a path, // then we need to create a reader that starts from the very beginning if offset < 0 && len(c.segments) > 0 { // if err := c.segments[0].Open(); err != nil { // log.Errorf("unable to open segment, %s", err) // } return &Reader{commitlog: c, idx: 0, position: 0}, nil } var idx int for i := 0; i < len(c.segments); i++ { idx = i if (i + 1) != len(c.segments) { lowerOffset := c.segments[i].BaseOffset upperOffset := c.segments[i+1].BaseOffset log.With("lower_offset", lowerOffset). With("upper_offset", upperOffset). With("offset", offset). With("segment", idx). Debugln("checking if offset in segment") if offset >= lowerOffset && offset < upperOffset { break } } } log.With("offset", offset).With("segment_index", idx).Debugln("finding offset in segment") // if err := c.segments[idx].Open(); err != nil { // log.Errorf("unable to open segment, %s", err) // } position, err := c.segments[idx].FindOffsetPosition(uint64(offset)) if err != nil { return nil, err } return &Reader{ commitlog: c, idx: idx, position: position, }, nil }
[ "func", "(", "c", "*", "CommitLog", ")", "NewReader", "(", "offset", "int64", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "c", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "RUnlock", "(", ")", "\n", "log", ".", "With", "(", "\"", "\"", ",", "len", "(", "c", ".", "segments", ")", ")", ".", "With", "(", "\"", "\"", ",", "offset", ")", ".", "Infoln", "(", "\"", "\"", ")", "\n\n", "// in the event there has been data committed to the segment but no offset for a path,", "// then we need to create a reader that starts from the very beginning", "if", "offset", "<", "0", "&&", "len", "(", "c", ".", "segments", ")", ">", "0", "{", "// if err := c.segments[0].Open(); err != nil {", "// \tlog.Errorf(\"unable to open segment, %s\", err)", "// }", "return", "&", "Reader", "{", "commitlog", ":", "c", ",", "idx", ":", "0", ",", "position", ":", "0", "}", ",", "nil", "\n", "}", "\n\n", "var", "idx", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "c", ".", "segments", ")", ";", "i", "++", "{", "idx", "=", "i", "\n", "if", "(", "i", "+", "1", ")", "!=", "len", "(", "c", ".", "segments", ")", "{", "lowerOffset", ":=", "c", ".", "segments", "[", "i", "]", ".", "BaseOffset", "\n", "upperOffset", ":=", "c", ".", "segments", "[", "i", "+", "1", "]", ".", "BaseOffset", "\n", "log", ".", "With", "(", "\"", "\"", ",", "lowerOffset", ")", ".", "With", "(", "\"", "\"", ",", "upperOffset", ")", ".", "With", "(", "\"", "\"", ",", "offset", ")", ".", "With", "(", "\"", "\"", ",", "idx", ")", ".", "Debugln", "(", "\"", "\"", ")", "\n", "if", "offset", ">=", "lowerOffset", "&&", "offset", "<", "upperOffset", "{", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "log", ".", "With", "(", "\"", "\"", ",", "offset", ")", ".", "With", "(", "\"", "\"", ",", "idx", ")", ".", "Debugln", "(", "\"", "\"", ")", "\n", "// if err := c.segments[idx].Open(); err != nil {", "// \tlog.Errorf(\"unable to open segment, %s\", err)", "// }", "position", ",", "err", ":=", "c", ".", "segments", "[", "idx", "]", ".", "FindOffsetPosition", "(", "uint64", "(", "offset", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Reader", "{", "commitlog", ":", "c", ",", "idx", ":", "idx", ",", "position", ":", "position", ",", "}", ",", "nil", "\n", "}" ]
// NewReader returns an io.Reader based on the provider offset.
[ "NewReader", "returns", "an", "io", ".", "Reader", "based", "on", "the", "provider", "offset", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/commitlog.go#L225-L272
14,042
compose/transporter
pipe/pipe.go
NewPipe
func NewPipe(pipe *Pipe, path string) *Pipe { p := &Pipe{ Out: make([]messageChan, 0), path: path, chStop: make(chan struct{}), } if pipe != nil { pipe.Out = append(pipe.Out, newMessageChan()) p.In = pipe.Out[len(pipe.Out)-1] // use the last out channel p.Err = pipe.Err p.Event = pipe.Event } else { p.Err = make(chan error) p.Event = make(chan events.Event, 10) // buffer the event channel } return p }
go
func NewPipe(pipe *Pipe, path string) *Pipe { p := &Pipe{ Out: make([]messageChan, 0), path: path, chStop: make(chan struct{}), } if pipe != nil { pipe.Out = append(pipe.Out, newMessageChan()) p.In = pipe.Out[len(pipe.Out)-1] // use the last out channel p.Err = pipe.Err p.Event = pipe.Event } else { p.Err = make(chan error) p.Event = make(chan events.Event, 10) // buffer the event channel } return p }
[ "func", "NewPipe", "(", "pipe", "*", "Pipe", ",", "path", "string", ")", "*", "Pipe", "{", "p", ":=", "&", "Pipe", "{", "Out", ":", "make", "(", "[", "]", "messageChan", ",", "0", ")", ",", "path", ":", "path", ",", "chStop", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n\n", "if", "pipe", "!=", "nil", "{", "pipe", ".", "Out", "=", "append", "(", "pipe", ".", "Out", ",", "newMessageChan", "(", ")", ")", "\n", "p", ".", "In", "=", "pipe", ".", "Out", "[", "len", "(", "pipe", ".", "Out", ")", "-", "1", "]", "// use the last out channel", "\n", "p", ".", "Err", "=", "pipe", ".", "Err", "\n", "p", ".", "Event", "=", "pipe", ".", "Event", "\n", "}", "else", "{", "p", ".", "Err", "=", "make", "(", "chan", "error", ")", "\n", "p", ".", "Event", "=", "make", "(", "chan", "events", ".", "Event", ",", "10", ")", "// buffer the event channel", "\n", "}", "\n\n", "return", "p", "\n", "}" ]
// NewPipe creates a new Pipe. If the pipe that is passed in is nil, then this pipe will be treated as a source pipe that just serves to emit messages. // Otherwise, the pipe returned will be created and chained from the last member of the Out slice of the parent. This function has side effects, and will add // an Out channel to the pipe that is passed in
[ "NewPipe", "creates", "a", "new", "Pipe", ".", "If", "the", "pipe", "that", "is", "passed", "in", "is", "nil", "then", "this", "pipe", "will", "be", "treated", "as", "a", "source", "pipe", "that", "just", "serves", "to", "emit", "messages", ".", "Otherwise", "the", "pipe", "returned", "will", "be", "created", "and", "chained", "from", "the", "last", "member", "of", "the", "Out", "slice", "of", "the", "parent", ".", "This", "function", "has", "side", "effects", "and", "will", "add", "an", "Out", "channel", "to", "the", "pipe", "that", "is", "passed", "in" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipe/pipe.go#L61-L80
14,043
compose/transporter
pipe/pipe.go
Stop
func (p *Pipe) Stop() { if !p.Stopped { p.Stopped = true // we only worry about the stop channel if we're in a listening loop if p.listening { close(p.chStop) p.wg.Wait() return } timeout := time.After(10 * time.Second) for { select { case <-timeout: log.With("path", p.path).Errorln("timeout reached waiting for Out channels to clear") return default: } if p.empty() { return } time.Sleep(1 * time.Second) } } }
go
func (p *Pipe) Stop() { if !p.Stopped { p.Stopped = true // we only worry about the stop channel if we're in a listening loop if p.listening { close(p.chStop) p.wg.Wait() return } timeout := time.After(10 * time.Second) for { select { case <-timeout: log.With("path", p.path).Errorln("timeout reached waiting for Out channels to clear") return default: } if p.empty() { return } time.Sleep(1 * time.Second) } } }
[ "func", "(", "p", "*", "Pipe", ")", "Stop", "(", ")", "{", "if", "!", "p", ".", "Stopped", "{", "p", ".", "Stopped", "=", "true", "\n\n", "// we only worry about the stop channel if we're in a listening loop", "if", "p", ".", "listening", "{", "close", "(", "p", ".", "chStop", ")", "\n", "p", ".", "wg", ".", "Wait", "(", ")", "\n", "return", "\n", "}", "\n\n", "timeout", ":=", "time", ".", "After", "(", "10", "*", "time", ".", "Second", ")", "\n", "for", "{", "select", "{", "case", "<-", "timeout", ":", "log", ".", "With", "(", "\"", "\"", ",", "p", ".", "path", ")", ".", "Errorln", "(", "\"", "\"", ")", "\n", "return", "\n", "default", ":", "}", "\n", "if", "p", ".", "empty", "(", ")", "{", "return", "\n", "}", "\n", "time", ".", "Sleep", "(", "1", "*", "time", ".", "Second", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Stop terminates the channels listening loop, and allows any timeouts in send to fail
[ "Stop", "terminates", "the", "channels", "listening", "loop", "and", "allows", "any", "timeouts", "in", "send", "to", "fail" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipe/pipe.go#L122-L147
14,044
compose/transporter
pipe/pipe.go
Send
func (p *Pipe) Send(msg message.Msg, off offset.Offset) { p.MessageCount++ for _, ch := range p.Out { A: for { select { case ch <- TrackedMessage{msg, off}: break A } } } }
go
func (p *Pipe) Send(msg message.Msg, off offset.Offset) { p.MessageCount++ for _, ch := range p.Out { A: for { select { case ch <- TrackedMessage{msg, off}: break A } } } }
[ "func", "(", "p", "*", "Pipe", ")", "Send", "(", "msg", "message", ".", "Msg", ",", "off", "offset", ".", "Offset", ")", "{", "p", ".", "MessageCount", "++", "\n", "for", "_", ",", "ch", ":=", "range", "p", ".", "Out", "{", "A", ":", "for", "{", "select", "{", "case", "ch", "<-", "TrackedMessage", "{", "msg", ",", "off", "}", ":", "break", "A", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Send emits the given message on the 'Out' channel. the send Timesout after 100 ms in order to chaeck of the Pipe has stopped and we've been asked to exit. // If the Pipe has been stopped, the send will fail and there is no guarantee of either success or failure
[ "Send", "emits", "the", "given", "message", "on", "the", "Out", "channel", ".", "the", "send", "Timesout", "after", "100", "ms", "in", "order", "to", "chaeck", "of", "the", "Pipe", "has", "stopped", "and", "we", "ve", "been", "asked", "to", "exit", ".", "If", "the", "Pipe", "has", "been", "stopped", "the", "send", "will", "fail", "and", "there", "is", "no", "guarantee", "of", "either", "success", "or", "failure" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipe/pipe.go#L160-L172
14,045
compose/transporter
adaptor/mongodb/reader.go
getOriginalDoc
func (r *Reader) getOriginalDoc(doc bson.M, c string, s *mgo.Session) (result bson.M, err error) { id, exists := doc["_id"] if !exists { return result, fmt.Errorf("can't get _id from document") } query := bson.M{} if f, ok := r.collectionFilters[c]; ok { query = bson.M(f) } query["_id"] = id err = s.DB("").C(c).Find(query).One(&result) if err != nil { err = fmt.Errorf("%s.%s %v %v", s.DB("").Name, c, id, err) } return }
go
func (r *Reader) getOriginalDoc(doc bson.M, c string, s *mgo.Session) (result bson.M, err error) { id, exists := doc["_id"] if !exists { return result, fmt.Errorf("can't get _id from document") } query := bson.M{} if f, ok := r.collectionFilters[c]; ok { query = bson.M(f) } query["_id"] = id err = s.DB("").C(c).Find(query).One(&result) if err != nil { err = fmt.Errorf("%s.%s %v %v", s.DB("").Name, c, id, err) } return }
[ "func", "(", "r", "*", "Reader", ")", "getOriginalDoc", "(", "doc", "bson", ".", "M", ",", "c", "string", ",", "s", "*", "mgo", ".", "Session", ")", "(", "result", "bson", ".", "M", ",", "err", "error", ")", "{", "id", ",", "exists", ":=", "doc", "[", "\"", "\"", "]", "\n", "if", "!", "exists", "{", "return", "result", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "query", ":=", "bson", ".", "M", "{", "}", "\n", "if", "f", ",", "ok", ":=", "r", ".", "collectionFilters", "[", "c", "]", ";", "ok", "{", "query", "=", "bson", ".", "M", "(", "f", ")", "\n", "}", "\n", "query", "[", "\"", "\"", "]", "=", "id", "\n\n", "err", "=", "s", ".", "DB", "(", "\"", "\"", ")", ".", "C", "(", "c", ")", ".", "Find", "(", "query", ")", ".", "One", "(", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "s", ".", "DB", "(", "\"", "\"", ")", ".", "Name", ",", "c", ",", "id", ",", "err", ")", "\n", "}", "\n", "return", "\n", "}" ]
// getOriginalDoc retrieves the original document from the database. // transporter has no knowledge of update operations, all updates work as wholesale document replaces
[ "getOriginalDoc", "retrieves", "the", "original", "document", "from", "the", "database", ".", "transporter", "has", "no", "knowledge", "of", "update", "operations", "all", "updates", "work", "as", "wholesale", "document", "replaces" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/reader.go#L309-L326
14,046
compose/transporter
adaptor/mongodb/reader.go
validOp
func (o *oplogDoc) validOp(ns string) bool { return ns == o.Ns && (o.Op == "i" || o.Op == "d" || o.Op == "u") }
go
func (o *oplogDoc) validOp(ns string) bool { return ns == o.Ns && (o.Op == "i" || o.Op == "d" || o.Op == "u") }
[ "func", "(", "o", "*", "oplogDoc", ")", "validOp", "(", "ns", "string", ")", "bool", "{", "return", "ns", "==", "o", ".", "Ns", "&&", "(", "o", ".", "Op", "==", "\"", "\"", "||", "o", ".", "Op", "==", "\"", "\"", "||", "o", ".", "Op", "==", "\"", "\"", ")", "\n", "}" ]
// validOp checks to see if we're an insert, delete, or update, otherwise the // document is skilled.
[ "validOp", "checks", "to", "see", "if", "we", "re", "an", "insert", "delete", "or", "update", "otherwise", "the", "document", "is", "skilled", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/reader.go#L342-L344
14,047
compose/transporter
adaptor/mongodb/client.go
WithURI
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { _, err := mgo.ParseURL(uri) if err != nil { return client.InvalidURIError{URI: uri, Err: err.Error()} } c.uri = uri return nil } }
go
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { _, err := mgo.ParseURL(uri) if err != nil { return client.InvalidURIError{URI: uri, Err: err.Error()} } c.uri = uri return nil } }
[ "func", "WithURI", "(", "uri", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "_", ",", "err", ":=", "mgo", ".", "ParseURL", "(", "uri", ")", "\n", "if", "err", "!=", "nil", "{", "return", "client", ".", "InvalidURIError", "{", "URI", ":", "uri", ",", "Err", ":", "err", ".", "Error", "(", ")", "}", "\n", "}", "\n", "c", ".", "uri", "=", "uri", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithURI defines the full connection string of the MongoDB database.
[ "WithURI", "defines", "the", "full", "connection", "string", "of", "the", "MongoDB", "database", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/client.go#L112-L121
14,048
compose/transporter
adaptor/mongodb/client.go
WithTimeout
func WithTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.sessionTimeout = DefaultSessionTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.sessionTimeout = t return nil } }
go
func WithTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.sessionTimeout = DefaultSessionTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.sessionTimeout = t return nil } }
[ "func", "WithTimeout", "(", "timeout", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "timeout", "==", "\"", "\"", "{", "c", ".", "sessionTimeout", "=", "DefaultSessionTimeout", "\n", "return", "nil", "\n", "}", "\n\n", "t", ",", "err", ":=", "time", ".", "ParseDuration", "(", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "client", ".", "InvalidTimeoutError", "{", "Timeout", ":", "timeout", "}", "\n", "}", "\n", "c", ".", "sessionTimeout", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithTimeout overrides the DefaultSessionTimeout and should be parseable by time.ParseDuration
[ "WithTimeout", "overrides", "the", "DefaultSessionTimeout", "and", "should", "be", "parseable", "by", "time", ".", "ParseDuration" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/client.go#L124-L138
14,049
compose/transporter
adaptor/mongodb/client.go
WithReadPreference
func WithReadPreference(readPreference string) ClientOptionFunc { return func(c *Client) error { if readPreference == "" { c.readPreference = DefaultReadPreference return nil } switch strings.ToLower(readPreference) { case "primary": c.readPreference = mgo.Primary case "primarypreferred": c.readPreference = mgo.PrimaryPreferred case "secondary": c.readPreference = mgo.Secondary case "secondarypreferred": c.readPreference = mgo.SecondaryPreferred case "nearest": c.readPreference = mgo.Nearest default: return InvalidReadPreferenceError{ReadPreference: readPreference} } return nil } }
go
func WithReadPreference(readPreference string) ClientOptionFunc { return func(c *Client) error { if readPreference == "" { c.readPreference = DefaultReadPreference return nil } switch strings.ToLower(readPreference) { case "primary": c.readPreference = mgo.Primary case "primarypreferred": c.readPreference = mgo.PrimaryPreferred case "secondary": c.readPreference = mgo.Secondary case "secondarypreferred": c.readPreference = mgo.SecondaryPreferred case "nearest": c.readPreference = mgo.Nearest default: return InvalidReadPreferenceError{ReadPreference: readPreference} } return nil } }
[ "func", "WithReadPreference", "(", "readPreference", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "readPreference", "==", "\"", "\"", "{", "c", ".", "readPreference", "=", "DefaultReadPreference", "\n", "return", "nil", "\n", "}", "\n", "switch", "strings", ".", "ToLower", "(", "readPreference", ")", "{", "case", "\"", "\"", ":", "c", ".", "readPreference", "=", "mgo", ".", "Primary", "\n", "case", "\"", "\"", ":", "c", ".", "readPreference", "=", "mgo", ".", "PrimaryPreferred", "\n", "case", "\"", "\"", ":", "c", ".", "readPreference", "=", "mgo", ".", "Secondary", "\n", "case", "\"", "\"", ":", "c", ".", "readPreference", "=", "mgo", ".", "SecondaryPreferred", "\n", "case", "\"", "\"", ":", "c", ".", "readPreference", "=", "mgo", ".", "Nearest", "\n", "default", ":", "return", "InvalidReadPreferenceError", "{", "ReadPreference", ":", "readPreference", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithReadPreference sets the MongoDB read preference based on the provided string.
[ "WithReadPreference", "sets", "the", "MongoDB", "read", "preference", "based", "on", "the", "provided", "string", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/client.go#L211-L233
14,050
compose/transporter
adaptor/mongodb/client.go
Connect
func (c *Client) Connect() (client.Session, error) { if c.mgoSession == nil { if err := c.initConnection(); err != nil { return nil, err } } return c.session(), nil }
go
func (c *Client) Connect() (client.Session, error) { if c.mgoSession == nil { if err := c.initConnection(); err != nil { return nil, err } } return c.session(), nil }
[ "func", "(", "c", "*", "Client", ")", "Connect", "(", ")", "(", "client", ".", "Session", ",", "error", ")", "{", "if", "c", ".", "mgoSession", "==", "nil", "{", "if", "err", ":=", "c", ".", "initConnection", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "c", ".", "session", "(", ")", ",", "nil", "\n", "}" ]
// Connect tests the mongodb connection and initializes the mongo session
[ "Connect", "tests", "the", "mongodb", "connection", "and", "initializes", "the", "mongo", "session" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/client.go#L236-L243
14,051
compose/transporter
adaptor/mongodb/client.go
session
func (c *Client) session() client.Session { sess := c.mgoSession.Copy() return &Session{sess} }
go
func (c *Client) session() client.Session { sess := c.mgoSession.Copy() return &Session{sess} }
[ "func", "(", "c", "*", "Client", ")", "session", "(", ")", "client", ".", "Session", "{", "sess", ":=", "c", ".", "mgoSession", ".", "Copy", "(", ")", "\n", "return", "&", "Session", "{", "sess", "}", "\n", "}" ]
// Session fulfills the client.Client interface by providing a copy of the main mgoSession
[ "Session", "fulfills", "the", "client", ".", "Client", "interface", "by", "providing", "a", "copy", "of", "the", "main", "mgoSession" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/mongodb/client.go#L304-L307
14,052
compose/transporter
adaptor/file/client.go
Connect
func (c *Client) Connect() (client.Session, error) { if c.file == nil { if err := c.initFile(); err != nil { return nil, err } } return &Session{c.file}, nil }
go
func (c *Client) Connect() (client.Session, error) { if c.file == nil { if err := c.initFile(); err != nil { return nil, err } } return &Session{c.file}, nil }
[ "func", "(", "c", "*", "Client", ")", "Connect", "(", ")", "(", "client", ".", "Session", ",", "error", ")", "{", "if", "c", ".", "file", "==", "nil", "{", "if", "err", ":=", "c", ".", "initFile", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "Session", "{", "c", ".", "file", "}", ",", "nil", "\n", "}" ]
// Connect initializes the file for IO
[ "Connect", "initializes", "the", "file", "for", "IO" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/file/client.go#L55-L62
14,053
compose/transporter
adaptor/file/client.go
Close
func (c *Client) Close() { if c.file != nil && c.file != os.Stdout { c.file.Close() } }
go
func (c *Client) Close() { if c.file != nil && c.file != os.Stdout { c.file.Close() } }
[ "func", "(", "c", "*", "Client", ")", "Close", "(", ")", "{", "if", "c", ".", "file", "!=", "nil", "&&", "c", ".", "file", "!=", "os", ".", "Stdout", "{", "c", ".", "file", ".", "Close", "(", ")", "\n", "}", "\n", "}" ]
// Close closes the underlying file
[ "Close", "closes", "the", "underlying", "file" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/file/client.go#L65-L69
14,054
compose/transporter
events/events.go
NewMetricsEvent
func NewMetricsEvent(ts int64, path string, records int) Event { e := &metricsEvent{ Ts: ts, Kind: "metrics", Path: path, Records: records, } return e }
go
func NewMetricsEvent(ts int64, path string, records int) Event { e := &metricsEvent{ Ts: ts, Kind: "metrics", Path: path, Records: records, } return e }
[ "func", "NewMetricsEvent", "(", "ts", "int64", ",", "path", "string", ",", "records", "int", ")", "Event", "{", "e", ":=", "&", "metricsEvent", "{", "Ts", ":", "ts", ",", "Kind", ":", "\"", "\"", ",", "Path", ":", "path", ",", "Records", ":", "records", ",", "}", "\n", "return", "e", "\n", "}" ]
// NewMetricsEvent creates a new metrics event
[ "NewMetricsEvent", "creates", "a", "new", "metrics", "event" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/events/events.go#L75-L83
14,055
compose/transporter
events/events.go
NewErrorEvent
func NewErrorEvent(ts int64, path string, record interface{}, message string) Event { e := &errorEvent{ Ts: ts, Kind: "error", Path: path, Record: record, Message: message, } return e }
go
func NewErrorEvent(ts int64, path string, record interface{}, message string) Event { e := &errorEvent{ Ts: ts, Kind: "error", Path: path, Record: record, Message: message, } return e }
[ "func", "NewErrorEvent", "(", "ts", "int64", ",", "path", "string", ",", "record", "interface", "{", "}", ",", "message", "string", ")", "Event", "{", "e", ":=", "&", "errorEvent", "{", "Ts", ":", "ts", ",", "Kind", ":", "\"", "\"", ",", "Path", ":", "path", ",", "Record", ":", "record", ",", "Message", ":", "message", ",", "}", "\n", "return", "e", "\n", "}" ]
// NewErrorEvent are events sent to indicate a problem processing on one of the nodes
[ "NewErrorEvent", "are", "events", "sent", "to", "indicate", "a", "problem", "processing", "on", "one", "of", "the", "nodes" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/events/events.go#L113-L122
14,056
compose/transporter
pipeline/node.go
NewNodeWithOptions
func NewNodeWithOptions(name, kind, ns string, options ...OptionFunc) (*Node, error) { compiledNs, err := regexp.Compile(strings.Trim(ns, "/")) if err != nil { return nil, err } n := &Node{ Name: name, Type: kind, path: name, depth: 1, nsFilter: compiledNs, pipe: pipe.NewPipe(nil, name), children: make([]*Node, 0), transforms: make([]*Transform, 0), done: make(chan struct{}), c: &client.Mock{}, reader: &client.MockReader{}, writer: &client.MockWriter{}, resumeTimeout: 60 * time.Second, writeTimeout: defaultWriteTimeout, compactionInterval: defaultCompactionInterval, } // Run the options on it for _, option := range options { if err := option(n); err != nil { return nil, err } } return n, nil }
go
func NewNodeWithOptions(name, kind, ns string, options ...OptionFunc) (*Node, error) { compiledNs, err := regexp.Compile(strings.Trim(ns, "/")) if err != nil { return nil, err } n := &Node{ Name: name, Type: kind, path: name, depth: 1, nsFilter: compiledNs, pipe: pipe.NewPipe(nil, name), children: make([]*Node, 0), transforms: make([]*Transform, 0), done: make(chan struct{}), c: &client.Mock{}, reader: &client.MockReader{}, writer: &client.MockWriter{}, resumeTimeout: 60 * time.Second, writeTimeout: defaultWriteTimeout, compactionInterval: defaultCompactionInterval, } // Run the options on it for _, option := range options { if err := option(n); err != nil { return nil, err } } return n, nil }
[ "func", "NewNodeWithOptions", "(", "name", ",", "kind", ",", "ns", "string", ",", "options", "...", "OptionFunc", ")", "(", "*", "Node", ",", "error", ")", "{", "compiledNs", ",", "err", ":=", "regexp", ".", "Compile", "(", "strings", ".", "Trim", "(", "ns", ",", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "n", ":=", "&", "Node", "{", "Name", ":", "name", ",", "Type", ":", "kind", ",", "path", ":", "name", ",", "depth", ":", "1", ",", "nsFilter", ":", "compiledNs", ",", "pipe", ":", "pipe", ".", "NewPipe", "(", "nil", ",", "name", ")", ",", "children", ":", "make", "(", "[", "]", "*", "Node", ",", "0", ")", ",", "transforms", ":", "make", "(", "[", "]", "*", "Transform", ",", "0", ")", ",", "done", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "c", ":", "&", "client", ".", "Mock", "{", "}", ",", "reader", ":", "&", "client", ".", "MockReader", "{", "}", ",", "writer", ":", "&", "client", ".", "MockWriter", "{", "}", ",", "resumeTimeout", ":", "60", "*", "time", ".", "Second", ",", "writeTimeout", ":", "defaultWriteTimeout", ",", "compactionInterval", ":", "defaultCompactionInterval", ",", "}", "\n", "// Run the options on it", "for", "_", ",", "option", ":=", "range", "options", "{", "if", "err", ":=", "option", "(", "n", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "n", ",", "nil", "\n", "}" ]
// NewNodeWithOptions initializes a Node with the required parameters and then applies // each OptionFunc provided.
[ "NewNodeWithOptions", "initializes", "a", "Node", "with", "the", "required", "parameters", "and", "then", "applies", "each", "OptionFunc", "provided", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L96-L125
14,057
compose/transporter
pipeline/node.go
WithReader
func WithReader(a adaptor.Adaptor) OptionFunc { return func(n *Node) error { r, err := a.Reader() n.reader = r return err } }
go
func WithReader(a adaptor.Adaptor) OptionFunc { return func(n *Node) error { r, err := a.Reader() n.reader = r return err } }
[ "func", "WithReader", "(", "a", "adaptor", ".", "Adaptor", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "r", ",", "err", ":=", "a", ".", "Reader", "(", ")", "\n", "n", ".", "reader", "=", "r", "\n", "return", "err", "\n", "}", "\n", "}" ]
// WithReader sets the client.Reader to be used to source data from.
[ "WithReader", "sets", "the", "client", ".", "Reader", "to", "be", "used", "to", "source", "data", "from", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L138-L144
14,058
compose/transporter
pipeline/node.go
WithWriter
func WithWriter(a adaptor.Adaptor) OptionFunc { return func(n *Node) error { w, err := a.Writer(n.done, &n.wg) n.writer = w return err } }
go
func WithWriter(a adaptor.Adaptor) OptionFunc { return func(n *Node) error { w, err := a.Writer(n.done, &n.wg) n.writer = w return err } }
[ "func", "WithWriter", "(", "a", "adaptor", ".", "Adaptor", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "w", ",", "err", ":=", "a", ".", "Writer", "(", "n", ".", "done", ",", "&", "n", ".", "wg", ")", "\n", "n", ".", "writer", "=", "w", "\n", "return", "err", "\n", "}", "\n", "}" ]
// WithWriter sets the client.Writer to be used to send data to.
[ "WithWriter", "sets", "the", "client", ".", "Writer", "to", "be", "used", "to", "send", "data", "to", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L147-L153
14,059
compose/transporter
pipeline/node.go
WithParent
func WithParent(parent *Node) OptionFunc { return func(n *Node) error { n.parent = parent parent.children = append(parent.children, n) n.path = parent.path + "/" + n.Name n.depth = parent.depth + 1 n.pipe = pipe.NewPipe(parent.pipe, n.path) return nil } }
go
func WithParent(parent *Node) OptionFunc { return func(n *Node) error { n.parent = parent parent.children = append(parent.children, n) n.path = parent.path + "/" + n.Name n.depth = parent.depth + 1 n.pipe = pipe.NewPipe(parent.pipe, n.path) return nil } }
[ "func", "WithParent", "(", "parent", "*", "Node", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "n", ".", "parent", "=", "parent", "\n", "parent", ".", "children", "=", "append", "(", "parent", ".", "children", ",", "n", ")", "\n", "n", ".", "path", "=", "parent", ".", "path", "+", "\"", "\"", "+", "n", ".", "Name", "\n", "n", ".", "depth", "=", "parent", ".", "depth", "+", "1", "\n", "n", ".", "pipe", "=", "pipe", ".", "NewPipe", "(", "parent", ".", "pipe", ",", "n", ".", "path", ")", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithParent sets the parent node and reconfigures the pipe.
[ "WithParent", "sets", "the", "parent", "node", "and", "reconfigures", "the", "pipe", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L156-L165
14,060
compose/transporter
pipeline/node.go
WithTransforms
func WithTransforms(t []*Transform) OptionFunc { return func(n *Node) error { n.transforms = t return nil } }
go
func WithTransforms(t []*Transform) OptionFunc { return func(n *Node) error { n.transforms = t return nil } }
[ "func", "WithTransforms", "(", "t", "[", "]", "*", "Transform", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "n", ".", "transforms", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithTransforms adds the provided transforms to be applied in the pipeline.
[ "WithTransforms", "adds", "the", "provided", "transforms", "to", "be", "applied", "in", "the", "pipeline", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L168-L173
14,061
compose/transporter
pipeline/node.go
WithCommitLog
func WithCommitLog(options ...commitlog.OptionFunc) OptionFunc { return func(n *Node) error { clog, err := commitlog.New(options...) n.clog = clog return err } }
go
func WithCommitLog(options ...commitlog.OptionFunc) OptionFunc { return func(n *Node) error { clog, err := commitlog.New(options...) n.clog = clog return err } }
[ "func", "WithCommitLog", "(", "options", "...", "commitlog", ".", "OptionFunc", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "clog", ",", "err", ":=", "commitlog", ".", "New", "(", "options", "...", ")", "\n", "n", ".", "clog", "=", "clog", "\n", "return", "err", "\n", "}", "\n", "}" ]
// WithCommitLog configures a CommitLog for the reader to persist messages.
[ "WithCommitLog", "configures", "a", "CommitLog", "for", "the", "reader", "to", "persist", "messages", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L176-L182
14,062
compose/transporter
pipeline/node.go
WithResumeTimeout
func WithResumeTimeout(timeout time.Duration) OptionFunc { return func(n *Node) error { n.resumeTimeout = timeout return nil } }
go
func WithResumeTimeout(timeout time.Duration) OptionFunc { return func(n *Node) error { n.resumeTimeout = timeout return nil } }
[ "func", "WithResumeTimeout", "(", "timeout", "time", ".", "Duration", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "n", ".", "resumeTimeout", "=", "timeout", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithResumeTimeout configures how long to wait before all sink offsets match the // newest offset.
[ "WithResumeTimeout", "configures", "how", "long", "to", "wait", "before", "all", "sink", "offsets", "match", "the", "newest", "offset", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L186-L191
14,063
compose/transporter
pipeline/node.go
WithWriteTimeout
func WithWriteTimeout(timeout string) OptionFunc { return func(n *Node) error { if timeout == "" { n.writeTimeout = defaultWriteTimeout return nil } wt, err := time.ParseDuration(timeout) if err != nil { return err } n.writeTimeout = wt return nil } }
go
func WithWriteTimeout(timeout string) OptionFunc { return func(n *Node) error { if timeout == "" { n.writeTimeout = defaultWriteTimeout return nil } wt, err := time.ParseDuration(timeout) if err != nil { return err } n.writeTimeout = wt return nil } }
[ "func", "WithWriteTimeout", "(", "timeout", "string", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "if", "timeout", "==", "\"", "\"", "{", "n", ".", "writeTimeout", "=", "defaultWriteTimeout", "\n", "return", "nil", "\n", "}", "\n", "wt", ",", "err", ":=", "time", ".", "ParseDuration", "(", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "n", ".", "writeTimeout", "=", "wt", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithWriteTimeout configures the timeout duration for a writer to return.
[ "WithWriteTimeout", "configures", "the", "timeout", "duration", "for", "a", "writer", "to", "return", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L194-L207
14,064
compose/transporter
pipeline/node.go
WithOffsetManager
func WithOffsetManager(om offset.Manager) OptionFunc { return func(n *Node) error { n.om = om return nil } }
go
func WithOffsetManager(om offset.Manager) OptionFunc { return func(n *Node) error { n.om = om return nil } }
[ "func", "WithOffsetManager", "(", "om", "offset", ".", "Manager", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "n", ".", "om", "=", "om", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithOffsetManager configures an offset.Manager to track message offsets.
[ "WithOffsetManager", "configures", "an", "offset", ".", "Manager", "to", "track", "message", "offsets", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L210-L215
14,065
compose/transporter
pipeline/node.go
WithCompactionInterval
func WithCompactionInterval(interval string) OptionFunc { return func(n *Node) error { if interval == "" { n.compactionInterval = defaultCompactionInterval return nil } ci, err := time.ParseDuration(interval) if err != nil { return err } n.compactionInterval = ci return nil } }
go
func WithCompactionInterval(interval string) OptionFunc { return func(n *Node) error { if interval == "" { n.compactionInterval = defaultCompactionInterval return nil } ci, err := time.ParseDuration(interval) if err != nil { return err } n.compactionInterval = ci return nil } }
[ "func", "WithCompactionInterval", "(", "interval", "string", ")", "OptionFunc", "{", "return", "func", "(", "n", "*", "Node", ")", "error", "{", "if", "interval", "==", "\"", "\"", "{", "n", ".", "compactionInterval", "=", "defaultCompactionInterval", "\n", "return", "nil", "\n", "}", "\n", "ci", ",", "err", ":=", "time", ".", "ParseDuration", "(", "interval", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "n", ".", "compactionInterval", "=", "ci", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithCompactionInterval configures the duration for running log compaction.
[ "WithCompactionInterval", "configures", "the", "duration", "for", "running", "log", "compaction", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L218-L231
14,066
compose/transporter
pipeline/node.go
start
func (n *Node) start(nsMap map[string]client.MessageSet) error { n.l.Infoln("adaptor Starting...") s, err := n.c.Connect() if err != nil { return err } if closer, ok := s.(client.Closer); ok { defer func() { n.l.Debugln("closing session...") closer.Close() n.l.Debugln("session closed...") }() } readFunc := n.reader.Read(nsMap, func(check string) bool { return n.nsFilter.MatchString(check) }) msgChan, err := readFunc(s, n.done) if err != nil { return err } var logOffset int64 for msg := range msgChan { if n.clog != nil { d, _ := mejson.Marshal(msg.Msg.Data().AsMap()) b, _ := json.Marshal(d) o, err := n.clog.Append( commitlog.NewLogFromEntry( commitlog.LogEntry{ Key: []byte(msg.Msg.Namespace()), Mode: msg.Mode, Op: msg.Msg.OP(), Timestamp: uint64(msg.Timestamp), Value: b, })) if err != nil { return err } logOffset = o n.l.With("offset", logOffset).Debugln("attaching offset to message") } n.pipe.Send(msg.Msg, offset.Offset{ Namespace: msg.Msg.Namespace(), LogOffset: uint64(logOffset), Timestamp: time.Now().Unix(), }) } n.l.Infoln("adaptor Start finished...") return nil }
go
func (n *Node) start(nsMap map[string]client.MessageSet) error { n.l.Infoln("adaptor Starting...") s, err := n.c.Connect() if err != nil { return err } if closer, ok := s.(client.Closer); ok { defer func() { n.l.Debugln("closing session...") closer.Close() n.l.Debugln("session closed...") }() } readFunc := n.reader.Read(nsMap, func(check string) bool { return n.nsFilter.MatchString(check) }) msgChan, err := readFunc(s, n.done) if err != nil { return err } var logOffset int64 for msg := range msgChan { if n.clog != nil { d, _ := mejson.Marshal(msg.Msg.Data().AsMap()) b, _ := json.Marshal(d) o, err := n.clog.Append( commitlog.NewLogFromEntry( commitlog.LogEntry{ Key: []byte(msg.Msg.Namespace()), Mode: msg.Mode, Op: msg.Msg.OP(), Timestamp: uint64(msg.Timestamp), Value: b, })) if err != nil { return err } logOffset = o n.l.With("offset", logOffset).Debugln("attaching offset to message") } n.pipe.Send(msg.Msg, offset.Offset{ Namespace: msg.Msg.Namespace(), LogOffset: uint64(logOffset), Timestamp: time.Now().Unix(), }) } n.l.Infoln("adaptor Start finished...") return nil }
[ "func", "(", "n", "*", "Node", ")", "start", "(", "nsMap", "map", "[", "string", "]", "client", ".", "MessageSet", ")", "error", "{", "n", ".", "l", ".", "Infoln", "(", "\"", "\"", ")", "\n\n", "s", ",", "err", ":=", "n", ".", "c", ".", "Connect", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "closer", ",", "ok", ":=", "s", ".", "(", "client", ".", "Closer", ")", ";", "ok", "{", "defer", "func", "(", ")", "{", "n", ".", "l", ".", "Debugln", "(", "\"", "\"", ")", "\n", "closer", ".", "Close", "(", ")", "\n", "n", ".", "l", ".", "Debugln", "(", "\"", "\"", ")", "\n", "}", "(", ")", "\n", "}", "\n", "readFunc", ":=", "n", ".", "reader", ".", "Read", "(", "nsMap", ",", "func", "(", "check", "string", ")", "bool", "{", "return", "n", ".", "nsFilter", ".", "MatchString", "(", "check", ")", "}", ")", "\n", "msgChan", ",", "err", ":=", "readFunc", "(", "s", ",", "n", ".", "done", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "var", "logOffset", "int64", "\n", "for", "msg", ":=", "range", "msgChan", "{", "if", "n", ".", "clog", "!=", "nil", "{", "d", ",", "_", ":=", "mejson", ".", "Marshal", "(", "msg", ".", "Msg", ".", "Data", "(", ")", ".", "AsMap", "(", ")", ")", "\n", "b", ",", "_", ":=", "json", ".", "Marshal", "(", "d", ")", "\n", "o", ",", "err", ":=", "n", ".", "clog", ".", "Append", "(", "commitlog", ".", "NewLogFromEntry", "(", "commitlog", ".", "LogEntry", "{", "Key", ":", "[", "]", "byte", "(", "msg", ".", "Msg", ".", "Namespace", "(", ")", ")", ",", "Mode", ":", "msg", ".", "Mode", ",", "Op", ":", "msg", ".", "Msg", ".", "OP", "(", ")", ",", "Timestamp", ":", "uint64", "(", "msg", ".", "Timestamp", ")", ",", "Value", ":", "b", ",", "}", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "logOffset", "=", "o", "\n", "n", ".", "l", ".", "With", "(", "\"", "\"", ",", "logOffset", ")", ".", "Debugln", "(", "\"", "\"", ")", "\n", "}", "\n", "n", ".", "pipe", ".", "Send", "(", "msg", ".", "Msg", ",", "offset", ".", "Offset", "{", "Namespace", ":", "msg", ".", "Msg", ".", "Namespace", "(", ")", ",", "LogOffset", ":", "uint64", "(", "logOffset", ")", ",", "Timestamp", ":", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ",", "}", ")", "\n", "}", "\n\n", "n", ".", "l", ".", "Infoln", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}" ]
// Start the adaptor as a source
[ "Start", "the", "adaptor", "as", "a", "source" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L439-L487
14,067
compose/transporter
pipeline/node.go
Stop
func (n *Node) Stop() { n.stop() for _, node := range n.children { node.Stop() } }
go
func (n *Node) Stop() { n.stop() for _, node := range n.children { node.Stop() } }
[ "func", "(", "n", "*", "Node", ")", "Stop", "(", ")", "{", "n", ".", "stop", "(", ")", "\n", "for", "_", ",", "node", ":=", "range", "n", ".", "children", "{", "node", ".", "Stop", "(", ")", "\n", "}", "\n", "}" ]
// Stop this node's adaptor, and sends a stop to each child of this node
[ "Stop", "this", "node", "s", "adaptor", "and", "sends", "a", "stop", "to", "each", "child", "of", "this", "node" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L622-L627
14,068
compose/transporter
pipeline/node.go
Validate
func (n *Node) Validate() bool { if n.parent == nil && len(n.children) == 0 { // the root node should have children return false } for _, child := range n.children { if !child.Validate() { return false } } return true }
go
func (n *Node) Validate() bool { if n.parent == nil && len(n.children) == 0 { // the root node should have children return false } for _, child := range n.children { if !child.Validate() { return false } } return true }
[ "func", "(", "n", "*", "Node", ")", "Validate", "(", ")", "bool", "{", "if", "n", ".", "parent", "==", "nil", "&&", "len", "(", "n", ".", "children", ")", "==", "0", "{", "// the root node should have children", "return", "false", "\n", "}", "\n\n", "for", "_", ",", "child", ":=", "range", "n", ".", "children", "{", "if", "!", "child", ".", "Validate", "(", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Validate ensures that the node tree conforms to a proper structure. // Node trees must have at least one source, and one sink. // dangling transformers are forbidden. Validate only knows about default adaptors // in the adaptor package, it can't validate any custom adaptors
[ "Validate", "ensures", "that", "the", "node", "tree", "conforms", "to", "a", "proper", "structure", ".", "Node", "trees", "must", "have", "at", "least", "one", "source", "and", "one", "sink", ".", "dangling", "transformers", "are", "forbidden", ".", "Validate", "only", "knows", "about", "default", "adaptors", "in", "the", "adaptor", "package", "it", "can", "t", "validate", "any", "custom", "adaptors" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L658-L669
14,069
compose/transporter
pipeline/node.go
Endpoints
func (n *Node) Endpoints() map[string]string { m := map[string]string{n.Name: n.Type} for _, child := range n.children { childMap := child.Endpoints() for k, v := range childMap { m[k] = v } } return m }
go
func (n *Node) Endpoints() map[string]string { m := map[string]string{n.Name: n.Type} for _, child := range n.children { childMap := child.Endpoints() for k, v := range childMap { m[k] = v } } return m }
[ "func", "(", "n", "*", "Node", ")", "Endpoints", "(", ")", "map", "[", "string", "]", "string", "{", "m", ":=", "map", "[", "string", "]", "string", "{", "n", ".", "Name", ":", "n", ".", "Type", "}", "\n", "for", "_", ",", "child", ":=", "range", "n", ".", "children", "{", "childMap", ":=", "child", ".", "Endpoints", "(", ")", "\n", "for", "k", ",", "v", ":=", "range", "childMap", "{", "m", "[", "k", "]", "=", "v", "\n", "}", "\n", "}", "\n", "return", "m", "\n", "}" ]
// Endpoints recurses down the node tree and accumulates a map associating node name with node type // this is primarily used with the boot event
[ "Endpoints", "recurses", "down", "the", "node", "tree", "and", "accumulates", "a", "map", "associating", "node", "name", "with", "node", "type", "this", "is", "primarily", "used", "with", "the", "boot", "event" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/pipeline/node.go#L673-L682
14,070
compose/transporter
adaptor/rethinkdb/client.go
WithURI
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { _, err := url.Parse(c.uri) if err != nil { return client.InvalidURIError{URI: uri, Err: err.Error()} } c.uri = uri return nil } }
go
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { _, err := url.Parse(c.uri) if err != nil { return client.InvalidURIError{URI: uri, Err: err.Error()} } c.uri = uri return nil } }
[ "func", "WithURI", "(", "uri", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "_", ",", "err", ":=", "url", ".", "Parse", "(", "c", ".", "uri", ")", "\n", "if", "err", "!=", "nil", "{", "return", "client", ".", "InvalidURIError", "{", "URI", ":", "uri", ",", "Err", ":", "err", ".", "Error", "(", ")", "}", "\n", "}", "\n", "c", ".", "uri", "=", "uri", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithURI defines the full connection string of the RethinkDB database.
[ "WithURI", "defines", "the", "full", "connection", "string", "of", "the", "RethinkDB", "database", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/client.go#L92-L101
14,071
compose/transporter
adaptor/rethinkdb/client.go
WithSessionTimeout
func WithSessionTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.sessionTimeout = DefaultTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.sessionTimeout = t return nil } }
go
func WithSessionTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.sessionTimeout = DefaultTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.sessionTimeout = t return nil } }
[ "func", "WithSessionTimeout", "(", "timeout", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "timeout", "==", "\"", "\"", "{", "c", ".", "sessionTimeout", "=", "DefaultTimeout", "\n", "return", "nil", "\n", "}", "\n\n", "t", ",", "err", ":=", "time", ".", "ParseDuration", "(", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "client", ".", "InvalidTimeoutError", "{", "Timeout", ":", "timeout", "}", "\n", "}", "\n", "c", ".", "sessionTimeout", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithSessionTimeout overrides the DefaultTimeout and should be parseable by time.ParseDuration
[ "WithSessionTimeout", "overrides", "the", "DefaultTimeout", "and", "should", "be", "parseable", "by", "time", ".", "ParseDuration" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/client.go#L104-L118
14,072
compose/transporter
adaptor/rethinkdb/client.go
WithWriteTimeout
func WithWriteTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.writeTimeout = DefaultTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.writeTimeout = t return nil } }
go
func WithWriteTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.writeTimeout = DefaultTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.writeTimeout = t return nil } }
[ "func", "WithWriteTimeout", "(", "timeout", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "timeout", "==", "\"", "\"", "{", "c", ".", "writeTimeout", "=", "DefaultTimeout", "\n", "return", "nil", "\n", "}", "\n\n", "t", ",", "err", ":=", "time", ".", "ParseDuration", "(", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "client", ".", "InvalidTimeoutError", "{", "Timeout", ":", "timeout", "}", "\n", "}", "\n", "c", ".", "writeTimeout", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithWriteTimeout overrides the DefaultTimeout and should be parseable by time.ParseDuration
[ "WithWriteTimeout", "overrides", "the", "DefaultTimeout", "and", "should", "be", "parseable", "by", "time", ".", "ParseDuration" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/client.go#L121-L135
14,073
compose/transporter
adaptor/rethinkdb/client.go
WithReadTimeout
func WithReadTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.readTimeout = DefaultTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.readTimeout = t return nil } }
go
func WithReadTimeout(timeout string) ClientOptionFunc { return func(c *Client) error { if timeout == "" { c.readTimeout = DefaultTimeout return nil } t, err := time.ParseDuration(timeout) if err != nil { return client.InvalidTimeoutError{Timeout: timeout} } c.readTimeout = t return nil } }
[ "func", "WithReadTimeout", "(", "timeout", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "if", "timeout", "==", "\"", "\"", "{", "c", ".", "readTimeout", "=", "DefaultTimeout", "\n", "return", "nil", "\n", "}", "\n\n", "t", ",", "err", ":=", "time", ".", "ParseDuration", "(", "timeout", ")", "\n", "if", "err", "!=", "nil", "{", "return", "client", ".", "InvalidTimeoutError", "{", "Timeout", ":", "timeout", "}", "\n", "}", "\n", "c", ".", "readTimeout", "=", "t", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WithReadTimeout overrides the DefaultTimeout and should be parseable by time.ParseDuration
[ "WithReadTimeout", "overrides", "the", "DefaultTimeout", "and", "should", "be", "parseable", "by", "time", ".", "ParseDuration" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/client.go#L138-L152
14,074
compose/transporter
adaptor/rethinkdb/client.go
Close
func (c *Client) Close() { if c.session != nil { c.session.Close(r.CloseOpts{NoReplyWait: false}) } }
go
func (c *Client) Close() { if c.session != nil { c.session.Close(r.CloseOpts{NoReplyWait: false}) } }
[ "func", "(", "c", "*", "Client", ")", "Close", "(", ")", "{", "if", "c", ".", "session", "!=", "nil", "{", "c", ".", "session", ".", "Close", "(", "r", ".", "CloseOpts", "{", "NoReplyWait", ":", "false", "}", ")", "\n", "}", "\n", "}" ]
// Close fulfills the Closer interface and takes care of cleaning up the rethink.Session
[ "Close", "fulfills", "the", "Closer", "interface", "and", "takes", "care", "of", "cleaning", "up", "the", "rethink", ".", "Session" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/client.go#L206-L210
14,075
compose/transporter
message/message.go
From
func From(op ops.Op, namespace string, d data.Data) Msg { return &Base{ Operation: op, TS: time.Now().Unix(), NS: namespace, MapData: d, confirm: nil, } }
go
func From(op ops.Op, namespace string, d data.Data) Msg { return &Base{ Operation: op, TS: time.Now().Unix(), NS: namespace, MapData: d, confirm: nil, } }
[ "func", "From", "(", "op", "ops", ".", "Op", ",", "namespace", "string", ",", "d", "data", ".", "Data", ")", "Msg", "{", "return", "&", "Base", "{", "Operation", ":", "op", ",", "TS", ":", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ",", "NS", ":", "namespace", ",", "MapData", ":", "d", ",", "confirm", ":", "nil", ",", "}", "\n", "}" ]
// From builds a message.Msg specific to an elasticsearch document
[ "From", "builds", "a", "message", ".", "Msg", "specific", "to", "an", "elasticsearch", "document" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/message/message.go#L33-L41
14,076
compose/transporter
message/message.go
WithConfirms
func WithConfirms(confirm chan struct{}, msg Msg) Msg { switch m := msg.(type) { case *Base: m.confirm = confirm } return msg }
go
func WithConfirms(confirm chan struct{}, msg Msg) Msg { switch m := msg.(type) { case *Base: m.confirm = confirm } return msg }
[ "func", "WithConfirms", "(", "confirm", "chan", "struct", "{", "}", ",", "msg", "Msg", ")", "Msg", "{", "switch", "m", ":=", "msg", ".", "(", "type", ")", "{", "case", "*", "Base", ":", "m", ".", "confirm", "=", "confirm", "\n", "}", "\n", "return", "msg", "\n", "}" ]
// WithConfirms attaches a channel to be able to acknowledge message processing.
[ "WithConfirms", "attaches", "a", "channel", "to", "be", "able", "to", "acknowledge", "message", "processing", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/message/message.go#L44-L50
14,077
compose/transporter
message/message.go
ID
func (m *Base) ID() string { if _, ok := m.MapData["_id"]; !ok { return "" } switch id := m.MapData["_id"].(type) { case string: return id case bson.ObjectId: return id.Hex() default: return fmt.Sprintf("%v", id) } }
go
func (m *Base) ID() string { if _, ok := m.MapData["_id"]; !ok { return "" } switch id := m.MapData["_id"].(type) { case string: return id case bson.ObjectId: return id.Hex() default: return fmt.Sprintf("%v", id) } }
[ "func", "(", "m", "*", "Base", ")", "ID", "(", ")", "string", "{", "if", "_", ",", "ok", ":=", "m", ".", "MapData", "[", "\"", "\"", "]", ";", "!", "ok", "{", "return", "\"", "\"", "\n", "}", "\n", "switch", "id", ":=", "m", ".", "MapData", "[", "\"", "\"", "]", ".", "(", "type", ")", "{", "case", "string", ":", "return", "id", "\n", "case", "bson", ".", "ObjectId", ":", "return", "id", ".", "Hex", "(", ")", "\n", "default", ":", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "id", ")", "\n", "}", "\n", "}" ]
// ID will attempt to convert the _id field into a string representation
[ "ID", "will", "attempt", "to", "convert", "the", "_id", "field", "into", "a", "string", "representation" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/message/message.go#L90-L102
14,078
compose/transporter
adaptor/rethinkdb/writer.go
prepareDocument
func prepareDocument(msg message.Msg) map[string]interface{} { if _, ok := msg.Data()["id"]; ok { return msg.Data() } if _, ok := msg.Data()["_id"]; ok { msg.Data().Set("id", msg.ID()) msg.Data().Delete("_id") } return msg.Data() }
go
func prepareDocument(msg message.Msg) map[string]interface{} { if _, ok := msg.Data()["id"]; ok { return msg.Data() } if _, ok := msg.Data()["_id"]; ok { msg.Data().Set("id", msg.ID()) msg.Data().Delete("_id") } return msg.Data() }
[ "func", "prepareDocument", "(", "msg", "message", ".", "Msg", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "if", "_", ",", "ok", ":=", "msg", ".", "Data", "(", ")", "[", "\"", "\"", "]", ";", "ok", "{", "return", "msg", ".", "Data", "(", ")", "\n", "}", "\n\n", "if", "_", ",", "ok", ":=", "msg", ".", "Data", "(", ")", "[", "\"", "\"", "]", ";", "ok", "{", "msg", ".", "Data", "(", ")", ".", "Set", "(", "\"", "\"", ",", "msg", ".", "ID", "(", ")", ")", "\n", "msg", ".", "Data", "(", ")", ".", "Delete", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "msg", ".", "Data", "(", ")", "\n", "}" ]
// prepareDocument checks for an `_id` field and moves it to `id`.
[ "prepareDocument", "checks", "for", "an", "_id", "field", "and", "moves", "it", "to", "id", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/writer.go#L96-L106
14,079
compose/transporter
adaptor/rethinkdb/writer.go
handleResponse
func handleResponse(resp *r.WriteResponse, confirms chan struct{}) error { if resp.Errors != 0 { if !strings.Contains(resp.FirstError, "Duplicate primary key") { // we don't care about this error return fmt.Errorf("%s\n%s", "problem inserting docs", resp.FirstError) } } if confirms != nil { confirms <- struct{}{} } return nil }
go
func handleResponse(resp *r.WriteResponse, confirms chan struct{}) error { if resp.Errors != 0 { if !strings.Contains(resp.FirstError, "Duplicate primary key") { // we don't care about this error return fmt.Errorf("%s\n%s", "problem inserting docs", resp.FirstError) } } if confirms != nil { confirms <- struct{}{} } return nil }
[ "func", "handleResponse", "(", "resp", "*", "r", ".", "WriteResponse", ",", "confirms", "chan", "struct", "{", "}", ")", "error", "{", "if", "resp", ".", "Errors", "!=", "0", "{", "if", "!", "strings", ".", "Contains", "(", "resp", ".", "FirstError", ",", "\"", "\"", ")", "{", "// we don't care about this error", "return", "fmt", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "\"", "\"", ",", "resp", ".", "FirstError", ")", "\n", "}", "\n", "}", "\n", "if", "confirms", "!=", "nil", "{", "confirms", "<-", "struct", "{", "}", "{", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// handleresponse takes the rethink response and turn it into something we can consume elsewhere
[ "handleresponse", "takes", "the", "rethink", "response", "and", "turn", "it", "into", "something", "we", "can", "consume", "elsewhere" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/rethinkdb/writer.go#L156-L166
14,080
compose/transporter
events/emitter.go
NewEmitter
func NewEmitter(listen chan Event, emit EmitFunc) Emitter { return &emitter{ listenChan: listen, emit: emit, stop: make(chan struct{}), started: false, } }
go
func NewEmitter(listen chan Event, emit EmitFunc) Emitter { return &emitter{ listenChan: listen, emit: emit, stop: make(chan struct{}), started: false, } }
[ "func", "NewEmitter", "(", "listen", "chan", "Event", ",", "emit", "EmitFunc", ")", "Emitter", "{", "return", "&", "emitter", "{", "listenChan", ":", "listen", ",", "emit", ":", "emit", ",", "stop", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "started", ":", "false", ",", "}", "\n", "}" ]
// NewEmitter creates a new emitter that will listen on the listen channel and use the emit EmitFunc // to process events
[ "NewEmitter", "creates", "a", "new", "emitter", "that", "will", "listen", "on", "the", "listen", "channel", "and", "use", "the", "emit", "EmitFunc", "to", "process", "events" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/events/emitter.go#L36-L43
14,081
compose/transporter
events/emitter.go
Start
func (e *emitter) Start() { if !e.started { e.started = true e.wg.Add(1) go e.startEventListener(&e.wg) } }
go
func (e *emitter) Start() { if !e.started { e.started = true e.wg.Add(1) go e.startEventListener(&e.wg) } }
[ "func", "(", "e", "*", "emitter", ")", "Start", "(", ")", "{", "if", "!", "e", ".", "started", "{", "e", ".", "started", "=", "true", "\n", "e", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "e", ".", "startEventListener", "(", "&", "e", ".", "wg", ")", "\n", "}", "\n", "}" ]
// Start the emitter
[ "Start", "the", "emitter" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/events/emitter.go#L46-L52
14,082
compose/transporter
events/emitter.go
Stop
func (e *emitter) Stop() { close(e.stop) e.wg.Wait() e.started = false }
go
func (e *emitter) Stop() { close(e.stop) e.wg.Wait() e.started = false }
[ "func", "(", "e", "*", "emitter", ")", "Stop", "(", ")", "{", "close", "(", "e", ".", "stop", ")", "\n", "e", ".", "wg", ".", "Wait", "(", ")", "\n", "e", ".", "started", "=", "false", "\n", "}" ]
// Stop sends a stop signal and waits for the inflight posts to complete before exiting
[ "Stop", "sends", "a", "stop", "signal", "and", "waits", "for", "the", "inflight", "posts", "to", "complete", "before", "exiting" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/events/emitter.go#L55-L59
14,083
compose/transporter
events/emitter.go
HTTPPostEmitter
func HTTPPostEmitter(uri, key, pid string) EmitFunc { return EmitFunc(func(event Event) error { ba, err := event.Emit() if err != nil { return err } req, err := http.NewRequest("POST", uri, bytes.NewBuffer(ba)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") if len(pid) > 0 && len(key) > 0 { req.SetBasicAuth(pid, key) } resp, err := http.DefaultClient.Do(req) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != 200 && resp.StatusCode != 201 { return BadStatusError{resp.StatusCode} } return nil }) }
go
func HTTPPostEmitter(uri, key, pid string) EmitFunc { return EmitFunc(func(event Event) error { ba, err := event.Emit() if err != nil { return err } req, err := http.NewRequest("POST", uri, bytes.NewBuffer(ba)) if err != nil { return err } req.Header.Set("Content-Type", "application/json") if len(pid) > 0 && len(key) > 0 { req.SetBasicAuth(pid, key) } resp, err := http.DefaultClient.Do(req) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != 200 && resp.StatusCode != 201 { return BadStatusError{resp.StatusCode} } return nil }) }
[ "func", "HTTPPostEmitter", "(", "uri", ",", "key", ",", "pid", "string", ")", "EmitFunc", "{", "return", "EmitFunc", "(", "func", "(", "event", "Event", ")", "error", "{", "ba", ",", "err", ":=", "event", ".", "Emit", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "uri", ",", "bytes", ".", "NewBuffer", "(", "ba", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "len", "(", "pid", ")", ">", "0", "&&", "len", "(", "key", ")", ">", "0", "{", "req", ".", "SetBasicAuth", "(", "pid", ",", "key", ")", "\n", "}", "\n", "resp", ",", "err", ":=", "http", ".", "DefaultClient", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "if", "resp", ".", "StatusCode", "!=", "200", "&&", "resp", ".", "StatusCode", "!=", "201", "{", "return", "BadStatusError", "{", "resp", ".", "StatusCode", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// HTTPPostEmitter listens on the event channel and posts the events to an http server // Events are serialized into json, and sent via a POST request to the given Uri // http errors are logged as warnings to the console, and won't stop the Emitter
[ "HTTPPostEmitter", "listens", "on", "the", "event", "channel", "and", "posts", "the", "events", "to", "an", "http", "server", "Events", "are", "serialized", "into", "json", "and", "sent", "via", "a", "POST", "request", "to", "the", "given", "Uri", "http", "errors", "are", "logged", "as", "warnings", "to", "the", "console", "and", "won", "t", "stop", "the", "Emitter" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/events/emitter.go#L91-L117
14,084
compose/transporter
adaptor/registry.go
GetAdaptor
func GetAdaptor(name string, conf Config) (Adaptor, error) { creator, ok := adaptors[name] if ok { a := creator() err := conf.Construct(a) return a, err } return nil, ErrNotFound{name} }
go
func GetAdaptor(name string, conf Config) (Adaptor, error) { creator, ok := adaptors[name] if ok { a := creator() err := conf.Construct(a) return a, err } return nil, ErrNotFound{name} }
[ "func", "GetAdaptor", "(", "name", "string", ",", "conf", "Config", ")", "(", "Adaptor", ",", "error", ")", "{", "creator", ",", "ok", ":=", "adaptors", "[", "name", "]", "\n", "if", "ok", "{", "a", ":=", "creator", "(", ")", "\n", "err", ":=", "conf", ".", "Construct", "(", "a", ")", "\n", "return", "a", ",", "err", "\n", "}", "\n", "return", "nil", ",", "ErrNotFound", "{", "name", "}", "\n", "}" ]
// GetAdaptor looks up an adaptor by name and then init's it with the provided Config. // returns ErrNotFound if the provided name was not registered.
[ "GetAdaptor", "looks", "up", "an", "adaptor", "by", "name", "and", "then", "init", "s", "it", "with", "the", "provided", "Config", ".", "returns", "ErrNotFound", "if", "the", "provided", "name", "was", "not", "registered", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/registry.go#L16-L24
14,085
compose/transporter
adaptor/registry.go
RegisteredAdaptors
func RegisteredAdaptors() []string { all := make([]string, 0) for i := range adaptors { all = append(all, i) } return all }
go
func RegisteredAdaptors() []string { all := make([]string, 0) for i := range adaptors { all = append(all, i) } return all }
[ "func", "RegisteredAdaptors", "(", ")", "[", "]", "string", "{", "all", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "i", ":=", "range", "adaptors", "{", "all", "=", "append", "(", "all", ",", "i", ")", "\n", "}", "\n", "return", "all", "\n", "}" ]
// RegisteredAdaptors returns a slice of the names of every adaptor registered.
[ "RegisteredAdaptors", "returns", "a", "slice", "of", "the", "names", "of", "every", "adaptor", "registered", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/registry.go#L27-L33
14,086
compose/transporter
adaptor/registry.go
Adaptors
func Adaptors() map[string]Adaptor { all := make(map[string]Adaptor) for name, c := range adaptors { a := c() all[name] = a } return all }
go
func Adaptors() map[string]Adaptor { all := make(map[string]Adaptor) for name, c := range adaptors { a := c() all[name] = a } return all }
[ "func", "Adaptors", "(", ")", "map", "[", "string", "]", "Adaptor", "{", "all", ":=", "make", "(", "map", "[", "string", "]", "Adaptor", ")", "\n", "for", "name", ",", "c", ":=", "range", "adaptors", "{", "a", ":=", "c", "(", ")", "\n", "all", "[", "name", "]", "=", "a", "\n", "}", "\n", "return", "all", "\n", "}" ]
// Adaptors returns an non-initialized adaptor and is best used for doing assertions to see if // the Adaptor supports other interfaces
[ "Adaptors", "returns", "an", "non", "-", "initialized", "adaptor", "and", "is", "best", "used", "for", "doing", "assertions", "to", "see", "if", "the", "Adaptor", "supports", "other", "interfaces" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/registry.go#L37-L44
14,087
compose/transporter
commitlog/segment.go
NewSegment
func NewSegment(path, format string, baseOffset int64, maxBytes int64) (*Segment, error) { logPath := filepath.Join(path, fmt.Sprintf(format, baseOffset)) log, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { return nil, err } s := &Segment{ log: log, path: logPath, writer: log, reader: log, maxBytes: maxBytes, BaseOffset: baseOffset, NextOffset: baseOffset, } err = s.init() if err == io.EOF { return s, nil } return s, err }
go
func NewSegment(path, format string, baseOffset int64, maxBytes int64) (*Segment, error) { logPath := filepath.Join(path, fmt.Sprintf(format, baseOffset)) log, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { return nil, err } s := &Segment{ log: log, path: logPath, writer: log, reader: log, maxBytes: maxBytes, BaseOffset: baseOffset, NextOffset: baseOffset, } err = s.init() if err == io.EOF { return s, nil } return s, err }
[ "func", "NewSegment", "(", "path", ",", "format", "string", ",", "baseOffset", "int64", ",", "maxBytes", "int64", ")", "(", "*", "Segment", ",", "error", ")", "{", "logPath", ":=", "filepath", ".", "Join", "(", "path", ",", "fmt", ".", "Sprintf", "(", "format", ",", "baseOffset", ")", ")", "\n", "log", ",", "err", ":=", "os", ".", "OpenFile", "(", "logPath", ",", "os", ".", "O_RDWR", "|", "os", ".", "O_CREATE", "|", "os", ".", "O_APPEND", ",", "0666", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ":=", "&", "Segment", "{", "log", ":", "log", ",", "path", ":", "logPath", ",", "writer", ":", "log", ",", "reader", ":", "log", ",", "maxBytes", ":", "maxBytes", ",", "BaseOffset", ":", "baseOffset", ",", "NextOffset", ":", "baseOffset", ",", "}", "\n\n", "err", "=", "s", ".", "init", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "s", ",", "nil", "\n", "}", "\n\n", "return", "s", ",", "err", "\n", "}" ]
// NewSegment creates a new instance of Segment with the provided parameters // and initializes its NextOffset and Position should the file be non-empty.
[ "NewSegment", "creates", "a", "new", "instance", "of", "Segment", "with", "the", "provided", "parameters", "and", "initializes", "its", "NextOffset", "and", "Position", "should", "the", "file", "be", "non", "-", "empty", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/segment.go#L48-L71
14,088
compose/transporter
commitlog/segment.go
IsFull
func (s *Segment) IsFull() bool { s.Lock() defer s.Unlock() return s.Position >= s.maxBytes }
go
func (s *Segment) IsFull() bool { s.Lock() defer s.Unlock() return s.Position >= s.maxBytes }
[ "func", "(", "s", "*", "Segment", ")", "IsFull", "(", ")", "bool", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "return", "s", ".", "Position", ">=", "s", ".", "maxBytes", "\n", "}" ]
// IsFull determines whether the current size of the segment is greater than or equal to the // maxBytes configured.
[ "IsFull", "determines", "whether", "the", "current", "size", "of", "the", "segment", "is", "greater", "than", "or", "equal", "to", "the", "maxBytes", "configured", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/segment.go#L125-L129
14,089
compose/transporter
commitlog/segment.go
ReadAt
func (s *Segment) ReadAt(p []byte, off int64) (n int, err error) { s.Lock() defer s.Unlock() return s.log.ReadAt(p, off) }
go
func (s *Segment) ReadAt(p []byte, off int64) (n int, err error) { s.Lock() defer s.Unlock() return s.log.ReadAt(p, off) }
[ "func", "(", "s", "*", "Segment", ")", "ReadAt", "(", "p", "[", "]", "byte", ",", "off", "int64", ")", "(", "n", "int", ",", "err", "error", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "return", "s", ".", "log", ".", "ReadAt", "(", "p", ",", "off", ")", "\n", "}" ]
// ReadAt calls ReadAt on the underlying log.
[ "ReadAt", "calls", "ReadAt", "on", "the", "underlying", "log", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/segment.go#L144-L148
14,090
compose/transporter
commitlog/segment.go
FindOffsetPosition
func (s *Segment) FindOffsetPosition(offset uint64) (int64, error) { if _, err := s.log.Seek(0, 0); err != nil { return 0, err } var position int64 for { b := new(bytes.Buffer) // get offset and size _, err := io.CopyN(b, s.log, 8) if err != nil { return position, ErrOffsetNotFound } o := encoding.Uint64(b.Bytes()[offsetPos:8]) _, err = io.CopyN(b, s.log, 4) if err != nil { return position, ErrOffsetNotFound } size := int64(encoding.Uint32(b.Bytes()[sizePos:12])) if offset == o { log.With("position", position).With("offset", o).Infoln("found offset position") return position, nil } position += size + logEntryHeaderLen // add 9 to size to include the timestamp and attribute _, err = s.log.Seek(size+9, 1) if err != nil { return 0, err } } }
go
func (s *Segment) FindOffsetPosition(offset uint64) (int64, error) { if _, err := s.log.Seek(0, 0); err != nil { return 0, err } var position int64 for { b := new(bytes.Buffer) // get offset and size _, err := io.CopyN(b, s.log, 8) if err != nil { return position, ErrOffsetNotFound } o := encoding.Uint64(b.Bytes()[offsetPos:8]) _, err = io.CopyN(b, s.log, 4) if err != nil { return position, ErrOffsetNotFound } size := int64(encoding.Uint32(b.Bytes()[sizePos:12])) if offset == o { log.With("position", position).With("offset", o).Infoln("found offset position") return position, nil } position += size + logEntryHeaderLen // add 9 to size to include the timestamp and attribute _, err = s.log.Seek(size+9, 1) if err != nil { return 0, err } } }
[ "func", "(", "s", "*", "Segment", ")", "FindOffsetPosition", "(", "offset", "uint64", ")", "(", "int64", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "s", ".", "log", ".", "Seek", "(", "0", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "var", "position", "int64", "\n", "for", "{", "b", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "// get offset and size", "_", ",", "err", ":=", "io", ".", "CopyN", "(", "b", ",", "s", ".", "log", ",", "8", ")", "\n", "if", "err", "!=", "nil", "{", "return", "position", ",", "ErrOffsetNotFound", "\n", "}", "\n", "o", ":=", "encoding", ".", "Uint64", "(", "b", ".", "Bytes", "(", ")", "[", "offsetPos", ":", "8", "]", ")", "\n\n", "_", ",", "err", "=", "io", ".", "CopyN", "(", "b", ",", "s", ".", "log", ",", "4", ")", "\n", "if", "err", "!=", "nil", "{", "return", "position", ",", "ErrOffsetNotFound", "\n", "}", "\n", "size", ":=", "int64", "(", "encoding", ".", "Uint32", "(", "b", ".", "Bytes", "(", ")", "[", "sizePos", ":", "12", "]", ")", ")", "\n\n", "if", "offset", "==", "o", "{", "log", ".", "With", "(", "\"", "\"", ",", "position", ")", ".", "With", "(", "\"", "\"", ",", "o", ")", ".", "Infoln", "(", "\"", "\"", ")", "\n", "return", "position", ",", "nil", "\n", "}", "\n", "position", "+=", "size", "+", "logEntryHeaderLen", "\n\n", "// add 9 to size to include the timestamp and attribute", "_", ",", "err", "=", "s", ".", "log", ".", "Seek", "(", "size", "+", "9", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "}", "\n", "}" ]
// FindOffsetPosition attempts to find the provided offset position in the // Segment.
[ "FindOffsetPosition", "attempts", "to", "find", "the", "provided", "offset", "position", "in", "the", "Segment", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/segment.go#L172-L205
14,091
compose/transporter
offset/offset.go
Bytes
func (o Offset) Bytes() []byte { valBytes := make([]byte, 8) encoding.PutUint64(valBytes, o.LogOffset) l := commitlog.NewLogFromEntry(commitlog.LogEntry{ Key: []byte(o.Namespace), Value: valBytes, Timestamp: uint64(o.Timestamp), }) return l }
go
func (o Offset) Bytes() []byte { valBytes := make([]byte, 8) encoding.PutUint64(valBytes, o.LogOffset) l := commitlog.NewLogFromEntry(commitlog.LogEntry{ Key: []byte(o.Namespace), Value: valBytes, Timestamp: uint64(o.Timestamp), }) return l }
[ "func", "(", "o", "Offset", ")", "Bytes", "(", ")", "[", "]", "byte", "{", "valBytes", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "encoding", ".", "PutUint64", "(", "valBytes", ",", "o", ".", "LogOffset", ")", "\n\n", "l", ":=", "commitlog", ".", "NewLogFromEntry", "(", "commitlog", ".", "LogEntry", "{", "Key", ":", "[", "]", "byte", "(", "o", ".", "Namespace", ")", ",", "Value", ":", "valBytes", ",", "Timestamp", ":", "uint64", "(", "o", ".", "Timestamp", ")", ",", "}", ")", "\n", "return", "l", "\n", "}" ]
// Bytes converts Offset to the binary format to be stored on disk.
[ "Bytes", "converts", "Offset", "to", "the", "binary", "format", "to", "be", "stored", "on", "disk", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/offset/offset.go#L28-L38
14,092
compose/transporter
adaptor/postgres/client.go
WithURI
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { _, err := url.Parse(uri) c.uri = uri return err } }
go
func WithURI(uri string) ClientOptionFunc { return func(c *Client) error { _, err := url.Parse(uri) c.uri = uri return err } }
[ "func", "WithURI", "(", "uri", "string", ")", "ClientOptionFunc", "{", "return", "func", "(", "c", "*", "Client", ")", "error", "{", "_", ",", "err", ":=", "url", ".", "Parse", "(", "uri", ")", "\n", "c", ".", "uri", "=", "uri", "\n", "return", "err", "\n", "}", "\n", "}" ]
// WithURI defines the full connection string for the Postgres connection
[ "WithURI", "defines", "the", "full", "connection", "string", "for", "the", "Postgres", "connection" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/postgres/client.go#L51-L57
14,093
compose/transporter
adaptor/postgres/client.go
Connect
func (c *Client) Connect() (client.Session, error) { if c.pqSession == nil { // there's really no way for this to error because we know the driver we're passing is // available. c.pqSession, _ = sql.Open("postgres", c.uri) uri, _ := url.Parse(c.uri) if uri.Path != "" { c.db = uri.Path[1:] } } err := c.pqSession.Ping() return &Session{c.pqSession, c.db}, err }
go
func (c *Client) Connect() (client.Session, error) { if c.pqSession == nil { // there's really no way for this to error because we know the driver we're passing is // available. c.pqSession, _ = sql.Open("postgres", c.uri) uri, _ := url.Parse(c.uri) if uri.Path != "" { c.db = uri.Path[1:] } } err := c.pqSession.Ping() return &Session{c.pqSession, c.db}, err }
[ "func", "(", "c", "*", "Client", ")", "Connect", "(", ")", "(", "client", ".", "Session", ",", "error", ")", "{", "if", "c", ".", "pqSession", "==", "nil", "{", "// there's really no way for this to error because we know the driver we're passing is", "// available.", "c", ".", "pqSession", ",", "_", "=", "sql", ".", "Open", "(", "\"", "\"", ",", "c", ".", "uri", ")", "\n", "uri", ",", "_", ":=", "url", ".", "Parse", "(", "c", ".", "uri", ")", "\n", "if", "uri", ".", "Path", "!=", "\"", "\"", "{", "c", ".", "db", "=", "uri", ".", "Path", "[", "1", ":", "]", "\n", "}", "\n", "}", "\n", "err", ":=", "c", ".", "pqSession", ".", "Ping", "(", ")", "\n", "return", "&", "Session", "{", "c", ".", "pqSession", ",", "c", ".", "db", "}", ",", "err", "\n", "}" ]
// Connect initializes the Postgres connection
[ "Connect", "initializes", "the", "Postgres", "connection" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/adaptor/postgres/client.go#L67-L79
14,094
compose/transporter
commitlog/logentry.go
ModeOpToByte
func (le LogEntry) ModeOpToByte() byte { return byte(int(le.Mode) | (int(le.Op) << opShift)) }
go
func (le LogEntry) ModeOpToByte() byte { return byte(int(le.Mode) | (int(le.Op) << opShift)) }
[ "func", "(", "le", "LogEntry", ")", "ModeOpToByte", "(", ")", "byte", "{", "return", "byte", "(", "int", "(", "le", ".", "Mode", ")", "|", "(", "int", "(", "le", ".", "Op", ")", "<<", "opShift", ")", ")", "\n", "}" ]
// ModeOpToByte converts the Mode and Op values into a single byte by performing bitwise operations. // Mode is stored in bits 0 - 1 // Op is stored in bits 2 - 4 // bits 5 - 7 are currently unused
[ "ModeOpToByte", "converts", "the", "Mode", "and", "Op", "values", "into", "a", "single", "byte", "by", "performing", "bitwise", "operations", ".", "Mode", "is", "stored", "in", "bits", "0", "-", "1", "Op", "is", "stored", "in", "bits", "2", "-", "4", "bits", "5", "-", "7", "are", "currently", "unused" ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/logentry.go#L34-L36
14,095
compose/transporter
commitlog/logentry.go
ReadEntry
func ReadEntry(r io.Reader) (uint64, LogEntry, error) { header := make([]byte, logEntryHeaderLen) if _, err := r.Read(header); err != nil { return 0, LogEntry{}, err } k, v, err := readKeyValue(encoding.Uint32(header[sizePos:tsPos]), r) if err != nil { return 0, LogEntry{}, err } l := LogEntry{ Key: k, Value: v, Timestamp: encoding.Uint64(header[tsPos:attrPos]), Mode: modeFromBytes(header), Op: opFromBytes(header), } return encoding.Uint64(header[offsetPos:sizePos]), l, nil }
go
func ReadEntry(r io.Reader) (uint64, LogEntry, error) { header := make([]byte, logEntryHeaderLen) if _, err := r.Read(header); err != nil { return 0, LogEntry{}, err } k, v, err := readKeyValue(encoding.Uint32(header[sizePos:tsPos]), r) if err != nil { return 0, LogEntry{}, err } l := LogEntry{ Key: k, Value: v, Timestamp: encoding.Uint64(header[tsPos:attrPos]), Mode: modeFromBytes(header), Op: opFromBytes(header), } return encoding.Uint64(header[offsetPos:sizePos]), l, nil }
[ "func", "ReadEntry", "(", "r", "io", ".", "Reader", ")", "(", "uint64", ",", "LogEntry", ",", "error", ")", "{", "header", ":=", "make", "(", "[", "]", "byte", ",", "logEntryHeaderLen", ")", "\n", "if", "_", ",", "err", ":=", "r", ".", "Read", "(", "header", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "LogEntry", "{", "}", ",", "err", "\n", "}", "\n", "k", ",", "v", ",", "err", ":=", "readKeyValue", "(", "encoding", ".", "Uint32", "(", "header", "[", "sizePos", ":", "tsPos", "]", ")", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "LogEntry", "{", "}", ",", "err", "\n", "}", "\n", "l", ":=", "LogEntry", "{", "Key", ":", "k", ",", "Value", ":", "v", ",", "Timestamp", ":", "encoding", ".", "Uint64", "(", "header", "[", "tsPos", ":", "attrPos", "]", ")", ",", "Mode", ":", "modeFromBytes", "(", "header", ")", ",", "Op", ":", "opFromBytes", "(", "header", ")", ",", "}", "\n", "return", "encoding", ".", "Uint64", "(", "header", "[", "offsetPos", ":", "sizePos", "]", ")", ",", "l", ",", "nil", "\n", "}" ]
// ReadEntry takes an io.Reader and returns a LogEntry.
[ "ReadEntry", "takes", "an", "io", ".", "Reader", "and", "returns", "a", "LogEntry", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/logentry.go#L39-L56
14,096
compose/transporter
commitlog/logentry.go
readKeyValue
func readKeyValue(size uint32, r io.Reader) ([]byte, []byte, error) { kvBytes := make([]byte, size) if _, err := r.Read(kvBytes); err != nil { return nil, nil, err } keyLen := encoding.Uint32(kvBytes[0:4]) // we can grab the key from keyLen and the we know the value is stored // after the keyLen + 8 (4 byte size of key and value) return kvBytes[4 : keyLen+4], kvBytes[keyLen+8:], nil }
go
func readKeyValue(size uint32, r io.Reader) ([]byte, []byte, error) { kvBytes := make([]byte, size) if _, err := r.Read(kvBytes); err != nil { return nil, nil, err } keyLen := encoding.Uint32(kvBytes[0:4]) // we can grab the key from keyLen and the we know the value is stored // after the keyLen + 8 (4 byte size of key and value) return kvBytes[4 : keyLen+4], kvBytes[keyLen+8:], nil }
[ "func", "readKeyValue", "(", "size", "uint32", ",", "r", "io", ".", "Reader", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "kvBytes", ":=", "make", "(", "[", "]", "byte", ",", "size", ")", "\n", "if", "_", ",", "err", ":=", "r", ".", "Read", "(", "kvBytes", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "keyLen", ":=", "encoding", ".", "Uint32", "(", "kvBytes", "[", "0", ":", "4", "]", ")", "\n", "// we can grab the key from keyLen and the we know the value is stored", "// after the keyLen + 8 (4 byte size of key and value)", "return", "kvBytes", "[", "4", ":", "keyLen", "+", "4", "]", ",", "kvBytes", "[", "keyLen", "+", "8", ":", "]", ",", "nil", "\n", "}" ]
// readKeyValue returns the key and value stored given the size and io.Reader.
[ "readKeyValue", "returns", "the", "key", "and", "value", "stored", "given", "the", "size", "and", "io", ".", "Reader", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/commitlog/logentry.go#L59-L68
14,097
compose/transporter
function/gojajs/goja.go
Apply
func (g *goja) Apply(msg message.Msg) (message.Msg, error) { if g.vm == nil { if err := g.initVM(); err != nil { return nil, err } } return g.transformOne(msg) }
go
func (g *goja) Apply(msg message.Msg) (message.Msg, error) { if g.vm == nil { if err := g.initVM(); err != nil { return nil, err } } return g.transformOne(msg) }
[ "func", "(", "g", "*", "goja", ")", "Apply", "(", "msg", "message", ".", "Msg", ")", "(", "message", ".", "Msg", ",", "error", ")", "{", "if", "g", ".", "vm", "==", "nil", "{", "if", "err", ":=", "g", ".", "initVM", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "g", ".", "transformOne", "(", "msg", ")", "\n", "}" ]
// Apply fulfills the function.Function interface by transforming the incoming message with the configured // JavaScript function.
[ "Apply", "fulfills", "the", "function", ".", "Function", "interface", "by", "transforming", "the", "incoming", "message", "with", "the", "configured", "JavaScript", "function", "." ]
9e154e76b7d2977d9ac7756660779b512cace87f
https://github.com/compose/transporter/blob/9e154e76b7d2977d9ac7756660779b512cace87f/function/gojajs/goja.go#L53-L60
14,098
ktrysmt/go-bitbucket
user.go
Profile
func (u *User) Profile() (interface{}, error) { urlStr := GetApiBaseURL() + "/user/" return u.c.execute("GET", urlStr, "") }
go
func (u *User) Profile() (interface{}, error) { urlStr := GetApiBaseURL() + "/user/" return u.c.execute("GET", urlStr, "") }
[ "func", "(", "u", "*", "User", ")", "Profile", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "urlStr", ":=", "GetApiBaseURL", "(", ")", "+", "\"", "\"", "\n", "return", "u", ".", "c", ".", "execute", "(", "\"", "\"", ",", "urlStr", ",", "\"", "\"", ")", "\n", "}" ]
// Profile is getting the user data
[ "Profile", "is", "getting", "the", "user", "data" ]
1f1c5e77687102cc8f6baa9f79276178be6f0ea3
https://github.com/ktrysmt/go-bitbucket/blob/1f1c5e77687102cc8f6baa9f79276178be6f0ea3/user.go#L9-L12
14,099
ktrysmt/go-bitbucket
user.go
Emails
func (u *User) Emails() (interface{}, error) { urlStr := GetApiBaseURL() + "/user/emails" return u.c.execute("GET", urlStr, "") }
go
func (u *User) Emails() (interface{}, error) { urlStr := GetApiBaseURL() + "/user/emails" return u.c.execute("GET", urlStr, "") }
[ "func", "(", "u", "*", "User", ")", "Emails", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "urlStr", ":=", "GetApiBaseURL", "(", ")", "+", "\"", "\"", "\n", "return", "u", ".", "c", ".", "execute", "(", "\"", "\"", ",", "urlStr", ",", "\"", "\"", ")", "\n", "}" ]
// Emails is getting user's emails
[ "Emails", "is", "getting", "user", "s", "emails" ]
1f1c5e77687102cc8f6baa9f79276178be6f0ea3
https://github.com/ktrysmt/go-bitbucket/blob/1f1c5e77687102cc8f6baa9f79276178be6f0ea3/user.go#L15-L18