Categorygithub.com/hcd233/Aris-url-gen
repositorypackage
0.1.0
Repository: https://github.com/hcd233/aris-url-gen.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Aris-url-gen

[ English | 简体中文 ]

Introduction

A high-performance URL shortening service developed in Go. The project name comes from the character Aris in Blue Archive, as shown in the figure below.



Aris: A character from Blue Archive

---

Features

  • Generate short URLs: Converts long URLs into short links
  • Customizable expiration time: Allows setting an expiration date for links
  • Bidirectional caching: High-performance caching using Redis
  • RESTful API: Provides a standard HTTP interface
  • Data persistence: URL mappings are stored in MySQL

Tech Stack

  • Web Framework: Fiber
  • ORM: GORM
  • Caching: Redis
  • Database: MySQL
  • Logging: Zap

API Endpoints

1. Generate Short URL

POST /v1/shortURL
Content-Type: application/json
{
    "originalURL": "https://example.com/very/long/url",
    "expireDays": 7  // Optional, expiration in days
}

2. Access Short URL

GET /v1/s/{shortURL}

Project Structure

.
├── cmd/                # Command line entry
├── internal/          
│   ├── api/           # API-related code
│   │   ├── dao/       # Data access layer
│   │   ├── dto/       # Data transfer objects
│   │   ├── handler/   # Request handlers
│   │   └── service/   # Business logic layer
│   ├── config/        # Configuration files
│   ├── logger/        # Logging
│   ├── resource/      # Resources
│   └── util/          # Utility functions
└── main.go            # Main entry point

Installation and Deployment

Prerequisites

  • Go 1.20+
  • MySQL 8.0+
  • Redis 6.0+

Local Development

  1. Clone the repository
git clone https://github.com/hcd233/Aris-url-gen.git
cd Aris-url-gen
  1. Install dependencies
go mod download
  1. Configure environment variables

Refer to api.env.template to set up the required environment variables

  1. Run the service
go run main.go

Deployment

Docker Deployment

  1. Create required volumes:
docker volume create mysql-data
docker volume create redis-data
  1. Deploy with docker-compose:
# Development environment
docker compose -f docker/debug-docker-compose.yml up -d

# Production environment
docker compose -f docker/docker-compose.yml up -d

Kubernetes Deployment

  1. Create namespace and configs:
kubectl apply -f kubernetes/namespace.yml
kubectl apply -f kubernetes/configmaps.yml
  1. Create secrets (configure secrets.yml first):
cp kubernetes/secrets.yml.template kubernetes/secrets.yml
# Edit secrets.yml with actual secret values
kubectl apply -f kubernetes/secrets.yml
  1. Create storage and deploy services:
kubectl apply -f kubernetes/pvc.yml
kubectl apply -f kubernetes/deployments.yml
kubectl apply -f kubernetes/services.yml

Helm Deployment

  1. Configure values.yaml:
cp helm/aris-url-gen/values.yaml.template helm/aris-url-gen/values.yaml
# Edit values.yaml with your configuration
  1. Install with Helm:
helm install aris-url-gen helm/aris-url-gen
  1. Upgrade or uninstall:
# Upgrade
helm upgrade aris-url-gen helm/aris-url-gen

# Uninstall
helm uninstall aris-url-gen

License

This project is licensed under the Apache License 2.0. See the LICENSE file for more details.