{"id":37432691,"url":"https://github.com/x-funs/go-fun","last_synced_at":"2026-02-25T16:08:44.606Z","repository":{"id":37394562,"uuid":"489254243","full_name":"x-funs/go-fun","owner":"x-funs","description":"Go with Fun (Functions) is a small and useful Golang util function library. It Includes such as Empty、Blank、Strtotime、Similarity、HttpGet etc.","archived":false,"fork":false,"pushed_at":"2026-01-30T08:58:42.000Z","size":289,"stargazers_count":218,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-10T13:29:01.479Z","etag":null,"topics":["go","golang","utility-library","utils"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/x-funs.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-05-06T07:14:02.000Z","updated_at":"2026-01-30T08:45:46.000Z","dependencies_parsed_at":"2024-01-29T10:34:16.482Z","dependency_job_id":"2fb33902-3ffe-4cfa-b94b-d2f419a28c98","html_url":"https://github.com/x-funs/go-fun","commit_stats":null,"previous_names":[],"tags_count":105,"template":false,"template_full_name":null,"purl":"pkg:github/x-funs/go-fun","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-funs%2Fgo-fun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-funs%2Fgo-fun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-funs%2Fgo-fun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-funs%2Fgo-fun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/x-funs","download_url":"https://codeload.github.com/x-funs/go-fun/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/x-funs%2Fgo-fun/sbom","scorecard":{"id":1242696,"data":{"date":"2026-01-19","repo":{"name":"github.com/x-funs/go-fun","commit":"f1348a1c8999f61efba116ad9af7c12adf0d6a97"},"scorecard":{"version":"v5.4.1-0.20260109214540-85483c21ffbb","commit":"85483c21ffbb0f125cf1d16aa53f283d574f4ca5"},"score":3.5,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 1/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#vulnerabilities"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: some github tokens can't read classic branch protection rules: https://github.com/ossf/scorecard-action/blob/main/docs/authentication/fine-grained-auth-token.md","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/85483c21ffbb0f125cf1d16aa53f283d574f4ca5/docs/checks.md#sast"}}]},"last_synced_at":"2026-01-31T00:36:38.576Z","repository_id":37394562,"created_at":"2026-01-31T00:36:38.576Z","updated_at":"2026-01-31T00:36:38.576Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29829423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T15:41:19.027Z","status":"ssl_error","status_checked_at":"2026-02-25T15:40:47.150Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","golang","utility-library","utils"],"created_at":"2026-01-16T06:36:38.064Z","updated_at":"2026-02-25T16:08:44.580Z","avatar_url":"https://github.com/x-funs.png","language":"Go","readme":"```\n                      ____          \n   ____ _____        / __/_  ______ \n  / __ `/ __ \\______/ /_/ / / / __ \\\n / /_/ / /_/ /_____/ __/ /_/ / / / /\n \\__, /\\____/     /_/  \\__,_/_/ /_/ \n/____/                              \n\n```\n\nGo with Fun (Functions) is a small and useful Golang util function library. It Includes such as Empty、Blank、Strtotime、Similarity、HttpGet etc.\n\nEnglish | [简体中文](./README_zh.md)\n\n## Installation\n\n```shell\ngo get -u github.com/x-funs/go-fun\n```\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/x-funs/go-fun\"\n)\n\nfunc main() {\n\t// Whether any type value is empty\n\tfmt.Println(fun.Empty(\"\"))\n\t\n\t// Whether string value is blank\n\tfmt.Println(fun.Blank(\"  \"))\n\t\n\t// Return MD5 string from a string\n\tfmt.Println(fun.Md5(\"go-fun\"))\n\t\n\t// Auto parse datetime layout to int64 timestamp\n\tfmt.Println(fun.StrToTime(\"2015-04-06 16:03:03\"))\n\tfmt.Println(fun.StrToTime(\"2015/04/06 16:03:03\"))\n\tfmt.Println(fun.StrToTime(\"2022-01-24T14:19:00Z\"))\n\tfmt.Println(fun.StrToTime(\"2022-01-24T14:19:01+07:00\"))\n\t\n\t// Slice deduplication filter\n\tfmt.Println(fun.SliceUnique([]string{\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"}))\n\n\t// Send a Simple HTTP GET request, Return HTML string\n\thtml, _ := fun.HttpGet(\"https://www.github.com\")\n\tfmt.Println(fun.String(html))\n}\n```\n\n## Documentation\n\n### DateTime\n\n#### Function List\n\n- **\u003cbig\u003e`Timestamp(millis ...any) int64`\u003c/big\u003e** Return the current unix timestamp.\n\n- **\u003cbig\u003e`Date(layouts ...any) string`\u003c/big\u003e** Return the formatted datetime string.\n\n- **\u003cbig\u003e`StrToTime(args ...any) int64`\u003c/big\u003e** Auto parse datetime layout to int64 timestamp, just like PHP strtotime().\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/x-funs/go-fun\"\n)\n\nfunc main() {\n\t// second timestamp\n\tfmt.Println(fun.Timestamp())\n\t// 1673225645\n\t\n\t// millisecond timestamp\n\tfmt.Println(fun.Timestamp(true))\n\t// 1673225645077\n\n\t// no arguments, format datetime now (default by '2006-01-02 15:04:05')\n\tfmt.Println(fun.Date())\n\t// 2006-01-02 15:04:05\n\n\t// format datetime by timestamp (default by '2006-01-02 15:04:05')\n\tfmt.Println(fun.Date(1650732457))\n\t// 2022-04-24 00:47:37\n\n\t// use layout format datetime by timestamp\n\tfmt.Println(fun.Date(time.RFC3339, 1650732457))\n\t// 2022-04-24T00:47:37+08:00\n\t\n\t// no arguments, same as Timestamp()\n\tfmt.Println(fun.StrToTime())\n\t// 1673226381\n\n\t// one day before now timestamp\n\tfmt.Println(fun.StrToTime(\"-1 day\"))\n\t// 1673139981 (yesterday)\n\n\tfmt.Println(fun.StrToTime(\"+1 day\", 1673225645))\n\t// 1673312045 (one day after a certain timestamp)\n}\n```\n\n### Helpers\n\n#### Function List\n\n- **\u003cbig\u003e`If(condition bool, trueVal, falseVal T) T`\u003c/big\u003e** Verify condition is true, return trueVal or falseVal\n\n- **\u003cbig\u003e`Empty(value any) bool`\u003c/big\u003e** Verify whether value it is empty, support string, integer, array, slice, map 验证\n\n- **\u003cbig\u003e`EmptyAll(values ...any) bool`\u003c/big\u003e** Verify whether values all are empty\n\n- **\u003cbig\u003e`EmptyAny(values ...any) bool`\u003c/big\u003e** Verify whether values any is empty\n\n- **\u003cbig\u003e`MemoryBytes() map[string]int64`\u003c/big\u003e** Return the current main memory metrics.\n\n- **\u003cbig\u003e`Memory(format string) map[string]int64`\u003c/big\u003e** Specified format return the current main memory metric.\n\n- **\u003cbig\u003e`Bytes(s string) []byte`\u003c/big\u003e** Efficient string to byte array, reference from `Gin`\n\n- **\u003cbig\u003e`String(b []byte) string`\u003c/big\u003e** Efficient byte array to string, reference from `Gin`\n\n- **\u003cbig\u003e`Command(bin string, argv []string, baseDir string) ([]byte, error)`\u003c/big\u003e** Execute system commands\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/x-funs/go-fun\"\n)\n\nfunc main() {\n\tfmt.Println(fun.Empty(nil))\n\t// true\n\n\tfmt.Println(fun.Empty(0))\n\t// true\n\n\tfmt.Println(fun.Empty(\"\"))\n\t// true\n\n\tfmt.Println(fun.Empty(false))\n\t// true\n\n\tfmt.Println(fun.Empty(\" \"))\n\t// false\n\n\tfmt.Println(fun.Empty(1))\n\t// false\n\n\tfmt.Println(fun.Empty(true))\n\t// false\n}\n```\n\n### Hash\n\n#### Function List\n\n- **\u003cbig\u003e`Md5(str string) string`\u003c/big\u003e** Return the Md5 string\n\n- **\u003cbig\u003e`Md5Bit16(str string) string`\u003c/big\u003e** Return the 16-bit Md5 string\n\n- **\u003cbig\u003e`Sha1(str string) string`\u003c/big\u003e** Return the Sha1 string\n\n- **\u003cbig\u003e`Sha256(str string) string`\u003c/big\u003e** Return the Sha256 string\n\n- **\u003cbig\u003e`Sha384(str string) string`\u003c/big\u003e** Return the Sha384 string\n\n- **\u003cbig\u003e`Sha512(str string) string`\u003c/big\u003e** Return the Sha512 string\n\n- **\u003cbig\u003e`Base64Encode(str string) string`\u003c/big\u003e** Return the Base64 string\n\n- **\u003cbig\u003e`Base64Decode(str string) string`\u003c/big\u003e** Return the Base64 decode string\n\n- **\u003cbig\u003e`Base64UrlEncode(str string) string`\u003c/big\u003e** Return the Url Safe Base64 string\n\n- **\u003cbig\u003e`Base64UrlDecode(str string) string`\u003c/big\u003e** Return the Url Safe Base64 decode string\n\n### Judgment\n\n#### Function List\n\n- **\u003cbig\u003e`IsNumber(str string) bool`\u003c/big\u003e** Determine whether all strings are numbers\n\n- **\u003cbig\u003e`IsUtf8(p []byte) bool`\u003c/big\u003e** Determine whether it is a UTF-8 code\n\n- **\u003cbig\u003e`IsASCIILetter(str string) bool`\u003c/big\u003e** Determine whether all strings are ASCII letters\n\n- **\u003cbig\u003e`IsLetter(str string) bool`\u003c/big\u003e** Determine whether all strings are letters\n\n- **\u003cbig\u003e`IsASCII(s string) bool`\u003c/big\u003e** Determine whether the string is all ASCII\n\n- **\u003cbig\u003e`IsEmail(str string) bool`\u003c/big\u003e** Verify Email\n\n- **\u003cbig\u003e`IsExist(path string) bool`\u003c/big\u003e**  Does the file or directory exist\n\n- **\u003cbig\u003e`IsDir(path string) bool`\u003c/big\u003e** Is it a directory\n\n### Map\n\n#### Function List\n\n- **\u003cbig\u003e`MapKeys[K comparable, V any](m map[K]V) []K`\u003c/big\u003e** Return slices of all keys of map\n\n- **\u003cbig\u003e`MapValues[K comparable, V any](m map[K]V) []V`\u003c/big\u003e** Return a slice of all values of map\n\n- **\u003cbig\u003e`MapMerge[K comparable, V any](maps ...map[K]V) map[K]V`\u003c/big\u003e** Merge multiple maps, if there are the same keys, the latter will overwrite the former\n\n### Math\n\n#### Function List\n\n- **\u003cbig\u003e`Max(a, b int) int`\u003c/big\u003e** Take int maximum\n\n- **\u003cbig\u003e`Min(a, b int) int`\u003c/big\u003e** Take int minimum\n\n- **\u003cbig\u003e`MaxInt64(a, b int64) int64`\u003c/big\u003e** Take int64 maximum\n\n- **\u003cbig\u003e`MinInt64(a, b int64) int64`\u003c/big\u003e** Take int64 minimum\n\n- **\u003cbig\u003e`MaxN[T GenNumber](args ...T) T`\u003c/big\u003e** Take the maximum value of n numbers\n\n- **\u003cbig\u003e`MinN[T GenNumber](args ...T) T`\u003c/big\u003e** Take the minimum value of n numbers\n\n### Random\n\n#### Function List\n\n- **\u003cbig\u003e`Random() int`\u003c/big\u003e** Return a random number `[0, MaxInt)`\n\n- **\u003cbig\u003e`RandomInt(min, max int) int`\u003c/big\u003e** Return a random number `[min, max)`\n\n- **\u003cbig\u003e`RandomInt64(min, max int64) int64`\u003c/big\u003e** Return a random number `[min, max)`\n\n- **\u003cbig\u003e`RandomString(length int) string`\u003c/big\u003e** Return a random string of the specified length, including letters and numbers.\n\n- **\u003cbig\u003e`RandomLetter(length int) string`\u003c/big\u003e** Return a random string of the specified length, containing only letters.\n\n- **\u003cbig\u003e`RandomNumber(length int) string`\u003c/big\u003e** Return a random string of the specified length, containing only numbers.\n\n- **\u003cbig\u003e`RandomPool(pool string, length int) string`\u003c/big\u003e** Return a random string of the specified length from the supplied string pool\n\n### Regex\n\n#### Function List\n\n- **\u003cbig\u003e`Matches(str, pattern string) bool`\u003c/big\u003e** Determines whether the string matches the specified regular expression.\n\n### Similarity\n\n#### Function List\n\n- **\u003cbig\u003e`Similarity(a, b string) float64`\u003c/big\u003e** Calculates the similarity of two original strings\n\n- **\u003cbig\u003e`SimilarityText(a, b string) float64`\u003c/big\u003e** Calculate the similarity of two strings after removing special symbols\n\n- **\u003cbig\u003e`LongestCommonSubString(x, y string) int`\u003c/big\u003e** Calculates the maximum common substring length of two strings\n\n### Slice\n\n#### Function List\n\n- **\u003cbig\u003e`SliceSplit[T comparable](slice []T, size int) [][]T`\u003c/big\u003e** Divide numeric and string slices according to the specified length\n\n- **\u003cbig\u003e`SliceUnion[T comparable](slices ...[]T) []T`\u003c/big\u003e** Sequential merge and deweight\n\n- **\u003cbig\u003e`SliceColumn[T, V any](slice []T, key any) []V`\u003c/big\u003e** Return a column of all rows\n\n- **\u003cbig\u003e`IntsToStrings(slice []int) []string`\u003c/big\u003e** Int slice to string slice\n\n- **\u003cbig\u003e`StringsToInts(slice []string) []int`\u003c/big\u003e** String slice to int slice\n\n- **\u003cbig\u003e`SliceContains[T comparable](slice []T, v T) bool`\u003c/big\u003e** Determine whether integer and string are in slice\n\n- **\u003cbig\u003e`SliceUnique[T comparable](slice []T) []T`\u003c/big\u003e** Devaluation of numeric and string slices (changes the order of elements)\n\n- **\u003cbig\u003e`SliceIndex[T comparable](slice []T, v T) int`\u003c/big\u003e** Find numeric and string slices according to the specified value\n\n- **\u003cbig\u003e`SliceLastIndex[T comparable](slice []T, v T) int`\u003c/big\u003e** The value and string slices are searched according to the specified value, and the last matching index is returned.\n\n- **\u003cbig\u003e`SliceRemove[T comparable](slice []T, v T) []T`\u003c/big\u003e** Removes the specified value from numeric and string slices\n\n- **\u003cbig\u003e`SliceRemoveBlank(slice []string) []string`\u003c/big\u003e** Remove null values from string slices\n\n- **\u003cbig\u003e`SliceTrim(slice []string) []string`\u003c/big\u003e** Trim string slices and automatically ignore null values\n\n- **\u003cbig\u003e`SliceConcat[T any](slice []T, values ...[]T) []T`\u003c/big\u003e** Merge multiple slices, non-degravimetric, non-original slices\n\n- **\u003cbig\u003e`SliceEqual[T comparable](slice1, slice2 []T) bool`\u003c/big\u003e** Are slices equal: the same length and the order and value of all elements are equal\n\n- **\u003cbig\u003e`SliceEvery[T any](slice []T, predicate func(index int, item T) bool) bool`\u003c/big\u003e** All elements in the slice satisfy the function, return true\n\n- **\u003cbig\u003e`SliceNone[T any](slice []T, predicate func(index int, item T) bool) bool`\u003c/big\u003e** Return true if all elements in the slice do not satisfy the function.\n\n- **\u003cbig\u003e`SliceSome[T any](slice []T, predicate func(index int, item T) bool) bool`\u003c/big\u003e** If one element in the slice satisfies the function, it Return true.\n\n- **\u003cbig\u003e`SliceFilter[T any](slice []T, predicate func(index int, item T) bool) []T`\u003c/big\u003e** Filter out all elements in the slice that satisfy the function\n\n- **\u003cbig\u003e`SliceForEach[T any](slice []T, iteratee func(index int, item T))`\u003c/big\u003e** All elements in the slice execute functions\n\n- **\u003cbig\u003e`SliceMap[T any, U any](slice []T, iteratee func(index int, item T) U) []U`\u003c/big\u003e** All elements in the slice execute functions and have return values.\n\n- **\u003cbig\u003e`SliceReduce[T any](slice []T, iteratee func(index int, result, item T) T, initial T) T`\u003c/big\u003e** Process all elements in slices to get results\n\n- **\u003cbig\u003e`SliceReplace[T comparable](slice []T, old T, new T, n int) []T`\u003c/big\u003e** Return a copy of the slice, with the first n elements replaced with the new\n\n- **\u003cbig\u003e`SliceReplaceAll[T comparable](slice []T, old T, new T) []T`\u003c/big\u003e** Return a copy of the slice, and all matching elements are replaced with new ones.\n\n- **\u003cbig\u003e`SliceUnionBy[T any, V comparable](predicate func(item T) V, slices ...[]T) []T`\u003c/big\u003e** Order merge and de-heavy, support custom functions\n\n- **\u003cbig\u003e`SliceIntersection[T comparable](slices ...[]T) []T`\u003c/big\u003e** Slices intersect and deweight (order cannot be guaranteed)\n\n- **\u003cbig\u003e`SliceSortBy(slice any, field string, sortType ...string) error`\u003c/big\u003e** Sort by field (field case should be consistent with field)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/x-funs/go-fun\"\n)\n\nfunc main() {\n\tfmt.Println(fun.SliceSplit([]string{\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\"}, 3))\n\t// [[a b c] [d e f] [g]]\n\n\tfmt.Println(fun.SliceUnion([]string{\"123\", \"124\"}, []string{\"124\", \"125\"}, []string{\"123\", \"125\"}))\n\t// [123 124 125]\n\n\tfmt.Println(\n\t\tfun.SliceColumn[map[string]string, string]([]map[string]string{\n\t\t\t{\"name\": \"admin\", \"code\": \"YF4133\"},\n\t\t\t{\"name\": \"user\", \"code\": \"MM8541\"},\n\t\t\t{\"name\": \"test\", \"code\": \"KH0002\"},\n\t\t\t{\"name\": \"demo\", \"code\": \"SJ9642\"},\n\t\t}, \"code\"),\n\t)\n\t// [YF4133 MM8541 KH0002 SJ9642]\n}\n```\n\n### String\n\n#### Function List\n\n- **\u003cbig\u003e`StrBefore(s, char string) string`\u003c/big\u003e** Intercept the substring before the position of the character when it first appears.\n\n- **\u003cbig\u003e`StrBeforeLast(s, char string) string`\u003c/big\u003e** Intercept the substring before the last appearance of the character\n\n- **\u003cbig\u003e`StrAfter(s, char string) string`\u003c/big\u003e** Interception of substrings after the position of the character when it first appears\n\n- **\u003cbig\u003e`StrAfterLast(s, char string) string`\u003c/big\u003e** Interception of substrings after the last appearance of the character\n\n- **\u003cbig\u003e`Blank(str string) bool`\u003c/big\u003e** Determine whether the string after Trim is blank.\n\n- **\u003cbig\u003e`BlankAll(strs ...string) bool`\u003c/big\u003e** Determine whether the string set after Trim is all blank.\n\n- **\u003cbig\u003e`BlankAny(strs ...string) bool`\u003c/big\u003e** Determine whether any string set after Trim contains a blank.\n\n- **\u003cbig\u003e`HasPrefixCase(str, prefix string) bool`\u003c/big\u003e** Determines whether the string starts with the specified prefix, ignoring case\n\n- **\u003cbig\u003e`HasSuffixCase(str, prefix string) bool`\u003c/big\u003e** Determine whether the string ends with the specified suffix, ignoring the case.\n\n- **\u003cbig\u003e`SplitTrim(str, sep string) []string`\u003c/big\u003e** The split string is a string slice, the split value is Trim, and the null value is automatically ignored.\n\n- **\u003cbig\u003e`SplitTrimToInts(str, sep string) []int`\u003c/big\u003e** The split string is an int slice, the split value is Trim, and the null value is automatically ignored.\n\n- **\u003cbig\u003e`Contains(str, substr string) bool`\u003c/big\u003e** Determines whether the string contains the specified substring\n\n- **\u003cbig\u003e`ContainsCase(str, substr string) bool`\u003c/big\u003e** Determine whether the string contains the specified substring, case-insensitive\n\n- **\u003cbig\u003e`ContainsAny(str string, substr ...string) bool`\u003c/big\u003e** Determine whether the string contains any of the specified substrings.\n\n- **\u003cbig\u003e`SnakeToCamel(str string, bigCamel bool) string`\u003c/big\u003e** Serpentine hump\n\n- **\u003cbig\u003e`CamelToSnake(str string) string`\u003c/big\u003e** Hump turns to snake\n\n- **\u003cbig\u003e`PadLeft(str string, padStr string, padLen int) string`\u003c/big\u003e** Fill the string on the left to the specified length\n\n- **\u003cbig\u003e`PadRight(str string, padStr string, padLen int) string`\u003c/big\u003e** The right side fills the string to the specified length.\n\n- **\u003cbig\u003e`PadBoth(str string, padStr string, padLen int) string`\u003c/big\u003e** Both sides fill the string to the specified length\n\n- **\u003cbig\u003e`Wrap(str string, wrapStr string) string`\u003c/big\u003e** Enclosed the original string with a string\n\n- **\u003cbig\u003e`Unwrap(str string, wrapStr string) string`\u003c/big\u003e** Remove string bounding, non-recursive\n\n- **\u003cbig\u003e`Reverse(str string) string`\u003c/big\u003e** Reverse string\n\n- **\u003cbig\u003e`Remove(str, remove string) string`\u003c/big\u003e** Removes the specified string in the string\n\n- **\u003cbig\u003e`RemovePrefix(str, prefix string) string`\u003c/big\u003e** Removes the string specified in the string on the left\n\n- **\u003cbig\u003e`RemoveSuffix(str string, suffix string) string`\u003c/big\u003e** The right side removes the specified string in the string.\n\n- **\u003cbig\u003e`RemoveAny(str string, removes ...string) string`\u003c/big\u003e** Removes the string set specified in the string\n\n- **\u003cbig\u003e`RemoveSign(str string) string`\u003c/big\u003e** Write all the data of the string into one line in turn, and remove meaningless strings (punctuation marks, symbols)\n\n- **\u003cbig\u003e`RemoveLines(str string) string`\u003c/big\u003e** Remove line breaks, which include \\n \\r\\n.\n\n- **\u003cbig\u003e`SubString(str string, pos, length int) string`\u003c/big\u003e** String interception\n\n- **\u003cbig\u003e`NormaliseSpace(str string) string`\u003c/big\u003e** Normalized the white space in this string, multiple spaces are merged into one space, and all white space characters such as line breaks and tabs are converted to a simple space.\n\n- **\u003cbig\u003e`NormaliseLine(str string) string`\u003c/big\u003e** Standardize line breaks in this string, and merge multiple line breaks into one line break.\n\n- **\u003cbig\u003e`Template(tpl string, data any) (string, error)`\u003c/big\u003e** Template rendering\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/x-funs/go-fun\"\n)\n\nfunc main() {\n\tfmt.Println(fun.StrBefore(\"http://admin:123123@127.0.0.1:27017\", \":\"))\n\t// http\n\n\tfmt.Println(fun.StrAfter(\"https://github.com\", \"://\"))\n\t// github.com\n\n\tfmt.Println(fun.StrBeforeLast(\"video.mp4.bak\", \".\"))\n\t// video.mp4\n\n\tfmt.Println(fun.StrAfterLast(\"video.mp4.bak\", \".\"))\n\t// bak\n}\n```\n\n### Struct\n\n#### Function List\n\n- **\u003cbig\u003e`StructCopy(src, dst any)`\u003c/big\u003e** Copy struct object\n\n### To\n\n#### Function List\n\n- **\u003cbig\u003e`Ip2Long(ipStr string) uint32`\u003c/big\u003e** String IP to integer\n\n- **\u003cbig\u003e`Long2Ip(long uint32) string`\u003c/big\u003e** Integer to string IP\n\n- **\u003cbig\u003e`ToString(value any) string`\u003c/big\u003e** Converts any type to a string\n\n- **\u003cbig\u003e`ToInt(value any) int`\u003c/big\u003e** Number or string to int type\n\n- **\u003cbig\u003e`ToLong(value any) int64`\u003c/big\u003e** ToInt64 alias, number or string to int64\n\n- **\u003cbig\u003e`ToBool(str string) bool`\u003c/big\u003e** string to bool type\n\n- **\u003cbig\u003e`ToUint(value any) uint`\u003c/big\u003e** Number or string to uint\n\n- **\u003cbig\u003e`ToUint8(value any) uint8`\u003c/big\u003e** Number or string to uint8\n\n- **\u003cbig\u003e`ToInt64(value any) int64`\u003c/big\u003e** Number or string to int64\n\n- **\u003cbig\u003e`ToFloat32(value any) float32`\u003c/big\u003e** Number or string to float32\n\n- **\u003cbig\u003e`ToFloat64(value any) float64`\u003c/big\u003e** Number or string to float64\n\n- **\u003cbig\u003e`ToUtf8(origin []byte, encode string) ([]byte, error)`\u003c/big\u003e** Specify character set conversion utf-8\n\n- **\u003cbig\u003e`Utf8To(utf8 []byte, encode string) ([]byte, error)`\u003c/big\u003e** utf-8 to specify character set\n\n- **\u003cbig\u003e`ToJson(object any) string`\u003c/big\u003e** Converts an object to a Json string\n\n- **\u003cbig\u003e`ToJsonIndent(object any) string`\u003c/big\u003e** Converts an object to a Indent Json string\n\n- **\u003cbig\u003e`ToDuration(value any) time.Duration`\u003c/big\u003e** Converts number or string to time.Duration, default is Nanosecond, string support \"ns,ms,us,s,m,h\"\n\n- **\u003cbig\u003e`ToDurationMs(value any) time.Duration`\u003c/big\u003e** Converts number or string to time.Duration, default is Millisecond, string support \"ns,ms,us,s,m,h\"\n\n\n### File\n\n#### Function List\n\n- **\u003cbig\u003e`Mkdir(dir string, perm os.FileMode) error`\u003c/big\u003e** Create a directory, ignoring if the directory already exists\n\n- **\u003cbig\u003e`FileExists(path string) bool`\u003c/big\u003e** Check whether the directory or file exists, return bool\n\n- **\u003cbig\u003e`WriteFile(name string, data []byte, flag int, perm os.FileMode, sync bool) error`\u003c/big\u003e** write file shortcut\n\n- **\u003cbig\u003e`WriteFileAppend(name string, data []byte, perm os.FileMode, sync bool) error`\u003c/big\u003e** write file shortcut with append mode\n\n### Http\n\n\u003e HttpXXResp the suffix, the return value is *Response\n\n\u003e HttpXXDo the suffix, Need to pass parameters *Request\n\n#### Function List\n\n- **\u003cbig\u003e`HttpGet(urlStr string, args ...any) ([]byte, error)`\u003c/big\u003e** The HttpGet parameter is the request address (HttpReq, timeout)\n\n- **\u003cbig\u003e`HttpPost(urlStr string, args ...any) ([]byte, error)`\u003c/big\u003e** The HttpPost parameter is the request address (body io.Reader, HttpReq, timeout)\n\n- **\u003cbig\u003e`HttpPostForm(urlStr string, args ...any) ([]byte, error)`\u003c/big\u003e** The HttpPostForm parameter is the request address (FormData map[string]string, HttpReq, timeout)\n\n- **\u003cbig\u003e`HttpPostJson(urlStr string, args ...any) ([]byte, error)`\u003c/big\u003e** The HttpPostJson parameter is the request address (JsonData string, HttpReq, timeout)\n\n- **\u003cbig\u003e`UrlParse(rawURL string) (*url.URL, error)`\u003c/big\u003e** Parses the string URL to the URL object. There will be no mistakes without scheme.\n\n- **\u003cbig\u003e`UserAgentRandom() string`\u003c/big\u003e** generates a random DESKTOP browser user-agent on every requests .\n\n- **\u003cbig\u003e`UserAgentRandomMobile() string`\u003c/big\u003e** generates a random MOBILE browser user-agent on every requests.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-funs%2Fgo-fun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fx-funs%2Fgo-fun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fx-funs%2Fgo-fun/lists"}