unix socket support (#2974)
### Pull Request Checklist <!-- Please read https://matrix-org.github.io/dendrite/development/contributing before submitting your pull request --> * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `Boris Rybalkin <ribalkin@gmail.com>` I need this for Syncloud project (https://github.com/syncloud/platform) where I run multiple apps behind an nginx on the same RPi like device so unix socket is very convenient to not have port conflicts between apps. Also someone opened this Issue: https://github.com/matrix-org/dendrite/issues/2924 --------- Co-authored-by: kegsay <kegan@matrix.org> Co-authored-by: Till <2353100+S7evinK@users.noreply.github.com>
This commit is contained in:
parent
6c20f8f742
commit
6b1c9eafa9
6 changed files with 171 additions and 29 deletions
45
setup/config/config_address.go
Normal file
45
setup/config/config_address.go
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
const (
|
||||
NetworkTCP = "tcp"
|
||||
NetworkUnix = "unix"
|
||||
)
|
||||
|
||||
type ServerAddress struct {
|
||||
Address string
|
||||
Scheme string
|
||||
UnixSocketPermission fs.FileMode
|
||||
}
|
||||
|
||||
func (s ServerAddress) Enabled() bool {
|
||||
return s.Address != ""
|
||||
}
|
||||
|
||||
func (s ServerAddress) IsUnixSocket() bool {
|
||||
return s.Scheme == NetworkUnix
|
||||
}
|
||||
|
||||
func (s ServerAddress) Network() string {
|
||||
if s.Scheme == NetworkUnix {
|
||||
return NetworkUnix
|
||||
} else {
|
||||
return NetworkTCP
|
||||
}
|
||||
}
|
||||
|
||||
func UnixSocketAddress(path string, perm fs.FileMode) ServerAddress {
|
||||
return ServerAddress{Address: path, Scheme: NetworkUnix, UnixSocketPermission: perm}
|
||||
}
|
||||
|
||||
func HTTPAddress(urlAddress string) (ServerAddress, error) {
|
||||
parsedUrl, err := url.Parse(urlAddress)
|
||||
if err != nil {
|
||||
return ServerAddress{}, err
|
||||
}
|
||||
return ServerAddress{parsedUrl.Host, parsedUrl.Scheme, 0}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue