{"id":15013609,"url":"https://github.com/surfiniaburger/api-go","last_synced_at":"2026-03-14T08:35:27.765Z","repository":{"id":255080862,"uuid":"847955715","full_name":"surfiniaburger/api-go","owner":"surfiniaburger","description":"Book library API ","archived":false,"fork":false,"pushed_at":"2024-09-08T17:04:39.000Z","size":96,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T16:10:42.567Z","etag":null,"topics":["docker","gcloud","golang","huggingface","jwt","mysql","pinecone","postman"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/surfiniaburger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2024-08-26T21:38:05.000Z","updated_at":"2024-09-08T17:04:43.000Z","dependencies_parsed_at":"2024-08-27T22:47:37.740Z","dependency_job_id":"61f523ce-64e4-4bfa-b3cd-5d519631054b","html_url":"https://github.com/surfiniaburger/api-go","commit_stats":null,"previous_names":["surfiniaburger/api-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfiniaburger%2Fapi-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfiniaburger%2Fapi-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfiniaburger%2Fapi-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/surfiniaburger%2Fapi-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/surfiniaburger","download_url":"https://codeload.github.com/surfiniaburger/api-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243307334,"owners_count":20270256,"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":["docker","gcloud","golang","huggingface","jwt","mysql","pinecone","postman"],"created_at":"2024-09-24T19:44:33.912Z","updated_at":"2025-12-25T08:51:30.781Z","avatar_url":"https://github.com/surfiniaburger.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Book keeping REST API in Go \n\n### Description\n library API project is a Go-based application designed to manage a digital library. It supports book creation, updates, deletion, and retrieval with JWT authentication for both users and admins. The API allows users to search books, post reviews, view reviews, and add books to their favorites list. Admins can manage the library by adding or removing books and reviews. The project also integrates Elasticsearch for enhanced book search functionality and uses MySQL as the primary database, with routes built using the Gorilla Mux router.\n\n### Installation\n\nOpen a PowerShell terminal (version 5.1 or later) and from the PS C:\\\u003e prompt, run: \n\n```bash \nSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser\nInvoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression\n\n```\nOnce installation is done install \n\n```bash\nscoop install main/make\n```\n\nand \n\n```bash\nscoop install main/gcc\n```\n\nRelaunch all terminals \n\nAlso make sure you have the following tools installed on your machine.\n\n- [Migrate (for DB migrations)](https://github.com/golang-migrate/migrate/tree/v4.17.0/cmd/migrate)\n\n## Running the project\n\nFirstly make sure you have a MySQL database running on your machine or just swap for any storage you like under `/db`.\n\nThen create a database with the name you want *(`ecom` is the default)* and run the migrations. Before you do so,\n\nLocate the `.env.example` file and copy it content inside a new file `.env`\n\n```env\n# Server\nPUBLIC_HOST=http://localhost\nPORT=8080\n\n# Database\nDB_USER=root\nDB_PASSWORD=mypassword\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_NAME=ecom\n```\n\nChange the password `mypassword` to your MYSQL localhost password.\n\n\nCreate the Database Manually:\n\n    Open the MySQL command line:\n\n```bash\nmysql -u root -p\n```\n\nAfter logging in, create the ecom database:\n\n```sql\n\nCREATE DATABASE ecom;\n```\nVerify that the database was created:\n\n\n```sql\nSHOW DATABASES;\n```\n\nYou should see ecom listed in the output.\n\n2. Run the Migration:\n\n    Now that the ecom database exists, try running the make migrate-up command:\n\n```bash\nmake migrate-up\n```\n\nAfter that, you can run the project with the following command:\n\n```bash\nmake run\n```\n\n## Running the tests\n\nTo run the tests, you can use the following command:\n\n```bash\nmake test\n```\n\n\n### Running the Project with Docker\n#### Step 1: Docker Setup\n\nTo use Docker for containerizing the application and the database, follow these steps:\n\n- Ensure you have Docker installed on your machine.\n\n- Create a docker-compose.yml file with the following content:\n\n```bash\n\nversion: '3'\nservices:\n\n  db:\n    image: mysql:8.0\n    healthcheck:\n      test: \"exit 0\"\n    volumes:\n      - db_data:/var/lib/mysql\n    ports:\n      - \"3306:3306\"\n    environment:\n      MYSQL_ROOT_PASSWORD: mypassword\n      MYSQL_DATABASE: ecom\n\n  api:\n    build: \n      context: .\n      dockerfile: Dockerfile\n    restart: on-failure\n    volumes:\n      - .:/go/src/api\n    ports:\n      - \"8080:8080\"\n    environment:\n      DB_HOST: db\n      DB_USER: root\n      DB_PASSWORD: mypassword\n      DB_NAME: ecom\n    links:\n      - db\n    depends_on:\n      - db\n\nvolumes:\n  db_data:\n```\nDon't forget to change `mypassword` to your database password\n\nCreate a Dockerfile in your project root:\n\n\n```bash\n\n    # syntax=docker/dockerfile:1\n\n    # Build the application from source\n    FROM golang:1.22.0 AS build-stage\n      WORKDIR /app\n\n      COPY go.mod go.sum ./\n      RUN go mod download\n\n      COPY . .\n\n      RUN CGO_ENABLED=0 GOOS=linux go build -o /api ./cmd/main.go\n\n      # Run the tests in the container\n    FROM build-stage AS run-test-stage\n      RUN go test -v ./...\n\n    # Deploy the application binary into a lean image\n    FROM scratch AS build-release-stage\n      WORKDIR /\n\n      COPY --from=build-stage /api /api\n\n      EXPOSE 8080\n\n      ENTRYPOINT [\"/api\"]\n``` \n\n#### Step 2: Running the Docker Containers\n\nTo start the application and database containers, use:\n\n```bash\ndocker-compose up --build\n```\n\nThis command will build and start both the MySQL database and the API service. The application will be accessible at http://localhost:8080.\n\n\n\n## API Endpoints\nUser Registration\n- Endpoint: POST /api/v1/register\n- Description: Registers a new user.\n- Payload Example:\n\n```bash\n{\n  \"email\": \"jdmasciano2@gmail.com\",\n  \"password\": \"ogbono\",\n  \"firstName\": \"ade\",\n  \"lastName\": \"burger\"\n}\n```\n\nAdmin Registration: Include \"role\": \"admin\" in the payload.\n\n```bash\n\n    {\n      \"email\": \"jd@gmail.com\",\n      \"password\": \"ogbono\",\n      \"firstName\": \"surfinia\",\n      \"lastName\": \"burg\",\n      \"role\": \"admin\"\n    }\n```\n\n\nUser Login\n\n- Endpoint: POST /api/v1/login\n\n- Description: Logs in a user and returns a JWT token.\n\n- Payload Example:\n\n\n```bash\n{\n  \"email\": \"me@me.com\",\n  \"password\": \"asd\"\n}\n```\n\nResponse Example:\n\n```bash\njson\n\n    {\n      \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmVzQXQiOjE3MjU5MTk0NTYsInVzZXJJRCI6IjEifQ.Ww85HQzCdhzp_LzJTg8UvxcrXj5eanLyLJDyDNQIG6E\"\n    }\n```\n\n\nGet User by ID\n\n- Endpoint: GET /api/v1/users/{id}\n\n- Description: Retrieves a user's information by their ID.\n\n- Response Example:\n\n```bash\n\n    {\n      \"id\": 4,\n      \"firstName\": \"ade\",\n      \"lastName\": \"surfinia\",\n      \"email\": \"me@ade.com\",\n      \"role\": \"user\",\n      \"createdAt\": \"2024-09-01T20:12:23Z\"\n    }\n``` \n\nYou can find more details on the Library API endpoints here (`https://docs.google.com/document/d/1vZ_6MTWN3PK9Ol02pT37M_--D5dRimy-XgiPwgoDlkM/edit?usp=sharing`)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurfiniaburger%2Fapi-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsurfiniaburger%2Fapi-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsurfiniaburger%2Fapi-go/lists"}