base

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppName string

AppName exposes application name to config module

Functions

func InSlice added in v0.1.3

func InSlice(value string, slice []string) bool

InSlice detects value presence in a string slice

func Panic

func Panic(err error)

Panic prints a non-nil error and terminates the program

Types

type Config

type Config struct {
	File                          string
	Host                          string      `yaml:"host"`
	Port                          int         `yaml:"port"`
	User                          string      `yaml:"user"`
	Password                      string      `yaml:"password"`
	Database                      string      `yaml:"database"`
	SSLMode                       string      `yaml:"sslmode"`
	Interval                      float64     `yaml:"interval"`
	ConnectTimeout                int         `yaml:"connect-timeout"`
	IdleTimeout                   float64     `yaml:"idle-timeout"`
	ActiveTimeout                 float64     `yaml:"active-timeout"`
	LogDestination                string      `yaml:"log-destination"`
	LogFile                       string      `yaml:"log-file"`
	LogFormat                     string      `yaml:"log-format"`
	PidFile                       string      `yaml:"pid-file"`
	SyslogIdent                   string      `yaml:"syslog-ident"`
	SyslogFacility                string      `yaml:"syslog-facility"`
	IncludeUsers                  StringFlags `yaml:"include-users"`
	IncludeUsersRegex             string      `yaml:"include-users-regex"`
	IncludeUsersRegexCompiled     *regexp.Regexp
	IncludeUsersFilters           []Filter
	ExcludeUsers                  StringFlags `yaml:"exclude-users"`
	ExcludeUsersRegex             string      `yaml:"exclude-users-regex"`
	ExcludeUsersRegexCompiled     *regexp.Regexp
	ExcludeUsersFilters           []Filter
	IncludeDatabases              StringFlags `yaml:"include-databases"`
	IncludeDatabasesRegex         string      `yaml:"include-databases-regex"`
	IncludeDatabasesRegexCompiled *regexp.Regexp
	IncludeDatabasesFilters       []Filter
	ExcludeDatabases              StringFlags `yaml:"exclude-databases"`
	ExcludeDatabasesRegex         string      `yaml:"exclude-databases-regex"`
	ExcludeDatabasesRegexCompiled *regexp.Regexp
	ExcludeDatabasesFilters       []Filter
	ExcludeListeners              bool `yaml:"exclude-listeners"`
	Cancel                        bool `yaml:"cancel"`
	// contains filtered or unexported fields
}

Config receives configuration options

func NewConfig

func NewConfig() *Config

NewConfig creates a Config object

func (*Config) CompileFilters added in v1.0.0

func (c *Config) CompileFilters()

CompileFilters creates Filter objects based on patterns and compiled regexp

func (*Config) CompileRegexes added in v0.1.3

func (c *Config) CompileRegexes() (err error)

CompileRegexes transforms regexes from string to regexp instance

func (*Config) Dsn

func (c *Config) Dsn() string

Dsn formats a connection string based on Config

func (*Config) Read

func (c *Config) Read(file string) error

Read loads options from a configuration file to Config

func (*Config) Reload

func (c *Config) Reload()

Reload reads from file to update configuration and re-compile regexes

type Context

type Context struct {
	Sessions chan *Session
	Done     chan bool
	Config   *Config
}

Context stores dynamic values like channels and exposes configuration

func NewContext

func NewContext(config *Config, sessions chan *Session, done chan bool) *Context

NewContext instanciates a Context

type Db

type Db struct {
	// contains filtered or unexported fields
}

Db centralizes connection to the database

func NewDb

func NewDb(dsn string) *Db

NewDb creates a Db object

func (*Db) CancelSessions added in v0.1.3

func (db *Db) CancelSessions(sessions []*Session)

CancelSessions terminates current query of a list of sessions

func (*Db) Connect

func (db *Db) Connect()

Connect connects to the instance and ping it to ensure connection is working

func (*Db) Disconnect

func (db *Db) Disconnect()

Disconnect ends connection cleanly

func (*Db) Sessions

func (db *Db) Sessions() (sessions []*Session)

Sessions connects to the database and returns current sessions

func (*Db) TerminateSessions

func (db *Db) TerminateSessions(sessions []*Session)

TerminateSessions terminates a list of sessions

type ExcludeFilter added in v1.0.0

