Skip to content

appleboy/com

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Common Functions

Run Tests GoDoc codecov Go Report Card

Common Functions is an open source collection of utility functions designed to simplify and accelerate Go development. This library provides robust, reusable helpers for common programming tasks such as random value generation, array and slice manipulation, file operations, and data type conversions. By centralizing frequently needed logic, it helps Go developers write cleaner, more efficient, and maintainable code across a wide range of projects.

Package Usage

array

Check if a value exists in a slice.

import "github.com/appleboy/com/array"

found := array.Contains([]int{1, 2, 3}, 2) // true

bytesconv

Zero-allocation conversion between string and []byte.

import "github.com/appleboy/com/bytesconv"

b := bytesconv.StrToBytes("hello")
s := bytesconv.BytesToStr([]byte{'w', 'o', 'r', 'l', 'd'})

convert

String case conversion, MD5 hashing, and float/byte conversion.

import "github.com/appleboy/com/convert"

snake := convert.SnakeCasedName("FooBar") // "foo_bar"
title := convert.TitleCasedName("foo_bar") // "FooBar"
hash := convert.MD5Hash("data")
b := convert.Float64ToByte(3.14)
f := convert.ByteToFloat64(b)

file

File and directory utilities.

import "github.com/appleboy/com/file"

isDir, _ := file.IsDir("/tmp")
isFile, _ := file.IsFile("/tmp/file.txt")
_ = file.Copy("src.txt", "dst.txt")
_ = file.Remove("/tmp/old")

gh

Set GitHub Actions output variables.

import "github.com/appleboy/com/gh"

_ = gh.SetOutput(map[string]string{"key": "value"})

random

Generate random strings for various use cases.

import "github.com/appleboy/com/random"

s, _ := random.StringWithCharset(16, random.Alphanumeric) // secure random string
fast := random.randStringBytesMaskImprSrcUnsafe(16) // fast, not secure

trace

Measure and log function execution time.

import "github.com/appleboy/com/trace"

trace.ExecuteTime("myTask", func() {
    // code to measure
})

About

This is an open source project for commonly used functions for the Go programming language.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •