dsn

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 6 Imported by: 0

README

dsn

Table of contents

Summary

A lightweight, scheme-aware parser that normalizes DSN strings from URLs and file paths into a structured form.

Description

This package provides a robust, scheme-aware DSN (Data Source Name) parser capable of handling URL-based DSNs ( such as MySQL, PostgreSQL, MongoDB, and SQLite), filesystem paths (both relative and absolute), file URLs, and bare schemes like memory or SQLite. It normalizes all inputs into a structured DSN type by extracting the scheme, user credentials, host (including multi-host formats), port, path, query parameters, and optional suffixes such as cache sizes. The parser automatically distinguishes between URLs and file paths, requires no external dependencies, and offers a consistent, reliable way to interpret configuration strings across different storage backends and connection formats.

Architecture

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPkg package error.
	ErrPkg = errors.New("dsn")
	// ErrInvalidDSN error.
	ErrInvalidDSN = fmt.Errorf("%w: invalid DSN", ErrPkg)
	// ErrInvalidQuery error.
	ErrInvalidQuery = fmt.Errorf("%w: invalid query", ErrPkg)
	// ErrInvalidPort error.
	ErrInvalidPort = fmt.Errorf("%w: invalid port", ErrPkg)
)

Functions

This section is empty.

Types

type DSN

type DSN struct {
	Scheme   string
	User     string
	Password string
	Host     string   // first host, for convenience
	Port     int      // first port, for convenience
	Hosts    []string // all hosts, including the first
	Ports    []int    // all ports, including the first
	Path     string
	Query    url.Values
	Raw      *url.URL
}

DSN represents a parsed data source name, supporting URL-based formats (e.g., mysql://, mongodb://, sqlite://) as well as file paths. It provides normalised access to scheme, credentials, host, port, path, query parameters, and optional cache size suffixes.

func Parse

func Parse(input string) (*DSN, error)

Parse interprets the given string as a DSN, handling URL-style formats, file URLs, bare schemes, and relative or absolute file paths.

Jump to

Keyboard shortcuts

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