-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
morph: support reloading morph endpoints with SIGHUP
Add a new function `Client.Reload` that passes the `WithEndpoints` option and closes the client if there is no endpoint in the config to which the client is connected. Add docs. Closes #1871. Signed-off-by: Andrey Butusov <[email protected]>
- Loading branch information
Showing
4 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package client | ||
|
||
import "slices" | ||
|
||
// Reload allows runtime reconfiguration for WithEndpoints parameter. | ||
func (c *Client) Reload(opts ...Option) { | ||
cfg := new(cfg) | ||
for _, o := range opts { | ||
o(cfg) | ||
} | ||
|
||
c.cfg.endpoints = cfg.endpoints | ||
|
||
c.endpoints = cfg.endpoints | ||
|
||
var conn = c.conn.Load() | ||
if conn == nil { | ||
return | ||
} | ||
currentEndpointID := conn.client.Endpoint() | ||
|
||
if slices.Index(c.endpoints, currentEndpointID) == -1 { | ||
conn.client.Close() | ||
} | ||
} |