Documentation
¶
Overview ¶
Package socker
Index ¶
- Constants
- Variables
- func JoinRuleAndAddr(rule, addr string) string
- func RegisterMatchRule(name string, rule MatchRule, priority int) (replaced bool)
- func ResetRulePriority(name string, priority int)
- func SplitRuleAndAddr(s string) (rule, addr string)
- type Auth
- type File
- type Filepath
- type Fs
- type FsLocal
- func (FsLocal) Abs(path string) (string, error)
- func (FsLocal) Base(path string) string
- func (FsLocal) Chmod(name string, mode os.FileMode) error
- func (FsLocal) Chown(name string, uid, gid int) error
- func (FsLocal) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (FsLocal) Clean(path string) string
- func (FsLocal) Close() error
- func (FsLocal) Create(name string) (File, error)
- func (FsLocal) Dir(path string) string
- func (FsLocal) Ext(path string) string
- func (f FsLocal) Filepath() Filepath
- func (FsLocal) FromSlash(path string) string
- func (FsLocal) Getwd() (dir string, err error)
- func (FsLocal) IsAbs(path string) bool
- func (FsLocal) IsExist(err error) bool
- func (FsLocal) IsNotExist(err error) bool
- func (FsLocal) IsPathSeparator(c uint8) bool
- func (FsLocal) IsPermission(err error) bool
- func (FsLocal) Join(elem ...string) string
- func (FsLocal) ListSeparator() uint8
- func (FsLocal) Lstat(name string) (os.FileInfo, error)
- func (FsLocal) Mkdir(name string, perm os.FileMode) error
- func (FsLocal) MkdirAll(path string, perm os.FileMode) error
- func (FsLocal) Open(name string) (File, error)
- func (FsLocal) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (FsLocal) Readlink(name string) (string, error)
- func (FsLocal) Rel(basepath, targpath string) (string, error)
- func (FsLocal) Remove(name string) error
- func (FsLocal) RemoveAll(path string) error
- func (FsLocal) Rename(oldpath, newpath string) error
- func (FsLocal) SameFile(fi1, fi2 os.FileInfo) bool
- func (FsLocal) Separator() uint8
- func (FsLocal) Split(path string) (dir, file string)
- func (FsLocal) SplitList(path string) []string
- func (FsLocal) Stat(name string) (os.FileInfo, error)
- func (FsLocal) Symlink(oldname, newname string) error
- func (FsLocal) ToSlash(path string) string
- func (FsLocal) Truncate(name string, size int64) error
- func (FsLocal) VolumeName(path string) string
- type FsSftp
- func (s FsSftp) Chmod(name string, mode os.FileMode) error
- func (s FsSftp) Chown(name string, uid, gid int) error
- func (s FsSftp) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (s FsSftp) Close() error
- func (s FsSftp) Create(name string) (File, error)
- func (s FsSftp) Filepath() Filepath
- func (s FsSftp) Getwd() (dir string, err error)
- func (s FsSftp) IsExist(err error) bool
- func (s FsSftp) IsNotExist(err error) bool
- func (s FsSftp) IsPermission(err error) bool
- func (s FsSftp) Lstat(name string) (os.FileInfo, error)
- func (s FsSftp) Mkdir(name string, perm os.FileMode) error
- func (s FsSftp) MkdirAll(path string, perm os.FileMode) error
- func (s FsSftp) Open(name string) (File, error)
- func (s FsSftp) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (s FsSftp) Readlink(name string) (string, error)
- func (s FsSftp) Remove(name string) error
- func (s FsSftp) RemoveAll(path string) error
- func (s FsSftp) Rename(oldpath, newpath string) error
- func (s FsSftp) SameFile(fi1, fi2 os.FileInfo) bool
- func (s FsSftp) Stat(name string) (os.FileInfo, error)
- func (s FsSftp) Symlink(oldname, newname string) error
- func (s FsSftp) Truncate(name string, size int64) error
- type MatchRule
- type Matcher
- type Mux
- type MuxAuth
- type SSH
- func (s *SSH) ClearError()
- func (s *SSH) Close()
- func (s *SSH) CmdOutput() []byte
- func (s *SSH) Dial(addr string, auth *Auth) (*SSH, error)
- func (s *SSH) DialConn(net, addr string) (net.Conn, error)
- func (s *SSH) Error() error
- func (s *SSH) Get(remotePath, path string) error
- func (s *SSH) Lcd(cwd string)
- func (s *SSH) Lcmd(cmd string, env ...string) ([]byte, error)
- func (s *SSH) LcmdBg(cmd, stdout, stderr string, env ...string) ([]byte, error)
- func (s *SSH) Lexists(path string) (bool, error)
- func (s *SSH) LocalFs() Fs
- func (s *SSH) LreadFile(path string) ([]byte, error)
- func (s *SSH) Lreaddir(path string, n int) ([]os.FileInfo, error)
- func (s *SSH) Lremove(path string, recursive bool) error
- func (s *SSH) LwriteFile(path string, data []byte) error
- func (s *SSH) NopClose() *SSH
- func (s *SSH) Put(path, remotePath string) error
- func (s *SSH) Rcd(cwd string)
- func (s *SSH) Rcmd(cmd string, env ...string) ([]byte, error)
- func (s *SSH) RcmdBg(cmd, stdout, stderr string, env ...string) ([]byte, error)
- func (s *SSH) RemoteFs() Fs
- func (s *SSH) ReserveCmdOutput(buf *bytes.Buffer) *SSH
- func (s *SSH) ReserveError(e *error) *SSH
- func (s *SSH) Rexists(path string) (bool, error)
- func (s *SSH) RreadFile(path string) ([]byte, error)
- func (s *SSH) Rreaddir(path string, n int) ([]os.FileInfo, error)
- func (s *SSH) Rremove(path string, recursive bool) error
- func (s *SSH) RwriteFile(path string, data []byte) error
- func (s *SSH) Status() (openAt time.Time, refs int32)
- func (s *SSH) TmpLcd(cwd string) *SSH
- func (s *SSH) TmpRcd(cwd string) *SSH
Constants ¶
View Source
const ( RulePlain = "plain" RuleRegexp = "regexp" RuleIpnet = "ipnet" )
Variables ¶
View Source
var ( ErrMuxClosed = errors.New("mux has been closed") ErrNoAuthMethod = errors.New("no auth method can be applied to agent") )
View Source
var ( ErrIsDir = errors.New("destination is directory") CopyBufferSize int64 = 1024 * 1024 CmdSeperator = "&&" // or ; )
View Source
var ErrConnClosed = errors.New("connection closed")
Functions ¶
func JoinRuleAndAddr ¶
func RegisterMatchRule ¶
func ResetRulePriority ¶
func SplitRuleAndAddr ¶
Types ¶
type Auth ¶
type Auth struct {
User string
Password string
PrivateKey string
PrivateKeyFile string
HostKeyCheck ssh.HostKeyCallback
TimeoutMs int
MaxSession int
// contains filtered or unexported fields
}
func (*Auth) MustSSHConfig ¶
func (a *Auth) MustSSHConfig() *ssh.ClientConfig
type File ¶
type File interface {
io.Closer
Chmod(mode os.FileMode) error
Chown(uid, gid int) error
Name() string
Read(b []byte) (n int, err error)
Readdir(n int) ([]os.FileInfo, error)
Readdirnames(n int) (names []string, err error)
Seek(offset int64, whence int) (ret int64, err error)
Stat() (os.FileInfo, error)
Truncate(size int64) error
Write(b []byte) (n int, err error)
WriteString(s string) (n int, err error)
}
File is the abstract interface for local and sftp file
type Filepath ¶
type Filepath interface {
Separator() uint8
ListSeparator() uint8
IsPathSeparator(c uint8) bool
Clean(path string) string
ToSlash(path string) string
FromSlash(path string) string
SplitList(path string) []string
Split(path string) (dir, file string)
Join(elem ...string) string
Ext(path string) string
Abs(path string) (string, error)
Rel(basepath, targpath string) (string, error)
Base(path string) string
Dir(path string) string
VolumeName(path string) string
IsAbs(path string) bool
}
type Fs ¶
type Fs interface {
Filepath() Filepath
Chmod(name string, mode os.FileMode) error
Chown(name string, uid, gid int) error
Chtimes(name string, atime time.Time, mtime time.Time) error
Getwd() (dir string, err error)
IsExist(err error) bool
IsNotExist(err error) bool
IsPermission(err error) bool
Mkdir(name string, perm os.FileMode) error
MkdirAll(path string, perm os.FileMode) error
Readlink(name string) (string, error)
Remove(name string) error
RemoveAll(path string) error
Rename(oldpath, newpath string) error
SameFile(fi1, fi2 os.FileInfo) bool
Symlink(oldname, newname string) error
Truncate(name string, size int64) error
Create(name string) (File, error)
Open(name string) (File, error)
OpenFile(name string, flag int, perm os.FileMode) (File, error)
Lstat(name string) (os.FileInfo, error)
Stat(name string) (os.FileInfo, error)
io.Closer
}
Fs is the abstract interface for local and sftp filesystem
type FsLocal ¶
type FsLocal struct {
// contains filtered or unexported fields
}
FsLocal is the wrapper for package os
func (FsLocal) IsNotExist ¶
func (FsLocal) IsPathSeparator ¶
func (FsLocal) IsPermission ¶
func (FsLocal) ListSeparator ¶
func (FsLocal) ListSeparator() uint8
func (FsLocal) VolumeName ¶
type FsSftp ¶
type FsSftp struct {
// contains filtered or unexported fields
}
func (FsSftp) IsNotExist ¶
func (FsSftp) IsPermission ¶
type MuxAuth ¶
type MuxAuth struct {
// AuthMethods holds all auth methods to destination host. The key can be any
// string.
AuthMethods map[string]*Auth
// DefaultAuth is the default auth method, it must be a key in AuthMethods field,
// only used if no auth method is matched for destination, can be empty.
DefaultAuth string
// AgentAuths define the rule which auth method is used to connect to destination host.
// The key is the format of "matcher:matchor", the value must be a key in
// AuthMethods field.
AgentAuths map[string]string
// AgentGates define the rule which gate is used to connect to destination host.
// The key is the format of "matcher:matchor", the value must be an valid "host:port"
// like string.
AgentGates map[string]string
// KeepAliveSeconds limit the lifetime of idle ssh connection, default is 300.
KeepAliveSeconds int
}
MuxAuth holds auth and gate configs
func (*MuxAuth) ApplyDefaultHostCheck ¶
func (a *MuxAuth) ApplyDefaultHostCheck(check ssh.HostKeyCallback)
ApplyDefaultHostCheck apply the checking function or ssh.InsecureIgnoreHostKey to each Auth instance.
type SSH ¶
type SSH struct {
// contains filtered or unexported fields
}
func (*SSH) ClearError ¶
func (s *SSH) ClearError()
func (*SSH) Close ¶
func (s *SSH) Close()
Closed should be called only if reference count is zero or it's Cloned by NopClose
func (*SSH) NopClose ¶
NopClose create a clone of current SSH instance and increase the reference count. The Close method of returned instance will do nothing but decrease parent reference count.
func (*SSH) ReserveError ¶
Click to show internal directories.
Click to hide internal directories.