package main import ( "bufio" "fmt" "net/url" "os" ) func main() { reader := bufio.NewScanner(os.Stdin) if !reader.Scan() { if reader.Err() != nil { fmt.Fprintf(os.Stderr, "No input detected") os.Exit(1) } } line := reader.Text() uri, err := url.Parse(line) if err != nil { fmt.Fprintf(os.Stderr, "failed to parse input: %s", err) os.Exit(1) } user := uri.User.Username() pw, _ := uri.User.Password() host := uri.Host db := uri.EscapedPath() fmt.Printf("export PGUSER=%s\n", user) fmt.Printf("export PGPASSWORD=%s\n", pw) fmt.Printf("export PGHOST=%s\n", host) fmt.Printf("export PGDATABASE=%s\n", db) }