url-shortener

command module
v0.0.0-...-5a5c85a Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: AGPL-3.0 Imports: 15 Imported by: 0

README

URL Shortener

Go Report Card

This is a simple URL shortener using the Gin framework and the GORM ORM. The only way to add links is to use an api endpoint, meaning that this is not suitable for public websites etc. The addresses are randomly generated.

To use this project you must add a configuration file as such to the folder in which the binary lies.

config.json

{
    "prefix": "placeholder/",
    "db": "test.db",
    "password": "placeholder"
}

You can choose to leave the prefix empty, however choosing a password and a filename for the sqlite database is required.

Additionally you can add an HTML file called badrequest.html to the subfolder templates, which will be displayed when an invalid link beginning with the specified prefix is opened by a user. Resources for this website, such as stylesheets or images may be placed in the resources directory, which is statically routed.

Usage

The API endpoint to add links is 127.0.0.1:8080/api/add Add new links by POSTing an html form containing the link as address and the password as password. A JSON containing the shortened address will be returned to you, unless an error has occured. I recommend Postman for ease of use.

Example

alt Postman screenshot showing how to add links

The API endpoint to remove links is 127.0.0.1:8080/api/remove

Simply provide the target of a shortened link to remove it.

Links can be updated by specifying their current target as old_address and their new target as new_address

The API endpoint to do this is 127.0.0.1:8080/api/update

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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