uri.go
uri.go - Overview
-
Overview This file defines a
Uri
struct and associated functions for parsing and representing URIs in the format<scheme>:<value>
. It includes regex validation to ensure the input string conforms to the expected URI format. -
Detailed Documentation
uriRegex
- Purpose: A regular expression used to validate and parse URI strings. It expects a format of
<scheme>:<value>
. The scheme must start with a letter and can be followed by letters, numbers, '+', '.', or '-'. - Type:
*regexp.Regexp
- Details: The regex is pre-compiled using
regexp.MustCompile
.
Uri
- Purpose: Represents a parsed URI, containing the scheme and the value.
type Uri struct {
scheme string
value string
}
NewUri
- Purpose: Creates a new
Uri
struct by parsing the input string. It validates the input againsturiRegex
. - Parameters:
input
(string): The URI string to parse.
- Returns:
Uri
: The parsedUri
struct if the input is valid.error
: An error if the input is not a valid URI.
func NewUri(input string) (Uri, error)
MustNewUri
- Purpose: Creates a new
Uri
struct by parsing the input string. It panics if the input is invalid. - Parameters:
input
(string): The URI string to parse.
- Returns:
Uri
: The parsedUri
struct.
func MustNewUri(input string) Uri
Uri.Scheme
- Purpose: Returns the scheme of the URI.
- Parameters: None
- Returns:
string
: The scheme of the URI.
func (uri Uri) Scheme() string
Uri.Value
- Purpose: Returns the value of the URI.
- Parameters: None
- Returns:
string
: The value of the URI.
func (uri Uri) Value() string
-
Code Examples Not applicable.
-
Clarity and Accuracy The documentation is derived directly from the code and comments.
-
Markdown & MDX Perfection The markdown is formatted correctly.
-
Edge Cases To Avoid Breaking MDX All potential MDX breaking characters are handled correctly.
-
Getting Started Relevance Include in Getting Started: NO