duannuan0074 2019-04-06 06:45
浏览 39

如何从某个应用程序目录导入所有子目录? [重复]

This question already has an answer here:

I am creating a http server with Golang. (I have a Php dev background.) In the internal/app/model I plan on making several packages with artificial logic and I would wish to load all the sub-directories of the model folder in main.go.

I have following folder structure:

[project folder]
\_cmd
     \_main.go
.
.
.
\_internal
          \_app
               \_model
                      \_article
                      \_product

I have tried something in this sense without success:

import (
    "[project_folder]/[project]/internal/app/model/*"
)
</div>
  • 写回答

1条回答 默认 最新

  • duanniesui6391 2019-04-06 06:53
    关注

    You would either:

    • need to place project_folder in $GOPATH/src (as in here): the old way
    • use a go mod init project_folder in order to declare a module named project_folder: the new way, with go modules. (use set GO111MODULE=on or export GO111MODULE=on)

    In the latter case, your project_folder can be anywhere: no more GOPATH.

    评论

报告相同问题?

悬赏问题

  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义