Bug on Element Decoding

Firstly, it fixes a serious bug that I found accidentally when working on the 0.2.X series. The bug was very simple to reproduce though. When PUSH -ing an Element into a Stack, the client always needs to provide a payload with the following structure:

{"element":"whatever"}

This way, any payload that doesn’t follow this format, i.e. element as key and the Element itself as value, should be rejected by the server. This actually didn’t happen, and the payload was not properly decoded, resulting in a nil element pushed on top of the Stack.

In order to fix this bug I applied the following procedure:

Reproduce the bug manually.

Write tests that could reproduce the bug, going top-bottom by components until I found the source of the problem, and expecting failures on such tests.

Write a fix in the identified source of the problem.

All green, success!

The source of the bug was when decoding the payload of the PUSH request into an Element type, so I had to take the incoming stream, convert it to bytes, check contents in a easy way, and if everything was OK, apply the decoding:

func (element *Element) Decode(r io.Reader) error {

elementBuffer := new(bytes.Buffer)

elementBuffer.ReadFrom(r)



if !bytes.HasPrefix(elementBuffer.Bytes(), []byte(`{"element"`)) {

return errors.New("malformed payload, missing element key?")

}



decoder := json.NewDecoder(elementBuffer)

return decoder.Decode(element)

}

For more information about this bug fix, check the related Pull Request.

Go Version in Status

Now it is possible to know which version of Go was used to compile piladb when checking its status:

{

"status": "OK",

"version": "0.1.2",

"go_version": "go1.8",

"host": "linux_amd64",

"pid": 17680,

"started_at": "2017-03-04T20:14:55.370710982+01:00",

"running_for": 12.213244858,

"number_goroutines": 4,

"memory_alloc": "525.15KiB"

}

New Ping Endpoint

You can check the health of a piladb server by doing ping to it. A request to the /_ping endpoint will return pong if the server is up and running.

Changes in Root Endpoint

Previously, a request to / did a redirect to the pilad subpackage README file. This wasn’t either functional or intuitive, so we decided that in this endpoint we want to thank the user and point them to some links of interest:

Complete GoDoc

We added the missing parts in our code documentation, so piladb’s GoDoc is complete now.

Extend Documentation

New juicy pages were added to our documentation: