Go Modules - naming convention of directories and packages












-1














I understand Go Modules are yet an experimental opt-in feature, and perhaps because of that, I cannot find clear guidance on how to name directories and packages.

In these Package names in Go Blog post and Package name in Effective Go, they talk about that the directory should match the package name - but I wasn't certain if Go Modules would follow the same pattern.



If I want to bundle my business logic in package business with many files, is it reasonable to create subdirectory validators/ and keep the same package name package business?



someDir
├── business
│   ├── businessA.go // package business
│   ├── businessB.go // package business
│   ├── businessC.go // package business
│   ├── go.mod // module example.com/business
│   └── validators
│   ├── businessValidatorX.go // package business, or validators?
│   ├── businessValidatorY.go // package business, or validators?
│   └── businessValidatorZ.go // package business, or validators?
└── main.go




Approach 1.



If I were to go with the same package name:



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

// both imports would be combined to the same `business` package?
func main() {
b := business.SomeLogic()
business.ValidateX(b) // validator from the same package
}


This looks to be prone to export conflict - but it is simple.



Approach 2.



If the validators/ path maps to package validators, the consuming code would look like the below instead.



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

func main() {
b := business.SomeLogic()
validators.ValidateX(b) // validator from a separate package
}




How should I manage a package consisted of many files? Is the Approach 1. reasonable, although it somewhat contradicts from the blog post and doc above?

Or should I go with Approach 2., complying with the convention, and add an alias as necessary in main.go?










share|improve this question






















  • Nothing in regard to naming packages has changed with the introduction of modules. Your idea of approach 1 is totally wrong and does not work: Packages cannot be "combined".
    – Volker
    Nov 21 at 4:47










  • Thanks for the input, but defining a single package with multiple files should be conventional (how there are businessA/B/C to orchestrate package business). Approach A was merely to structure files using extra subdirectory. Does that mean I’m better off putting all files in a single directory and not have subdirectory at all, if I were to achieve something along the line with Approach 1?
    – Ryota
    Nov 21 at 8:33






  • 1




    You have to read How to Write Go Code. There is one and only one way to write Go code. A package is one folder and may contain one or more source code files. Approach 1 is 100% undoabe in Go. Forget about that now and forever. It is one folder == one package. And there is no opinion or desire to have here.
    – Volker
    Nov 21 at 9:10










  • Thanks for the clear answer, it seemed as if the Go Module introduced slight flexibility with it, but clearly I was reading it wrong. May I shamelessly ask - would you mind posting it as an answer, so that I can close this question? With the Go Modules in picture, I had difficulty finding the right doc, and this may still be useful for newbies like myself.
    – Ryota
    Nov 21 at 11:06










  • @Volker - I played a bit more and posted an answer with some information along the line with your comment. It may be an over-complication, but I find having a clear answer with some reference helps, if by any chance someone ends up finding this post. Thanks for your input anyways.
    – Ryota
    Nov 22 at 23:04


















-1














I understand Go Modules are yet an experimental opt-in feature, and perhaps because of that, I cannot find clear guidance on how to name directories and packages.

In these Package names in Go Blog post and Package name in Effective Go, they talk about that the directory should match the package name - but I wasn't certain if Go Modules would follow the same pattern.



If I want to bundle my business logic in package business with many files, is it reasonable to create subdirectory validators/ and keep the same package name package business?



someDir
├── business
│   ├── businessA.go // package business
│   ├── businessB.go // package business
│   ├── businessC.go // package business
│   ├── go.mod // module example.com/business
│   └── validators
│   ├── businessValidatorX.go // package business, or validators?
│   ├── businessValidatorY.go // package business, or validators?
│   └── businessValidatorZ.go // package business, or validators?
└── main.go




Approach 1.



If I were to go with the same package name:



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

// both imports would be combined to the same `business` package?
func main() {
b := business.SomeLogic()
business.ValidateX(b) // validator from the same package
}


This looks to be prone to export conflict - but it is simple.



