Hi,
I am looking for a single method interface type in the stdlib with a method that just returns []byte. Any suggestions?
评论:
DenzelM:
metakeule:What are you hoping to accomplish, exactly?
DenzelM:What are you hoping to accomplish with your question? :-D
radovskyb:To understand your motivation, your intent. It's not exactly a question that I've ever come across, or a need. Mainly because there's usually a reason for conforming to an interface, i.e., not simply blind conformance. And I'm assuming, you have a reason... unless you don't. In other words, I'm looking for the root cause of your question. Make sense?
DenzelM:Running an inspection library I wrote in Go, I have found at least these examples. I'm sure I could find more that return aliases for
[]byte
if I checked, but here's a few to name some.Package: httputil Interface: BufferPool Method: func Get() []byte Package: http Interface: http2headersOrContinuation Method: func HeaderBlockFragment() []byte Package: macho Interface: Load Method: func Raw() []byte Package: cipher Interface: AEAD Method: func Seal(dst, nonce, plaintext, additionalData []byte) []byte Package: tls Interface: macFunction Method: func MAC(digestBuf, seq, header, data, extra []byte) []byte Package: tls Interface: constantTimeHash Method: func ConstantTimeSum(b []byte) []byte Package: tls Interface: handshakeMessage Method: func marshal() []byte Package: hash Interface: Hash Method: func Sum(b []byte) []byte
Edit: I've now included the package names for you to have a look if you'd like.
Edit 2: I actually just realized you asked for a single method interface, so the above probably are incorrect for that question.
Here are the single method ones from the above:
Package http: Interface: http2headersOrContinuation Method: func HeaderBlockFragment() []byte Package tls: Interface: constantTimeHash Method: func ConstantTimeSum(b []byte) []byte Package macho: Interface: Load Method: func Raw() []byte
Edit 3: The only single method interface out of the above that doesn't implement any other interfaces is the
Load
from themacho
package one.
radovskyb:That's pretty cool, is your tool open-source?
DenzelM:Sure: https://github.com/radovskyb/inspect.
I just modified the example here to get the results: https://github.com/radovskyb/inspect/tree/master/example/extract_all_interfaces.
Now if only I could remember how to format better on reddit xD
Edit: The tool is quite simple at the moment and haven't really worked on it in a while, but I'm sure I'll slowly add to it over time like I have been once in a great while :P
radovskyb:That's sweet, thanks for sharing! It'd be awesome to turn it into a cmdline tool that could construct queries that match patterns. Then we could run these type of queries as a one-liner; making Inspect a great compliment to Go Guru.
I'm not suggesting you do this, per se, since it would be a lot of work and I'm sure you have your hands full. I'm just thinking out loud.
metakeule:I'm not the busiest person lately so that isn't much of a problem :P
If I or someone else was going to turn it into a cmd line tool rather than just a library, I might consider first rewriting some of it to make it a bit better (it's not too bad at the moment I suppose), but then again, could be a fun idea :P
I hoped for a more general one like fmt.Stringer. debug/macho looks like a very specialized lib, seeing it for the first time.. ;-) But thanks anyway.
