...

Package pgpassfile

import "github.com/jackc/pgpassfile"
Overview
Index

Overview ▾

Package pgpassfile is a parser PostgreSQL .pgpass files.

type Entry

Entry represents a line in a PG passfile.

type Entry struct {
    Hostname string
    Port     string
    Database string
    Username string
    Password string
}

type Passfile

Passfile is the in memory data structure representing a PG passfile.

type Passfile struct {
    Entries []*Entry
}

func ParsePassfile

func ParsePassfile(r io.Reader) (*Passfile, error)

ParsePassfile reads r and parses it into a Passfile.

func ReadPassfile

func ReadPassfile(path string) (*Passfile, error)

ReadPassfile reads the file at path and parses it into a Passfile.

func (*Passfile) FindPassword

func (pf *Passfile) FindPassword(hostname, port, database, username string) (password string)

FindPassword finds the password for the provided hostname, port, database, and username. For a Unix domain socket hostname must be set to "localhost". An empty string will be returned if no match is found.

See https://www.postgresql.org/docs/current/libpq-pgpass.html for more password file information.