-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: allow to specify several endpoints
This change relies on protobuf spec, where it doesn't matter how many times the field appears in the byte stream, because decoder will always take the last one for non-repeated fields. We use it to our advantage and simply pass primary endpoint address at the end, but we take it as the first. Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
- Loading branch information
Showing
6 changed files
with
75 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
// Package pb provides protobuf definitions for the SideroLink API. | ||
package pb | ||
|
||
import ( | ||
"errors" | ||
"slices" | ||
) | ||
|
||
// MakeEndpoints sets the endpoints. | ||
func MakeEndpoints(endpoints ...string) []string { | ||
if len(endpoints) == 0 { | ||
panic(errors.New("no endpoints provided")) | ||
} | ||
|
||
// To preserve GRPC backwards compatibility, we put the first endpoint at the end. | ||
if len(endpoints) > 1 { | ||
endpoints[0], endpoints[len(endpoints)-1] = endpoints[len(endpoints)-1], endpoints[0] | ||
} | ||
|
||
return endpoints | ||
} | ||
|
||
// GetEndpoints returns the endpoints. | ||
func (m *ProvisionResponse) GetEndpoints() []string { | ||
if m == nil || len(m.ServerEndpoint) == 0 { | ||
return nil | ||
} | ||
|
||
endpoints := slices.Clone(m.ServerEndpoint) | ||
|
||
// To preserve GRPC backwards compatibility, we put the first endpoint at the end. | ||
if len(endpoints) > 1 { | ||
endpoints[0], endpoints[len(endpoints)-1] = endpoints[len(endpoints)-1], endpoints[0] | ||
} | ||
|
||
return endpoints | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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