dongshuzhuo5659 2018-08-08 12:49
浏览 53

游戏服务器的Golang目录组织[关闭]

I making game server in golang and i have such entities as Player and Skill. Player can use his skills whilst Skill could affect players. Player file and skills files live in logic directory(and in package logic). I want to move skills files into separate directory skills. I could not place it in logic directory and keep logic package for them cause golang not allowed it. Also i could not make package skills and place the directory on same level as logic directory because i got:

import cycle not allowed

package main
imports projname/server/logic
imports projname/server/skills
imports projname/server/logic

What's wrong with my project architecture and how could i fix it?

  • 写回答

1条回答 默认 最新

  • dongpu3347 2018-08-08 13:12
    关注

    your main package imports logic package. It also imports skills which also imports logic. Go is very strict about not allowing import cycles.

    • If you are forced to import logic in main, because you are using some type declared in logic to init a function or handler in skills. You could, probably declare that type in skills rather than in logic.

    • If you are importing logic because some function from logic is being used in main. You could write a wrapper in skills (with a new function), which calls the function from logic(which is already being called).

    Either way you have to try and remove the import of logic in main.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型