type ExcludeFilter struct {
	// contains filtered or unexported fields
}

ExcludeFilter to include a string when it's not included in a list of strings

func NewExcludeFilter added in v1.0.0

func NewExcludeFilter(patterns []string) ExcludeFilter

NewExcludeFilter to create an ExcludeFilter

func (ExcludeFilter) Include added in v1.0.0

func (f ExcludeFilter) Include(s string) bool

Include returns true when the string is not included in the patterns Implements the Filter interface

func (ExcludeFilter) String added in v1.0.0

func (f ExcludeFilter) String() string

String to pretty print an ExcludeFilter Implements the Filter interface

type ExcludeFilterRegex added in v1.0.0

type ExcludeFilterRegex struct {
	// contains filtered or unexported fields
}

ExcludeFilterRegex to include a string when it doesnn't match a regex

func NewExcludeFilterRegex added in v1.0.0

func NewExcludeFilterRegex(regex *regexp.Regexp) ExcludeFilterRegex

NewExcludeFilterRegex to create an ExcludeFilterRegex

func (ExcludeFilterRegex) Include added in v1.0.0

func (f ExcludeFilterRegex) Include(s string) bool

Include returns true when the string doesn't match the regex Implements the Filter interface

func (ExcludeFilterRegex) String added in v1.0.0

func (f ExcludeFilterRegex) String() string

String to pretty print an ExcludeFilterRegex Implements the Filter interface

type Filter added in v1.0.0

type Filter interface {
	Include(string) bool
	String() string
}

Filter interface to tell if a string should be included or not

type IncludeFilter added in v1.0.0

type IncludeFilter struct {
	// contains filtered or unexported fields
}

IncludeFilter to include a string when it's included in a list of strings

func NewIncludeFilter added in v1.0.0

func NewIncludeFilter(patterns []string) IncludeFilter

NewIncludeFilter to create an IncludeFilter

func (IncludeFilter) Include added in v1.0.0

func (f IncludeFilter) Include(s string) bool

Include returns true when a string is included in a list of patterns Implements the Filter interface

func (IncludeFilter) String added in v1.0.0

func (f IncludeFilter) String() string

String to pretty print an IncludeFilter Implements the Filter interface

type IncludeFilterRegex added in v1.0.0

type IncludeFilterRegex struct {
	// contains filtered or unexported fields
}

IncludeFilterRegex to include a string when it matches a regex

func NewIncludeFilterRegex added in v1.0.0

func NewIncludeFilterRegex(regex *regexp.Regexp) IncludeFilterRegex

NewIncludeFilterRegex to create an IncludeFilterRegex

func (IncludeFilterRegex) Include added in v1.0.0

func (f IncludeFilterRegex) Include(s string) bool

Include returns true when the string matches the regex Implements the Filter interface

func (IncludeFilterRegex) String added in v1.0.0

func (f IncludeFilterRegex) String() string

String to pretty print an IncludeFilterRegex Implements the Filter interface

type Session

type Session struct {
	Pid             int64
	User            string
	Db              string
	Client          string
	State           string
	Query           string
	StateDuration   float64
	ApplicationName string
}

Session represents a PostgreSQL backend

func NewSession

func NewSession(pid int64, user string, db string, client string, state string, query string, stateDuration float64, applicationName string) *Session

NewSession instanciates a Session

func (*Session) Equal added in v1.0.1

func (s *Session) Equal(session *Session) bool

Equal returns true when two sessions share the same process id

func (*Session) Format added in v0.1.5

func (s *Session) Format(format string) string

Format returns a Session as a string by replacing placeholders with their respective value

func (*Session) InSlice added in v1.0.1

func (s *Session) InSlice(sessions []*Session) bool

InSlice returns true when this sessions in present in the slice

func (*Session) IsIdle

func (s *Session) IsIdle() bool

IsIdle returns true when a session is doing nothing

type StringFlags added in v0.1.3

type StringFlags []string

StringFlags append multiple string flags into a string slice

func (*StringFlags) Set added in v0.1.3

func (s *StringFlags) Set(value string) error

Set adds alues into the slice

func (*StringFlags) String added in v0.1.3

func (s *StringFlags) String() string

String for implementing flag interface

Jump to

Keyboard shortcuts

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