<p>I am working on a re-write of a simple chat bot I have and was working on breaking up the functions into several files.</p>
<p>I am trying to figure out how I can have a value and function be global across all the functions without importing them all in each and every go file.</p>
<p>structure is as follows.</p>
<pre><code>main.go
logging/
logging.go
connector/
console.go
discord.go
parsers/
text.go
img.go
config/
config.go
</code></pre>
<p>and so on.</p>
<p>the connector are packages "<path_to_folder>/connector"</p>
<p>Being new to golang I am still working on learning this stuff.</p>
<hr/>**评论:**<br/><br/>jaffee1: <pre><p>This: <a href="https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1" rel="nofollow">https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1</a> is a good read for package layout tips. The TLDR is break up your subpackages by dependency and keep the main structures and interfaces for whatever you're doing at the top level. main.go almost always goes in a subpackage under a cmd/ directory. I like to develop everything as a library and have my main.go be about 4 lines just calling into it.</p></pre>parkervcp: <pre><p>Thank you.</p></pre>hell_0n_wheel: <pre><blockquote>
<p>trying to figure something out</p>
</blockquote>
<p>No, looks like you're posting on Reddit.</p>
<p>What you're trying isn't possible. You need to import a symbol in order to use it in a module.</p>
<p>I'd posit you've got a problem you're trying to solve with said "global"... and there's likely a better solution. But you aren't telling us your problem.</p></pre>parkervcp: <pre><p>I am not a coder by any means but I have enough to get by. Working on my bot has gotten me further along. With the 2 responses I have gotten so far the other one is what I was looking at.</p>
<p>Yes I get that I am asking on reddit. I was also hoping for a bit more formative help here. Not a snarky response. I have been reading all I could online to try to figure it out. You have no idea how long I have actually spent on this.</p></pre>hell_0n_wheel: <pre><p>You're asking something so fundamental, I get the impression you haven't spent any time with the materials that so many have worked to help people like you.</p>
<blockquote>
<p>I have been reading all I could online to try to figure it out.</p>
</blockquote>
<p>"trying to figure something out" means you're experimenting with your own code, or with someone else's code, or reading the source, scouring the language and library documentation, doing a heck of a lot more than tooling around with google.</p>
<p>Poking around online is only going to lead you down rabbit holes, and you won't even know if you're solving the right problem. And here you are. I'm pretty sure you're in the wrong rabbit hole. </p>
<p>And unless you share your problem with us, we'll never be able to help you. You might get unstuck here, but that's no guarantee you're headed somewhere that won't get you even more stuck.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传