Skip to content

Commit 047e617

Browse files
implement haproxy socket type from configuration
1 parent d84c082 commit 047e617

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Functions in table returned by `require("pgmoon")`:
110110

111111
Creates a new `Postgres` object from a configuration object. All fields are
112112
optional unless otherwise stated. The newly created object will not
113-
automatically connect, you must call `conect` after creating the object.
113+
automatically connect, you must call `connect` after creating the object.
114114

115115
Available options:
116116

@@ -122,7 +122,7 @@ Available options:
122122
* `"ssl"`: enable ssl (default: `false`)
123123
* `"ssl_verify"`: verify server certificate (default: `nil`)
124124
* `"ssl_required"`: abort the connection if the server does not support SSL connections (default: `nil`)
125-
* `"socket_type"`: the type of socket to use, one of: `"nginx"`, `"luasocket"`, `cqueues` (default: `"nginx"` if in nginx, `"luasocket"` otherwise)
125+
* `"socket_type"`: the type of socket to use, one of: `"nginx"`, `"haproxy"`, `"luasocket"`, `"cqueues"` (default: `"nginx"` if in nginx, `"luasocket"` otherwise)
126126
* `"application_name"`: set the name of the connection as displayed in `pg_stat_activity`. (default: `"pgmoon"`)
127127
* `"pool"`: (OpenResty only) name of pool to use when using OpenResty cosocket (default: `"#{host}:#{port}:#{database}"`)
128128
* `"pool_size"`: (OpenResty only) Passed directly to OpenResty cosocket connect function, [see docs](https://github.com/openresty/lua-nginx-module#tcpsockconnect)

pgmoon-dev-1.rockspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package = "pgmoon"
22
version = "dev-1"
33

44
source = {
5-
url = "git://github.com/leafo/pgmoon.git"
5+
url = "git://github.com/mecampbellsoup/pgmoon.git",
6+
tag = "luasocket-to-haproxy"
67
}
78

89
description = {

pgmoon/socket.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ do
2525
settimeout = true
2626
}
2727
luasocket = {
28-
tcp = function(...)
29-
local socket = require("socket")
30-
local sock = socket.tcp(...)
28+
tcp = function(socket_type, ...)
29+
local sock
30+
if socket_type == "haproxy" then
31+
sock = core.tcp(...)
32+
else
33+
local socket = require("socket")
34+
sock = socket.tcp(...)
35+
end
3136
local proxy = setmetatable({
3237
sock = sock,
3338
send = function(self, ...)
@@ -98,6 +103,8 @@ return {
98103
socket = ngx.socket.tcp()
99104
elseif "luasocket" == _exp_0 then
100105
socket = luasocket.tcp()
106+
elseif "haproxy" == _exp_0 then
107+
socket = luasocket.tcp(socket_type)
101108
elseif "cqueues" == _exp_0 then
102109
socket = require("pgmoon.cqueues").CqueuesSocket()
103110
else

pgmoon/socket.moon

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ luasocket = do
2323
}
2424

2525
{
26-
tcp: (...) ->
27-
socket = require "socket"
28-
sock = socket.tcp ...
26+
tcp: (socket_type, ...) ->
27+
local sock
28+
if socket_type == "haproxy"
29+
sock = core.tcp ...
30+
else
31+
socket = require "socket"
32+
sock = socket.tcp ...
2933
proxy = setmetatable {
3034
:sock
3135
send: (...) => @sock\send flatten ...
@@ -80,6 +84,8 @@ luasocket = do
8084
ngx.socket.tcp!
8185
when "luasocket"
8286
luasocket.tcp!
87+
when "haproxy"
88+
luasocket.tcp(socket_type)
8389
when "cqueues"
8490
require("pgmoon.cqueues").CqueuesSocket!
8591
else

0 commit comments

Comments
 (0)