@thebotguy's Golang poetic challenge to @J

dev-challenges
thebotguys-tavern

#1

In these days @thebotguy and @J (you can find them on Syscoin Discord) had a discussion about coding and @J told him:

Dedicate to me a poem in Go language and I will be faithfully yours

Why not helping @thebotguy in his idea? The exercise is the following:

We are going to use the Echo Labstack Web Framework to build APIs to create a lorem ipsum generator for @J

Prerequisites

You need to create an API which serves from the root endpoint (aka /) which serves any time a random lorem ipsum generator. The minimum number of sentences of the paragraph is 3, the maximum is 7.

Do your best and show what you can do to help the poor @thebotguy :slight_smile:


#2

First serious entry I tip 200 SYS! :grin:


#3

Saw this ‘challenge’ posted on the Go forum :stuck_out_tongue:

Unless there’s something I’m missing here…

package main

import (
	"net/http"

	"github.com/drhodes/golorem"
	"github.com/labstack/echo"
)

func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, lorem.Paragraph(3, 7))
	})
	e.Logger.Fatal(e.Start(":9000"))
}

#4

Yippie, well done, that’s exactly what I meant.

It wasn’t created to be hard, but to show people the Tavern. Happy to see this on the Go Forum as well


#5

200 Syscoin to you, DM me your wallet address or alias!


#6

Where can I get a syscoin wallet? xD

https://www.syscoin.org/resources/ is down :stuck_out_tongue:


#7

We are rebranding the website today haha.

And here is the Core repo: https://github.com/syscoin


#8

New buddy is coming to town. Thanks @Benjamin_Radovsky for your gopherness


#9

A brief explanation of the code for newcomers to the language

package main

import (
	"net/http"

	"github.com/drhodes/golorem"
	"github.com/labstack/echo"
)

func main() {
    // initializes a new echo object, to allow to handle server calls 
    e := echo.New()
    // We define a GET endpoint with handle on '/' path,
    // the context is used to define a set of variables useful to
    // the echo environment, and to create particular behaviours,
    // btw it's not needed for this challenge (only kept to respect
    // thesignature ofthe closure being passed)
    e.GET("/", func(c echo.Context) error {
        // return c.String(http.StatusOK, lorem.Paragraph(3, 7))
        // is splitted into (for explanation purpose) in 
        loremContent := lorem.Paragraph(3, 7) // create the Lorem Ipsum paragraph
                                              // using the lorem library
        return c.String(
            http.StatusOK, // We define the return value of the status of API Call
            loremContent // and the content being returned with the response body
        )
        // this call in echo framework produces an error object, 
        // which will be internally parsed if necessary
    })

    // this line starts the echo web server on the port 9000 in "localhost" 
    // and logs if an error occurs anytime.
    e.Logger.Fatal(e.Start(":9000"))
}

#10