-
Notifications
You must be signed in to change notification settings - Fork 0
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 #40 from Phillezi/34-move-communication-with-the-s…
…torage-manager-to-separate-client 34 move communication with the storage manager to separate client
- Loading branch information
Showing
9 changed files
with
424 additions
and
208 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,48 @@ | ||
package util | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
) | ||
|
||
// GetCommonDomain returns the common domain from multiple domains by removing subdomains. | ||
// It assumes domains provided are hosts without a scheme. | ||
func GetCommonDomain(domains ...string) (string, error) { | ||
if len(domains) == 0 { | ||
return "", errors.New("no domains provided") | ||
} | ||
|
||
commonParts := strings.Split(domains[0], ".") | ||
|
||
for _, domain := range domains[1:] { | ||
parts := strings.Split(domain, ".") | ||
commonParts = findCommonSuffix(commonParts, parts) | ||
|
||
if len(commonParts) == 0 { | ||
return "", errors.New("no common domain found") | ||
} | ||
} | ||
|
||
commonDomain := strings.Join(reverse(commonParts), ".") | ||
return commonDomain, nil | ||
} | ||
|
||
// findCommonSuffix finds the longest common suffix between two domain part arrays | ||
func findCommonSuffix(parts1, parts2 []string) []string { | ||
i, j := len(parts1)-1, len(parts2)-1 | ||
var common []string | ||
|
||
for ; i >= 0 && j >= 0 && parts1[i] == parts2[j]; j-- { | ||
common = append(common, parts1[i]) | ||
i-- | ||
} | ||
|
||
return common | ||
} | ||
|
||
func reverse(arr []string) (reversed []string) { | ||
for i := len(arr) - 1; i >= 0; i-- { | ||
reversed = append(reversed, arr[i]) | ||
} | ||
return reversed | ||
} |
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,23 @@ | ||
package browser | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
func Open(url string) error { | ||
var cmd *exec.Cmd | ||
switch { | ||
case runtime.GOOS == "linux": | ||
cmd = exec.Command("xdg-open", url) | ||
case runtime.GOOS == "windows": | ||
cmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url) | ||
case runtime.GOOS == "darwin": | ||
cmd = exec.Command("open", url) | ||
default: | ||
return fmt.Errorf("unsupported platform") | ||
} | ||
fmt.Printf("Trying to open: %s in web browser\n\n", url) | ||
return cmd.Start() | ||
} |
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 was deleted.
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
Oops, something went wrong.