Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrServerClosed is returned by the Server's Start, Serve and ServeConn methods after a call to Close. ErrServerClosed = errors.New("server: Server closed") // ErrServerAlreadyStarted is returned by the Server's Start if its already have been called. ErrServerAlreadyStarted = errors.New("server: Server already started") )
var ( // ErrConfigDistributorClosed is returned by the ConfigDistributor's Get and Subscribe methods after a call to Close. ErrConfigDistributorClosed = errors.New("config_distributor: ConfigDistributor is closed") )
var ( // ErrSessionClosed is returned by the Server's Start after a call to Close. ErrSessionClosed = errors.New("session: Session closed") )
Functions ¶
Types ¶
type Config ¶
type Config struct { // Local IP address and port on which Gevolut will listen for client connections. Listen string // Database connection string for the proxied PostgreSQL server. DatabaseURL string `toml:"database-url"` }
Config contains configuration parameters for the server package. cli package use this to unmarshall the gevulot.toml.
type ConfigChangedCheckFn ¶
ConfigChangedCheckFn is a predicate function that must return true when previous config differs from the new one. We use this to notify config subscribers only about relevant changes.
type ConfigDistributor ¶
type ConfigDistributor struct {
// contains filtered or unexported fields
}
ConfigDistributor is an implementation of ConfigStore. It takes a channel that receives config updates and multiplexes it into multiple subscribed channels.
func NewConfigDistributor ¶
func NewConfigDistributor(configChan <-chan *Config) *ConfigDistributor
NewConfigDistributor initializes a new ConfigDistributor.
func (*ConfigDistributor) Close ¶
func (p *ConfigDistributor) Close()
Close stops the monitoring goroutine and cancels all subscriptions.
func (*ConfigDistributor) Get ¶
func (p *ConfigDistributor) Get() (*Config, error)
Get returns current active configuration. Get will block execution until new configuration arrive.
func (*ConfigDistributor) Subscribe ¶
func (p *ConfigDistributor) Subscribe(ch chan<- *Config, checks ...ConfigChangedCheckFn) error
Subscribe subscribes given channel to configuration updates. If checks are specified, new config will be sent to the channel only if one of them returns true.
func (*ConfigDistributor) Unsubscribe ¶
func (p *ConfigDistributor) Unsubscribe(ch chan<- *Config)
Unsubscribe cancels subscription for the given channel.
type ConfigStore ¶
type ConfigStore interface { // Get returns current active configuration. Get() (*Config, error) // Subscribe subscribes given channel to configuration updates. // If checks are specified, new config will be sent to the channel only if one of them returns true. Subscribe(ch chan<- *Config, checks ...ConfigChangedCheckFn) error // Unsubscribe cancels subscription for the given channel. Unsubscribe(ch chan<- *Config) }
ConfigStore represents API that server package using to get configuration parameters.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a one-time event that may occur in the future. Borrowed from gRPC.
func (*Event) Done ¶
func (e *Event) Done() <-chan struct{}
Done returns a channel that will be closed when Fire is called.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a masking PostgreSQL proxy server.
func NewServer ¶
func NewServer(config ConfigStore) *Server
NewServer initializes a new Server instance.
func (*Server) Close ¶
Close immediately closes the Server's listener and all active sessions. Close returns any error returned from closing the listener.
Once Close has been called on a server, it may not be reused; future calls to methods such as Serve or Start will return ErrServerClosed.
func (*Server) Serve ¶
Serve sets the Server listener (closing existing one if set) and then calls ServeConn for every accepted client connection.
Serve blocks until the listener returns a non-nil error. The caller typically invokes Serve in a go statement.
func (*Server) ServeConn ¶
ServeConn proxies given connection to the PostgreSQL database specified in the Server's config.
ServeConn blocks, serving the connection until the client or the database hangs up. The caller typically invokes ServeConn in a go statement.
func (*Server) Start ¶
Start listens on the TCP network address specified in the Server's config and then calls Serve to handle incoming connections from the clients to the proxied database.
When Server's configuration changed (e.g., when listen port has been modified in the configuration file), Start automatically changes the listener.
Start can only be called once per Server instance.
Start always returns a non-nil error. After Close, the returned error is ErrServerClosed; after consequent Start, the returned error is ErrServerAlreadyStarted.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a proxied PostgreSQL database session.
func NewSession ¶
func NewSession(client net.Conn, config ConfigStore) *Session
NewSession initializes a new Session.