/podcast_go_backend

Podcast App Tutorial Project Backend side

Primary LanguageGo

Music App Go Backend

A Go-based backend service for a music application that provides podcast management, user authentication, and search functionality using MongoDB.

Features

  • Podcast management (create, list, search)
  • User authentication (login, registration)
  • JWT-based authentication
  • MongoDB integration
  • RESTful API endpoints
  • Text search capabilities

Prerequisites

  • Go 1.16 or higher
  • MongoDB 4.4 or higher
  • Git

Installation

  1. Install MongoDB (if not already installed):

    brew tap mongodb/brew && brew install mongodb-community
  2. Clone the repository:

    git clone <repository-url>
    cd music_app_go_backend
  3. Install dependencies:

    go mod download
  4. Set up environment variables: Create a .env file in the root directory with the following variables:

    MONGODB_URI=mongodb://localhost:27017
    PORT=8080
    JWT_SECRET=your-secret-key
    

Project Structure

music_app_go_backend/
├── internal/
│   ├── controllers/     # HTTP handlers
│   ├── models/          # Data models
│   └── utils/           # Utility functions
│       ├── constants/   # Constants
│       ├── db/          # Database utilities
│       └── manager/     # JWT manager
├── main.go              # Application entry point
└── go.mod               # Go module file

API Endpoints

Authentication

  • POST /login - User login
  • POST /create - User registration

Podcasts

  • GET /podcast - List all podcasts
  • POST /podcast - Create a new podcast
  • GET /search?q={query} - Search podcasts

Explore

  • GET /explore - Get explore page content

Running the Application

  1. Start MongoDB:

    brew services start mongodb-community
  2. Run the application:

    go run main.go

The server will start on http://localhost:8080 by default.

Example API Usage

User Registration

curl -X POST http://localhost:8080/create \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "password": "password123"}'

User Login

curl -X POST http://localhost:8080/login \
  -H "Content-Type: application/json" \
  -d '{"email": "user@example.com", "password": "password123"}'

Create Podcast

curl -X POST http://localhost:8080/podcast \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your-jwt-token>" \
  -d '{"title": "My Podcast", "description": "A great podcast"}'

Search Podcasts

curl -X GET "http://localhost:8080/search?q=podcast"

Development

Adding New Features

  1. Create new models in internal/models/
  2. Add controllers in internal/controllers/
  3. Update routes in main.go

Testing

To run tests:

go test ./...

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.