golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.27k stars 17.57k forks source link

encoding/json: marshaller does not provide Base64Url support #14804

Open cyberphone opened 8 years ago

cyberphone commented 8 years ago
  1. Go version: 5.3
  2. Operating system: Windows 8.1 64-bit
  3. What did you do? https://play.golang.org/p/k1Wgec8cVB
  4. What did you expect to see? I had hoped that there would be a field option allowing you to override the default encoding because Base64Url is nowadays the preferred format in standards including IETF's JOSE
  5. What did you see instead? No such option :-)
OneOfOne commented 8 years ago

What's wrong with doing it client side instead of making the json encoder do mime sniffing on the data?

img.src = 'data:image/png;base64,' + data.Blob;
cyberphone commented 8 years ago

@OneOfOne There's nothing wrong with sniffing in a browser scenario but I'm targeting another class of applications where there is no room for such measures: https://cyberphone.github.io/openkeystore/resources/docs/jsonsignatures.html

Yes, an option must also work for unmarshalling.

OneOfOne commented 8 years ago

It's rather trivial to implement your own type for that though.

https://play.golang.org/p/FYFtvrdWnq

cyberphone commented 8 years ago

@OneOfOne Indeed I could but you should consider this issue related to a bunch of issues which makes the current Marshaller/Unmarshaller close to useless in my context: https://github.com/golang/go/issues/14750 https://github.com/golang/go/issues/14749 https://github.com/golang/go/issues/14135