path

package module
v0.0.0-...-8837a92 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2017 License: MIT Imports: 3 Imported by: 0

README

path

Package path implements a strongly typed path string. It enforces a forward slash ("/") separator, and and insures all paths end with a separator.

Example

package main

import (
    "fmt"

    "github.com/Avalanche-io/path"
)

func main() {
    p, err := path.New("/path/to/file.txt")
    if err != nil {
        panic(err)
    }
    fmt.Println(p) // "/path/to/"
    p, err = path.New("/path/to/dir/")
    if err != nil {
        panic(err)
    }
    fmt.Println(p) // "/path/to/dir/"
    p, err = path.New(".")
    if err != nil {
        panic(err)
    }
    fmt.Println(p) // "./"
}

License

This package is governed by the MIT License. See LICENSE file for details.

Documentation

Overview

Package path implements a strongly typed path string. It enforces a forward slash ("/") separator, and and insures all paths end with a separator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDir

func IsDir(path string) bool

Types

type Path

type Path string

func New

func New(path string) (*Path, error)

New creates a path from a string, with the following rules:

Removes all URL prefixes. Reduces two or more "/" to one. Appends a "/" if there are no "/" in the string. Removes all characters after the last "/".

If input is empty or nil, return nil path and error.

func (*Path) Append

func (p *Path) Append(subpath *Path) *Path

Appends sub-path to path managing slashes appropriately.

func (*Path) EveryPath

func (p *Path) EveryPath() []string

func (*Path) IsAbsolute

func (p *Path) IsAbsolute() bool

Returns true of path starts with "/", false otherwise.

func (*Path) Split

func (p *Path) Split() (string, string)

func (*Path) String

func (p *Path) String() string

Implements Stringer interface

Jump to

Keyboard shortcuts

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