{"id":19213759,"url":"https://github.com/loveinsky100/common4go","last_synced_at":"2025-02-23T08:17:29.622Z","repository":{"id":144267621,"uuid":"291731304","full_name":"loveinsky100/common4go","owner":"loveinsky100","description":"common method for golang, such like number format, future task, basic collections","archived":false,"fork":false,"pushed_at":"2020-09-01T08:13:23.000Z","size":15,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-04T17:47:35.272Z","etag":null,"topics":["common","common4go","future","gocommon","golang","hashmap","list","set","threadpool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loveinsky100.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":"2020-08-31T14:03:36.000Z","updated_at":"2021-12-09T06:05:02.000Z","dependencies_parsed_at":"2023-07-05T00:01:27.183Z","dependency_job_id":null,"html_url":"https://github.com/loveinsky100/common4go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveinsky100%2Fcommon4go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveinsky100%2Fcommon4go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveinsky100%2Fcommon4go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loveinsky100%2Fcommon4go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loveinsky100","download_url":"https://codeload.github.com/loveinsky100/common4go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240286516,"owners_count":19777353,"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":["common","common4go","future","gocommon","golang","hashmap","list","set","threadpool"],"created_at":"2024-11-09T14:07:32.491Z","updated_at":"2025-02-23T08:17:29.420Z","avatar_url":"https://github.com/loveinsky100.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# common4go\nCommon Go lang data structures, utilities, Future Task etc  \nIf you are java programmer, It will help you.   \n\nList, HashMap, HashSet  \ngorouter pool(thread pool), Future Task  \nbasic number conversion  \ncommon logs(in dev)\n\n# Installation\nWith Go and git installed:\n\n```\ngo get github.com/loveinsky100/common4go\n````\n\n# Data Structures\n## List\n\n1.ArrayList  \n2.SyncArrayList  \n\n```golang\n\ttype List interface {\n\t\t// add item to list\n\t\tAdd(value interface{})\n\t\n\t\t// get index item\n\t\tGet(index int) (interface{}, bool)\n\t\n\t\t// remove item\n\t\tRemove(index int) bool\n\t\n\t\t// loop item\n\t\tForeach(consumer func(value interface{}, index int) bool)\n\t\n\t\t// get item len\n\t\tSize() int\n\t}\n``` \n\n```golang\n\t// create array list\n\tlist := collections.NewArrayList()\n\n\t// create sync array list\n\tlist := collections.NewSyncArrayList()\n\n\t// create sync list base on array list\n\tlist := collections.NewSyncList(collections.NewArrayList())\n```\n\n## Map\n1.HashMap  \n2.SyncHashMap\n\n```golang\ntype Map interface {\n\tPut(key interface{}, value interface{})\n\n\tRemove(key interface{})\n\n\tGet(key interface{}) (interface{}, bool)\n\n\tForeach(consumer func(key interface{}, value interface{}) bool)\n}\n```\n\n```golang\n\t// create hash map\n\thashMap := collections.NewHashMap()\n\n\t// create sync hash map\n\thashMap := collections.NewSyncHashMap()\n```\n\n## Set\n1.HashSet\n\n```golang\ntype Set interface {\n\t\n\tAdd(key interface{})\n\n\tRemove(key interface{})\n\n\tContains(key interface{}) bool\n\n\tForeach(consumer func(key interface{}) bool)\n}\n```\n\n```golang\n\t// create hash set\n\thashSet := collections.NewHashSet()\n\n\t// create sync hash set\n\thashSet := collections.NewSyncHashSet()\n```\n# Future Task\n## Future\nyou can you use future task like java, and also you need use future task in a go router pool, such like thread pool in java, but go router pool is diffrent between thread pool, it only provide max pool size and reject handler, there are no min pool size or wait queue.\n\n```golang\ntype GoRouterPool interface {\n\tAdd(callable Callable) (Future, error)\n\tAddHandler(handler func() (interface{}, error)) (Future, error)\n}\n\ntype Future interface {\n\t// wait until task done or panic\n\tGet() (interface{}, error)\n\n\t// wait until task done or timeout, notice: when task timeout it will still running in background until return method\n\tGetWithTimeout(timeout time.Duration) (interface{}, error)\n\n\t// cancel task, when task not enter, you can cancel it, true: cancel success false:\n\tCancel() bool\n\n\t// check is done or in other status\n\tStatus() FutureStatus\n\n\t// execute task, you need not call is when you put it in routers pool\n\tExecute()\n}\n```\n\nhow to use \n```golang\n\tpool := routers.NewGoRouterPool(10, \u0026routers.CallableRejectedHandler {\n\t\tHandler: func(callable routers.Callable) {\n\t\t\t// do some thing\n\t\t},\n\t})\n\n\tfuture, err := pool.AddHandler(func() (interface{}, error) {\n\t\ttime.Sleep(time.Millisecond * 100)\n\t\treturn 1, nil\n\t})\n\n\tif err != nil {\n\t\t// reject\n\t\tt.Errorf(\"an error occured: reject\", err)\n\t}\n\n\tv, err := future.GetWithTimeout(time.Millisecond * 200)\n\tif err != nil {\n\t\tt.Errorf(\"an error occured: %+v\", err)\n\t}\n```\n\n# number conversion\n```golang\nnumbers.ToInt64(int8(120))\nnumbers.ToFloat64(\"2.198900\")\nnumbers.ToString(2.198900)\nnumbers.ToBool(1)\nnumbers.ToBool(\"FALSE\")\n```\n\n# dev\n### schedule task like EventLoop \u0026 EventLoopGroup\n### linked list\n### queue \u0026 stack \u0026 cache\n### logs","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floveinsky100%2Fcommon4go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floveinsky100%2Fcommon4go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floveinsky100%2Fcommon4go/lists"}