douluo1330 2012-05-28 19:23
浏览 13
已采纳

程序必须访问包中的全局变量

I've a package with global variables related to a file open (*os.File), and its logger associated. By another side, I'll build several commands that are going to use that package and I want not open the file to set it as logger every time I run a command.

So, the first program to run will set the global variables, and here is my question:

  • Do the next programs to use the package can access to those global variables without problem? It could be created a command with a flag to initialize those values before of be used by another programs, and another flag to finish it (unset the global variables in the package).

  • If that is not possible, which is the best option to avoid such IO-bound? To use a server in Unix sockets?

  • 写回答

1条回答 默认 最新

  • duandoucou7200 2012-05-28 19:38
    关注

    Assuming by 'program' you actually mean 'process', the answer is no.

    If you want to share a (customized perhaps) logging functionality between processes then I would consider a daemon-like (Go doesn't yet AFAIK support writing true daemons) process/server and any kind of IPC you see handy.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?