linker

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

README

Linker: HTTP URL Shortener

Linker is a Golang based URL shortening service. This self-hosted binary provides fast and efficient HTTP redirection.

Linker is backed by a MySQL database to store name and URL mappings.

Config

Linker is configured using the following file in "/etc/linker.conf". This file path can be changed using the "-c" flag or by setting the "LINKER_CONFIG" environment variable.

Default Config

{
    "key": "",
    "cert": "",
    "listen": "0.0.0.0:80",
    "timeout": 5,
    "default": "https://duckduckgo.com",
    "db": {
        "name": "linker",
        "server": "tcp(localhost:3306)",
        "username": "linker_user",
        "password": "password"
    }
}

Command Line Options

Linker - HTTP Web URL Shortener v3
iDigitalFlame & PurpleSec 2020 - 2023 (idigitalflame.com)

Usage:
  -h              Print this help menu.
  -l              List the URL mapping and exit.
  -d              Dump the default configuration and exit.
  -a <name> <URL> Add the specified <name> to <URL> mapping.
  -r <name>       Delete the specified <name> to URL mapping.
  -c <file>       Configuration file path. The environment
                  variable "LINKER_CONFIG" can be used to
                  specify the file path instead.

Documentation

Index

Constants

View Source
const Defaults = `` /* 273-byte string literal not displayed */

Defaults is a string representation of the default configuration for Linker. This can be used in a JSON file to configure a Linker instance.

Variables

This section is empty.

Functions

This section is empty.

Types

type Linker

type Linker struct {
	http.Server
	// contains filtered or unexported fields
}

Linker is a struct that contains the web service and SQL queries that support the Linker URL shortener.

func New

func New(s string) (*Linker, error)

New creates a new Linker instance and attempts to gather the initial configuration from a JSON formatted file. The path to this file can be passed in the string argument or read from the "LINKER_CONFIG" environment variable.

This function will return an error if the load could not happen on the configuration file is invalid.

func (*Linker) Add

func (l *Linker) Add(n, u string) error

Add will attempt to add a redirect with the name of the first string to the URL provided in the second string argument.

This function will return an error if the add fails.

func (*Linker) Close

func (l *Linker) Close() error

Close will attempt to close the connection to the database and stop any running services associated with the Linker struct.

func (*Linker) Delete

func (l *Linker) Delete(n string) error

Delete will attempt to remove the redirect name and URL using the mapping name.

This function will return an error if the deletion fails. This function will pass even if the URL does not exist.

func (*Linker) List

func (l *Linker) List() error

List will gather and print all the current link dataset.

This function returns an error if there is an error reading from the database.

func (*Linker) Listen

func (l *Linker) Listen() error

Listen will start the listing session for Linker to redirect HTTP requests. This function will block until the Close function is called or a SIGINT is received.

This function will return an error if there is an issue during the listener creation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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