DEV Community

dio arafi
dio arafi

Posted on

Building a Video Room Management API: Integrating Go, Twilio, and Zap Logging

As the demand for real-time video communication grows, integrating video room management with third-party services becomes increasingly essential. The VideoKick project offers a Go-based solution that leverages the Twilio API for creating and managing video rooms, complemented by a logging system using Uber's Zap for efficient monitoring.


Directory Structure

The directory structure of the VideoKick project is designed for modularity and maintainability:

videokick/
├── docs/                # API documentation using Swagger
├── internal/
│   ├── video/           # Video module
│   │   └── handler.go   # Handler for video endpoints
│   ├── twilio/          # Twilio client module
│   │   └── client.go    # Twilio client initialization
│   └── pkg/             # Utility and common modules
│       └── logger.go    # Logger configuration using Zap
├── main.go              # Application entry point
└── routes/
    └── routes.go        # API routing configuration
Enter fullscreen mode Exit fullscreen mode

Key Features

  1. Video Room Creation: Utilizes the Twilio API to create unique video rooms for each request.

  2. Efficient Logging: Employs Zap, a high-performance logger, for rapid and effective application logging.

  3. API Documentation: Swagger is used for interactive documentation, facilitating developer exploration of the API.

Dependencies

  • Gin: An HTTP framework used for routing and middleware handling.
  • Twilio: A service that supports video and voice communication, integrated via the twilio-go module.
  • Zap: A high-performance logger provided by Uber for fast and efficient application logging.

Installation Steps

  1. Clone the Repository

Begin by cloning the VideoKick repository to your local machine:

   git clone https://gitlab.com/dioarafi1/videokick.git
   cd videokick
Enter fullscreen mode Exit fullscreen mode
  1. Install Dependencies

Ensure that Go is installed on your system. To download all required dependencies for the project, run:

   go mod tidy
Enter fullscreen mode Exit fullscreen mode
  1. Initialize Swagger

To set up API documentation, initialize Swagger with the command:

   swag init
Enter fullscreen mode Exit fullscreen mode
  1. Configure Environment

Set your Twilio SID and Token in a .env file or a YAML configuration. Example format for .env:

   TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxx
   TWILIO_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxx
   TWILIO_VERIFY_SID=Vxxxxxxxxxxxxxxxxxxxxxxx
Enter fullscreen mode Exit fullscreen mode

API Usage

Create Video Room

This endpoint is used to create a new video room with Twilio. The request is made using the POST method.

Sample Request:

curl -X POST http://localhost:8080/videos/room \
-H "Content-Type: application/json" \
-d '{
  "uniqueName": "testRoom"
}'
Enter fullscreen mode Exit fullscreen mode

Retrieve List of Video Rooms

To obtain a list of all existing video rooms, use the following endpoint with the GET method:

curl -X GET http://localhost:8080/videos/rooms
Enter fullscreen mode Exit fullscreen mode

Twilio Configuration

The Twilio module is configured in internal/twilio/client.go. For further customization, please refer to the Twilio Video API documentation and the Twilio Go Library.

Logger Configuration with Zap

The logger in this application is configured using Zap, with settings located in pkg/logger/logger.go. The logger will be initialized in main.go for global usage throughout the application.

Swagger Documentation

Once the server is running, the Swagger documentation can be accessed at the following endpoint:

Swagger Docs: http://localhost:8080/docs

Swagger provides an interactive interface to test each endpoint and view sample requests and responses from the API.


Additional References


By following this guide, you can easily set up and run VideoKick as a Twilio-based video room management service. This approach also offers flexibility in monitoring API activities through Zap logging and simplifies API exploration via Swagger.









Top comments (0)