device

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Path Manipulation Errors
	ErrDuplicateFilePathOption    = errors.New("Duplicate file path option")
	ErrPrefixSuffixSetWithReplace = errors.New("Prefix or Suffix set with Replace.")
	ErrSeparatorLength            = errors.New("Separator length must be 1.")
	ErrNoFileNameSet              = errors.New("File name was not set by options.")

	// Device ID Errors
	ErrEmptyDeviceID = errors.New("Device ID cannot be empty")
	ErrMissingEnvVar = errors.New("Cannot set EnvVariable with empty value")

	// Directory errors
	ErrDirectoryInvalid = errors.New("Directory Type is invalid")
	ErrDirectoryUnset   = errors.New("Directory path has not been set")
	ErrDirectoryJoin    = errors.New("Failed to join directory path")
)

Functions

func Arch

func Arch() string

Arch returns the current architecture.

func Exists

func Exists(fileName string) bool

Exists checks if a file exists.

func HostName

func HostName() (string, error)

HostName returns the hostname of the current machine.

func ID

func ID() (string, error)

ID returns the device ID.

func Init

func Init(options ...Option) error

Init initializes the device package.

func IsAndroid

func IsAndroid() bool

IsAndroid returns true if the current platform is android.

func IsDesktop

func IsDesktop() bool

IsDesktop returns true if the current platform is ANY desktop platform.

func IsFile

func IsFile(fileName string) bool

IsFile returns true if the given path is a file

func IsIOS

func IsIOS() bool

IsIOS returns true if the current platform is iOS.

func IsLinux

func IsLinux() bool

IsLinux returns true if the current platform is linux.

func IsMacOS

func IsMacOS() bool

IsMacOS returns true if the current platform is macOS.

func IsMobile

func IsMobile() bool

IsMobile returns true if the current platform is ANY mobile platform.

func IsWindows

func IsWindows() bool

IsWindows returns true if the current platform is windows.

func Platform

func Platform() string

Platform returns formatted GOOS for Text format. Returns: ["MacOS", "Windows", "Linux", "Android", "iOS"]

func Stat

func Stat() (map[string]string, error)

Stat returns the device stat.

Types

type FilePathOptFunc

type FilePathOptFunc func(path string) FilePathOption

FilePathOptFunc is a function that returns a FilePathOption.

var WithPrefix FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypePrefix,
		value:           path,
	}
}

WithPrefix sets the prefix for the file path.

var WithReplace FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeReplace,
		value:           path,
	}
}

WithReplace sets the replace string for the file path.

var WithSeparator FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeSeparator,
		value:           path,
	}
}

WithSeparator sets the separator for the file path.

var WithSuffix FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeSuffix,
		value:           path,
	}
}

WithSuffix sets the suffix for the file path.

type FilePathOption

type FilePathOption interface {
	Apply() *filePathOptions
}

FilePathOption is a function option for FilePath.

type Folder

type Folder string
var (
	// Determined/Provided Paths
	Home      Folder // ApplicationDocumentsDir on Mobile, HOME_DIR on Desktop
	Support   Folder // AppSupport Directory
	Temporary Folder // AppCache Directory

	// Calculated Paths
	Database   Folder // Device DB Folder
	Downloads  Folder // Temporary Directory on Mobile for Export, Downloads on Desktop
	Wallet     Folder // Encrypted Storage Directory
	ThirdParty Folder // Sub-Directory of Support, used for Textile

)

func (Folder) Create

func (f Folder) Create(fileName string) (*os.File, error)

Create creates a file.

func (Folder) CreateFolder

func (f Folder) CreateFolder(dirName string) (Folder, error)

CreateFolder creates a folder.

func (Folder) Delete

func (f Folder) Delete(fileName string) error

Delete removes a file or a folder.

func (Folder) Exists

func (f Folder) Exists(fileName string) bool

Exists checks if a file exists.

func (Folder) GenPath

func (f Folder) GenPath(path string, opts ...FilePathOption) (string, error)

GenPath generates a path from a folder and a file name.

func (Folder) JoinPath

func (f Folder) JoinPath(ps ...string) string

JoinPath joins a folder and a file name.

func (Folder) MkdirAll

func (f Folder) MkdirAll() error

MkdirAll creates a directory and all its parents.

func (Folder) Path

func (f Folder) Path() string

Path returns the path of the folder.

func (Folder) ReadFile

func (f Folder) ReadFile(fileName string) ([]byte, error)

ReadFile reads a file.

func (Folder) WriteFile

func (f Folder) WriteFile(fileName string, data []byte) error

WriteFile writes a file.

type Option

type Option func(o *options)

func SetDeviceID

func SetDeviceID(id string) Option

SetDeviceID sets the device ID

func WithHomePath

func WithHomePath(p string) Option

WithHomePath sets the Home Directory

func WithSupportPath

func WithSupportPath(p string) Option

WithSupportPath sets the Support Directory

func WithTempPath

func WithTempPath(p string) Option

WithTempPath sets the Temporary Directory

Jump to

Keyboard shortcuts

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