Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal:go/build: refer local package by [import "#/x/y/z"] style #24229

Closed
vipally opened this issue Mar 3, 2018 · 1 comment
Closed

proposal:go/build: refer local package by [import "#/x/y/z"] style #24229

vipally opened this issue Mar 3, 2018 · 1 comment

Comments

@vipally
Copy link

vipally commented Mar 3, 2018

The problem: Examples of with/without local package reference

Here are two examples of "hello world" main packages:
<ProjectRoot>/problem/withoutlocal
<ProjectRoot>/problem/withlocal <- github.com/vipally/localpackage/problem/local

"withoutlocal" works well anywhere <ProjectRoot> is, even out of GoPath.
"withlocal" works only when "<ProjectRoot> = <GoPath>/github.com/vipally/localpackage"
How does go team think about this difference?

It makes "withlocal" packages non-independent due to reference "LOCAL" packages as "GLOBAL" style.
If I want my package works well anywhere, I have to write everything in one single "HUGE-package".
Just like: all.Printf/all.OpenFile/all.GOROOT/...

We must explicit followed priority of go dependency package find process:
<ProjectRoot>: with highest-priorty path to find local packages.
<Vendor>     : with second-priorty path to find explicit-version of local-referenced the third-party packages.
<GoRoot>     : with third-priorty path to find standard packages.
<GoPath>     : with lowest-priorty path to find third-party packages.

Think about that not every go-project is wrote for open-source(aim to share with others).
Thousands of private go-projects(eg:game-servers) focus on their own particular logic-flow only 
and never shared private-packages at all.
We just called these projects "independent-projects".
Because they have hundreds-of private-packages but no one is wrote for share.

That is to say, they never care "where I am", but "what I need".

Unfortunately, these kind of projects are always "huge". 
Maybe millions-of lines or thousands-of private-packages reference inside?

In this case, change project name or source control server become heavy work, 
because the working path changes and thousands-of private-packages reference code have to be update.

But if local-packages are referenced by "#/modules/module1" style, 
everything is change the name of project root only then.

How do you think about the difference between such styles of referencing local-packages?
"#/modules/module1"
(<GoPath>/) "server/user/project/modules/module1"

My solution

1. use such way to define a LocalRoot to replacing GoPath

LocalRoot is a <root> directory that contains such patten of sub-tree "<root>/src/vendor/" up from current path.
A LocalRoot has the same tree structure with GoPath and GoRoot.

Actually, a LocalRoot is a private GoPath that is accessible to sub-packages only.

This is the minimal state of a valid LocalRoot:
	LocalRoot
	│
	└─src
	    ├─vendor
	    │  ...
	    └─...

After build and install, it may become as:
	LocalRoot
	│  
	├─bin
	│    ...
	├─pkg
	│  └─windows_amd64
	│      └─...
	└─src
	    │  ...     
	    ├─vendor
	    │  └─...
	    └─...

2. use such way to refer local package

import "#/x/y/z"

Which means [import "x/y/z"] from LocalRoot, and never search from GoPath/GoRoot.

details:
GoNuts
Problem
Solution

@bradfitz
Copy link
Contributor

bradfitz commented Mar 3, 2018

@bradfitz bradfitz closed this as completed Mar 3, 2018
@golang golang locked and limited conversation to collaborators Mar 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants