We have a great, fast growing, microservices based service of storing whatever and their personal data. We are known for our compliance with all DataSecurity laws, and wanna keep going with that.
So, let's say we have some Golang struct like:
type PersonalData struct {
Title string `json:"title"`
}
type Whatever struct {
Uuid string `json:"uuid"`
Data PersonalData `json:"data"`
}
We have stored numerous "whatevers" in NoSQL database, for example:
DB.Write(
Whatever{"a-b-c-d", PersonalData{"i'm whatever"}}
)
Which, despite we call them whatevers, have their PersonalData.
Next day, whatever with uuid a-b-c-d
decided to call itself "i'm whoever"
instead of "i'm whatever"
. Which means we need to change a title.
Ofcourse we please whatever with this request. That's be:
we := DB.Get("a-b-c-d")
we.Data.Title = "i'm whoever"
DB.Write(we)
Good job so far!
But happens so, that there is another service, let's call it ServiceX, might be third-party or so, which needs to know whether personal data changed(updated), but can't read the data itself.
Let's just send it pings when we have update requests, won't we? Yeeeah, but no. Despite we process update request, we don't know if data actually changed, while that ServiceX is very lazy, so can be disturbed only and ONLY then, when data ACTUALLY changed.
Let's help ServiceX, let's make a hashsum!
Make a Marshaller(no need of unmarshaller) for structs, which would make hash check sum for any struct, e.g.:
import "hasher"
/// a few lines later
obj := Whatever{"a-b-c-d", PersonalData{"i'm whatever"}}
hash := hasher.Marshall(obj)
fmt.Println(hash) // => "f714d0221fef51f2c0d26fa1ac1e3513"
// a few moments later
obj.Data.Title = "i'm whoever"
hash := hasher.Marshall(obj)
fmt.Println(hash) // => "605671cbae106e973f9b0f50dbbcf416"
Make it possible to define which fields must be "participating" in hashing.
For example we add new field to struct PersonalData
:
type PersonalData struct {
Title string `json:"title"`
Address string `json:"address" hasher:"+"`
}
So if we pass such object to our hasher.Marshall
it will lookup only for the fields with "hasher" tag.
Make it working with nested structs.
Tests, comments, all that fancy things ;)
- You choose any hashing algorythm you prefer.
- You can call your package and function any name you prefer.
- Package should be installable with
go get
and Go Modules - Names, comments, everything must be in english.
You can contact me any with any questions at any time via: