goshnix

package module
v0.0.0-...-075fa88 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2016 License: MIT Imports: 7 Imported by: 0

README

goshnix

A powerful UNIX utility for performing Golang API over SSH. It abstracts the underlying method for Goshnix supported API, so that your program logic stays same

GoDoc

Version

1.0.0

Get It
go get github.com/swarvanusg/goshnix
Use it
Initiate Goshnix Client
goshclient, err := goshnix.Init("<host_ip>", "<port>", "<uname>", "<pass>")
Use Goshnix Client as a Std Lib

Check you environment variable

envval, err := goshclient.Getenv("<key>")

Get a file stat

fileinfo, _ := goshclient.Stat("<filepath>")
// Check if its a dir (as of std lib)
if fileinfo.IsDir() {
  // ...
}

Get the list of directory entries

var fileinfos []os.FileInfo
fileinfos, _ := goshclient.ReadDir("<dirpath>")

For full listing of supported API see the godoc.

Use Goshnix API to Understand Error

Goshnix returned error could be communication error as well as command execution error. Goshnix provides API to understand proper error sub-type

filecontent, err := goshclient.ReadFile(filename string)
if err != nil {
  // Check error type
  switch {
  case Isssherror(err):
    // ssh error handling logic
  case Iscmderror(err):
    // cmd error handling logic
  }
}
How it works

For each of the API, one or multiple UNIX commands gets executed over ssh to the targeted host.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Iscmderror

func Iscmderror(err error) bool

Iscmderror check if error is due to command execution failed

func Isssherror

func Isssherror(err error) bool

Isssherror check if error is due to any ssh connection error

Types

type Cmderror

type Cmderror struct {
	Command    string
	Errorstr   string
	Returncode int
}

func (Cmderror) Error

func (e Cmderror) Error() string

type Goshnix

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

The Goshnix lib client

func Init

func Init(host, port, uname, pass string) (*Goshnix, error)

Initialize the goshnix client

func (*Goshnix) Chmod

func (goshnix *Goshnix) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target

func (*Goshnix) Chown

func (goshnix *Goshnix) Chown(name string, uid, gid int) error

Chown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link's target

func (*Goshnix) Environ

func (goshnix *Goshnix) Environ() ([]string, error)

Environ returns a copy of strings representing the environment, in the form "key=value"

func (*Goshnix) Getenv

func (goshnix *Goshnix) Getenv(key string) (string, error)

Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present

func (*Goshnix) Hostname

func (goshnix *Goshnix) Hostname() (name string, err error)

Hostname returns the host name reported by the kernel

func (*Goshnix) Kill

func (goshnix *Goshnix) Kill(pid int) error

Kill a running process by its pid

func (goshnix *Goshnix) Link(oldname, newname string) error

Link creates newname as a hard link to the oldname file

func (*Goshnix) LookupEnv

func (goshnix *Goshnix) LookupEnv(key string) (string, bool, error)

LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true

func (*Goshnix) Mkdir

func (goshnix *Goshnix) Mkdir(name string, perm os.FileMode) error

Mkdir creates a new directory with the specified name and permission bits

func (*Goshnix) ReadDir

func (goshnix *Goshnix) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename

func (*Goshnix) ReadFile

func (goshnix *Goshnix) ReadFile(filename string) ([]byte, error)

ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

func (goshnix *Goshnix) Readlink(name string) (string, error)

Readlink returns the destination of the named symbolic link

func (*Goshnix) Remove

func (goshnix *Goshnix) Remove(name string) error

Remove removes the named file or directory

func (*Goshnix) RemoveAll

func (goshnix *Goshnix) RemoveAll(path string) error

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters

func (*Goshnix) Rename

func (goshnix *Goshnix) Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath. If newpath already exists, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories

func (*Goshnix) Setenv

func (goshnix *Goshnix) Setenv(key, value string) error

Setenv sets the value of the environment variable named by the key (TODO: As the ssh session is new each time, it could make the Setenv useless)

func (*Goshnix) Stat

func (goshnix *Goshnix) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file

func (goshnix *Goshnix) Symlink(oldname, newname string) error

Symlink creates newname as a symbolic link to oldname

Jump to

Keyboard shortcuts

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