windows

package module
v0.0.0-...-5274db7 Latest Latest
Warning

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

Go to latest
Published: May 18, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

Build status Code Climate Coverage Status GoDoc

windows

Golang library implementing a number of Windows specific features; such as to-and-from system encoding and UTF-8, along with functional APIs for dealing with paths and files.

Installation

go get github.com/jbenden/windows

License

The windows Golang library is Apache 2.0 licensed.

Documentation

Overview

Package windows implements a number of Windows specific features; such as to-and-from system encoding and UTF-8, along with functional APIs for programmatically interacting with paths and files.

Index

Constants

View Source
const (
	CP1252      int = 1252
	UnicodeFFFE     = 1201
	Macintosh       = 10000
	UTF32           = 12000
	UTF32BE         = 12001
	UsASCII         = 20127
	ISO88591        = 28591
	ISO88592        = 28592
	UTF7            = 65000
	UTF8            = 65001
)

Possible Windows Code Pages

Variables

View Source
var ErrInvalidDrive = errors.New("path: invalid drive specified")

ErrInvalidDrive indicates an invalid character was used as a drive letter.

View Source
var ErrInvalidEncoding = errors.New("windows: invalid string encoding")

ErrInvalidEncoding is returned as a result of an invalid conversion.

View Source
var ErrInvalidNarrow = errors.New("windows: invalid narrow encoded string")

ErrInvalidNarrow is returned as a result of an invalid conversion to a narrow byte sequence.

View Source
var ErrInvalidWide = errors.New("windows: invalid wide-character encoded string")

ErrInvalidWide is returned as a result of an invalid conversion to a wide-character sequence.

Functions

func ComputerName

func ComputerName() (name string, e error)

ComputerName returns the NetBIOS machine name. There are edge-cases for a seemingly wrong machine name to be returned. See the reference below for information on when this occurs.

See also MSDN, “GetComputerName function,” https://msdn.microsoft.com/en-us/library/windows/desktop/ms724295(v=vs.85).aspx

func ConfigDirectory

func ConfigDirectory() (dir string, e error)

ConfigDirectory returns the running machine's application configuration and/or local data directory. Write access may require Administrator privileges.

func ConfigHomeDirectory

func ConfigHomeDirectory() (dir string, e error)

ConfigHomeDirectory returns the current user's application configuration directory on the user's roaming profile. All configuration file written are possibly synchronized between multiple machines the user may have access to.

func DataHomeDirectory

func DataHomeDirectory() (dir string, e error)

DataHomeDirectory returns the current user's application data configuration directory on the user's local, specific to the current machine, profile. All configuration data written are only stored on the current machine. For possibly synchronized configuration data, see ConfigHomeDirectory().

func GetSystemCodePage

func GetSystemCodePage() (cp int)

GetSystemCodePage returns Window's default system code page.

func HomeDirectory

func HomeDirectory() (dir string, e error)

HomeDirectory returns the current user's directory on the machine; typically a folder inside the “C:\Users” directory.

func SystemCodePageToUtf8

func SystemCodePageToUtf8(text string) (s string, e error)

SystemCodePageToUtf8 converts the given string from Window's system code page to an UTF-8 string.

func SystemDirectory

func SystemDirectory() (dir string, e error)

SystemDirectory returns the machine's system path location; typically “C:\WINDOWS\system32”.

func Utf8ToSystemCodePage

func Utf8ToSystemCodePage(text string) (s string, e error)

Utf8ToSystemCodePage converts the given UTF-8 string to Window's system code page.

Types

type PathImpl

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

PathImpl holds state between each of the functional calls returned by Path().

func Path

func Path(path string) *PathImpl

Path parses a local or remote file or directory by purely lexical processing, and returns an object for use through functional semantics.

It is able to parse the following types of input:

  1. Relative file or directory
  2. Absolute file or directory
  3. UNC file or directory
  4. UNICODE absolute file or directory
  5. UNICODE UNC file or directory

Errors are collected during the parsing, for all possible validation errors describe by the referenced MSDN article later described.

See also MSDN, “Naming Files, Paths, and Namespaces,” https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx

func (*PathImpl) Device

func (p *PathImpl) Device() string

Device returns the drive letter from a parsed absolute path.

func (*PathImpl) Dirs

func (p *PathImpl) Dirs() []string

Dirs returns an array of all parsed leading directories.

func (*PathImpl) Errors

func (p *PathImpl) Errors() []error

Errors returns an array of all parse and validation errors encountered when parsing.

func (*PathImpl) IsAbsolute

func (p *PathImpl) IsAbsolute() bool

IsAbsolute checks whether the Path refers to a non-relative location.

func (*PathImpl) IsDirectoryExists

func (p *PathImpl) IsDirectoryExists() bool

IsDirectoryExists checks whether the Path refers to an existing directory.

func (*PathImpl) IsLocal

func (p *PathImpl) IsLocal() bool

IsLocal checks whether the Path refers to a location on the current machine.

func (*PathImpl) IsRelative

func (p *PathImpl) IsRelative() bool

IsRelative checks whether the Path refers to a non-absolute location.

func (*PathImpl) IsRemote

func (p *PathImpl) IsRemote() bool

IsRemote checks whether the Path refers to a location that is not on the current machine.

func (*PathImpl) MakeAbsolute

func (p *PathImpl) MakeAbsolute() *PathImpl

MakeAbsolute checks whether the Path refers to a relative location on the current machine. If so, it non-destructively converts the relative location to an absolute one by querying the path through the operating system.

Because MakeAbsolute is non-destructive, the returned pointer to PathImpl may NOT be the same as called with!

func (*PathImpl) MakeDirectory

func (p *PathImpl) MakeDirectory() *PathImpl

MakeDirectory checks whether the Path has a Name(). If so, the Name() is added to the set of Dirs() and is cleared.

func (*PathImpl) Name

func (p *PathImpl) Name() string

Name returns the file name or last directory from a parsed path.

func (*PathImpl) Node

func (p *PathImpl) Node() string

Node returns the server name from a parsed UNC path.

func (*PathImpl) ToString

func (p *PathImpl) ToString() string

ToString returns a fully-qualified representation of the parsed Path.

func (*PathImpl) ToUnicodeUNC

func (p *PathImpl) ToUnicodeUNC() string

ToUnicodeUNC returns a fully-qualified UNICODE UNC representation of the parsed Path.

Jump to

Keyboard shortcuts

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