Approach 2.



If the validators/ path maps to package validators, the consuming code would look like the below instead.



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

func main() {
b := business.SomeLogic()
validators.ValidateX(b) // validator from a separate package
}




How should I manage a package consisted of many files? Is the Approach 1. reasonable, although it somewhat contradicts from the blog post and doc above?

Or should I go with Approach 2., complying with the convention, and add an alias as necessary in main.go?










share|improve this question






















  • Nothing in regard to naming packages has changed with the introduction of modules. Your idea of approach 1 is totally wrong and does not work: Packages cannot be "combined".
    – Volker
    Nov 21 at 4:47










  • Thanks for the input, but defining a single package with multiple files should be conventional (how there are businessA/B/C to orchestrate package business). Approach A was merely to structure files using extra subdirectory. Does that mean I’m better off putting all files in a single directory and not have subdirectory at all, if I were to achieve something along the line with Approach 1?
    – Ryota
    Nov 21 at 8:33






  • 1




    You have to read How to Write Go Code. There is one and only one way to write Go code. A package is one folder and may contain one or more source code files. Approach 1 is 100% undoabe in Go. Forget about that now and forever. It is one folder == one package. And there is no opinion or desire to have here.
    – Volker
    Nov 21 at 9:10










  • Thanks for the clear answer, it seemed as if the Go Module introduced slight flexibility with it, but clearly I was reading it wrong. May I shamelessly ask - would you mind posting it as an answer, so that I can close this question? With the Go Modules in picture, I had difficulty finding the right doc, and this may still be useful for newbies like myself.
    – Ryota
    Nov 21 at 11:06










  • @Volker - I played a bit more and posted an answer with some information along the line with your comment. It may be an over-complication, but I find having a clear answer with some reference helps, if by any chance someone ends up finding this post. Thanks for your input anyways.
    – Ryota
    Nov 22 at 23:04
















-1












-1








-1







I understand Go Modules are yet an experimental opt-in feature, and perhaps because of that, I cannot find clear guidance on how to name directories and packages.

In these Package names in Go Blog post and Package name in Effective Go, they talk about that the directory should match the package name - but I wasn't certain if Go Modules would follow the same pattern.



If I want to bundle my business logic in package business with many files, is it reasonable to create subdirectory validators/ and keep the same package name package business?



someDir
├── business
│   ├── businessA.go // package business
│   ├── businessB.go // package business
│   ├── businessC.go // package business
│   ├── go.mod // module example.com/business
│   └── validators
│   ├── businessValidatorX.go // package business, or validators?
│   ├── businessValidatorY.go // package business, or validators?
│   └── businessValidatorZ.go // package business, or validators?
└── main.go




Approach 1.



If I were to go with the same package name:



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

// both imports would be combined to the same `business` package?
func main() {
b := business.SomeLogic()
business.ValidateX(b) // validator from the same package
}


This looks to be prone to export conflict - but it is simple.



Approach 2.



If the validators/ path maps to package validators, the consuming code would look like the below instead.



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

func main() {
b := business.SomeLogic()
validators.ValidateX(b) // validator from a separate package
}




How should I manage a package consisted of many files? Is the Approach 1. reasonable, although it somewhat contradicts from the blog post and doc above?

Or should I go with Approach 2., complying with the convention, and add an alias as necessary in main.go?










share|improve this question













I understand Go Modules are yet an experimental opt-in feature, and perhaps because of that, I cannot find clear guidance on how to name directories and packages.

In these Package names in Go Blog post and Package name in Effective Go, they talk about that the directory should match the package name - but I wasn't certain if Go Modules would follow the same pattern.



If I want to bundle my business logic in package business with many files, is it reasonable to create subdirectory validators/ and keep the same package name package business?



