FAQ
Thx for your reply.

Sorry for asking, but why would you need that?

I use gokit, and I write Publisher
(https://github.com/go-kit/kit/blob/master/loadbalancer/publisher.go) for
netflix/eureka (with the client https://github.com/hudl/fargo) for service
discovery.
I also use EndpointCache
(https://github.com/go-kit/kit/blob/master/loadbalancer/endpoint_cache.go)
for managing the cache of the endpoints.

This EndpointCache uses map[string]endpointCloser
(https://github.com/go-kit/kit/blob/master/loadbalancer/endpoint_cache.go#L24)
for caching all endpoints.
For updating this cache, I use Replace(instances []string)
(https://github.com/go-kit/kit/blob/master/loadbalancer/endpoint_cache.go#L47)
that takes []string for each instance of endpoint.
And this instance's string have to be equal as it use as key of the map
(https://github.com/go-kit/kit/blob/master/loadbalancer/endpoint_cache.go#L55)

Anyway, I write my own marshaller, and use the standard json unmarshaller.

Thx again.


Le jeudi 12 novembre 2015 19:11:13 UTC+1, Konstantin Khomoutov a écrit :
On Thu, 12 Nov 2015 09:50:02 -0800 (PST)
Jérôme LAFORGE <jerome....@gmail.com <javascript:>> wrote:
Can I consider that output of json.Marshal is deterministic for the
same struct with the identical values?

For example :
http://play.golang.org/p/Sb1rTfGkFj

In the above example, can I consider that result will always the same
into result string (with the same sha1sum for example)?
There is no inversion of field into json result?
Sorry for asking, but why would you need that?

The JSON standard says nothing about explicit ordering of fields in the
representations of objects because, naturally, those fields refer to
*named* fields in the source/destination objects, so a JSON object has
essentially the same semantics as a hash map which binds keys to values
but does not impose any ordering. To cite the json.org's title page:
JSON is built on two structures:

* A collection of name/value pairs. In various languages, this is
realized as an object, record, struct, dictionary, hash table, keyed
list, or associative array.
* An ordered list of values. In most
languages, this is realized as an array, vector, list, or sequence.

These are universal data structures. Virtually all modern
programming languages support them in one form or another. It makes
sense that a data format that is interchangeable with programming
languages also be based on these structures.

In JSON, they take on these forms:

An object is an unordered set of name/value pairs. An object begins
with { (left brace) and ends with } (right brace). Each name is
followed by : (colon) and the name/value pairs are separated by ,
(comma).
An array is an ordered collection of values. An array begins with
[ (left bracket) and ends with ] (right bracket). Values are
separated by , (comma).
...
Notice the word "unordered" used when describing objects.

I hence think that making any guarantees about how encoding/json works
beyond those specified in the JSON spec would be stange.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 16 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 12, '15 at 5:50p
activeNov 17, '15 at 3:34a
posts16
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase