gocommon

package module
v0.0.0-...-eb8883e Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 14 Imported by: 5

README

GO-Common

License

go-common, the Golang common library, is a common library for the harvester project. We want to build some essential and efficient functions. Let the other developers can reuse it easily.

ToDo

  • Improve the code coverage.

Documentation

Overview

Dummy package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupFile

func BackupFile(source string) (string, error)

func BackupFileToDir

func BackupFileToDir(sourcePath, dstDir string) (string, error)

func BackupFileToDirWithSuffix

func BackupFileToDirWithSuffix(sourcePath, dstDir, suffix string) (string, error)

func GenRandNumber

func GenRandNumber(boundary int64) (int64, error)

GenRandNumber generates a random positive number less than the boundary value. The return value should be [0, boundary) and error is nil when success. If the error is not nil, the return value is 0.

func GenerateTempFile

func GenerateTempFile(buf []byte, prefix string) (string, error)

Generate Temp file with buffer, return the file name

func GenerateTempFileFullOptions

func GenerateTempFileFullOptions(buf []byte, prefix, dirPath string, perm fs.FileMode) (string, error)

Generate Temp file with buffer, directory and permission, return the file name

func GenerateTempFileWithDir

func GenerateTempFileWithDir(buf []byte, prefix, dirPath string) (string, error)

Generate Temp file with buffer and directory, return the fullpath

func GenerateTempFileWithPerm

func GenerateTempFileWithPerm(buf []byte, prefix string, perm fs.FileMode) (string, error)

Generate Temp file with buffer and permission, return the file name

func GenerateYAMLTempFile

func GenerateYAMLTempFile(obj interface{}, prefix string) (string, error)

Generate Temp file with YAML content, return the file name

func GenerateYAMLTempFileFullOptions

func GenerateYAMLTempFileFullOptions(obj interface{}, prefix, dirPath string, perm fs.FileMode) (string, error)

Generate Temp file with YAML content and permission, return the file name

func GenerateYAMLTempFileWithDir

func GenerateYAMLTempFileWithDir(obj interface{}, prefix, dirPath string) (string, error)

func GenerateYAMLTempFileWithPerm

func GenerateYAMLTempFileWithPerm(obj interface{}, prefix string, perm fs.FileMode) (string, error)

func GetFileName

func GetFileName(path string) string

func RemoveFiles

func RemoveFiles(path ...string) error

func RestartService

func RestartService(unit string) error

func SliceContentCmp

func SliceContentCmp[T comparable](x, y []T) bool

SliceContentCmp compares two slices and returns true if they have the same content with any order.

func SliceDedupe

func SliceDedupe[T comparable](x []T) []T

SliceDedupe removes duplicated items and return a non-deplucated items slice.

func WatchDBusSignal

func WatchDBusSignal(ctx context.Context, iface, objPath string, handlerFunc func(s *dbus.Signal))

func WatchFileChange

func WatchFileChange(ctx context.Context, handler FSNotifyHandler, monitorTargets []string)

Types

type FSNotifyHandler

type FSNotifyHandler interface {
	Notify(event fsnotify.Event)
}

func AnyOf

func AnyOf(nextHandler FSNotifyHandler, op fsnotify.Op, ops ...fsnotify.Op) FSNotifyHandler

AnyOf propagates the fsnotify Event to the next FSNotifyHandler only if the event type is one of the specified fsnotify Ops.

type FSNotifyHandlerFunc

type FSNotifyHandlerFunc func(event fsnotify.Event)

FSNotifyHandlerFunc is a callback for fsnotify Events.

func (FSNotifyHandlerFunc) Notify

func (f FSNotifyHandlerFunc) Notify(event fsnotify.Event)

Jump to

Keyboard shortcuts

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