com

module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT

README

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
})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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