address

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package address provides functions for working with "happy" addresses, which are URL-like strings that define the location of a resource in the "happy" system. It includes functions for parsing and resolving addresses, as well as methods for converting addresses to strings and checking the format of addresses. The package also provides a convenient way to get the current application's address in the "happy" system.

Index

Constants

View Source
const (
	// MustCompile against following expression.
	Regexp = "^[a-z][a-z0-9-./]*[a-z0-9]$"
)

Variables

View Source
var (
	ErrAddr = errors.New("address")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	// contains filtered or unexported fields
}

Address represents a happy address in the form of happy://host/instance/path. The happy address is a scheme-based URL that defines the location of a module or service within a service mesh.

func Current

func Current() (*Address, error)

Current returns format of current application happy proto address.

func CurrentForDepth

func CurrentForDepth(d int) (*Address, error)

Current returns format of current application happy proto address.

func FromModule

func FromModule(host, modulepath string) (*Address, error)

FromModule returns a new Address created from the given go module path. If the module is empty, the resulting address will be an empty address. If the module is not an empty string, it must be a valid module path that conforms to Go's package name syntax and will be used to create a new address.

func Parse

func Parse(rawAddr string) (*Address, error)

Parse takes a string address and returns a new Address instance. If the address is not valid, an error is returned.

func (*Address) Host

func (a *Address) Host() string

func (*Address) Instance

func (a *Address) Instance() string

func (*Address) Module

func (a *Address) Module() string

func (*Address) Parse

func (a *Address) Parse(ref string) (*Address, error)

Parse takes a string representation of an address and returns a pointer to a new Address struct. If the input string is not a valid representation of an address, an error is returned.

func (*Address) ResolveService

func (a *Address) ResolveService(svc string) (*Address, error)

ResolveService returns the resolved service Adddress for the given network and instance address. If the address cannot be resolved, it returns an error.

func (*Address) ReverseDNS added in v0.15.0

func (a *Address) ReverseDNS() string

func (*Address) String

func (a *Address) String() string

String reassembles the Address into a valid URL string. The general form of the result is one of:

happy://userinfo@host/path?query#fragment

Any non-ASCII characters in host are escaped. To obtain the path, String uses net.URL.EscapedPath().

In the second form, the following rules apply:

  • if u.User is nil, userinfo@ is omitted.
  • if u.Host is non-empty and u.Path begins with a /, the form host/path does not add its own /.
  • if u.RawQuery is empty, ?query is omitted.
  • if u.Fragment is empty, #fragment is omitted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL