<p>Hi, </p>
<p>I am looking for a single method interface type in the stdlib with a method that just returns []byte. Any suggestions?</p>
<hr/>**评论:**<br/><br/>DenzelM: <pre><p>What are you hoping to accomplish, exactly?</p></pre>metakeule: <pre><p>What are you hoping to accomplish with your question? :-D</p></pre>DenzelM: <pre><p>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?</p></pre>radovskyb: <pre><p>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 <code>[]byte</code> if I checked, but here's a few to name some.</p>
<pre><code>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
</code></pre>
<p>Edit: I've now included the package names for you to have a look if you'd like.</p>
<p>Edit 2: I actually just realized you asked for a single method interface, so the above probably are incorrect for that question.</p>
<p>Here are the single method ones from the above:</p>
<pre><code>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
</code></pre>
<p>Edit 3: The only single method interface out of the above that doesn't implement any other interfaces is the <code>Load</code> from the <code>macho</code> package one.</p></pre>DenzelM: <pre><p>That's pretty cool, is your tool open-source?</p></pre>radovskyb: <pre><p>Sure: <a href="https://github.com/radovskyb/inspect" rel="nofollow">https://github.com/radovskyb/inspect</a>.</p>
<p>I just modified the example here to get the results: <a href="https://github.com/radovskyb/inspect/tree/master/example/extract_all_interfaces" rel="nofollow">https://github.com/radovskyb/inspect/tree/master/example/extract_all_interfaces</a>.</p>
<p>Now if only I could remember how to format better on reddit xD</p>
<p>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</p></pre>DenzelM: <pre><p>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 <em>Inspect</em> a great compliment to <em>Go Guru</em>.</p>
<p>I'm not suggesting <em>you</em> 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.</p></pre>radovskyb: <pre><p>I'm not the busiest person lately so that isn't much of a problem :P</p>
<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</p></pre>metakeule: <pre><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.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传