{"id":15775874,"url":"https://github.com/felipelaptrin/go-api","last_synced_at":"2025-03-31T14:43:45.743Z","repository":{"id":128987339,"uuid":"525371199","full_name":"felipelaptrin/go-api","owner":"felipelaptrin","description":"Simple API using Golang","archived":false,"fork":false,"pushed_at":"2022-08-16T13:23:08.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-11T17:08:50.692Z","etag":null,"topics":["api","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/felipelaptrin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-08-16T12:32:10.000Z","updated_at":"2024-02-27T14:00:29.000Z","dependencies_parsed_at":"2023-05-09T20:00:50.808Z","dependency_job_id":null,"html_url":"https://github.com/felipelaptrin/go-api","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"466c96c37699e9cdbf891162d1512198b44899ab"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipelaptrin%2Fgo-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipelaptrin%2Fgo-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipelaptrin%2Fgo-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/felipelaptrin%2Fgo-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/felipelaptrin","download_url":"https://codeload.github.com/felipelaptrin/go-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246484474,"owners_count":20785095,"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":["api","go"],"created_at":"2024-10-04T17:03:20.776Z","updated_at":"2025-03-31T14:43:45.717Z","avatar_url":"https://github.com/felipelaptrin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-api\n\n## Description\nThis is a simple API built using Go and MySQL.\n\n## Tools\nThe following tools/packages/modules were used:\n\n- Database: `MySQL`\n- Web server: `Mux`\n- ORM: `Gorm`\n\n## API Design\nThe API was build using the following folder structure:\n\n```\n├── config          // Database settings\n├── controllers     // Business logic\n├── models          // Database tables\n├── repository      // Functions used to query data from the database\n├── routes          // Routes of the API\n├── schemas         // Responses\n└── utils           // Common functions to be used\n```\n\nWe can make it easier to understand with the picture below.\n![API Flow](/docs/flow.png)\n\n1- User makes a HTTP request to the API.\n2- The specified route will execute a specific controller function.\n3- The function needs to interact with the database to gather information. To better isolation of each layer, the controller function will call the repository function to interact with the database and gather the data.\n4- The repository is responsible for direct communication with the database.\n5- Repository will return the gathered information to the controller.\n6- Controller will execute the business logic and use the schema layer to create the response.\n7- HTTP response is returned to the user.\n\n\n## Running the API\nA docker-compose was created to setup, using Docker, the API and MySQL dabase. \n\nSo simply running `docker-compose up` will spin up all the infrastructure.\n\n## Routes\n\nThe following routes were created.\n\n- GET `/user`\n\nGet all users.\n\n- GET `/user/{id}`\n\nReturn information about a specific user given its ID.\n\n- POST `/user`\n\nAdds a new user to the database. Accepts the following body:\n```json\n{\n    \"name\": \u003c\u003c name of the user \u003e\u003e,\n    \"email\": \u003c\u003c email of the user\u003e\u003e,\n    \"status\": \u003c\u003c bool indicating if user is active or not\u003e\u003e\n}\n```\n\n- PUT `/user/{id}`\n\nEdit information about a user given its ID. Accepts same body as the POST `/user` route.\n\n- DELETE `/user/{id}`\n\nDelete a user given its ID.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipelaptrin%2Fgo-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelipelaptrin%2Fgo-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelipelaptrin%2Fgo-api/lists"}