someDir
├── business
│   ├── businessA.go // package business
│   ├── businessB.go // package business
│   ├── businessC.go // package business
│   ├── go.mod // module example.com/business
│   └── validators
│   ├── businessValidatorX.go // package business, or validators?
│   ├── businessValidatorY.go // package business, or validators?
│   └── businessValidatorZ.go // package business, or validators?
└── main.go




Approach 1.



If I were to go with the same package name:



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

// both imports would be combined to the same `business` package?
func main() {
b := business.SomeLogic()
business.ValidateX(b) // validator from the same package
}


This looks to be prone to export conflict - but it is simple.



Approach 2.



If the validators/ path maps to package validators, the consuming code would look like the below instead.



// main.go
package main

import (
"example.com/business"
"example.com/business/validators"
)

func main() {
b := business.SomeLogic()
validators.ValidateX(b) // validator from a separate package
}




How should I manage a package consisted of many files? Is the Approach 1. reasonable, although it somewhat contradicts from the blog post and doc above?

Or should I go with Approach 2., complying with the convention, and add an alias as necessary in main.go?







go module go-modules






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 1:40









Ryota

898




898












  • Nothing in regard to naming packages has changed with the introduction of modules. Your idea of approach 1 is totally wrong and does not work: Packages cannot be "combined".
    – Volker
    Nov 21 at 4:47










  • Thanks for the input, but defining a single package with multiple files should be conventional (how there are businessA/B/C to orchestrate package business). Approach A was merely to structure files using extra subdirectory. Does that mean I’m better off putting all files in a single directory and not have subdirectory at all, if I were to achieve something along the line with Approach 1?
    – Ryota
    Nov 21 at 8:33






  • 1




    You have to read How to Write Go Code. There is one and only one way to write Go code. A package is one folder and may contain one or more source code files. Approach 1 is 100% undoabe in Go. Forget about that now and forever. It is one folder == one package. And there is no opinion or desire to have here.
    – Volker
    Nov 21 at 9:10










  • Thanks for the clear answer, it seemed as if the Go Module introduced slight flexibility with it, but clearly I was reading it wrong. May I shamelessly ask - would you mind posting it as an answer, so that I can close this question? With the Go Modules in picture, I had difficulty finding the right doc, and this may still be useful for newbies like myself.
    – Ryota
    Nov 21 at 11:06










  • @Volker - I played a bit more and posted an answer with some information along the line with your comment. It may be an over-complication, but I find having a clear answer with some reference helps, if by any chance someone ends up finding this post. Thanks for your input anyways.
    – Ryota
    Nov 22 at 23:04




















  • Nothing in regard to naming packages has changed with the introduction of modules. Your idea of approach 1 is totally wrong and does not work: Packages cannot be "combined".
    – Volker
    Nov 21 at 4:47










  • Thanks for the input, but defining a single package with multiple files should be conventional (how there are businessA/B/C to orchestrate package business). Approach A was merely to structure files using extra subdirectory. Does that mean I’m better off putting all files in a single directory and not have subdirectory at all, if I were to achieve something along the line with Approach 1?
    – Ryota
    Nov 21 at 8:33






  • 1




    You have to read How to Write Go Code. There is one and only one way to write Go code. A package is one folder and may contain one or more source code files. Approach 1 is 100% undoabe in Go. Forget about that now and forever. It is one folder == one package. And there is no opinion or desire to have here.
    – Volker
    Nov 21 at 9:10










  • Thanks for the clear answer, it seemed as if the Go Module introduced slight flexibility with it, but clearly I was reading it wrong. May I shamelessly ask - would you mind posting it as an answer, so that I can close this question? With the Go Modules in picture, I had difficulty finding the right doc, and this may still be useful for newbies like myself.
    – Ryota
    Nov 21 at 11:06










  • @Volker - I played a bit more and posted an answer with some information along the line with your comment. It may be an over-complication, but I find having a clear answer with some reference helps, if by any chance someone ends up finding this post. Thanks for your input anyways.
    – Ryota
    Nov 22 at 23:04


















