shrt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: ISC Imports: 4 Imported by: 0

README

go-shrt
========

This is a URL shortener. There are many like it, but this is mine. Try
putting all the vowels in "shrt" and enjoy yourself!

Also handles go-get redirects.

There's no UI to add a new shortlink at this time. Just edit the DB by
hand and kill -HUP the process.

building
--------

$ make

installation
------------

# make install

using
-----

Note that by default shrt expects its data files to be relative to the
current directory.

$ shrt -h
usage: shrt [-hv] [-d dbpath] [-c cfgpath] [-l listenaddr] [init]
$ shrt init
server name: example.com
SCM type: git # or hg, etc.. used for go-get redirects
repo suffix (blank for none): .git # suffix to add to go-get repo URIs
redirect base url: https://git.example.com
bare redirect url: https://www.example.com
$ shrt -l localhost:8080
2020/12/06 12:57:01 listening on localhost:8080

HTTPS is out-of-scope. Use a reverse-proxy with TLS termination.

more documentation
------------------

$ man 1 shrt

Documentation

Overview

The shrt module implements a simple (perhaps simplistic) URL shortener. It also handles go-get requests. See the cmd/shrt package documentation for a fuller explanation of the server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ShrtFile

type ShrtFile struct {
	// contains filtered or unexported fields
}

The ShrtFile struct contains the data read from a specially-formatted file. The syntax of the file is human readable. Each line represents a key-value pair. The key is everything to the left of the first equals sign, and the value is everything to the right. Whitespace is trimmed from the beginning and end of both keys and values.

func NewShrtFile

func NewShrtFile(path string) (*ShrtFile, error)

The NewShrtFile function creates a new ShrtFile. The filesystem is checked for the existence of a node at the specified path, and the NewShrtFile returns an error if something is there. This constitutes a weak check, since a file could easily be created before Write() is called, in which case the existing file will be truncated.

func ReadShrtFile

func ReadShrtFile(db string) (*ShrtFile, error)

The ReadShrtFile function reads an existing ShrtFile from the filesystem and returns a pointer to a ShrtFile object. See the ShrtFile documentation for the expected file format.

func (*ShrtFile) Get

func (s *ShrtFile) Get(key string) string

The Get method gets the value of the specified key. If the key does not exist, an empty string is returned.

func (*ShrtFile) Put

func (s *ShrtFile) Put(key, value string)

The Put method adds a the specified value, associating it with the specified key. The value is overwritten if the key already exists.

func (*ShrtFile) Write

func (s *ShrtFile) Write() error

The Write method serializes the contents of the ShrtFile to the file path specified when the ShrtFile was created. If a file already exists at the specified path, it is truncated and overwritten.

Directories

Path Synopsis
cmd
shrt
shrt is a URL shortener service (much like bit.ly without the trackers) that also handles go-get requests.
shrt is a URL shortener service (much like bit.ly without the trackers) that also handles go-get requests.

Jump to

Keyboard shortcuts

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