Documentation
¶
Overview ¶
Package xormguard integrates sqlguard with xorm (xorm.io/xorm).
Analysis is driven by the single shared sqlguard core (middleware.Guard), so redaction-by-default, stable fingerprints, the pluggable real-grammar parser, slow-query timing and N+1 detection behave identically to the database/sql driver wrapper, pgxguard, gormguard and bunguard. There is no parallel option surface — configure with the standard middleware options:
engine, _ := xorm.NewEngine("postgres", dsn)
engine.AddHook(xormguard.New(
middleware.WithSlowQueryThreshold(500*time.Millisecond),
middleware.WithN1Detection(10, time.Second),
))
xorm's contexts.Hook exposes the rendered SQL and the measured execution time on the ContextHook in AfterProcess, so this uses the explicit Check+CheckLatency pair (matching gormguard): static rules run on every query, latency is reported only on success.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hook ¶
type Hook struct {
// contains filtered or unexported fields
}
Hook implements xorm's contexts.Hook and drives every traced statement through the shared sqlguard analysis core.
func New ¶
func New(opts ...middleware.Option) *Hook
New creates a new sqlguard xorm hook. It accepts the standard sqlguard middleware options (WithAnalyzer, WithReporter, WithSlowQueryThreshold, WithParser, WithN1Detection, …) — the same option set every other sqlguard surface uses, so there is no parallel configuration surface to drift.
func (*Hook) AfterProcess ¶
func (h *Hook) AfterProcess(c *contexts.ContextHook) error
AfterProcess implements contexts.Hook. c.SQL holds the rendered SQL, c.ExecuteTime the measured latency, and c.Err the query error (which is returned unchanged so the hook never swallows it).
func (*Hook) BeforeProcess ¶
BeforeProcess implements contexts.Hook. xorm stamps the start time itself and reports the elapsed duration as ContextHook.ExecuteTime in AfterProcess, so there is nothing to do here but pass the context through.