{"id":16675784,"url":"https://github.com/imajinyun/gohelper","last_synced_at":"2025-03-13T04:27:33.476Z","repository":{"id":227446347,"uuid":"771401859","full_name":"imajinyun/gohelper","owner":"imajinyun","description":"[Go] A package of Go helper functions for business development, just like Java hutool.","archived":false,"fork":false,"pushed_at":"2024-09-12T07:21:54.000Z","size":46,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T21:49:34.774Z","etag":null,"topics":["function","functions","go","go-functions","go-helpers","helper","helpers"],"latest_commit_sha":null,"homepage":"","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/imajinyun.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}},"created_at":"2024-03-13T08:32:14.000Z","updated_at":"2024-09-12T07:21:57.000Z","dependencies_parsed_at":"2024-06-20T20:30:38.514Z","dependency_job_id":"5f64b27a-bceb-42cb-81d8-ebb72150633c","html_url":"https://github.com/imajinyun/gohelper","commit_stats":null,"previous_names":["imajinyun/gohelper"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajinyun%2Fgohelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajinyun%2Fgohelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajinyun%2Fgohelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imajinyun%2Fgohelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imajinyun","download_url":"https://codeload.github.com/imajinyun/gohelper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243339265,"owners_count":20275658,"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":["function","functions","go","go-functions","go-helpers","helper","helpers"],"created_at":"2024-10-12T13:07:37.672Z","updated_at":"2025-03-13T04:27:33.450Z","avatar_url":"https://github.com/imajinyun.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gohelper\n\n[![Go](https://github.com/imajinyun/gohelper/actions/workflows/go.yml/badge.svg)](https://github.com/imajinyun/gohelper/actions/workflows/go.yml)\n\nA package of Go helper functions for business development.\n\n## Installation\n\nMake sure that Go is installed on your computer. Type the following command in your terminal:\n\n```bash\ngo get github.com/imajinyun/gohelper\n```\n\nAdd following line in your `*.go` file:\n\n```go\nimport \"github.com/imajinyun/gohelper\"\n```\n\n## Examples\n\n### Cond\n\n1. Simplify the judgment of if else to a single line of code:\n\n```go\nflag, expr := 0, \"some version\"\nif expr == \"v1\" {\n  flag = 1\n} else if expr == \"v2\" {\n  flag = 2\n}\n\nflag = gohelper.If(expr == \"v1\", 1, gohelper.If(expr == \"v2\", 2, 0))\n```\n\n### Conv\n\n1. Convert data to string:\n\n```go\n// Output: [hello world]\ngohelper.ToString([]string{\"hello\", \"world\"})\n```\n\n2. Convert data to JSON string:\n\n```go\n// Output: {\"id\":1,\"name\":\"jack\"}\ngohelper.ToJson(map[string]any{\"id\": 1, \"name\": \"jack\"})\n```\n\n### Date\n\n1. Get the current date and time object:\n\n```go\n// Output: 2024-09-12 12:02:15\ntim, err := gohelper.NowDateTime(\"Asia/Shanghai\", \"2006-01-02 15:04:05\")\nif err != nil {\n  panic(err)\n}\ntim.ToString()\n```\n\n2. Get the year, month, day, hour, minute, and second of the date and time object:\n\n```go\n// Output: 2024\ntim.Year()\n\n// Output: 256\ntim.YearDay()\n\n// Output: September\ntim.Month()\n\n// Output: 12\ntim.Day()\n\n// Output: 12\ntim.Hour()\n\n// Output: 2\ntim.Minute()\n\n// Output: 15\ntim.Second()\n```\n\n3. Get the begin and end of the day of the date and time object:\n\n```go\n// Output: 2024-09-12 00:00:00\ntim.BeginOfDay().Format(time.DateTime)\n\n// Output: 2024-09-12 23:59:59\ntim.BeginOfDay().Format(time.DateTime)\n\n// Output: 2024-09-01 00:00:00\ntim.BeginOfMonth().Format(time.DateTime)\n\n// Output: 2024-09-01 23:59:59\ntim.EndOfMonth().Format(time.DateTime)\n\n// Output: 2024-01-01 00:00:00\ntim.BeginOfYear().Format(time.DateTime)\n\n// Output: 2024-12-31 23:59:59\ntim.EndOfYear().Format(time.DateTime)\n```\n\n### Map\n\n1. If the specified key cannot obtain a value, return the given default value:\n\n```go\n// Output: default value\nmps := make(map[string]any)\nmps.GetOrDefault(\"mykey\", \"default value\")\n```\n\n### Str\n\n####\n\n1. Generate string with options (include uppercase, numbers, and symbols):\n\n```go\n// Output: knvmfcmpfqiqcbrh\ngohelper.RandStr(16)\n\n// Output: nD\u003efKDvaF\\R+1h.G\ngohelper.RandStrWithOption(16, Option{\n  IncludeNumber:    true,\n  IncludeUppercase: true,\n  IncludeSymbol:    true,\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimajinyun%2Fgohelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimajinyun%2Fgohelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimajinyun%2Fgohelper/lists"}