berry

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 9 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

berry

Build Status Code Coverage go.mod version GitHub Go Report Card PkgGoDev

Utility functions in Go.

Hacking

  • To build the Go docs locally:

  • To run all tests along with code coverage report

    • $ go test ./... -v -coverprofile coverage.out
    • $ go tool cover -html=coverage.out
  • To publish the Go module:

    • $ git tag v0.x.0
    • $ git push origin v0.x.0
    • $ GOPROXY=proxy.golang.org go list -m github.com/sangupta/berry@v0.x.0

License

MIT License. Copyright (c) 2022, Sandeep Gupta.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AreSlicesEqual

func AreSlicesEqual[T comparable](slice1 []T, slice2 []T) bool

Check if 2 slices are equal or not. The slices are considered equal if and only if there are of same length, and elements at the same index in slices are equal. If any of the slice is `nil` will return a `false`.

func ConvertToBool

func ConvertToBool(value interface{}) (bool, error)

Convert the given value represented as `interface{}` to boolean. Returns `false` if value is `nil`. Returns `true` if the value is numeric and not-zero, or if the value is `string` and represents a `bool`, or if the value is non-primitive.

func ConvertToFloat64

func ConvertToFloat64(value interface{}, defaultValue float64) (float64, error)

Convert the given value represented as `interface{}` to a `float64` value. Returns the `defaultValue` is the value is `nil`. Returns an `error` if the value cannot be cast to a number. For non-primitive values, the `defaultValue` is returned.

func ConvertToInt64

func ConvertToInt64(value interface{}, defaultValue int64) (int64, error)

Convert the given value represented as `interface{}` to a `int64` value. Returns the `defaultValue` is the value is `nil`. Returns an `error` if the value cannot be cast to a number. For non-primitive values, the `defaultValue` is returned.

func ConvertToString

func ConvertToString(value interface{}) string

Convert the given value represented as `interface{}` to its string representation.

func ConvertToUint64

func ConvertToUint64(value interface{}, defaultValue uint64) (uint64, error)

Convert the given value represented as `interface{}` to a `uint64` value. Returns the `defaultValue` is the value is `nil`. Returns an `error` if the value cannot be cast to a number. For non-primitive values, the `defaultValue` is returned.

func DoesPathExist

func DoesPathExist(path string) (bool, error)

Check if a given path exists or not?

func IsMap

func IsMap(value interface{}) bool

Check if value represents a `map` or not. Returns `false` if value is `nil`.

func IsNumber

func IsNumber(value interface{}) bool

Check if value is a primitve number or not. Returns `false` if value is `nil`.

func IsSlice

func IsSlice(value interface{}) bool

Check if value represents a slice or not. Returns `false` if value is `nil`.

func SliceContains

func SliceContains[T comparable](slice []T, element T) bool

Check if the slice contains the given element or not. Returns `false` if the slice is `nil`, or empty or the element cannot be found.

func SliceIndex

func SliceIndex[T comparable](slice []T, element T) int

Find the index of the given element in the slice. The functions returns `-1` if the slice is `nil` or empty or the element cannot be found.

func SliceMax

func SliceMax[T Number](slice []T) (T, error)

Find the minimum value from the slice of numbers. Returns an `error` if the slice is nil, or is empty.

func SliceMin

func SliceMin[T Number](slice []T) (T, error)

Find the minimum value from the slice of numbers. Returns an `error` if the slice is nil, or is empty.

func SliceModify

func SliceModify[T comparable](slice []T, modifier func(item T) T) bool

Modify the slice using a modifier function. Each element of the slice is sent to the modifier, and the returned value is updated in the slice at same index. The method has no effect if the slice is `nil`.

func SliceReverse

func SliceReverse[T comparable](slice []T) []T

Reverse a slice and return the same. If the slice is `nil` or has less than or equal to one element, no action is taken.

Types

type FileAsset

type FileAsset struct {
	Id             string `json:"id"`        // the unique ID for this file
	Name           string `json:"name"`      // name of this file
	Path           string `json:"path"`      // path of this file
	Extension      string `json:"extension"` // extension extracted for this file
	MimeType       string `json:"mimeType"`  // mime type base on extension of this file
	IsFolder       bool   `json:"isFolder"`  // whether the file is a folder or not
	IsSymbolicLink bool   `json:"isSymLink"` // whether the file is a symlink or not
	Size           uint64 `json:"size"`      // size of file
	Created        int64  `json:"created"`   // when was the file created
	Modified       int64  `json:"modified"`  // when was the file last modified
}

func ListFiles

func ListFiles(path string, recursive bool) ([]*FileAsset, error)

type FileFilter

type FileFilter func(asset FileAsset) bool

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64
}

Defines the primitive types that define the `Number` interface.

Jump to

Keyboard shortcuts

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