Nothing in regard to naming packages has changed with the introduction of modules. Your idea of approach 1 is totally wrong and does not work: Packages cannot be "combined".
– Volker
Nov 21 at 4:47




Nothing in regard to naming packages has changed with the introduction of modules. Your idea of approach 1 is totally wrong and does not work: Packages cannot be "combined".
– Volker
Nov 21 at 4:47












Thanks for the input, but defining a single package with multiple files should be conventional (how there are businessA/B/C to orchestrate package business). Approach A was merely to structure files using extra subdirectory. Does that mean I’m better off putting all files in a single directory and not have subdirectory at all, if I were to achieve something along the line with Approach 1?
– Ryota
Nov 21 at 8:33




Thanks for the input, but defining a single package with multiple files should be conventional (how there are businessA/B/C to orchestrate package business). Approach A was merely to structure files using extra subdirectory. Does that mean I’m better off putting all files in a single directory and not have subdirectory at all, if I were to achieve something along the line with Approach 1?
– Ryota
Nov 21 at 8:33




1




1




You have to read How to Write Go Code. There is one and only one way to write Go code. A package is one folder and may contain one or more source code files. Approach 1 is 100% undoabe in Go. Forget about that now and forever. It is one folder == one package. And there is no opinion or desire to have here.
– Volker
Nov 21 at 9:10




You have to read How to Write Go Code. There is one and only one way to write Go code. A package is one folder and may contain one or more source code files. Approach 1 is 100% undoabe in Go. Forget about that now and forever. It is one folder == one package. And there is no opinion or desire to have here.
– Volker
Nov 21 at 9:10












Thanks for the clear answer, it seemed as if the Go Module introduced slight flexibility with it, but clearly I was reading it wrong. May I shamelessly ask - would you mind posting it as an answer, so that I can close this question? With the Go Modules in picture, I had difficulty finding the right doc, and this may still be useful for newbies like myself.
– Ryota
Nov 21 at 11:06




Thanks for the clear answer, it seemed as if the Go Module introduced slight flexibility with it, but clearly I was reading it wrong. May I shamelessly ask - would you mind posting it as an answer, so that I can close this question? With the Go Modules in picture, I had difficulty finding the right doc, and this may still be useful for newbies like myself.
– Ryota
Nov 21 at 11:06












@Volker - I played a bit more and posted an answer with some information along the line with your comment. It may be an over-complication, but I find having a clear answer with some reference helps, if by any chance someone ends up finding this post. Thanks for your input anyways.
– Ryota
Nov 22 at 23:04






@Volker - I played a bit more and posted an answer with some information along the line with your comment. It may be an over-complication, but I find having a clear answer with some reference helps, if by any chance someone ends up finding this post. Thanks for your input anyways.
– Ryota
Nov 22 at 23:04














1 Answer
1






active

oldest

votes


















0














Approach 2 is correct.



Being a Go newbie, I had mistakenly thought that Approach 1 was one possible way, as Go does allow having package name different from directory name.



As Volker helped in the comments, Approach 1 is definitely not possible.

You will get a straight compilation error when trying to combine packages.



compilation error



The introduction of Go Modules does not affect the best practices outlined in existing documents, such as:




  • How to Write Go Code

  • Effective Go


As a side note, I also came to know that package name should be singular form.




  • Style guideline for Go packages


So that would leave me with the following structure along with Approach 2:



structure following the convention






share|improve this answer





















  • Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
    – Volker
    Nov 23 at 6:16












  • But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
    – Volker
    Nov 23 at 6:19










  • Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
    – Ryota
    Nov 23 at 9:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404155%2fgo-modules-naming-convention-of-directories-and-packages%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Approach 2 is correct.



Being a Go newbie, I had mistakenly thought that Approach 1 was one possible way, as Go does allow having package name different from directory name.



As Volker helped in the comments, Approach 1 is definitely not possible.

You will get a straight compilation error when trying to combine packages.



compilation error



The introduction of Go Modules does not affect the best practices outlined in existing documents, such as:




  • How to Write Go Code

  • Effective Go


