common

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

common is a package that summarizes the common processing of lssh package.

Index

Constants

View Source
const (
	ARCHIVE_NONE = iota
	ARCHIVE_GZIP
)

enum

Variables

This section is empty.

Functions

func Contains

func Contains(list interface{}, elem interface{}) bool

func ControlMasterOverrideFlags added in v0.9.0

func ControlMasterOverrideFlags() []cli.Flag

func GetControlMasterOverride added in v0.9.0

func GetControlMasterOverride(c *cli.Context) (*bool, error)

func GetDefaultConfigCandidates added in v0.9.0

func GetDefaultConfigCandidates(home, xdgConfigHome string) []string

func GetDefaultConfigPath

func GetDefaultConfigPath() (path string)

func GetFilesBase64

func GetFilesBase64(paths []string, iscompress int) (result string, err error)

GetFilesBase64 returns a base64 encoded string of file content of paths.

func GetFullPath

func GetFullPath(path string) (fullPath string)

GetFullPath returns a fullpath of path. Expands `~` to user directory ($HOME environment variable).

func GetIdFromName

func GetIdFromName(file string, name string) (id uint32, err error)

GetUserName return user name from /etc/passwd and uid.

func GetMaxLength

func GetMaxLength(list []string) (MaxLength int)

GetMaxLength returns a max length of list. Length is byte length.

func GetNameFromId

func GetNameFromId(file string, id uint32) (name string, err error)

GetUserName return user name from /etc/passwd and uid.

func GetOrderNumber

func GetOrderNumber(value string, array []string) int

Get order num in array

func GetPassPhrase

func GetPassPhrase(msg string) (input string, err error)

GetPassPhrase gets the passphrase from virtual terminal input and returns the result. Works only on UNIX-based OS.

func GetUniqueSlice

func GetUniqueSlice(data []string) (result []string)

GetUniqueSlice return slice, removes duplicate values from data(slice).

func IsDirPath

func IsDirPath(path string) (isDir bool)

IsDirPath identifies is the directory from the PATH string.

func IsExist

func IsExist(filename string) bool

IsExist returns existence of file.

func MapMerge

func MapMerge(m ...map[string]interface{}) map[string]interface{}

MapMerge merges multiple Maps

func MapReduce

func MapReduce(map1, map2 map[string]interface{}) map[string]interface{}

MapReduce sets map1 value to map2 if map1 and map2 have same key, and value of map2 is zero value. Available interface type is string or []string or bool.

WARN: This function returns a map, but updates value of map2 argument too.

func MapToStruct

func MapToStruct(mapVal map[string]interface{}, val interface{}) (ok bool)

MapToStruct sets value of mapVal to public field of val struct. Raises panic if mapVal has keys of private field of val struct or field that val struct doesn't have.

WARN: ok value is not used. Always returns false.

func NewSHA1Hash

func NewSHA1Hash(n ...int) string

NewSHA1Hash generates a new SHA1 hash based on a random number of characters.

func NormalizeGenerateLSSHConfArgs added in v0.9.0

func NormalizeGenerateLSSHConfArgs(args []string) []string

NormalizeGenerateLSSHConfArgs rewrites --generate-lssh-conf without an explicit value to use the default OpenSSH config path.

func NormalizeTrailingBoolFlags added in v0.9.0

func NormalizeTrailingBoolFlags(args []string, boolFlags, valueFlags map[string]bool) []string

NormalizeTrailingBoolFlags moves known trailing bool flags ahead of the first positional argument so ParseArgs can still interpret them as options. valueFlags lists options that consume the following argument as their value.

func ParseArgs

func ParseArgs(options []cli.Flag, args []string) []string

ParseArgs return os.Args parse short options (ex.) [-la] => [-l,-a] )

TODO(blacknon): Migrate to github.com/urfave/cli version 1.22.

func ParseForwardPathPair added in v0.9.0

func ParseForwardPathPair(value string) (left, path string, err error)

ParseForwardPathPair parses `<left>:<path>` style arguments used by filesystem forwarding options.

func ParseForwardPort

func ParseForwardPort(value string) (local, remote string, err error)

ParseForwardPort return forward address and port from string.

ex.)

  • `localhost:8000:localhost:18000` => local: "localhost:8000", remote: "localhost:18000"
  • `8080:localhost:18080` => local: "localhost:8080", remote: "localhost:18080"
  • `localhost:2222:12222` => local: "localhost:2222", remote: "localhost:12222"

func ParseForwardSpec added in v0.8.0

func ParseForwardSpec(value string) (localNetwork, local, remoteNetwork, remote string, err error)

ParseForwardSpec parses OpenSSH-style local forward arguments and supports TCP and Unix domain socket combinations.

func ParseHostPath

func ParseHostPath(value string) (host []string, path string)

ParseHostPath return host and path, from host:/path/to/dir/file.

func ParseNFSForwardPortPath

func ParseNFSForwardPortPath(value string) (port, path string, err error)

ParseNFSForwardPortPath parses `port:/path` style NFS/SMB forwarding args.

func ParseTunnelSpec

func ParseTunnelSpec(s string) (int, int, error)

ParseTunnelSpec parses a tunnel specification string of the form `<num|any>:<num|any>` and returns local and remote units. `any` maps to sshlib.TunnelDeviceAny.

func RandomString

func RandomString(n int) string

RandomString generates a random string of n length

func StringCompression

func StringCompression(mode int, data []byte) (result []byte, err error)

StringCompression compresses bytes in the specified mode.

func StructToMap

func StructToMap(val interface{}) (mapVal map[string]interface{}, ok bool)

StructToMap returns a map that converted struct to map. Keys of map are set from public field of struct.

WARN: ok value is not used. Always returns false.

func WalkDir

func WalkDir(dir string) (files []string, err error)

WalkDir return file path list ([]string).

Types

This section is empty.

Jump to

Keyboard shortcuts

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