Initial commit

This commit is contained in:
2024-05-24 16:35:20 -04:00
commit aba755dc81
5 changed files with 48 additions and 0 deletions

35
main.go Normal file
View File

@@ -0,0 +1,35 @@
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)
}