trying to figure something out

blov · · 610 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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 &#34;&lt;path_to_folder&gt;/connector&#34;</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&#39;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&#39;re posting on Reddit.</p> <p>What you&#39;re trying isn&#39;t possible. You need to import a symbol in order to use it in a module.</p> <p>I&#39;d posit you&#39;ve got a problem you&#39;re trying to solve with said &#34;global&#34;... and there&#39;s likely a better solution. But you aren&#39;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&#39;re asking something so fundamental, I get the impression you haven&#39;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>&#34;trying to figure something out&#34; means you&#39;re experimenting with your own code, or with someone else&#39;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&#39;t even know if you&#39;re solving the right problem. And here you are. I&#39;m pretty sure you&#39;re in the wrong rabbit hole. </p> <p>And unless you share your problem with us, we&#39;ll never be able to help you. You might get unstuck here, but that&#39;s no guarantee you&#39;re headed somewhere that won&#39;t get you even more stuck.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

610 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传