go-short-url

command module
v0.0.0-...-bcd771c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 3 Imported by: 0

README

go-short-url

Overview

go-short-url is a URL shortener service written in Go (Golang) with an HTMX frontend. This project makes it easy to shorten URLs for easier sharing and management, while also offering retrieval of original URLs based on their shortened versions. It runs on a lightweight HTTP server on port 8080 with a simple frontend.

Features

  • GET and POST methods for shortening and retrieving URLs
  • Customizable hash size for the generated URLs
  • Basic error handling for unsupported methods and invalid URLs

Prerequisites

  • Go 1.16 or above

Getting Started

To get started, clone the repository and navigate into its directory:

git clone https://github.com/yourusername/go-short-url.git
cd go-short-url
docker-compose up -d

Go to: http://127.0.0.1:8080

API Endpoints

Shorten a URL (POST)

To shorten a URL, make a POST request to the root /:

curl -d "url=http://example.com" -X POST http://127.0.0.1:8080/
Retrieve a URL (GET)

To retrieve the original URL, navigate to the shortened URL in your browser or use a GET request. For example:

curl http://127.0.0.1:8080/{hash}

Error Handling

  • "Method not allowed": Unsupported HTTP method
  • "Invalid URL format": URL doesn't meet the required format
  • "URL not found": The hash doesn't correspond to any stored URL
  • "Something went wrong": Internal server error

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

This project is under the MIT License. See LICENSE.md for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL