()
| 15 | } |
| 16 | |
| 17 | func main() { |
| 18 | flag.Usage = func() { |
| 19 | fmt.Fprintf(os.Stderr, "usage: %s [options]\n", os.Args[0]) |
| 20 | flag.PrintDefaults() |
| 21 | } |
| 22 | |
| 23 | flag.StringVar(&options.listenAddress, "listen", "127.0.0.1:15432", "Listen address") |
| 24 | flag.StringVar(&options.responseCommand, "response-command", "fortune | cowsay -f elephant", "Command to execute to generate query response") |
| 25 | flag.Parse() |
| 26 | |
| 27 | ln, err := net.Listen("tcp", options.listenAddress) |
| 28 | if err != nil { |
| 29 | log.Fatal(err) |
| 30 | } |
| 31 | log.Println("Listening on", ln.Addr()) |
| 32 | |
| 33 | for { |
| 34 | conn, err := ln.Accept() |
| 35 | if err != nil { |
| 36 | log.Fatal(err) |
| 37 | } |
| 38 | log.Println("Accepted connection from", conn.RemoteAddr()) |
| 39 | |
| 40 | b := NewPgFortuneBackend(conn, func() ([]byte, error) { |
| 41 | return exec.Command("sh", "-c", options.responseCommand).CombinedOutput() |
| 42 | }) |
| 43 | go func() { |
| 44 | err := b.Run() |
| 45 | if err != nil { |
| 46 | log.Println(err) |
| 47 | } |
| 48 | log.Println("Closed connection from", conn.RemoteAddr()) |
| 49 | }() |
| 50 | } |
| 51 | } |
nothing calls this directly
no test coverage detected