Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package.json equivalent in Golang

Tags:

node.js

go

I am coming over to Go from Node.js and I am used to adding all my modules and then people just have to go npm install when cloning my package.

What is the equivalent of this with Go? I have a few imports and don't want people to have to manually install it if they use my package.

I also not sure if I create a simple Go application with just a package main if that allows people to just go get. I have really picked up on the Go way of repo sharing like Node.js

like image 601
FrickeFresh Avatar asked Aug 14 '17 05:08

FrickeFresh


People also ask

What is npx vs npm?

Difference between NPM vs NPXNPM is a package manager used to install, delete, and update Javascript packages on your machine. NPX is a package executer, and it is used to execute javascript packages directly, without installing them.

What is npx?

NPX: The npx stands for Node Package Execute and it comes with the npm, when you installed npm above 5.2.0 version then automatically npx will installed. It is an npm package runner that can execute any package that you want from the npm registry without even installing that package.

What is npm install?

npm install downloads a package and it's dependencies. npm install can be run with or without arguments. When run without arguments, npm install downloads dependencies defined in a package. json file and generates a node_modules folder with the installed modules.

What does npm do?

npm is the package manager for the Node JavaScript platform. It puts modules in place so that node can find them, and manages dependency conflicts intelligently. It is extremely configurable to support a wide variety of use cases. Most commonly, it is used to publish, discover, install, and develop node programs.


2 Answers

What is the equivalent of this with Go? I have a few imports and don't want people to have to manually install it if they use my package.

You don't have to do anything. People will not have to manually install the packages you import. When someone does

go get github.com/FrickeFresh/awesome

all of the dependencies you import in your awesome package will be downloaded automatically as needed.

Go get skips testing files by default, but a user can download those too by including -t:

go get -t github.com/FrickeFresh/awesome

But that's not something you need to worry about.

If you want to delve into vendoring specific versions of dependencies, there are a number of articles/tools available. The official tool is dep:

https://github.com/golang/dep

like image 113
WaltPurvis Avatar answered Sep 19 '22 19:09

WaltPurvis


Basically you should take a look at vendoring. There exist tools that help you with versioning. Personally, I use vendetta which is just a little tool that "go gets" the referenced packages as git submodules into the vendor folder. So if anyone checks out my repo they simply do git submodule update --init --recursive. The package version can be specified as a git commit id in the respective submodule.

There also exist tools where you maintain the deps in a file, check out here.

like image 41
skomp Avatar answered Sep 20 '22 19:09

skomp