The sequence

Report a typo

Below, you will see a Go program that launches a web server using Gin with a single route /sequence:

package main

import (
    "github.com/gin-gonic/gin"
    "net/http"
)

var previous int32 = 0
var current int32 = 1
var counter int32 = 0

func main() {
    router := gin.Default()
    router.GET("/sequence", theSequence)
    router.Run("127.0.0.1:8080")
}

func theSequence(context *gin.Context) {
    counter += 1

    tmp := current
    current = previous + current
    previous = tmp

    context.String(http.StatusOK, "%d. %d", counter, current)
}

The corresponding answer consists of two numbers: an ordinal number and a number in a sequence, separated by a dot. Run the code and request a route then open a web browser and go to the address 127.0.0.1:8080 (don't forget to specify the route) and keep refreshing the page until the sequence number is 7. Write the two numbers in the correct sequence, e.g., 3. 3 in the textbox below:

Tip: The route is 127.0.0.1:8080/sequence

Enter a short text
___

Create a free account to access the full topic