meetup-clone

module
v0.0.0-...-d8b85fd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2025 License: MIT

README

MeetUp Clone

A backend API for a meetup-clone

Getting Started

  • Install dependencies
go mod tidy
  • Create a .env directory and add api.env and postgres.env files
mkdir .env
touch .env/api.env
touch .env/postgres.env # Only needed if you are using `docker-compose.dev.yml`
  • Add environment variables to the .env/*.env files

    • .env/api.env

      # App environment variables
      export DEBUG=true
      export FRONTEND_URL=http://localhost:3000
      # API_URL should match SERVER_ADDR
      export API_URL=localhost:8000
      export SECRET_KEY=<secret-key>
      
      # Server environment variables
      export SERVER_ADDR=:8000
      # SERVER_ENVIRONMENT: dev, test, prod
      export SERVER_ENVIRONMENT=dev
      
      # Database environment variables
      export DB_ADDR=postgres://<user>:<password>@<host>:<port>/<dbName>?sslmode=disable
      export DB_MAX_OPEN_CONNS=30
      export DB_MAX_IDLE_CONNS=30
      export DB_MAX_IDLE_TIME=15m
      
      # JWT environment variables
      export JWT_ISSUER=meetup_clone
      export JWT_AUDIENCE=meetup_clone
      export JWT_SECRET_KEY=<jwt-secret-key>
      export JWT_ACCESS_EXP=3
      
      # Cache environment variables
      export MEMCACHED_CONNS=<host>:<port>,<host>:<port>
      
      # Test environment variables
      export TEST_DB_ADDR=postgres://<user>:<password>@<host>:<port>/<dbName>_test?sslmode=disable
      
    • .env/postgres.env - Only needed if you are using docker-compose.dev.yml

      POSTGRES_PORT=5432
      POSTGRES_USER=postgres
      POSTGRES_PASSWORD=postgres
      POSTGRES_MULTIPLE_DATABASES=meetup, meetup_test
      TZ=UTC
      PGTZ=UTC
      
  • Start the api services i.e postgres

    NOTE: This step is for only those using the docker option. If you have local instances, skip this step.

make services-up
# OR if you need sudo
sudo make services-up

# Stop the services
make services-down

# Stop services and destroy container
make services-kill
  • Run migrations on the test and main db

    NOTE: You must have migrate installed.

make migrate-up
make test-migrate-up
  • Run tests
make test

# Tests with coverage
# Create a coverage.out directory before running tests with coverage
make test-cov
  • Run server
make gen-docs && make runserver
# or you can use air
air

Directories

Path Synopsis
cmd
api command
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
app
auth
Package auth provides tools for handling authentication within the API.
Package auth provides tools for handling authentication within the API.
config
Package config provides application configuration settings that are used throughout the application.
Package config provides application configuration settings that are used throughout the application.
db
Package db provides functions for establishing and managing database connections used throughout the application.
Package db provides functions for establishing and managing database connections used throughout the application.
logger
Package logger provides a function Get that returns a zerolog.Logger instance for global logging, allowing consistent logging throughout the application.
Package logger provides a function Get that returns a zerolog.Logger instance for global logging, allowing consistent logging throughout the application.
middleware
Package middleware provides a collection of middleware functions that can be used to enhance and modify the behavior of the application, such as handling requests, logging, authentication, and more.
Package middleware provides a collection of middleware functions that can be used to enhance and modify the behavior of the application, such as handling requests, logging, authentication, and more.
models
Package models defines the data models that are mapped to the database.
Package models defines the data models that are mapped to the database.
services/response
Package response provides various structs and utility functions for generating consistent API responses, including success and error responses.
Package response provides various structs and utility functions for generating consistent API responses, including success and error responses.
store
Package store contains the logic for interacting with the database, including SQL queries and operations that map data between the models and the database.
Package store contains the logic for interacting with the database, including SQL queries and operations that map data between the models and the database.
utils
Package utils contains common functionality and helper functions that are used throughout the application.
Package utils contains common functionality and helper functions that are used throughout the application.
utils/testutils
Package testutils contains helper functions and utilities to assist with running tests.
Package testutils contains helper functions and utilities to assist with running tests.
validate
Package validate contains custom validation functions that can be used with the validator package to perform complex or application-specific validations.
Package validate contains custom validation functions that can be used with the validator package to perform complex or application-specific validations.