Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Gert Cuykens
Ok thanks, I will try that but don't think it will be elegant for
turning on and off plain json in a code base, because I have to change
every json.Marshal and json.Umarshal

On Fri, Dec 27, 2019 at 10:21 AM Dan Kortschak  wrote:
>
> MarshalText?
>
> On Fri, 2019-12-27 at 09:51 +0100, Gert Cuykens wrote:
> > Thanks, Which should I use instead then? The reason I use it is so I
> > can easily switch between regular json payloads for debugging and
> > encrypted/signed urlencode payloads
> >
> > On Fri, Dec 27, 2019 at 9:39 AM Axel Wagner
> >  wrote:
> > >
> > > `MarshalJSON` needs to output a valid JSON value, according to the
> > > interface. If you don't need the result to be valid JSON, then
> > > don't use encoding/json. If you want to use JSON to use it as part
> > > of a larger value, you could output a JSON string (but you should
> > > familiarize yourself with what a JSON string can and can't contain
> > > - e.g. if your encrypted bytes contain quotes, that'll be
> > > problematic).
> > >
> > > On Fri, Dec 27, 2019 at 7:55 AM Gert 
> > > wrote:
> > > >
> > > > https://play.golang.org/p/6qKkJhVsnU1
> > > >
> > > > type Payload struct{}
> > > >
> > > > func (p Payload) MarshalJSON() ([]byte, error) {
> > > > return []byte("my custom encryption stuf"), nil
> > > > }
> > > >
> > > > func main() {
> > > > p := Payload{}
> > > > j, err := json.Marshal(p)
> > > > if err != nil {
> > > > fmt.Println(err)
> > > > }
> > > > fmt.Println(string(j))
> > > > }
> > > >
> > > > json: error calling MarshalJSON for type main.Payload: invalid
> > > > character 'm' looking for beginning of value
> > > >
> > > >
> > > > How do you skip the check from json.Marshal and just return the
> > > > []byte directly whatever they are?
> > > >
> > > > --
> > > > 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+unsubscr...@googlegroups.com.
> > > > To view this discussion on the web visit
> > > > https://groups.google.com/d/msgid/golang-nuts/554c8ca8-2bca-4321-9ee5-0524e28422a3%40googlegroups.com
> > > > .
> >
> >
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAG7ytiv8VEAC3fjr3Ln9bwmHJOXUd%3DQiPpGtsua4%2BHK1zv4TfQ%40mail.gmail.com.


Re: [go-nuts] MarshalJSON() output encrypted json

2019-12-27 Thread Gert Cuykens
Thanks, Which should I use instead then? The reason I use it is so I
can easily switch between regular json payloads for debugging and
encrypted/signed urlencode payloads

On Fri, Dec 27, 2019 at 9:39 AM Axel Wagner
 wrote:
>
> `MarshalJSON` needs to output a valid JSON value, according to the interface. 
> If you don't need the result to be valid JSON, then don't use encoding/json. 
> If you want to use JSON to use it as part of a larger value, you could output 
> a JSON string (but you should familiarize yourself with what a JSON string 
> can and can't contain - e.g. if your encrypted bytes contain quotes, that'll 
> be problematic).
>
> On Fri, Dec 27, 2019 at 7:55 AM Gert  wrote:
>>
>> https://play.golang.org/p/6qKkJhVsnU1
>>
>> type Payload struct{}
>>
>> func (p Payload) MarshalJSON() ([]byte, error) {
>> return []byte("my custom encryption stuf"), nil
>> }
>>
>> func main() {
>> p := Payload{}
>> j, err := json.Marshal(p)
>> if err != nil {
>> fmt.Println(err)
>> }
>> fmt.Println(string(j))
>> }
>>
>> json: error calling MarshalJSON for type main.Payload: invalid character 'm' 
>> looking for beginning of value
>>
>>
>> How do you skip the check from json.Marshal and just return the []byte 
>> directly whatever they are?
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/554c8ca8-2bca-4321-9ee5-0524e28422a3%40googlegroups.com.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAG7ytitqTBT7CeGkPgwnm7UpFpNRUqmKzGoqj11OiAHTQu9BGA%40mail.gmail.com.


Re: [go-nuts] Re: [Go2] Reflect

2017-08-07 Thread Gert Cuykens
On Mon, Aug 7, 2017 at 12:03 PM, roger peppe  wrote:
> ISTM that the only thing you're suggesting is to change
> the spelling of "reflect.ValueOf" to "reflect".
>
> I don't understand what semantics you'd expect
>
> fmt.Println("value:", r.Value(int))
>
> to have. What's the parameter to that Value method?
>

Merge ValueOf and TypeOf into one reflect() build in and make the
reflect type transform easier with other types fmt.Println("value:",
int(r.Value))

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] [Go2] Proposal remove function return type brackets

2017-07-24 Thread Gert Cuykens
Valid argument thx

On Sun, Jul 23, 2017 at 7:23 PM, Rémy Oudompheng
 wrote:
> With this proposal, can you tell whether the following function F
> returns one argument (a function) or two arguments (a function and an
> error) :
>
> func F() func(string) []byte, error {
>blah
> }
>
> Rémy.
>
> 2017-07-23 18:18 GMT+02:00 Gert :
>> I personally don't think () is necessary for output types and is only
>> confusing with the function attributes
>>
>> Example
>>
>> func Hello(b string) ([]byte, error) {
>>   
>> }
>>
>> func Hello(b string) []byte, error {
>>   
>> }
>>
>> func Hello(b string) a []byte, b error {
>>   
>> }
>>
>> Feel free to counter argument against the proposal or if already proposed
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.