douqianke7467
douqianke7467
2017-12-13 08:48

Go项目结构-最佳做法

已采纳

I need to create GO project (first time) for production, I searched on web for best practices and found the following

https://github.com/golang-standards/project-layout

For this I've two main questions.

  1. I see that most of go projects logic is inside the main function, but in case I need some utils folder with files there, where should I put it ? I don't want that the main function will be mass of 500 or more lines of code

  2. In our company the projects should be build like following

    myproj
      |-src
        |-cmd
        |  |-main.go
        |-utils
        |-vendor
    

Our company project build as above structure i.e. the project files is under the src folder, is it right? (can we have issue in the future with this structure type).

I was able to compile this project in our landscape but since everything is under src I'm not sure.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douzangdang2225 douzangdang2225 4年前

    based on https://github.com/anacrolix/torrent

    GOPATH
      |-src
        |-projectA
          |-cmd (of projectA)
            |-cmdA
              |-main.go
            |-cmdB
              |-main.go
          |-vendor
          |-pkg lib
          |-pkg libB
        |-projectB
        ...
    
    点赞 评论 复制链接分享
  • doulingna9420 doulingna9420 4年前

    Following is go project structure I have used for go projects

    my-project
         |-> api
         |-> api_test
         |-> controllers
         |-> controllers_test
         |-> models
         |-> routes
         |-> server
         |-> vendor
         |main.go
         |Readme.txt    
    

    Find more about go project structure

    https://golang.org/doc/code.html

    点赞 评论 复制链接分享

相关推荐