{"id":21192228,"url":"https://github.com/bujosa/facade-design-pattern","last_synced_at":"2025-03-14T21:13:20.033Z","repository":{"id":220890065,"uuid":"750600237","full_name":"bujosa/facade-design-pattern","owner":"bujosa","description":"See example of facade design pattern in go","archived":false,"fork":false,"pushed_at":"2024-02-04T23:28:31.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-11T10:53:20.343Z","etag":null,"topics":["design-patterns","facade-pattern","golang","structural-patterns"],"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/bujosa.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}},"created_at":"2024-01-31T00:10:36.000Z","updated_at":"2024-02-04T23:56:31.000Z","dependencies_parsed_at":"2024-02-05T01:37:54.688Z","dependency_job_id":"f55e51b1-0f7e-4c52-92bc-1c3d2c8f3d35","html_url":"https://github.com/bujosa/facade-design-pattern","commit_stats":null,"previous_names":["bujosa/facade-design-pattern"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bujosa%2Ffacade-design-pattern","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bujosa%2Ffacade-design-pattern/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bujosa%2Ffacade-design-pattern/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bujosa%2Ffacade-design-pattern/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bujosa","download_url":"https://codeload.github.com/bujosa/facade-design-pattern/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243646667,"owners_count":20324586,"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":["design-patterns","facade-pattern","golang","structural-patterns"],"created_at":"2024-11-20T19:08:02.197Z","updated_at":"2025-03-14T21:13:20.014Z","avatar_url":"https://github.com/bujosa.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Facade Design Pattern\n\nThe Facade design pattern provides a simplified interface to a complex subsystem. It involves a single wrapper class which contains a set of members required by the client. These members access the system on behalf of the facade client and hide the implementation details.\n\nIn the provided Go code, the facade pattern is used to simplify the process of retrieving weather data from the OpenWeatherMap API.\n\n## Code Explanation\n\nThe code defines a `CurrentWeatherDataRetriever` interface with two methods: `GetByGeoCoordinates` and `GetByCityAndCountryCode`. These methods are used to retrieve weather data either by geographical coordinates or by city and country code.\n\nThe `CurrentWeatherData` struct implements this interface. It contains an `APIkey` field and uses it to make HTTP requests to the OpenWeatherMap API.\n\nThe `Weather` struct is a data structure that maps to the JSON response from the OpenWeatherMap API. It contains fields for various weather parameters like temperature, pressure, humidity, etc.\n\nThe `doRequest` method is a helper method that performs the actual HTTP request to the OpenWeatherMap API, checks the response status code, and parses the response body into a `Weather` struct.\n\nThe `responseParser` method is used to parse the HTTP response body into a `Weather` struct.\n\nThe `GetByGeoCoordinates` and `GetByCityAndCountryCode` methods use the `doRequest` method to retrieve weather data from the OpenWeatherMap API. They format the API URL with the appropriate parameters and pass it to the `doRequest` method.\n\nIn this way, the `CurrentWeatherData` struct acts as a facade, providing a simple interface for retrieving weather data and hiding the complexities of making HTTP requests and parsing JSON responses.\n\n## Running the Tests\n\nTo run the tests, you will need to set your OpenWeatherMap API key and a flag to indicate whether to run integration tests as environment variables. You can do this by creating a `.env` file in your project root and adding your variables there. See the `.env.example` file for an example of how to set up your `.env` file.\n\nOnce you've set up your `.env` file, you can run your tests with the `go test` command. The tests will automatically use the variables from your `.env` file.\n\nHere is an example of how to set up your `.env` file:\n\n```bash\nAPIKEY=your_api_key\nINTEGRATION=true\n\ngo test\n```\n\n## Documentation\n\nYou can find the official documentation for the OpenWeatherMap API [here](https://openweathermap.org/api).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbujosa%2Ffacade-design-pattern","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbujosa%2Ffacade-design-pattern","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbujosa%2Ffacade-design-pattern/lists"}