Skip to main content

uri.go

uri.go - Overview

  1. 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.

  2. 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 against uriRegex.
  • Parameters:
    • input (string): The URI string to parse.
  • Returns:
    • Uri: The parsed Uri 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 parsed Uri 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
  1. Code Examples Not applicable.

  2. Clarity and Accuracy The documentation is derived directly from the code and comments.

  3. Markdown & MDX Perfection The markdown is formatted correctly.

  4. Edge Cases To Avoid Breaking MDX All potential MDX breaking characters are handled correctly.

  5. Getting Started Relevance Include in Getting Started: NO