mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-14 17:44:42 +00:00
Add a -socket option that configures the server to listen on a Unix-domain socket or Windows named pipe instead of a TCP port. This allows webhook to be used behind a reverse proxy on multi-tenant shared hosting without the need to choose (and the permission to bind to) a free port number. On Windows, -socket is expected to be a named pipe such as \\.\pipe\webhook, and the code uses https://github.com/microsoft/go-winio to bind the listening socket. On other platforms, -socket is the path to a Unix domain socket such as /tmp/webhook.sock, or an abstract socket name starting with @, bound using the regular net.Listen function with the "network" parameter set to "unix". Note: this pushes our minimum Go version up to 1.21 as that is what go-winio requires, but that is already the minimum version against which we are testing in the CI matrix.
20 lines
723 B
Go
20 lines
723 B
Go
package socket
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// RawSockaddr allows structs to be used with [Bind] and [ConnectEx]. The
|
|
// struct must meet the Win32 sockaddr requirements specified here:
|
|
// https://docs.microsoft.com/en-us/windows/win32/winsock/sockaddr-2
|
|
//
|
|
// Specifically, the struct size must be least larger than an int16 (unsigned short)
|
|
// for the address family.
|
|
type RawSockaddr interface {
|
|
// Sockaddr returns a pointer to the RawSockaddr and its struct size, allowing
|
|
// for the RawSockaddr's data to be overwritten by syscalls (if necessary).
|
|
//
|
|
// It is the callers responsibility to validate that the values are valid; invalid
|
|
// pointers or size can cause a panic.
|
|
Sockaddr() (unsafe.Pointer, int32, error)
|
|
}
|