csclient: new package

This is the start of the client-side charm store code.

We also factor out the JSON equality checking so that the csclient tests
can use it.

Github seems to have deleted this comment, but I just came
across it and wanted to reply.

Yes, I did think about this, and it would be nice to do it right.
A "slice to nearest rune" primitive would be nice to have.
Just using utf8.LastRune isn't good enough.
In the end, I didn't think it was worth the effort here,
but I am a big fan of multi-wide awareness in general,
so I'd like to do it right at some point.


On 14 October 2014 16:19, Martin Hilton <notifications@github.com> wrote:

> In csclient/csclient.go:
>
> > +	}
> > +	if result == nil {
> > +		// The caller doesn't care about the response body.
> > +		return nil
> > +	}
> > +	if err := json.Unmarshal(data, result); err != nil {
> > +		return errgo.Notef(err, "cannot unmarshal response %q", sizeLimit(data))
> > +	}
> > +	return nil
> > +}
> > +
> > +func sizeLimit(data []byte) []byte {
> > +	if len(data) < 1024 {
> > +		return data
> > +	}
> > +	return append(data[0:1024], fmt.Sprintf(" ... [%d bytes omitted]", len(data)-1024)...)
>
> This is really pedantic, but your slice could cut a rune in half causing
> up to one rune's worth of corrupt output.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/juju/charmstore/pull/145/files#r18835523>.
>