{"id":18326530,"url":"https://github.com/ghosind/utils","last_synced_at":"2025-04-09T16:27:43.540Z","repository":{"id":49335751,"uuid":"516038372","full_name":"ghosind/utils","owner":"ghosind","description":"Utilities for Golang","archived":false,"fork":false,"pushed_at":"2023-12-05T13:07:30.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-15T09:46:47.652Z","etag":null,"topics":["go-utils","golang","golang-library"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/ghosind/utils","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghosind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-07-20T15:34:23.000Z","updated_at":"2022-07-23T15:57:35.000Z","dependencies_parsed_at":"2023-12-05T13:52:10.661Z","dependency_job_id":null,"html_url":"https://github.com/ghosind/utils","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Futils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Futils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Futils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghosind%2Futils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghosind","download_url":"https://codeload.github.com/ghosind/utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248067049,"owners_count":21042221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go-utils","golang","golang-library"],"created_at":"2024-11-05T19:07:12.281Z","updated_at":"2025-04-09T16:27:43.518Z","avatar_url":"https://github.com/ghosind.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Utilities for Golang\n\n![Test](https://github.com/ghosind/utils/workflows/utils/badge.svg)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ghosind/utils)](https://goreportcard.com/report/github.com/ghosind/utils)\n[![codecov](https://codecov.io/gh/ghosind/utils/branch/main/graph/badge.svg)](https://codecov.io/gh/ghosind/utils)\n[![Latest version](https://img.shields.io/github/v/release/ghosind/utils?include_prereleases)](https://github.com/ghosind/utils)\n![License Badge](https://img.shields.io/github/license/ghosind/utils)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ghosind/utils.svg)](https://pkg.go.dev/github.com/ghosind/utils)\n\nA set of utilities functions for Golang.\n\n\u003e PLEASE NOTE: This package is working with Go 1.18 and later versions.\n\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n  - [Handle Pointers](#handle-pointers)\n  - [Conditional Expression](#conditional-expression)\n- [Available Utilities](#available-utilities)\n  - [Conditional](#conditional)\n  - [Map Manipulation](#map-manipulation)\n  - [Type](#type)\n  - [Pointer and Value](#pointer-and-value)\n- [License](#license)\n\n## Installation\n\nYou can install this package with [`go get`](https://golang.org/cmd/go) command:\n\n```sh\ngo get -u github.com/ghosind/utils\n```\n\n## Getting Started\n\n### Handle Pointers\n\nWith the `Pointer` method, you can easy to get a pointer that points to any value you want.\n\n```go\nstr := \"Hello world\" // string\n// get the pointer of the string, it equal to strp := \u0026str\nstrp := utils.Pointer(str) // string pointer, and it point to str\nlog.Print(*strp) // Hello world\n\n// It's also working for literal values\nintp := utils.Pointer(1)\n// You can't do:\n// intp := \u00261\nlog.Print(*intp) // 1\n```\n\nYou can also use `Value` or `ValueWithDefault` to get the value of the pointer. For nil pointer, `Value` method will return the zero value of the type, and `ValueWithDefault` method will return the default value you set.\n\n```go\nutils.Value(strp) // Hello world\nutils.ValueWithDefault(str, \"Default\") // Hello world\n\nstrp = nil\nutils.Value(strp) // \"\" (empty string)\nutils.ValueWithDefault(str, \"Default\") // Default\n```\n\n### Conditional Expression\n\nGolang does not provided ternary operator (`?:`), but you can use `utils.Conditional` or `utils.ConditionalExpr` to make it like a ternary expression.\n\n```go\na := 1\nb := 2\nbigger := utils.Conditional(a \u003e b, a, b) // a \u003e b ? a : b\n// bigger: 2\n```\n\n## Available Utilities\n\n### Conditional\n\n- [`Conditional`](https://pkg.go.dev/github.com/ghosind/utils#Conditional): An alternative of ternary operator, same of `cond ? trueExpr : falseExpr`.\n\n- [`ConditionalExpr`](https://pkg.go.dev/github.com/ghosind/utils#ConditionalExpr): An alternative to the conditional (ternary) operator (?:), it'll run expression by the conditional result.\n\n- [`Max`](https://pkg.go.dev/github.com/ghosind/utils#Max): Gets the maximum value between the two values.\n\n- [`MaxN`](https://pkg.go.dev/github.com/ghosind/utils#MaxN): Returns the maximum value in the list and returns the zero value of the type if no parameter.\n\n- [`Min`](https://pkg.go.dev/github.com/ghosind/utils#Min): Gets the minimum value between the two values.\n\n- [`MinN`](https://pkg.go.dev/github.com/ghosind/utils#MinN): Returns the minimum value in the list and returns the zero value of the type if no parameter.\n\n### Error Handling\n\n- [`Try`](https://pkg.go.dev/github.com/ghosind/utils#Try): Recoverable function container.\n\n- [`TryCatch`](https://pkg.go.dev/github.com/ghosind/utils#TryCatch): An alternative of `try...catch...finally` statement.\n\n### Math\n\n- [`Matrix`](https://pkg.go.dev/github.com/ghosind/utils#Matrix): Creates and initializes a n*m matrix.\n\n### Map Manipulation\n\n- [`CloneMap`](https://pkg.go.dev/github.com/ghosind/utils#CloneMap): Creates a new map, and copies all the keys and their value from the source map.\n\n- [`CopyMap`](https://pkg.go.dev/github.com/ghosind/utils#CopyMap): Copies all keys and their value from the source map into the destination map.\n\n### Type\n\n- [`IsComparableType`](https://pkg.go.dev/github.com/ghosind/utils#IsComparableType): Check the type of value is comparable or not.\n\n- [`IsSameType`](https://pkg.go.dev/github.com/ghosind/utils#IsSameType): Compares two values' type.\n\n- [`IsSameRawType`](https://pkg.go.dev/github.com/ghosind/utils#IsSameRawType): Compares two values' type without pointer.\n\n- [`TypeOf`](https://pkg.go.dev/github.com/ghosind/utils#TypeOf): Gets the type of the value represented in string.\n\n- [`RawTypeOf`](https://pkg.go.dev/github.com/ghosind/utils#RawTypeOf): Gets the type string name without pointer.\n\n- [`GetElem`](https://pkg.go.dev/github.com/ghosind/utils#GetElem): Gets element without pointer.\n\n### Pointer and Value\n\n- [`Pointer`](https://pkg.go.dev/github.com/ghosind/utils#Pointer): Gets the pointer of a value.\n\n- [`PointerWithDefault`](https://pkg.go.dev/github.com/ghosind/utils#PointerWithDefault): Gets the pointer if it is not nil, or the default pointer.\n\n- [`Value`](https://pkg.go.dev/github.com/ghosind/utils#Value): Gets the value of a pointer, or the zero value of the type if the pointer is nil.\n\n- [`ValueWithDefault`](https://pkg.go.dev/github.com/ghosind/utils#ValueWithDefault): Gets the value of a pointer, or the default value if the pointer is nil.\n\n- [`PointerSlice`](https://pkg.go.dev/github.com/ghosind/utils#PointerSlice): Converts a slice to a pointer slice.\n\n- [`ValueSlice`](https://pkg.go.dev/github.com/ghosind/utils#ValueSlice): Converts a pointer slice to a slice.\n\n- [`PointerMap`](https://pkg.go.dev/github.com/ghosind/utils#PointerMap): Converts a map to a pointer map.\n\n- [`ValueMap`](https://pkg.go.dev/github.com/ghosind/utils#ValueMap): Converts a pointer map to a map.\n\n## License\n\nDistributed under the MIT License. See LICENSE file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghosind%2Futils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghosind%2Futils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghosind%2Futils/lists"}