{"id":13600765,"url":"https://github.com/Evertras/go-interface-examples","last_synced_at":"2025-04-11T01:30:23.380Z","repository":{"id":37530822,"uuid":"275278249","full_name":"Evertras/go-interface-examples","owner":"Evertras","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-08T04:10:18.000Z","size":146,"stargazers_count":348,"open_issues_count":2,"forks_count":32,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-06T11:08:26.749Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Evertras.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}},"created_at":"2020-06-27T01:26:03.000Z","updated_at":"2025-03-05T23:58:35.000Z","dependencies_parsed_at":"2023-12-08T05:23:51.779Z","dependency_job_id":"61be1bfc-d10c-4da7-b4d1-e69d2a61588d","html_url":"https://github.com/Evertras/go-interface-examples","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/Evertras%2Fgo-interface-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evertras%2Fgo-interface-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evertras%2Fgo-interface-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Evertras%2Fgo-interface-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Evertras","download_url":"https://codeload.github.com/Evertras/go-interface-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248324943,"owners_count":21084837,"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":[],"created_at":"2024-08-01T18:00:48.124Z","updated_at":"2025-04-11T01:30:22.980Z","avatar_url":"https://github.com/Evertras.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# go-interface-examples\n\nSome examples of using Go interfaces to make cleaner, more testable code.\n\nThese assume general familiarity with Go syntax and the ability to write\nsimple programs.  If you haven't already, take [a tour of Go](https://tour.golang.org/welcome/1)!\nYou'll be introduced to interfaces there.  You should also read\n[Effective Go](https://golang.org/doc/effective_go.html#interfaces).\n\nThe point of this repository is to expand on those ideas and explore them\nwith simple but relatable examples to explain *why* Go tells you to use\ninterfaces the way it does.\n\n## The Outside World\n\n*What are interfaces? What problems do interfaces solve? Why do I care?*\n\n*My code is hard to test because it has to talk to a database!  What do?  What's this 'mock' thing I hear about?*\n\n*Why should I pass in dependencies instead of just creating them or using globals?*\n\n[Let's find out!](./outside-world)\n\nThis is pretty entry level.  We'll explore creating a simple service that\nends up being easy to reason about and easy to test thanks to Go interfaces.\nWe'll start as simple as possible and explore why we make each iteration of\nchanges towards a more robust solution.  This will be \"interfaces the long way\".\n\nI think this is a good read if you're new to Go and/or relatively new to coding\nin general.  You may find it useful even if you're intermediate, however, as\nI hope it articulates a lot of the underlying reasons behind doing the things\nyou may already be doing with interfaces/IoC/DI.\n\n## Declare interfaces locally\n\n*Why does Go tell me to declare interfaces at the consumer level?*\n\n*What's up with [this tweet](https://web.archive.org/web/20190508021859/https://twitter.com/davecheney/status/942593128355192832)?*\n\n[See the article here.](./local-interfaces)\n\nThere's a reason libraries don't usually give you an interface to work with,\nand why you shouldn't provide one either.  Let's explore why.\n\nThis is an example of defining your interfaces locally in each package rather\nthan trying to do an \"interface package\" or providing giant interfaces from\na single package that also contains the implementation.\n\nI think this is a good read if you're coming to Go from another language\nand may have preconceived ideas of what interfaces should be because of that.\nYou'll need to be at least a little familiar with Go at this point and\nmay have written a service or two.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvertras%2Fgo-interface-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEvertras%2Fgo-interface-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEvertras%2Fgo-interface-examples/lists"}