fizzbuzz

package
v0.0.0-...-f7f2675 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package fizzbuzz implementation all handler for FizzBuzz API

Package fizzbuzz implementation all handler for FizzBuzz API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FizzBuzz

func FizzBuzz(c *fiber.Ctx) error

FizzBuzz generates a FizzBuzz sequence based on the values of `Int1`, `Int2`, `Limit`, `Str1`, and `Str2` in the `fizzbuzz.Request` object stored in the request context `c`. The generated sequence is returned as a JSON response.

The `Int1` and `Int2` values are used as divisors to determine if a given number is divisible by either one of them or both. If a number is divisible by both, the strings `Str1` and `Str2` are concatenated, otherwise, only the appropriate string is appended to the result slice. If the number is not divisible by either one of the integers, the number is appended as a string to the result slice.

The generated FizzBuzz sequence is returned as a JSON response in the same order as it was generated. @Summary Return FizzBuzz result. @Description Returns a list of strings with numbers from 1 to limit, where: \n 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. @Tags FizzBuzz @Accept */* @Produce json @Help Name ? type required description @Param int1 path int true "Give the first number" default(3) @Param int2 path int true "Give the second number" default(5) @Param limit path int true "Give limit of fizzbuzz" default(100) @Param str1 path string true "Give the first word" default(fizz) @Param str2 path string true "Give the second word" default(buzz) @Failure 400 {array} string @Success 200 {array} string @Router /api/v1/fizzbuzz/:int1/:int2/:limit/:str1/:str2 [get]

func FizzBuzzControls

func FizzBuzzControls(c *fiber.Ctx) error

FizzBuzzControls takes in 5 parameters from a Fiber HTTP Context object: int1, int2, limit, str1, and str2. The function first checks if int1, int2, and limit are valid integers. If any of these parameters are not valid integers, it will return a response with status code 400 and an error message. If int1 or int2 are equal to 0, or if limit is equal to 0, the function will return a response with status code 400 and an error message. If all the parameters are valid, it will create a new FizzBuzz request object with these parameters and store it in the context's UserValue field under the key "fizzbuzz.Request". It then calls the Next() function to pass the context object to the next middleware or handler. If an error occurs at any point, it will return a response with status code 400 and an error message.

func FizzBuzzHits

func FizzBuzzHits(c *fiber.Ctx) error

FizzBuzzHits is an HTTP middleware function that updates a global map of FizzBuzz request statistics with information about the current request. It retrieves the FizzBuzz request parameters from the user value stored in the request context, increments the corresponding hit counter in the statistics map, and then passes the request on to the next middleware or endpoint handler.

Parameters: - c: a pointer to the fiber.Ctx object representing the HTTP request context.

Returns: - an error value, which is typically nil, since there is no meaningful error condition for this endpoint.

func Stats

func Stats(c *fiber.Ctx) error

Stats is an HTTP handler function that returns statistics about the most frequently requested FizzBuzz endpoint. It retrieves the statistics from a shared global map that is updated by the "FizzBuzzHits" function. The statistics include the FizzBuzz request parameters that were used most frequently, as well as the number of times that those parameters were used.

Parameters: - c: a pointer to the fiber.Ctx object representing the HTTP request context.

Returns: - an error value, which is typically nil, since there is no meaningful error condition for this endpoint. @Summary Return FizzBuzz statistics. @Description Return the parameters corresponding to the most used request, as well as the number of hits for this request. @Tags FizzBuzz @Accept */* @Produce json @Help Name ? type required description @Success 200 {object} fizzbuzz.Stats @Router /api/v1/fizzbuzz/stats [get]

Types

This section is empty.

Jump to

Keyboard shortcuts

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