I have some local packages defined within my application, for example, I have a crud model located at model/crud/crud.go
Within my application I am calling upon them using import("model/crud"), for all of my local dependencies.
This resolves perfectly fine within the context of my application on my local machine, however when I try to push to openshift I get the following error:
imports model/crud: unrecognized import path "model/crud"
It looks like when openshift runs the build tool, it is attempting to run go get on these imports in order to include them in the build path when compiling.
Is there a better way to resolve vendor specific dependencies without having to create a separate repo for them? I don't want to have to manage two separate repositories if I don't have to.
To find the import path you are supposed to use, take "$GOPATH/src/[...]/model/crud" and just remove the "$GOPATH/src/" part.
You should use the full import path. For example "github.com/user/project/model/crud"
Related
Hard to put in a single sentence, but here is the situation. I am developing a golang package, my intention is for it to be go-gettable. The core of the package provides some "central" functionality, an http middleware. And I need several "adapter" packages to support some of the most famous golang http frameworks.
Each adapter responsibility is to get the required information from the http request and then consume a core service where the logic resides. So the main logic resides in a single place while each adapter acts like, well, an adapter.
The first approach I can think of is to have both the core and adapters as part of the same module, but this will add a lot of unnecessary dependencies to the importing project. For instance, if you want to import the package to support framework A the package will indirectly add all the dependencies required by the adapters for other frameworks, even when not used.
The approach I am considering is to have several modules in the same package: a core module and a separate module for each adapter. Each adapter module will then import the core module:
|- core
| |- go.mod
|
|- adapter1
| |- go.mod
|
|- adapter2
|- go.mod
This way, adapter 1 module could be imported and will only carry it's dependencies and those of the core module, leaving adapter 2 dependencies out of the picture.
I got this structure to work locally: I can successfully import adapter 1, or adapter 2, from another golang project using go mod replace statement but when I push changes to the git repo and try to import directly from there I can't get go mod to download the latest version/tag of each package, not even by explicitly providing the version tag I want to use. It keeps downloading an older version and complaining about some missing code parts (that exist only in the latest version).
I followed this guide on sourcing multiple modules on a single repository but an important distinction is that in my case, I am sourcing a module that references another module in the same repo, while the example in the guide shows how to source modules independently.
So my question is, is it at all possible to source a go module that references another go module on the same repo?
Would it be a better approach to have my "core" module on a separate repository and then an "adapters" repo/module with a package for each adapter?
The purpose of having it all in the same repo is to make the development easier, but it is complicating version control a lot.
Any advice will be greatly appreciated. If you need me to clarify something I would gladly do so. Thanks in advance.
Consider that any go install would not be possible with a replace directive in your go.mod (issue 44840).
That would result in the error message:
The go.mod file for the module providing named packages contains one or more
replace directives.
It must not contain directives that would cause it to be interpreted differently
than if it were the main module.
So one module per repositories is preferable, and you can then group your repositories into one parent Git repository (through submodules, each one following a branch for easy update) for convenience.
I have two repos github.com/x/a and github.com/x/b and they both have Go modules at the root of each. How can i access a package that that is in the other repo? Normally I would be able to access it by doing a go get github.com/x/b if I want to use b in a. But neither are in production and we are still working in a development branch so I need to find a way to do this locally. Any ideas?
The quick and dirty way is to clone the repository into GOPATH/src. Then you can import the packages simply with
import "a" or import "b"
If I use bazel to build my protobuf dependent Go serverless functions, bazel will make the protobuf generated go code available at the import path that I specify.
Google cloud functions for go requires one to use go modules.
How can I add the dummy import path created by bazel to my go.mod file? The function deploy to google cloud fails because the dummy import can not be resolved. (G cloud requires me to upload my go source, AWS lambdas would allow me to upload a binary, which would work fine.)
I'm guessing I'll have to either go with AWS lambdas, use serverless containers, or write a genrule that copies the outputs of the proto generated code into my source directory but I'd like to avoid that ugliness.
I work at Google on Go and Google Cloud Functions.
I see a few options for using Cloud Functions:
Publish the generated code publicly. You may not want to do this for a variety of reasons.
Copy the generated code into your source directory. This is the easiest. When you deploy your function, the current directory gets zipped up and sent to be built. We don't copy any dependencies from outside your current directory. If you do this, you can import the generated code by having the package path be prefixed by the module path of your directory.
Use vendoring. If you run go mod vendor and have that grab your generated code (at whatever path you choose), it will create a vendor directory with all of your dependencies. The Cloud Functions builder prefers go.mod over vendor, though. So you would have to .gcloudignore the go.mod and go.sum file to make sure they don't get uploaded when you deploy your code. https://cloud.google.com/functions/docs/writing/specifying-dependencies-go has more information.
I used to group related parts of my application like so:
Project Name
--Web UI
--Windows Service
--File Drop
"File Drop" is an example that might be related to both the service and the web site.
However, tentacle deploys each package separately, so with that I get something that looks more like (assuming ProjectName is used in the package id):
--ProjectName.WebUI
--ProjectName.WindowsService
How should I deploy a related shared folder? Can you group applications in some way? If not is there a recommended pattern to creating shared resources?
I should add that I'm using octopack. I figure I certainly can manually put a nuget package together and use the relative dir parameters for IIS Sites and Services, but that starts to get more difficult.
It sounds like you want to use Custom Installation Directory. This will let you control what directory the package is extracted to.
You can also do some custom setup in a deploy.ps1 file for each of your packages.
Revel models are defined under the models package; so in order to import them one must use the full repo path relative to the %GOPATH/src folder which in this case project/app/models thus results in
import PROJECTNAME/app/models
so far, so good i'f you'r using your app name as the folder name of your local dev machine and have dev+prod environments only.
Heroku's docs recommends using multiple apps for different environment (i.e. for staging). with the same repository with distinct origins;
This is where problem starts, now, since the staging enviromnent resides on alternative appname(let's say PROJECTNAME_STAGING), it's sources are stored under PROJECTNAME_STAGING but the actual code still import PROJECTNAME/app/models instead of import PROJECTNAME_STAGING/app/models; so compile fails, etc.
Is there any possibility to manage multiple environments with a single local repo and multiple origins with revel's heroku buildpack? or a feature is needed in the buildpack that is yet to be implemented?
In addition, there is this possible issue with the .godir file that is required to be versioned and contain the git path to the app, so what about the multi-environment duality regarding this file?
Solution was simple enougth;
The buildpack uses the string in .godir both for the argument for revel run as well as the directory name under GOPATH/src. My .godir file had a git.heroku.com/<APPNAME>.git format; Instead I just used APPNAME format.