Documentation
¶
Index ¶
- Constants
- Variables
- func After(query, word string) string
- func RegisterHooks(auditor *Auditor, dbType string) (string, error)
- type Action
- type Auditor
- func (a *Auditor) GetTableName(query string) (tableName string, err error)
- func (a *Auditor) Save(ctx context.Context, query string, args []interface{}, lastInsertID int64, ...) error
- func (a *Auditor) SetDB(opts ...DBOption) error
- func (a *Auditor) SetEvent(ctx context.Context, event Event, tableName, query string, args []interface{}) (Event, error)
- type DBOption
- type Event
- type Hooks
- type MysqlParser
- type Option
- type Parser
- type PostgresParser
- type WhereClause
- type WhereStmt
- type Work
Constants ¶
View Source
const ( MysqlDB string = "mysql" PostgresDB string = "postgres" MongoDB string = "mongo" )
Variables ¶
View Source
var ( MysqlCreate = "" /* 509-byte string literal not displayed */ MysqlInsert = "" /* 167-byte string literal not displayed */ MysqlSelect = "SELECT * FROM %s WHERE %v %s ?" PostgresCreate = "" /* 299-byte string literal not displayed */ PostgresInsert = "" /* 180-byte string literal not displayed */ PostgresSelect = "SELECT * FROM %s WHERE %v %s $1" // todo: support IN operator )
View Source
var ( ErrInvalidQuery = fmt.Errorf("invalid query") ErrDriverNotSupported = fmt.Errorf("driver is not supported") )
View Source
var ( ErrInvalidDatabaseDriver = fmt.Errorf("invalid database driver") ErrNoAuditSet = fmt.Errorf("no audit is set from the request context") )
View Source
var (
ErrInvalidConnection = fmt.Errorf("invalid database connection")
)
Functions ¶
Types ¶
type Auditor ¶
type Auditor struct {
// contains filtered or unexported fields
}
func (*Auditor) GetTableName ¶
type Event ¶
type Event struct { ActorID uint64 `db:"actor_id"` TableRowID uint64 `db:"table_row_id"` Table string `db:"table_name"` Action Action `db:"action"` OldValues string `db:"old_values"` NewValues string `db:"new_values"` HTTPMethod string `db:"http_method"` URL string `db:"url"` IPAddress string `db:"ip_address"` UserAgent string `db:"user_agent"` CreatedAt time.Time `db:"created_at"` WhereClause WhereClause IsExempted bool }
type Hooks ¶
type Hooks struct {
Auditor *Auditor
}
Hooks satisfies the sqlhook.Hooks interface
type MysqlParser ¶
type MysqlParser struct {
// contains filtered or unexported fields
}
type Option ¶
type Option func(*Auditor)
func WithTableException ¶
WithTableException list of tables not to be audited
func WithTableName ¶
WithTableName customise the audit table name
type Parser ¶
type Parser struct { *MysqlParser *PostgresParser // contains filtered or unexported fields }
type PostgresParser ¶
type PostgresParser struct {
// contains filtered or unexported fields
}
type WhereClause ¶
type WhereClause struct {
// contains filtered or unexported fields
}
type WhereStmt ¶
type WhereStmt struct { Version int `json:"version"` Stmts []struct { Stmt struct { DeleteStmt struct { Relation struct { Relname string `json:"relname"` Inh bool `json:"inh"` Relpersistence string `json:"relpersistence"` Location int `json:"location"` } `json:"relation"` WhereClause struct { AExpr struct { Kind string `json:"kind"` Name []struct { String struct { Str string `json:"str"` } `json:"String"` } `json:"name"` Lexpr struct { ColumnRef struct { Fields []struct { String struct { Str string `json:"str"` } `json:"String"` } `json:"fields"` Location int `json:"location"` } `json:"ColumnRef"` } `json:"lexpr"` Rexpr struct { ParamRef struct { Number int `json:"number"` Location int `json:"location"` } `json:"ParamRef"` } `json:"rexpr"` Location int `json:"location"` } `json:"A_Expr"` } `json:"whereClause"` } `json:"DeleteStmt"` UpdateStmt struct { Relation struct { Relname string `json:"relname"` Inh bool `json:"inh"` Relpersistence string `json:"relpersistence"` Location int `json:"location"` } `json:"relation"` TargetList []struct { ResTarget struct { Name string `json:"name"` Val struct { ParamRef struct { Number int `json:"number"` Location int `json:"location"` } `json:"ParamRef"` } `json:"val"` Location int `json:"location"` } `json:"ResTarget"` } `json:"targetList"` WhereClause struct { AExpr struct { Kind string `json:"kind"` Name []struct { String struct { Str string `json:"str"` } `json:"String"` } `json:"name"` Lexpr struct { ColumnRef struct { Fields []struct { String struct { Str string `json:"str"` } `json:"String"` } `json:"fields"` Location int `json:"location"` } `json:"ColumnRef"` } `json:"lexpr"` Rexpr struct { ParamRef struct { Number int `json:"number"` Location int `json:"location"` } `json:"ParamRef"` } `json:"rexpr"` Location int `json:"location"` } `json:"A_Expr"` } `json:"whereClause"` } `json:"UpdateStmt"` } `json:"stmt"` } `json:"stmts"` }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.