message

package
v0.0.0-...-5d6a5f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
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

func GetNonIDKeys(r IDRecord) []string

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

func RecordToMSI(r Record) map[string]interface{}

RecordToMSI converts any record to a map[string]interface{} (note: column order is not preserved in a map[string]interface{})

func RecordToStrings

func RecordToStrings(r Record) []string

RecordToStrings converts a record to a slice of the values as strings. This is useful for things like CSVs.

func String

func String(m interface{}) string

String will extract a string from a message one way or another.

func Strings

func Strings(m interface{}) []string

Strings will extract a []string from a message one way or another.

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.

func (Batch) Size

func (b Batch) Size() int

Size returns the length of the batch.

func (Batch) String

func (b Batch) String() string

String implements fmt.Stringer.

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.

func (*Bytes) In

func (j *Bytes) In() interface{}

In returns the message wrapped in the json message.

func (*Bytes) String

func (j *Bytes) String() string

String implements the fmt.Stringer interface.

type Clienter

type Clienter interface {
	Client() *http.Client
}

Clienter is a message interface that has or is an http.Client

type Cmd

type Cmd struct {
	Name string
	Args []string
}

Cmd is a message that represents a command to run this is a convenience message type that implements the x.Commander interface

func (Cmd) Arguments

func (c Cmd) Arguments() []string

Arguments returns the arguments for the command

func (Cmd) Command

func (c Cmd) Command() string

Command returns the command name

type ContextGetter

type ContextGetter interface {
	GetContext() context.Context
}

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

func (Event) String

func (e Event) String() string

String implements the fmt.Stringer interface

func (Event) Strings

func (e Event) Strings() []string

Strings implements the Strinsger interface for Event

type FileInfo

type FileInfo struct {
	os.FileInfo
	PathInfo
}

FileInfo represents the info including path of a file or directory. This is to pull together our PathInfo and the os.FileInfo.

func (FileInfo) String

func (fi FileInfo) String() string

String implements fmt.Stringer and includes a trailing '/' for directories

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

type IDRecord interface {
	Record
	GetIDKeys() []string
	GetIDVals() []interface{}
}

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

type InsertDelta struct {
	Record
	Table string
}

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

type Message struct {
	Metadata // any structured data needed for the message
	Body     []byte
}

Message is a baseline implementation of a Messenger. This is currently used to migration from the old pipeline project.

func (Message) String

func (bm Message) String() string

String implements fmt.Stringer.

type Metadata

type Metadata map[string]interface{}

Metadata is a map to hold metadata about a message.

func (Metadata) Get

func (s Metadata) Get(key string) (interface{}, bool)

Get gets a value from the metadata.

func (Metadata) Set

func (s Metadata) Set(key string, val interface{})

Set sets a value in the metadata.

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

type MutableRecord interface {
	Record
	Set(string, interface{})
}

MutableRecord defines what it takes to mutate a record

func NewRecord

func NewRecord() MutableRecord

NewRecord creates a *Record empty

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 Path

type Path string

Path is a string that can be used as a PathInfo implementation

func (Path) Path

func (fp Path) Path() string

Path implements the PathInfo interface

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

func NewQuery(sql string, args []interface{}, numbereArgs bool) *Query

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

func (q Query) GetContext() context.Context

GetContext implements the message.ContextGetter interface

func (Query) String

func (q Query) String() string

String converts the query to a completed SQL string ready to run. This generally should only be used in testing and debugging as the mysql.Exec will properly handle the args separatly from the SQL.

func (Query) ToSQL

func (q Query) ToSQL() (string, []interface{})

ToSQL implements the message.SQLGetter 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 Requester

type Requester interface {
	Request() *http.Request
}

Requester is a message interface that has or is an http.Request

type SQLResult

type SQLResult struct {
	sql.Result
}

SQLResult wraps the sql.Result and adds a String func for convenient output of the results.

func (SQLResult) String

func (r SQLResult) String() string

String implements the fmt.Stringer interface

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL