Coder Social home page Coder Social logo

go-fizz-buzz's Introduction

Fizz-Buzz REST server - Golang

This project is a technical test for leboncoin

Exercise: Write a simple fizz-buzz REST server.

The original fizz-buzz consists in writing all numbers from 1 to 100, and just replacing all multiples of 3 by fizz, all multiples of 5 by buzz, and all multiples of 15 by fizzbuzz.

The output would look like this: "1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,...,buzz."


Your goal is to implement a web server that will expose a REST API endpoint that:

  • Accepts five parameters: three integers int1, int2 and limit, and two strings str1 and str2.
  • Returns a list of strings with numbers from 1 to limit, where: all multiples of int1 are replaced by str1, all multiples of int2 are replaced by str2, all multiples of int1 and int2 are replaced by str1str2.

The server needs to be:

  • Ready for production
  • Easy to maintain by other developers

Bonus: add a statistics endpoint allowing users to know what the most frequent request has been. This endpoint should:

  • Accept no parameter
  • Return the parameters corresponding to the most used request, as well as the number of hits for this request"

Launch

with docker:

docker compose up

without Docker: 1st time:

make postgres
make createdb
make migrateup

make server

then:

make start_postgres
make server

ℹ️ To get more infos about the makefile commands

make help

Then it's possible to explore the API with Postman importing the following tests : postman/fizzbuzz.postman_collection.json

Remove

⚠️ remove the database created:

make fclean

Tests

You launch the tests with the following command:

make test

Development

  • To update the database schema, create a new migration with make new_migration then apply your migration with make migrateup1 - see migrate documentation
  • For new sql request, edit the /db/query part, then generate the code with make sqlc - see sqlc documentation
  • Update the mock to test database interface with make mock - see mock documentation

go-fizz-buzz's People

Contributors

ebaudet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.