A library containing useful functions for working with Go types.

Go Type Tools

A library containing useful functions for working with Go types.

Table of Contents

  1. Reasoning
  2. Examples
    1. Array
    2. Map
    3. Int
    4. String
  3. Usage
  4. License
  5. Contributing
  6. Issues
  7. Changelog
  8. Future

Reasoning

One of the main reasons I wanted to create this library was becuause of the lack of functionality in the standard library. Common things like filters, union, intersection, etc. are not available in the standard library. This library is meant to be a collection of useful functions for working with Go types, improve readability and reduce boilerplate.

← Back to Table of Contents

Examples

Here are some examples of how/when to use this library.

Array

Filter

package main

func main() {
	// Create a new array of strings
	arr := []string{"a", "b", "c"}

	// Filter the array
	filtered := arraytools.Filter(arr, func(item string) bool {
		return item == "b"
	})

	// Print the filtered array
	fmt.Println(filtered)
}

Union

package main

func main() {
	// Create a new array of strings
	arr1 := []string{"a", "b", "c"}
	arr2 := []string{"c", "d", "e"}

	// Union the arrays
	union := arraytools.Union(arr1, arr2)

	// Print the union
	fmt.Println(union)
}

Map

Filter

package main

func main() {
	// Create a new map of strings
	m := map[string]string{
		"a": "1",
		"b": "2",
		"c": "3",
	}

	// Filter the map
	filtered := maptools.Filter(m, func(key string, value string) bool {
		return value == "2"
	})

	// Print the filtered map
	fmt.Println(filtered)
}

String

ToIntArray

package main

func main() {
	// Create a new string
	s := "2313,543,1"

	// To int array
	ints := stringtools.ToIntArray(s, ",")

	// Print the int array
	fmt.Println(ints)
}

Int

SecondsToDays

package main

func main() {
	// Create a new int
	i := inttools.SecondsToDays(86400)

	// Print the int
	fmt.Println(i)
}

← Back to Table of Contents

Usage

Import the package and use the functions you need.

import "github.com/eloonstra/go-type-tools/pkg/arraytools"
import "github.com/eloonstra/go-type-tools/pkg/maptools"
import "github.com/eloonstra/go-type-tools/pkg/stringtools"
import "github.com/eloonstra/go-type-tools/pkg/inttools"

← Back to Table of Contents

License

This project is licensed under the MIT license.

← Back to Table of Contents

Contributing

Contributions are welcome! Please open an issue or pull request if you have any suggestions.

← Back to Table of Contents

Issues

Currently, there are no known issues.

← Back to Table of Contents

Changelog

v0.0.1 (12-01-2022)

  • Initial release.

← Back to Table of Contents

Future

  • When Go 1.18 is released, implement generic functions for array and map tools.
  • Add MapBy functions to array, map, string, and int tools.
  • Add additional functions to string tools for converting to and from other types.

← Back to Table of Contents

Similar Resources

A block parser tool that allows extraction of various data types on DAS

das-database A block parser tool that allows extraction of various data types on DAS (register, edit, sell, transfer, ...) from CKB Prerequisites Ubun

Nov 11, 2022

MenuStart plugin to nwg-panel, also capable of working standalone

MenuStart plugin to nwg-panel, also capable of working standalone

nwg-menu This code provides the MenuStart plugin to nwg-panel. It also may be used standalone, however, with a little help from command line arguments

Sep 9, 2022

Working towards a control plane for the MiCo Tool and the MiCoProxy

A simple control plane for MiCo This is still largely a work in progress The overall idea is to build a kubernetes DaemonSet that watches kubernetes s

May 4, 2022

Additional Terraform resources for working with AWS KMS

This is a (hopefully temporary) Terraform provider for working with AWS KMS, particularly for generating data keys. It attempts to correct a deficienc

Nov 29, 2021

Automated-gke-cilium-networkpolicy-demo - Quickly provision and tear down a GKE cluster with Cilium enabled for working with Network Policy.

Automated GKE Network Policy Demo Before running the automation, make sure you have the correct variables in env-automation/group_vars/all.yaml. There

Jan 1, 2022

A golang package for comparing and working with k0s version numbers

version A go-language package for managing k0s version numbers. It is based on hashicorp/go-version but adds sorting and comparison capabilities for t

Feb 7, 2022

Gologin is Golang (Go) login manager working with RDBMS Databases

Gologin is Golang (Go) login manager working with RDBMS Databases

What is Gologin Gologin is an easy to setup professional login manager for Go web applications. It helps you protect your application resources from u

Aug 28, 2022

The mec platform for service register/discovery/subscribe and other functions.roject main repo.

EdgeGallery MEP project Introduction Edgegallery MEP is an open source implementation of MEC platform according to ETSI MEC 003 [1] and 011 [2] docume

Nov 15, 2022

A Kubernetes Network Fabric for Enterprises that is Rich in Functions and Easy in Operations

A Kubernetes Network Fabric for Enterprises that is Rich in Functions and Easy in Operations

中文教程 Kube-OVN, a CNCF Sandbox Level Project, integrates the OVN-based Network Virtualization with Kubernetes. It offers an advanced Container Network

Dec 29, 2022
Extypes - Extra data types useful for database

ExTypes Extra data types useful for database JSON Object JSON Object is useful f

Jan 27, 2022
library for working with github api, written in Golang

gitdata library for working with github api, written in Golang Example: get user data package main import ( "fmt" "log" "github.com/a1excoder/git

May 19, 2022
Cli tool to save useful links to read it later
Cli tool to save useful links to read it later

lnk - Cli tool to save useful links still in development Usage lnk <new|list> [url] - new: creates a new link url: required params, which i

Jun 23, 2022
go-ima is a tool that checks if a file has been tampered with. It is useful in ensuring integrity in CI systems
go-ima is a tool that checks if a file has been tampered with.  It is useful in ensuring integrity in CI systems

go-ima Tool that checks the ima-log to see if a file has been tampered with. How to use Set the IMA policy to tcb by configuring GRUB GRUB_CMDLINE_LIN

Apr 26, 2022
Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism
Automatically capture all potentially useful information about each executed command (as well as its output) and get powerful querying mechanism

nhi is a revolutionary tool which automatically captures all potentially useful information about each executed command and everything around, and delivers powerful querying mechanism.

Nov 29, 2022
Package trn introduces a Range type with useful methods to perform complex operations over time ranges

Time Ranges Package trn introduces a Range type with useful methods to perform c

Aug 18, 2022
simple web app that print its environment variable, useful for testing on k8s

Index Sample web app that pints environment variables. Start it: docker-compose up Use it: > curl localhost:8080 PATH=/usr/local/sbin:/usr/local/bin:/

Jan 10, 2022
Some useful tools to help manage attachments in my local markdown projects.

Some useful tools to help manage attachments in my local markdown projects.

Oct 8, 2022
Reconciler - A library to avoid overstuffed Reconcile functions of Kubernetes operators

reconciler A library to avoid overstuffed Reconcile functions of Kubernetes oper

May 31, 2022
A Go library that provides functions for bytes and bits.

Byteman A Golang library that provides functions for bytes and bits. Usage See byteman_test.go, numbers_test.go and strings_test.go. Test # Test every

Apr 19, 2022