location

package
v0.48.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package location contains functionality related to source location.

Index

Constants

View Source
const (
	TypeStdin   = "stdin"
	TypeFile    = "local_file"
	TypeSQL     = "sql"
	TypeHTTP    = "http_file"
	TypeUnknown = "unknown"
)

Variables

This section is empty.

Functions

func Abs

func Abs(loc string) string

Abs returns the absolute path of loc. That is, relative paths etc. are resolved. If loc is not a file path or it cannot be processed, loc is returned unmodified.

func Filename

func Filename(loc string) (string, error)

Filename returns the final component of the file/URL path.

func IsSQL

func IsSQL(loc string) bool

IsSQL returns true if source location loc seems to be a DSN for a SQL driver.

func Redact

func Redact(loc string) string

Redact returns a redacted version of the source location loc, with the password component (if any) of the location masked.

func Short

func Short(loc string) string

Short returns a short location string. For example, the base name (data.xlsx) for a file, or for a DSN, user@host[:port]/db.

func WithPassword

func WithPassword(loc, passw string) (string, error)

WithPassword returns the location string with the password value set, overriding any existing password. If loc is not a URL (e.g. it's a file path), it is returned unmodified.

Types

type Fields

type Fields struct {
	// Loc is the original unparsed location value.
	Loc string

	// DriverType is the associated source driver type, which may
	// be empty until later determination.
	DriverType drivertype.Type

	// Scheme is the original location Scheme.
	Scheme string

	// User is the username, if applicable.
	User string

	// Pass is the password, if applicable.
	Pass string

	// Hostname is the Hostname, if applicable.
	Hostname string

	// Name is the "source Name", e.g. "sakila". Typically this
	// is the database Name, but for a file location such
	// as "/path/to/things.xlsx" it would be "things".
	Name string

	// Ext is the file extension, if applicable.
	Ext string

	// DSN is the connection "data source Name" that can be used in a
	// call to sql.Open. Empty for non-SQL locations.
	DSN string

	// Port is the Port number or 0 if not applicable.
	Port int
}

Fields is a parsed representation of a source location.

func Parse

func Parse(loc string) (*Fields, error)

Parse parses a location string, returning a Fields instance representing the decomposition of the location. On return the Fields.DriverType field may not be set: further processing may be required.

type Type

type Type string

Type is an enumeration of the various types of source location.

func TypeOf

func TypeOf(loc string) Type

TypeOf returns the type of loc, or locTypeUnknown if it can't be determined.

func (Type) IsURL added in v0.47.4

func (t Type) IsURL() bool

IsURL returns true if t is TypeHTTP or TypeSQL.

Jump to

Keyboard shortcuts

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