gotiny

command module
v0.0.0-...-3df1e6d Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 3 Imported by: 0

README

Gotiny server

A Tiny URL (API) server in Go

Prerequisites

Have Go > 1.13 installed

Installation

go get github.com/chrisvdg/gotiny
cd %GOPATH/src/github.com/chrisvdg/gotiny
go build -mod vendor

Docker

# Build images
docker build -t gotiny .

# Run basic http server
docker run -p 80:80 gotiny

# Run with custom arguments
docker run --rm gotiny --help

Usage

A client library is available in the gotiny_client repository.
The following examples use CURL instead.

Launch a gotiny server on the default port (":8080"),
without any authentication and pretty print the json output.

./gotiny -j


# Create a new entry using CURL (in another terminal window)
curl -d "id=google&url=google.com" -X POST http://localhost:8080/api/tiny
{
	"id": "google",
	"url": "http://google.com",
	"created": 1590330837
}

In a webbrowser surf to http://localhost:8080/api/tiny/google
where it should directed to the Google home page.

# Create a new entry with a generated ID
curl -d "url=chris.gent" -X POST http://localhost:8080/api/tiny
{
	"id": "b2p76",
	"url": "http://chris.gent",
	"created": 1590331741
}

Now in a webbrowser go to http://localhost:8080/api/tiny/b2p76
where it should directed to my home page.

# List entries (you can also enter this URL into a browser)
curl http://localhost:8080/api/tiny
[
	{
		"id": "google",
		"url": "http://google.com",
		"created": 1590330837
	},
	{
		"id": "b2p76",
		"url": "http://chris.gent",
		"created": 1590331741
	}
]


# Get details of an entry (you can also enter this URL into a browser)
curl http://localhost:8080/api/tiny/google/expand
{
	"id": "google",
	"url": "http://google.com",
	"created": 1590330837
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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