Go question about HTTP Header
John Arbash Meinel
john at arbash-meinel.com
Tue Dec 11 12:40:46 UTC 2012
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I happened to look at the implementation of net/http Header here:
http://golang.org/src/pkg/net/http/header.go?s=436:474#L10
I realize that it works, because map is a "pointer" type (the actual
map references the underlying storage). So even though
texproto.MIMEHeader(h) is actually creating a new map object, they
both reference the same real hash map, so adding data to it updates
the same storage.
I'm guessing they wrote that code because they wanted to use
textproto's multipart mime handling, but wanted to have a
net/http.Header object, rather than also having you import
net/textproto directly.
Is there a way to do that sort of thing without having to curry all
the functions? For example, could you do:
type Header ??? {
textproto.MIMEHeader
}
I don't think this works:
type Header textproto.MIMEHeader
because that actually gives you a whole new namespace of functions,
and doesn't inherit any methods from MIMEHeader. (it might not even be
possible, as 'type' may only allow basic types and 'struct/interface'
to follow the name.)
It just seems... odd to do it this way, and I'm trying to think if
there are cleaner ways to do something similar.
How big is the 'map' object in memory as well? (The pointer type, not
the underlying hash map.) I know slice is like 3 words (length,
capacity and pointer?). Is map roughly the same?
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Cygwin)
Comment: Using GnuPG with undefined - http://www.enigmail.net/
iEYEARECAAYFAlDHKc4ACgkQJdeBCYSNAANgzwCfdiPgaiuaaznDHAU5bnxxx7aP
ruwAnjsieOPwtd4oAvC7ZEqp3iGg9u+X
=lIwZ
-----END PGP SIGNATURE-----
More information about the Juju-dev
mailing list