首页 > 其他分享 >Go - Project structure

Go - Project structure

时间:2024-02-14 12:11:47浏览次数:28  
标签:files project tests layout Project Go main structure

The Go language maintainer has no strong convention about structuring a project in Go. However, one layout has emerged over the years: project-layout (https://github.com/golang-standards/project-layout).


If our project is small enough (only a few files), or if our organization has already created its standard, it may not be worth using or migrating to project-layout. Otherwise, it might be worth considering. Let’s look at this layout and see what the main directories are:
 /cmd—The main source files. The main.go of a foo application should live in /cmd/foo/main.go.
 /internal—Private code that we don’t want others importing for their applications or libraries.
 /pkg—Public code that we want to expose to others.
 /test—Additional external tests and test data. Unit tests in Go live in the same package as the source files. However, public API tests or integration tests, for example, should live in /test.
 /configs—Configuration files.
 /docs—Design and user documents.
 /examples—Examples for our application and/or a public library.
 /api—API contract files (Swagger, Protocol Buffers, etc.).
 /web—Web application-specific assets (static files, etc.).
 /build—Packaging and continuous integration (CI) files.
 /scripts—Scripts for analysis, installation, and so on.
 /vendor—Application dependencies (for example, Go modules dependencies).
There’s no /src directory like in some other languages. The rationale is that /src is too generic; hence, this layout favors directories such as /cmd, /internal, or /pkg.

 

标签:files,project,tests,layout,Project,Go,main,structure
From: https://www.cnblogs.com/zhangzhihui/p/18015121

相关文章

  • Go 100 mistakes - #11: Not using the functional options pattern
      Here,WithPortreturnsaclosure.Aclosureisananonymousfunctionthatreferences variablesfromoutsideitsbody;inthiscase,theportvariable.Theclosurerespectsthe Optiontypeandimplementstheport-validationlogic.Eachconfigfieldr......
  • 8小时golang速成(五)Golang高阶 1、goroutine
    1、goroutine 协程并发协程:coroutine。也叫轻量级线程。与传统的系统级线程和进程相比,协程最大的优势在于“轻量级”。可以轻松创建上万个而不会导致系统资源衰竭。而线程和进程通常很难超过1万个。这也是协程别称“轻量级线程”的原因。一个线程中可以有任意多个......
  • Go 100 mistakes - #10: Not being aware of the possible problems with type embedd
     Becausethemutexisembedded,wecandirectlyaccesstheLockandUnlockmethods fromtheireceiver.Wementionedthatsuchanexampleisawrongusageoftypeembedding.What’s thereasonforthis?Sincesync.Mutexisanembeddedtype,theLockand......
  • 8小时速成golang(四)反射reflect 和 结构体标签
    编程语言中反射的概念在计算机科学领域,反射是指一类应用,它们能够自描述和自控制。也就是说,这类应用通过采用某种机制来实现对自己行为的描述(self-representation)和监测(examination),并能根据自身行为的状态和结果,调整或修改应用所描述行为的状态和相关的语义。每种语言的反射模......
  • Django+nginx+uwsgi
    在云服务器上搭建web网站服务器的系统是CentOS7.6一、安装Python3.8.181、安装gccyuminstallgcc-y2、安装编译python的依赖yuminstallzlibzlib-devel-yyuminstallbzip2bzip2-devel-yyuminstallncursesncurses-devel-yyuminstallreadlinereadline-d......
  • Go 100 mistakes - #9: Being confused about when to use generics
    Go1.18addsgenericstothelanguage.Inanutshell,thisallowswritingcodewithtypes thatcanbespecifiedlaterandinstantiatedwhenneeded. Onelastthingtonoteabouttypeparametersisthattheycan’tbeusedwith methodarguments,onlywith......
  • Django 模版变量
    Django模版变量Django模版语言的语法主要分为以下四个部分:变量标签过滤器注释一、模版变量1)变量的命名规范Django对于模版变量的命名规范没有太多的要求,可以使用任何字母、数字和下划线的组合来命名,且必须以字母或下划线开头,但是变量名称中不能有空格或者标点符号。2......
  • WGOI R1 真夏飞焰 题解.18014664
    【题目大意】给定序列\(a\),我们定义序列\(a,b\)是「\(k\)相似」的,当且仅当对于\(a\)中每一个四元组\((l_1,r_1,l_2,r_2)\),若满足\(r_1-l_1+1=r_2-l_2+1\lek,l_2=r_1+1,a_{l_1\ldotsr_1}=a_{l_2\ldotsr_2}\),则有\(b_{l_1\ldotsr_1}=b_{l_2\ldot......
  • Go 100 mistakes - #8: any says nothing
    WithGo1.18,thepredeclaredtypeanybecameanaliasforanempty interface;hence,alltheinterface{}occurrencescanbereplacedbyany. IffuturedevelopersneedtousetheStore struct,theywillprobablyhavetodigintothedocumentationorre......
  • Go 100 mistakes - #7: Returning interfaces
       Allinall,inmostcases,weshouldn’treturninterfacesbutconcreteimplementa-tions.Otherwise,itcanmakeourdesignmorecomplexduetopackagedependencies andcanrestrictflexibilitybecausealltheclientswouldhavetorelyonthesam......