As a side note, I also came to know that package name should be singular form.




  • Style guideline for Go packages


So that would leave me with the following structure along with Approach 2:



structure following the convention






share|improve this answer





















  • Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
    – Volker
    Nov 23 at 6:16












  • But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
    – Volker
    Nov 23 at 6:19










  • Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
    – Ryota
    Nov 23 at 9:59
















0














Approach 2 is correct.



Being a Go newbie, I had mistakenly thought that Approach 1 was one possible way, as Go does allow having package name different from directory name.



As Volker helped in the comments, Approach 1 is definitely not possible.

You will get a straight compilation error when trying to combine packages.



compilation error



The introduction of Go Modules does not affect the best practices outlined in existing documents, such as:




  • How to Write Go Code

  • Effective Go


As a side note, I also came to know that package name should be singular form.




  • Style guideline for Go packages


So that would leave me with the following structure along with Approach 2:



structure following the convention






share|improve this answer





















  • Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
    – Volker
    Nov 23 at 6:16












  • But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
    – Volker
    Nov 23 at 6:19










  • Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
    – Ryota
    Nov 23 at 9:59














0












0








0






Approach 2 is correct.



Being a Go newbie, I had mistakenly thought that Approach 1 was one possible way, as Go does allow having package name different from directory name.



As Volker helped in the comments, Approach 1 is definitely not possible.

You will get a straight compilation error when trying to combine packages.



compilation error



The introduction of Go Modules does not affect the best practices outlined in existing documents, such as:




  • How to Write Go Code

  • Effective Go


As a side note, I also came to know that package name should be singular form.




  • Style guideline for Go packages


So that would leave me with the following structure along with Approach 2:



structure following the convention






share|improve this answer












Approach 2 is correct.



Being a Go newbie, I had mistakenly thought that Approach 1 was one possible way, as Go does allow having package name different from directory name.



As Volker helped in the comments, Approach 1 is definitely not possible.

You will get a straight compilation error when trying to combine packages.



compilation error



The introduction of Go Modules does not affect the best practices outlined in existing documents, such as:




  • How to Write Go Code

  • Effective Go


As a side note, I also came to know that package name should be singular form.




  • Style guideline for Go packages


So that would leave me with the following structure along with Approach 2:



structure following the convention







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 22:59









Ryota

898




898












  • Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
    – Volker
    Nov 23 at 6:16












  • But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
    – Volker
    Nov 23 at 6:19










  • Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
    – Ryota
    Nov 23 at 9:59


















  • Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
    – Volker
    Nov 23 at 6:16












  • But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
    – Volker
    Nov 23 at 6:19










  • Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
    – Ryota
    Nov 23 at 9:59
















Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
– Volker
Nov 23 at 6:16






Well, I have to disappoint you. This answer is technically not correct as approach 1 is possible. You see, I lied in my comment above. Nevertheless my advice and your conclusion are 100% valid. There is just one golden way to structure your code layout and build your packages and projects. This is explained in How to Write Go Code and perfectly illustrated by the stdlib and the rest of the supporting Go repos and everybody should follow this advice and nothing else.
– Volker
Nov 23 at 6:16














But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
– Volker
Nov 23 at 6:19




But: It is technically not true. Instead of building your code with the go tool one can invoke the compiler and linker manually (or typically through a makefile or some other build tooling) and this allows to combine arbitrary files into one package. Nobody sane does this ever as this break each and every Go tool in the world, but it is possible and it is done.
– Volker
Nov 23 at 6:19












Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
– Ryota
Nov 23 at 9:59




Hmm, that is an eyeopening point. As I find Go having golden rules and being opinionated how things should be done, I appreciate how the community can heavily rely on the conventions, more so than other languages IMO. Working around the go tools is probably beyond the scope of the original question, but certainly a valid point.
– Ryota
Nov 23 at 9:59


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404155%2fgo-modules-naming-convention-of-directories-and-packages%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland