Skip to content
Just another URL shortener service. Go + Redis + gRPC.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
logger
pb
storage
.dockerignore
.editorconfig
.gitignore
Dockerfile
README.md
go.mod
go.sum
handlers.go
handlers_test.go
main.go
start-dev.sh

README.md

dwarf

A high-throughput URL shortener microservice built with Go.

  • gRPC for communication
  • Redis store out of the box
  • Fast & simple

Usage

See start-dev.sh for a complete list of available environmental variables. To use in a docker container, we have an image here.

GET /{short-hash} -> 301 redirection

Dwarf will deliver a 301 redirection to the destination URL or redirect to the fallback URL specified with NOTFOUND_REDIRECT_URL.

Creating short links

You must communicate with dwarf via gRPC in order to generate new shortened URLs.

service Dwarf {
	rpc Create(CreateRequest) returns (CreateResponse) {}
}

message CreateRequest {
	repeated string urls = 1;
}

message CreateResponse {
	repeated string urls = 2;
}

Your response will return a set of shortened urls in the same order that they were sent:

// -> Request
{ "urls": ["http://long-url.com/1", "http://long-url.com/2"] }

// -> Response
{ "urls": ["http://sh.ort/Mp", "http://sh.ort/uJ"] }

A dwarf gRPC client written with node.js

To generate short urls, use a gRPC client such as this node client.

Development

Redis Store

Spin up an instance of redis with:

docker run -p "6379:6379" --rm --name dwarf-redis redis:4-alpine

Testing

go test github.com/LevInteractive/dwarf/ -v

Note that the tests rely on a running redis instance.

You can’t perform that action at this time.