Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marianozunino/go-short
This project is a URL shortener built in Go
https://github.com/marianozunino/go-short
Last synced: about 7 hours ago
JSON representation
This project is a URL shortener built in Go
- Host: GitHub
- URL: https://github.com/marianozunino/go-short
- Owner: marianozunino
- License: mit
- Created: 2024-08-06T15:48:42.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-08-07T13:37:48.000Z (5 months ago)
- Last Synced: 2024-09-18T10:10:35.645Z (4 months ago)
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# URL Shortener
This project is a URL shortener built in Go. It uses [templ.guide](https://templ.guide/) for HTML components, [sqlc](https://github.com/kyleconroy/sqlc) for generating type-safe SQL code, and SQLite as the database.
## Features
- Shorten long URLs
- Redirect to original URLs using shortened links
- Simple and clean HTML templates
- Lightweight and fast with Go and SQLite## Requirements
- Go 1.16 or later
- [sqlc](https://github.com/kyleconroy/sqlc)
- [migrate](https://github.com/golang-migrate/migrate) for database migrations## Installation
1. Clone the repository:
```sh
git clone https://github.com/yourusername/url-shortener.git
cd url-shortener
```2. Install the dependencies:
```sh
go mod download
```3. Install `sqlc`:
```sh
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
```4. Install `migrate`:
```sh
go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
```## Usage
### Running Migrations
Create a new migration:
```sh
migrate create -dir migrations -ext sql initial
```Run the migrations:
```sh
migrate -database sqlite3://db.test -path migrations up
```### Generating SQL Code with sqlc
To generate Go code from the SQL queries, run:
```sh
sqlc generate
```### Running the Application
To start the URL shortener application, run:
```sh
go run main.go
```## Configuration
The application can be configured using environment variables:
- `DATABASE_URL`: The URL for the SQLite database (default: `sqlite3://db.test`)
## Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.