这个使用 Go 和 Hexagonal 架构的 URL 缩短服务采用无服务器的方法,可实现高效的扩展和性能。
这个使用 Go 和 Hexagonal 架构的 URL 缩短服务采用无服务器的方法,可实现高效的扩展和性能。
This URL shortener service, built with Go and Hexagonal Architecture, leverages a serverless approach for efficient scalability and performance. It uses a variety of AWS services to provide a robust, maintainable, and highly available URL shortening service.
Clone the Repository:
git clone https://github.com/Furkan-Gulsen/golang-url-shortener.git
cd golang-url-shortenerBuild the Project: Use the Makefile to build the project:
make buildmake deployUnit Tests: Run unit tests for specific functions:
make unit-testBenchmark Tests: Perform benchmark tests:
make benchmark-testTo clean up the build artifacts:
make cleanTo delete the deployed stack:
make delete| AWS Service | Estimated Cost for 1 Million Requests | Notes |
|---|---|---|
| AWS Lambda | $0.20 | First 1M requests/month are free, after that, it's $0.20 per 1 million requests |
| API Gateway | $3.50 | First 1M requests/month are free, after that, it's $3.50 per 1 million request. |
| DynamoDB | $1.25 | 2 writes per generate, 1 write per redirect, 2 reads per stats |
| CloudFront | $0.75 - $2.20 | Based on 1M HTTPS requests |
| ElastiCache (Redis) | Variable | Dependent on node size and time running |
| SQS | $0.40 | First 1M requests/month are free, after that, it's $0.40 per 1 million requests. |
Warning: This is a calculation based entirely on guesswork.
Image Resource: https://aws.amazon.com/blogs/compute/developing-evolutionary-architecture-with-aws-lambda
Hexagonal Architecture in a serverless context, specifically using Go language, is a fascinating topic that combines modern architectural patterns with the agility and scalability of serverless computing. Let's break down the key concepts and how your project structure fits into this model.
Core Concept: Hexagonal Architecture, also known as Ports and Adapters Architecture, is designed to create a loosely coupled application that isolates the core logic from external concerns. The idea is to allow an application to be equally driven by users, programs, automated tests, or batch scripts, and to be developed and tested in isolation from its eventual runtime devices and databases.
Ports and Adapters: In this architecture, the 'ports' are the interfaces that define how data can enter and leave the application or system. The 'adapters' are implementations that interact with the outside world, such as a database, a web server, or other systems.
Adapters:
cache (e.g., redis.go): This likely represents the caching mechanism, an adapter to an external caching service like Redis.functions: These are serverless functions for different operations (delete, generate, notification, redirect, stats), each with its own bootstrap and main.go. They serve as entry points for various operations, acting as adapters to external triggers or requests.handlers (e.g., delete.go, generate.go): These are likely the controllers or use-case handlers that interact with the core domain logic.repository (e.g., link.go, stats.go): Represents the data access layer, an adapter for database interaction.Core Directory:
link.go, stats.go): Contains the business logic and entities of your application.cache.go, link.go): Interfaces that define the expected operations (like CRUD) for various entities.link.go, stats.go): Implements business logic or domain services.Tests Directory:
benchmark, unit) to ensure that both the core logic and adapters work as expected.Other Files:
go.mod, go.sum: Go module files for managing dependencies.Makefile, README.md: For building the project and documentation.samconfig.toml, template.yaml: AWS SAM configuration files for deploying serverless functions.In a serverless context, Hexagonal Architecture brings several benefits:
This library is licensed under the MIT-0 License. See the LICENSE file.
暂无开放 Issues,或尚未同步最近议题。