{"id":21366402,"url":"https://github.com/letscool/lc-go","last_synced_at":"2025-06-30T10:32:15.784Z","repository":{"id":59045035,"uuid":"529781589","full_name":"LETSCOOL/lc-go","owner":"LETSCOOL","description":"go lib","archived":false,"fork":false,"pushed_at":"2022-12-08T04:16:13.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-16T07:42:56.968Z","etag":null,"topics":["dependency","dependency-injection","dij","go","golang","injection","library"],"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/LETSCOOL.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}},"created_at":"2022-08-28T06:27:45.000Z","updated_at":"2022-12-15T08:01:01.000Z","dependencies_parsed_at":"2023-01-25T08:16:42.885Z","dependency_job_id":null,"html_url":"https://github.com/LETSCOOL/lc-go","commit_stats":null,"previous_names":["yuchi518/lc-go"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/LETSCOOL/lc-go","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LETSCOOL%2Flc-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LETSCOOL%2Flc-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LETSCOOL%2Flc-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LETSCOOL%2Flc-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LETSCOOL","download_url":"https://codeload.github.com/LETSCOOL/lc-go/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LETSCOOL%2Flc-go/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262755996,"owners_count":23359450,"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":["dependency","dependency-injection","dij","go","golang","injection","library"],"created_at":"2024-11-22T07:14:54.990Z","updated_at":"2025-06-30T10:32:15.740Z","avatar_url":"https://github.com/LETSCOOL.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## lc-go\nA golang library, include following packages:\n1. lg\n2. mongobj\n3. dij\n\n### lg (Language)\n\n- Ife\n    ```go\n    // aka. text = (len(text) != 0) ? text : \"some text\"\n    text = Ife(len(text) != 0, text, \"some text\")\n    ```\n    ```go\n    // aka i = (i != 0) ? i : 123\n    i = Ife(i != 0, i, 123)\n    ```\n- MakeIterator, MakeInverseIterator\n    ```go \n    ints := []int{0, 10, 20, 30, 40, 50, 60, 70, 80, 90}\n    iter := MakeIterator(ints)\n    totalValues := 0\n    for v, b, i := iter(); b; v, b, i = iter() {\n        totalValues += v\n    }\n    ```\n- IterateFunc, IterateFuncInversely\n    ```go\n    totalValues := 0\n    IterateFuncInversely(ints, func(v int, i int) (stop bool) {\n        totalValues += v\n        return\n    })\n    ```\n- map-reduce\n    ```go\n    array := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}\n    floatArray := Map(array, func(in int) float64 {\n        return float64(in) * 0.3\n    })\n    result := Reduce(floatArray, \"\", func(v float64, lastResult string) string {\n        return fmt.Sprintf(\"%s-%1.2f\", lastResult, v)\n    })\n    ```\n\n### mongobj (MongoDb Object)\n(omit)\n\n### dij (Dependency Injection) - **draft**\n- Sample code\n```go\npackage main\n\nimport (\n  . \"github.com/letscool/lc-go/dij\"\n  \"log\"\n  \"reflect\"\n)\n\ntype SampleApp struct {\n  lib1 *SampleLib1 `di:\"lib1\"`\n  lib2 *SampleLib2 `di:\"lib2\"`\n}\n\ntype SampleLib1 struct {\n  lib2 *SampleLib2 `di:\"lib2\"`\n}\n\ntype SampleLib2 struct {\n  val int `di:\"val\"`\n}\n\nfunc main() {\n  appTyp := reflect.TypeOf(SampleApp{})\n  ref := DependencyReference{\"val\": 123}\n  inst, err := CreateInstance(appTyp, \u0026ref, \"^\")\n  if err != nil {\n    log.Fatal(err)\n  }\n  if app, ok := inst.(*SampleApp); ok {\n    if app.lib2 != app.lib1.lib2 {\n      log.Fatalf(\"incorrect injection, app.lib2(%v) != app.lib1.lib2(%v)\\n\", app.lib2, app.lib1.lib2)\n    }\n    if app.lib2.val != 123 {\n      log.Fatalf(\"incorrect injection, app.lib2.val(%d) != 123\\n\", app.lib2.val)\n    }\n  } else {\n    log.Fatalf(\"didn't create a correct instance, %v\", reflect.TypeOf(inst))\n  }\n}\n```\nFollowing code uses *BuildInstance* instance of *CreateInstance*, it should be an easier way.\n```go\nfunc main() {\n  ref := DependencyReference{\"val\": 123}\n  app, err := BuildInstance(\u0026SampleApp{}, \u0026ref, \"^\")\n  if err != nil {\n    log.Fatal(err)\n  }\n  if app.lib2 != app.lib1.lib2 {\n    log.Fatalf(\"incorrect injection, app.lib2(%v) != app.lib1.lib2(%v)\\n\", app.lib2, app.lib1.lib2)\n  }\n  if app.lib2.val != 123 {\n    log.Fatalf(\"incorrect injection, app.lib2.val(%d) != 123\\n\", app.lib2.val)\n  }\n}\n```\n\nSee more [examples](https://github.com/LETSCOOL/go-examples).\n\n- Libraries/Services refer dij\n  - [dij-gin](https://github.com/LETSCOOL/dij-gin): dij-style gin library, gin library but wrap it by dij. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletscool%2Flc-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletscool%2Flc-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletscool%2Flc-go/lists"}