common

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package common is a package that summarizes the common processing of bssh package. nolint:goerr113

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHelpFlag added in v0.6.13

func CheckHelpFlag(c *cli.Context)

CheckHelpFlag checks the help flag then show app help and exit.

func Contains added in v0.6.13

func Contains(s []string, e string) bool

Contains tells if s contains element e.

func CreateRateLimit added in v1.0.2

func CreateRateLimit(r io.Reader) io.Reader

func ExpandHomeDir added in v0.6.13

func ExpandHomeDir(f string) string

ExpandHomeDir expands the ~ in the path if it is available.

func GetFilesBase64 added in v0.5.1

func GetFilesBase64(paths []string) (string, 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 added in v0.6.13

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

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

func GetMaxLength

func GetMaxLength(list []string) int

GetMaxLength returns a max byte length of list.

func GetNameFromID added in v0.6.13

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

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

func GetOrderNumber added in v0.6.13

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

GetOrderNumber get order num in array.

func GetPassPhrase added in v0.6.13

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 added in v0.6.13

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

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

func IsExist

func IsExist(filename string) bool

IsExist returns existence of file.

func IsHidden added in v1.0.0

func IsHidden(basedir, path string) bool

IsHidden tells a path is hidden after basedir.

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 added in v0.6.13

func NewSHA1Hash(n ...int) string

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

func ParseArgs added in v0.6.13

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

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

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

func ParseForwardPort added in v0.6.13

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 RandomString added in v0.6.13

func RandomString(n int) string

RandomString generates a random string of n length.

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 added in v0.6.13

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