-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Contextualist/feat-tailscale
Tailscale integration
- Loading branch information
Showing
23 changed files
with
926 additions
and
196 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// Merge strategy lists from two parties into a common one, | ||
// following the precedency set by the first party. | ||
func strategyConsensus(pa, pb []string) (c []string) { | ||
pbSet := make(map[string]struct{}, len(pb)) | ||
for _, x := range pb { | ||
pbSet[x] = struct{}{} | ||
} | ||
|
||
for _, x := range pa { | ||
if _, ok := pbSet[x]; ok { | ||
c = append(c, x) | ||
} | ||
} | ||
logger.Debugf("strategy: a=%v, b=%v, consensus=%v", pa, pb, c) | ||
return | ||
} | ||
|
||
// Map a func onto a slice, for each element returning a result or an error | ||
func tryEach[U, V any](a []U, fn func(U) (V, error)) (r []V, errs []error) { | ||
for _, x := range a { | ||
y, err := fn(x) | ||
if err != nil { | ||
logger.Debugf("attempt failed: %v", err) | ||
errs = append(errs, err) | ||
continue | ||
} | ||
r = append(r, y) | ||
} | ||
return | ||
} | ||
|
||
// Map a func onto a slice, until returning the first successful result | ||
func tryUntil[U, V any](a []U, fn func(U) (V, error)) (r V, err error) { | ||
var errs []error | ||
for _, x := range a { | ||
r, err = fn(x) | ||
if err != nil { | ||
logger.Debugf("attempt failed: %v", err) | ||
errs = append(errs, err) | ||
continue | ||
} | ||
return | ||
} | ||
err = fmt.Errorf("all attempts failed: %w", errors.Join(errs...)) | ||
return | ||
} | ||
|
||
func must[T any](t T, err error) T { | ||
if err != nil { | ||
panic(err) | ||
} | ||
return t | ||
} |
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
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
Oops, something went wrong.