link-tracker

module
v0.0.0-...-c8dc403 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: Apache-2.0

README

This repository serves as a starting point for building web services. It uses minimal dependencies, implements idiomatic code and follows as much as possible the following best practices:

It also includes a makefile whose default target run the following tools:

  • go mod tidy
  • go fmt
  • goimports
  • go test

Go installation

  • Download Go tools from https://golang.org/dl
  • If you are on a Unix-like system using bash, add the following lines to your .profile:
    • export GOPATH=$HOME/go
    • export PATH=$PATH:$GOPATH/bin

Note: Despite being mentioned in many blog posts, there is no need to define GOROOT.

Build locally

After cloning the repository, execute the following command under the root directory

make run

The main branch does not use any framework. It relies on simple primitives built on top of the standard library. Here you will find the same program using the gin framework. It is worth noting that despite changing the entire transport implementation, the domain layer remains intact.

Business Problem

This project provides a web service for creating and redirecting URLs upon password validation. It also tracks how many times a URL is visited with a simple counter. As implementation note, the service is not thread safe, and the repository is volatile, meaning that the default implementation stores the data in memory.

curl -POST http://localhost:8080/link -d '{"link":"https://www.google.com", "password":"123"}'

You can either use cURL and follow the redirection with -L or opening a browser and navigate to the link. For a link with id 1 please visit: http://localhost:8080/link/1?password=123

Acknowledgement

All the content in this repository is heavily inspired by the amazing work done by Bill Kennedy from ArdanLabs.

I strongly recommend taking any of his courses and check many useful links and open-source material in his repository.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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