Documentation
¶
Overview ¶
Package passfile provides a mechanism for reading database credentials from passfiles.
Example (Entries) ¶
package main
import (
"log"
"os/user"
"github.com/xo/dburl/passfile"
)
func main() {
u, err := user.Current()
if err != nil {
log.Fatal(err)
}
// read ~/.usqlpass or $ENV{USQLPASS}
entries, err := passfile.Entries(u, "usqlpass")
if err != nil {
log.Fatal(err)
}
for i, entry := range entries {
log.Printf("%d: %v", i, entry)
}
}
Output:
Example (Match) ¶
package main
import (
"log"
"os/user"
"github.com/xo/dburl"
"github.com/xo/dburl/passfile"
)
func main() {
u, err := user.Current()
if err != nil {
log.Fatal(err)
}
v, err := dburl.Parse("pg://")
if err != nil {
log.Fatal(err)
}
// read ~/.usqlpass or $ENV{USQLPASS}
user, err := passfile.Match(u, v, "usqlpass")
if err == nil {
v.User = user
}
log.Println("url:", v.String())
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Protocol, Host, Port, DBName, Username, Password string
}
Entry is a passfile entry.
Corresponds to a non-empty line in a passfile.
type ErrEmptyField ¶
ErrEmptyField is the empty field error.
func (*ErrEmptyField) Error ¶
func (err *ErrEmptyField) Error() string
Error satisfies the error interface.
type ErrInvalidEntry ¶
type ErrInvalidEntry struct {
Line int
}
ErrInvalidEntry is the invalid entrty error.
func (*ErrInvalidEntry) Error ¶
func (err *ErrInvalidEntry) Error() string
Error satisfies the error interface.
type Error ¶
type Error string
Error is a error.
const ( // ErrUnableToNormalizeURL is the unable to normalize URL error. ErrUnableToNormalizeURL Error = "unable to normalize URL" // ErrMustNotBeDirectory is the must not be directory error. ErrMustNotBeDirectory Error = "must not be directory" // ErrHasGroupOrWorldAccess is the has group or world access error. ErrHasGroupOrWorldAccess Error = "has group or world access" )
Click to show internal directories.
Click to hide internal directories.