Documentation ¶
Index ¶
- Variables
- func Get(msg interface{}, v interface{}) bool
- func GetNonIDKeys(r IDRecord) []string
- func RecordToMSI(r Record) map[string]interface{}
- func RecordToStrings(r Record) []string
- func String(m interface{}) string
- func Strings(m interface{}) []string
- type BasicIDRecord
- type BasicRecord
- func (r *BasicRecord) FromMSI(msi map[string]interface{}) *BasicRecord
- func (r BasicRecord) Get(key string) (interface{}, bool)
- func (r BasicRecord) GetKeys() []string
- func (r BasicRecord) GetVals() []interface{}
- func (r *BasicRecord) Set(key string, val interface{})
- func (r BasicRecord) SetKeyOrder(keys ...string) OrderedRecord
- func (r BasicRecord) String() string
- type Batch
- type Bytes
- type Clienter
- type Cmd
- type ContextGetter
- type DeleteDelta
- type Diff
- type Event
- type FileInfo
- type Hasher
- type IDRecord
- type Inner
- type InsertDelta
- type Keyer
- type Message
- type Metadata
- type MutableIDRecord
- type MutableOrderedRecord
- type MutableRecord
- type OrderedRecord
- type Path
- type PathInfo
- type Query
- type Record
- type Requester
- type SQLResult
- type Stringser
- type StructRecord
- type ToSQLer
- type UpdateDelta
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotAStruct = errors.New("not a struct")
ErrNotAStruct is for when the provided arg is not a struct
Functions ¶
func Get ¶
func Get(msg interface{}, v interface{}) bool
Get will get the desired type out of wrapped messages.
func GetNonIDKeys ¶
GetNonIDKeys gets all the keys for the record that aren't a part of the ID. This can be useful when building SQL queries for a record.
func RecordToMSI ¶
RecordToMSI converts any record to a map[string]interface{} (note: column order is not preserved in a map[string]interface{})
func RecordToStrings ¶
RecordToStrings converts a record to a slice of the values as strings. This is useful for things like CSVs.
Types ¶
type BasicIDRecord ¶
type BasicIDRecord struct { MutableRecord IDKeys []string }
BasicIDRecord is a basic implementation of the IDRecord interface
func (BasicIDRecord) GetIDKeys ¶
func (idr BasicIDRecord) GetIDKeys() []string
GetIDKeys gets the identifying keys from the IDRecord
func (BasicIDRecord) GetIDVals ¶
func (idr BasicIDRecord) GetIDVals() []interface{}
GetIDVals gets the identifying values from the IDRecord and returns nil if any of the values weren't found.
type BasicRecord ¶
type BasicRecord struct { Keys []string Vals []interface{} // contains filtered or unexported fields }
BasicRecord is a collection of key/value pairs where the keys are strings. It is similar to a map[string]interface{} accept it keeps column order and implements the OrderedRecord interface. Use the NewBasicRecord func instead of BasicRecord{} as the properties won't be initialized.
func NewBasicRecord ¶
func NewBasicRecord() *BasicRecord
NewBasicRecord creates a *BasicRecord empty with the properties initialized.
func (*BasicRecord) FromMSI ¶
func (r *BasicRecord) FromMSI(msi map[string]interface{}) *BasicRecord
FromMSI sets the keys and vals of the record to the data in the map[string]interface{}
func (BasicRecord) Get ¶
func (r BasicRecord) Get(key string) (interface{}, bool)
Get will return the value for the specified key or nil. The returned bool indicates if the key existed or not.
func (BasicRecord) GetKeys ¶
func (r BasicRecord) GetKeys() []string
GetKeys implements the Record interface
func (BasicRecord) GetVals ¶
func (r BasicRecord) GetVals() []interface{}
GetVals implements the Record interface
func (*BasicRecord) Set ¶
func (r *BasicRecord) Set(key string, val interface{})
Set will add or update the key value pair
func (BasicRecord) SetKeyOrder ¶
func (r BasicRecord) SetKeyOrder(keys ...string) OrderedRecord
SetKeyOrder sets the order of the keys and returns a new struct. This is useful if you need to maintain column order for things like CSV output etc... This can also be useful to extract only the needed columns into a new record.
func (BasicRecord) String ¶
func (r BasicRecord) String() string
String implements the fmt.Stringer interface
type Batch ¶
type Batch []interface{}
Batch is a message type that can contain a list of other messages.
type Bytes ¶
type Bytes struct { M interface{} B []byte }
Bytes wraps a message with the bytes version of the message and keeps the original message around.
type Cmd ¶
Cmd is a message that represents a command to run this is a convenience message type that implements the x.Commander interface
type ContextGetter ¶
ContextGetter defines what it takes to get the context from a message.
type DeleteDelta ¶
type DeleteDelta struct { IDRecord // IDRecord as we need to identify this record in the delete statement Table string }
DeleteDelta is the delta type for updates
func NewDeleteDelta ¶
func NewDeleteDelta(r IDRecord, table string) *DeleteDelta
NewDeleteDelta is a delete change record related to a table.
func (DeleteDelta) GetArgs ¶
func (d DeleteDelta) GetArgs() []interface{}
GetArgs implements the ArgGetter interface
func (DeleteDelta) GetSQL ¶
func (d DeleteDelta) GetSQL() string
GetSQL implements the SQLGetter interface
type Diff ¶
type Diff struct { Left interface{} `json:"mg"` Right interface{} `json:"pg"` }
Diff is a message that holds two messages that differ but that match by Key()
type Event ¶
type Event struct { Timestamp time.Time // the time that the event occured Source interface{} // the source or fhte event (log file or device etc...) Message interface{} // the actual event message itself (usually a string) }
Event is a message type that
Example ¶
package main import ( "fmt" "time" "github.com/Reisender/pipe/message" ) func main() { fmt.Println(message.Event{ Timestamp: time.Time{}, Source: "/var/log/foo.log", Message: "DEBUG: some formatted log even message", }) }
Output: 0001-01-01T00:00:00Z /var/log/foo.log DEBUG: some formatted log even message
type FileInfo ¶
FileInfo represents the info including path of a file or directory. This is to pull together our PathInfo and the os.FileInfo.
type Hasher ¶
type Hasher interface {
Hash() string
}
Hasher defines a message that has a Hash() func. The Hash() func is mean to return a hash of the content in the message. Then the hash value of the message can easily be compaired with the content of other messages.
type IDRecord ¶
IDRecord is an identifyable record. That means the ID for the record (composite or not) is defined on the record.
type Inner ¶
type Inner interface {
In() interface{}
}
Inner defines the In function wrapping messages should implement.
type InsertDelta ¶
InsertDelta is the delta type for inserts
func NewInsertDelta ¶
func NewInsertDelta(r Record, table string) *InsertDelta
NewInsertDelta is an insert change record related to a table
func (InsertDelta) GetArgs ¶
func (d InsertDelta) GetArgs() []interface{}
GetArgs implements the ArgGetter interface
func (InsertDelta) GetSQL ¶
func (d InsertDelta) GetSQL() string
GetSQL implements the SQLGetter interface
type Keyer ¶
type Keyer interface {
Key() string
}
Keyer defines a message that has a Key() func that can be used as the "key" for this message.
type Message ¶
Message is a baseline implementation of a Messenger. This is currently used to migration from the old pipeline project.
type Metadata ¶
type Metadata map[string]interface{}
Metadata is a map to hold metadata about a message.
type MutableIDRecord ¶
type MutableIDRecord interface { MutableRecord GetIDKeys() []string GetIDVals() []interface{} }
MutableIDRecord is the same as IDRecord but with a MutableRecord underlying it. It can be casted to an IDRecord.
func NewIDRecord ¶
func NewIDRecord(IDKeys ...string) MutableIDRecord
NewIDRecord created a record that implements IDRecord and as such is identifiable // with some of value or combination of values from the record.
type MutableOrderedRecord ¶
type MutableOrderedRecord interface { MutableRecord SetKeyOrder(...string) OrderedRecord }
MutableOrderedRecord is the same as OrderedRecord but wih a MutableRecord
func NewRecordFromMSI ¶
func NewRecordFromMSI(msi map[string]interface{}) MutableOrderedRecord
NewRecordFromMSI creates a *Record from a map[string]interface{} This is a convenience function to combine new and FromMSI
type MutableRecord ¶
MutableRecord defines what it takes to mutate a record
type OrderedRecord ¶
type OrderedRecord interface { Record SetKeyOrder(...string) OrderedRecord }
OrderedRecord defines a record that specifies the column order. This is useful for things like CSVs or bulk SQL inserts where the order matters.
type PathInfo ¶
type PathInfo interface {
Path() string
}
PathInfo is the interface for providing the info for a path. This follows the os.FileInfo interface convention and is designed to bring the path and the FileInfo together.
type Query ¶
type Query struct { SQL string Args []interface{} Context context.Context // some drivers prefer the numbered args ($1,$2...) instead of ? for placeholders NumberArgs bool }
Query is an SQL query that has the arguments in a sparate slice. This allows for the DB.Exec() call to properly handle the args.
func NewQuery ¶
NewQuery is a constructor for a Query struct. It can support both the ? and the $1 format of placeholder for the args.
func (Query) GetContext ¶
GetContext implements the message.ContextGetter interface
type Record ¶
type Record interface { Get(string) (interface{}, bool) GetKeys() []string GetVals() []interface{} }
Record defines what it takes to be a record message
type SQLResult ¶
SQLResult wraps the sql.Result and adds a String func for convenient output of the results.
type Stringser ¶
type Stringser interface {
Strings() []string
}
Stringser the interface for Strings() which is like String() but as a slice of strings. This can be useful for things like CSVs
type StructRecord ¶
type StructRecord struct {
// contains filtered or unexported fields
}
StructRecord wraps a struct and implements the Record interface based on the given tag lookup as the "Keys". For example: many db drivers use a 'db' tag on struct fields to know how to translate to the database column. the GetKeys() call of this returns the 'db' tag values. You should always use the NewStructRecord constructor to create this.
func NewStructRecord ¶
func NewStructRecord(strct interface{}, tagName ...string) (StructRecord, error)
NewStructRecord createa a new StructRecord. The tagName arg is optional and will be used instead of the default field name. While the tagName arg is a slice, only the [0] value is used. The value of the tag for a given field is ignore if it is "" or "-". and will be skipped. If the tag value has a "," in it, the part before comma is used as the tag value. This allows for values like "id,omitempty"
func (StructRecord) Get ¶
func (sr StructRecord) Get(key string) (interface{}, bool)
Get implements the Record interface
func (StructRecord) GetKeys ¶
func (sr StructRecord) GetKeys() []string
GetKeys implements the Record interface
func (StructRecord) GetVals ¶
func (sr StructRecord) GetVals() []interface{}
GetVals implements the Record interface
func (StructRecord) In ¶
func (sr StructRecord) In() interface{}
In implements the Inner interface and returns the original struct that this wraps.
type ToSQLer ¶
type ToSQLer interface {
ToSQL() (string, []interface{})
}
ToSQLer defines the SQL func to extract the SQL from a message.
type UpdateDelta ¶
type UpdateDelta struct { IDRecord // IDRecord as we need to identify this record in the update statement Changes Record // for holding old values Table string }
UpdateDelta is the delta type for updates
func NewUpdateDelta ¶
func NewUpdateDelta(r IDRecord, table string) *UpdateDelta
NewUpdateDelta is an insert change record related to a table
func (UpdateDelta) GetArgs ¶
func (d UpdateDelta) GetArgs() []interface{}
GetArgs implements the ArgGetter interface and returns the args for the query excluding the args related to the ID keys.
func (UpdateDelta) GetSQL ¶
func (d UpdateDelta) GetSQL() string
GetSQL implements the SQLGetter interface