FAQ
I have added a function, "SetSalt", to an interface to can re-use the code
of other function:
   https://github.com/kless/crypt/blob/master/crypt.go#L42

What I do, is to get the md5_crypt, for then to set a different prefix:
   https://github.com/kless/crypt/blob/master/apr1_crypt/apr1_crypt.go#L28

where SetSalt in md5_crypt, sets the new values:
   https://github.com/kless/crypt/blob/master/md5_crypt/md5_crypt.go#L159

var md5Crypt = md5_crypt.New()


func init() {
  md5Crypt.SetSalt(&common.Salt{
   MagicPrefix: []byte(MagicPrefix),
  })
}


But when I set directly the entire struct, "c.Salt=salt", it is not copying
it like I was expecting, since the MagiPrefix follows being what was in md5:

func (c crypter) SetSalt(salt *common.Salt) {

  c.Salt = salt

}


The only way is set it thus:

c.Salt.MagicPrefix = salt.MagicPrefix


===

Now well, if I can set it the next code which is similar (with the exceptionofthe interface),
why is failling in upper code?

* * *
package main

import "fmt"

type foo struct {
     s string
     i int
}

type bar struct{ Foo *foo }

var foo1 = &foo{
     "b",
     500,
}

func main() {
     _bar := bar{
         &foo{
             "a",
             10,
         },
     }
     fmt.Println(_bar.Foo)

     _bar.Foo = foo1
     fmt.Println(_bar.Foo)
}
* * *
&{a 10}
&{b 500}

--
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/groups/opt_out.

Search Discussions

  • Chris dollin at Jul 1, 2013 at 10:06 am

    On 1 July 2013 10:49, Archos wrote:
    But when I set directly the entire struct, "c.Salt=salt", it is not
    copying it like I was expecting, since the MagiPrefix follows being what
    was in md5:

    func (c crypter) SetSalt(salt *common.Salt) {

    c.Salt = salt

    }

    You're setting the Salt field of the function-local variable c. This
    won't change the receiver in your call to SetSalt (wherever that
    is).

    Likely you want

       func (c *crypter) SetSalt( ...

    Chris

    --
    Chris "allusive" Dollin

    --
    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/groups/opt_out.
  • Archos at Jul 1, 2013 at 10:16 am
    I had tried that, but I got the next error:
         crypter does not implement crypt.Crypter (Cost method requires pointer
    receiver)

    After of seing your message, I have fixed it using:

    func New() crypt.Crypter {
         return &crypter{}
    }

    Thanks, Chris

    El lunes, 1 de julio de 2013 11:06:20 UTC+1, chris dollin escribió:
    On 1 July 2013 10:49, Archos <raul...@sent.com <javascript:>> wrote:


    But when I set directly the entire struct, "c.Salt=salt", it is not
    copying it like I was expecting, since the MagiPrefix follows being what
    was in md5:

    func (c crypter) SetSalt(salt *common.Salt) {

    c.Salt = salt

    }

    You're setting the Salt field of the function-local variable c. This
    won't change the receiver in your call to SetSalt (wherever that
    is).

    Likely you want

    func (c *crypter) SetSalt( ...

    Chris

    --
    Chris "allusive" Dollin
    --
    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/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 1, '13 at 9:49a
activeJul 1, '13 at 10:16a
posts3
users2
websitegolang.org

2 users in discussion

Archos: 2 posts Chris dollin: 1 post

People

Translate

site design / logo © 2022 Grokbase