{"id":15034256,"url":"https://github.com/deeptiman/generic-programming","last_synced_at":"2026-03-17T21:03:34.427Z","repository":{"id":214803370,"uuid":"722789102","full_name":"Deeptiman/generic-programming","owner":"Deeptiman","description":"A Case Study on Golang Generic Code","archived":false,"fork":false,"pushed_at":"2023-12-30T21:52:15.000Z","size":1256,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-20T12:05:08.824Z","etag":null,"topics":["abstract-syntax-tree","compiler","compiler-principles","cpp","generic-programming","generic-types","go","golang","golang-application","golang-examples","golang-generics","golang-library","golang-package","google","java","software-architecture","software-development","software-engineering","software-testing","unit-test"],"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/Deeptiman.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}},"created_at":"2023-11-24T00:43:19.000Z","updated_at":"2024-10-09T05:55:32.000Z","dependencies_parsed_at":"2023-12-30T22:30:09.213Z","dependency_job_id":"2d5a2dbe-0251-4cd7-a297-f2c48cc5b0e0","html_url":"https://github.com/Deeptiman/generic-programming","commit_stats":null,"previous_names":["deeptiman/generic-programming"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deeptiman%2Fgeneric-programming","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deeptiman%2Fgeneric-programming/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deeptiman%2Fgeneric-programming/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deeptiman%2Fgeneric-programming/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Deeptiman","download_url":"https://codeload.github.com/Deeptiman/generic-programming/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234787012,"owners_count":18886444,"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":["abstract-syntax-tree","compiler","compiler-principles","cpp","generic-programming","generic-types","go","golang","golang-application","golang-examples","golang-generics","golang-library","golang-package","google","java","software-architecture","software-development","software-engineering","software-testing","unit-test"],"created_at":"2024-09-24T20:24:23.576Z","updated_at":"2025-12-28T22:05:43.775Z","avatar_url":"https://github.com/Deeptiman.png","language":"Go","readme":"# Generic Programming in Go\nGolang released generic programming with a specific goal for developers to write a standard set of types to utilize as type parameters for functions and type structs. The syntax to write a generic function is like `func F[T any] (p T){ … }` that can be used to perform a common use case. Also, types can have type parameters list `type O[T1, T2 any] struct`.\n\n## Publication\n**Deep Dive into Go Generic Type Structures and Syntax**\n\nhttps://codingpirate.com/deep-dive-into-go-generic-type-structures-and-syntax-6f1a68e2c9c5\n\n## Repository\nThis repository will provide an example module written with the Go generic type structure. The following code snippet shows a middleware module to showcase the **type parameter** and **function type arguments** features in the Go generic design.\n\n````````````````go\n\ntype LoginFn[P AuthParameter, R AuthClaimResponse] func(context.Context, P) (R, error)\n\ntype AuthParameter interface {\n\tEmployee | Admin | Customer\n}\n\ntype AuthClaimResponse interface {\n\t*GeneralClaimResponse | *AdminClaimResponse\n}\n\nfunc authMiddleware[P AuthParameter, R AuthClaimResponse](\n\tctx context.Context,\n\tloginFn LoginFn[P, R], authReq P) (R, error) {\n\tvar retry = 5\n\treturn loginWithRetry(ctx, retry, loginFn, authReq)\n}\n\nfunc loginWithRetry[P AuthParameter, R AuthClaimResponse](\n\tctx context.Context,\n\tretry int,\n\tloginFn LoginFn[P, R], authReq P) (R, error) {\n\tresp, err := loginFn(ctx, authReq)\n\tif err != nil {\n\t\tif retry--; retry \u003e= 0 {\n\t\t\treturn loginWithRetry(ctx, retry, loginFn, authReq)\n\t\t}\n\n\t\treturn nil, err\n\t}\n\n\tfmt.Println(\"login successful \")\n\n\treturn resp, nil\n}\n````````````````\n\n### How to run the test?\n\n``````sh\ngo test -v -count=1 -race -cover --coverprofile=unit.out ./... \u0026\u0026 go tool cover -html=unit.out\n``````\n\n## References\n- https://go.googlesource.com/proposal/+/HEAD/design/43651-type-parameters.md\n- https://go.dev/blog/type-inference\n\n## License\nThis project is licensed under the \u003ca href=\"https://github.com/Deeptiman/generic-programming/blob/main/LICENSE\"\u003eMIT License\u003c/a\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeptiman%2Fgeneric-programming","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeeptiman%2Fgeneric-programming","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeeptiman%2Fgeneric-programming/lists"}