<p>I wrote a structure like this --> <a href="https://imgur.com/IULKNol" rel="nofollow">https://imgur.com/IULKNol</a>
But there are some deficiencies. </p>
<p>So how can i assignment to variable? Or How do I do this? --> <a href="https://imgur.com/L9R4KVX" rel="nofollow">https://imgur.com/L9R4KVX</a>
Thanks in advance.</p>
<hr/>**评论:**<br/><br/>tiberiousr: <pre><p>Write NewRuleSet so that it returns a struct that you can attach methods to.</p></pre>ripeassmango: <pre><p>your issue is that NewRuleSet does not return a variable</p>
<p>try this</p>
<pre><code>func NewRuleSet() ([]string, []string) {
return []string{}, []string{}
}
</code></pre>
<p>then in your main/test function</p>
<pre><code>func main() {
depp, conf := NewRuleSet()
}
</code></pre>
<p>in Go, like many other languages, you need to explicitly declare what a function returns.</p>
<p>edit:</p>
<p>also, you will need to modify your AddDep and AddConflict to take in the string array as an argument</p></pre>nagai: <pre><pre><code>type RuleSet struct {
depp []string
conf []string
}
func NewRuleSet() *RuleSet {
return &RuleSet{[]string{}, []string{}}
}
func (r *RuleSet) IsCoherent() {
...
}
</code></pre></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传