FAQ
Hello Everyone,

I am on a workflow system and trying to implement the dynamic logic similar
to the hash function in Crypto library. I could figure out how the
functions are being handled but unable to make sense of package import.

The crypto seems to work in following way.

    - sha3/register.go
    <https://github.com/golang/crypto/blob/master/sha3/register.go> registers
    hash function new224 with crypto

crypto.RegisterHash(crypto.SHA3_224, New224)

    - The registered functions are added to hash map in crypto.go
    <https://golang.org/src/crypto/crypto.go>
    - Hashes are generated using one of the registered functions in map

func New224() hash.Hash { return &state{rate: 144, outputLen: 28, dsbyte:
0x06} }

  While i understand this bit, i can't figure out how package imports are
working.

Crypto.go has no reference to the package sha3. How does runtime know
structure of 'state' or any package level dependancies that function has?

when you pass function as parameter, does it carry package dependancies
with itself?


Hope my ask is not very vague :)

Thanks,
Amol


--
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

  • James Bardin at Aug 4, 2015 at 5:07 pm

    On Tuesday, August 4, 2015 at 7:22:46 AM UTC-4, Amol Umbarkar wrote:

    While i understand this bit, i can't figure out how package imports are
    working.

    Crypto.go has no reference to the package sha3. How does runtime know
    structure of 'state' or any package level dependancies that function has?
    The crypto package doesn't need to know anything about the underlying type
    of the hash, the registered function returns an interface (hash.Hash). The

    when you pass function as parameter, does it carry package dependancies
    with itself?
    I'm not sure how to answer that. If your code is passing a function from a
    package, you are already importing that package into your code. You can't
    "inject" a dependency into another package.

    If you want another example to look at, the "image" package using the same
    type of registration for different
    formats: http://tgolang.org/pkg/image/#example_

    --
    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.
  • Amol Umbarkar at Aug 4, 2015 at 5:44 pm
    Thanks, James.
    I will look into image package.

    Amol
    On Tue, Aug 4, 2015 at 10:37 PM, James Bardin wrote:


    On Tuesday, August 4, 2015 at 7:22:46 AM UTC-4, Amol Umbarkar wrote:


    While i understand this bit, i can't figure out how package imports are
    working.

    Crypto.go has no reference to the package sha3. How does runtime know
    structure of 'state' or any package level dependancies that function has?
    The crypto package doesn't need to know anything about the underlying type
    of the hash, the registered function returns an interface (hash.Hash). The

    when you pass function as parameter, does it carry package dependancies
    with itself?
    I'm not sure how to answer that. If your code is passing a function from a
    package, you are already importing that package into your code. You can't
    "inject" a dependency into another package.

    If you want another example to look at, the "image" package using the same
    type of registration for different formats:
    http://tgolang.org/pkg/image/#example_

    --
    You received this message because you are subscribed to a topic in the
    Google Groups "golang-nuts" group.
    To unsubscribe from this topic, visit
    https://groups.google.com/d/topic/golang-nuts/vFDpyv2VKr0/unsubscribe.
    To unsubscribe from this group and all its topics, send an email to
    golang-nuts+unsubscribe@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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 4, '15 at 11:22a
activeAug 4, '15 at 5:44p
posts3
users2
websitegolang.org

2 users in discussion

Amol Umbarkar: 2 posts James Bardin: 1 post

People

Translate

site design / logo © 2022 Grokbase