-
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 #16 from official-stallion/15-connection-uri
15 connection uri
- Loading branch information
Showing
5 changed files
with
50 additions
and
7 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
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,38 @@ | ||
package stallion | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// url | ||
// each url contains of the following parts: | ||
// - host | ||
// - port | ||
type url struct { | ||
address string | ||
} | ||
|
||
// urlUnpack | ||
// manages to create url struct from url string. | ||
func urlUnpack(inputUrl string) (*url, error) { | ||
// check the input url protocol | ||
protocolSplit := strings.Split(inputUrl, "://") | ||
if len(protocolSplit) < 2 { | ||
return nil, fmt.Errorf("invalid uri") | ||
} | ||
|
||
// protocol must be 'st' | ||
if protocolSplit[0] != "st" { | ||
return nil, fmt.Errorf("not using stallion protocol (st://...)") | ||
} | ||
|
||
// exporting the host:port pair. | ||
if len(strings.Split(protocolSplit[1], ":")) < 2 { | ||
return nil, fmt.Errorf("server ip or port is not given") | ||
} | ||
|
||
return &url{ | ||
address: protocolSplit[1], | ||
}, nil | ||
} |