Questions tagged [go-modules]

A module is a collection of related Go packages. Modules are the unit of source code interchange and versioning. The go command has direct support for working with modules, including recording and resolving dependencies on other modules. Modules replace the old GOPATH-based approach to specifying which source files are used in a given build.

The Go Module concept was first published by Russ Cox here: Defining Go Modules.

Module support first appeared in Go 1.11 (in preliminary phase).

The go tool has built-in and extensive support for modules, documentation can be found at Go tool: Module maintenance and at Modules, module versions, and more. The command go help mod also provides sufficient details.

570 questions
-3
votes
1 answer

go mod " cannot find package" when I use the external package in the other file

When I use go mod and I have just one .go file all things are ok and go mod can download the external package and use it but when I use the external package in the other file (not main.go file) I get this error (when run go run main.go)…
azibom
  • 1,769
  • 1
  • 7
  • 21
-3
votes
1 answer

Import a github managed go package

I am new to go module building. What im trying to do is to create a go library with commonly used methods that other developers can use in their go code. So first in my internal github, Ive created a repo https://internalgithub//lib-go.git The…
Jason Stanley
  • 386
  • 1
  • 3
  • 20
-3
votes
1 answer

golang module name change causes local tests to fail

I have a fork of someone's code. Their module name is formatted like so: module github.com/foo/bar/v3 I've made some changes locally and have updated the local go.mod to be v4 instead of v3 but this now causes the running of the tests locally to…
Integralist
  • 5,899
  • 5
  • 25
  • 42
-3
votes
1 answer

go-run is giving me an error `cannot find package` on a relative submodule

I have the following dir structure ~/test | lala - lala.go - main.go And the contents: main.go: package main import ( "fmt" "./lala" _ "github.com/lib/pq" ) func main() { …
-3
votes
2 answers

How to run sibling Go applications (modules) from the parent directory

I have multiple Go projects (and all of them are also Go modules) all in a folder. They are all HTTP servers and exchanging REST calls, thus, I need all of them up and running simultaneously. So, for local testing purposes, I thought it would be…
vahdet
  • 6,357
  • 9
  • 51
  • 106
-3
votes
1 answer

Go application version in modules

How do we add application version in go modules(NOT Dependency version)?I would like to hear from other people on this.I am not sure how to do this
Sanchu Varkey
  • 49
  • 1
  • 5
-3
votes
1 answer

Relative import in Go for protobuf , cannot find module path

I'm trying to write a service in go with gRPC, and when i import the protobuff file , getting an error. i tried removing all the modules in my go path and reinitialising the go modules build _/Users/tibinlukose/cart-service/pb: cannot find module…
Tibin
  • 612
  • 1
  • 8
  • 21
-3
votes
1 answer

Problem with modules and importing folders

I have some problems with how Go importing and modules works. I have a project with this structure: My-Project |- Program 1 |- main.go |- go.mod |- Program 2 |- main.go |- go.mod |- Support |- go_file.go The two programs have…
Rockietto
  • 109
  • 1
  • 11
-4
votes
1 answer

Execute the program every 5 minutes with gocron

I need to run my Co program continuously with five minute interval. I tried using gocron but the program is not giving any output. func hi() { fmt.Println("hi") } func main() { gocron.Every(5).Minute().Do(hi) } I expect this to run and…
-4
votes
1 answer

Should I checkin pkg/mod/cache to git?

I'm using go mod for my project. If my understanding is right, go.mod and go.sum can be checked in. However, I'm curious to know if I should check in pkg/mod/cache as well.
user3587025
  • 173
  • 1
  • 4
  • 17
-4
votes
1 answer

Can I run "go mod tidy" recursively?

I have a Go repo which is like this: sdkpackage go.mod _examples one go.mod two go.mod three go.mod I know multiple modules in a single repository are not recommended for most use cases (from wiki), but my scenario fits under one of…
Ed Harrod
  • 3,423
  • 4
  • 32
  • 53
-4
votes
1 answer

Goland: How to use a custom modfile instead of go.mod?

My project consists of multiple go modules which I need to work on simultaneously. This is made easy by using the replace directive in the go.mod file. Further, in order to prevent this change from getting accidentally checked in, the go tools…
cosmiczilch
  • 43
  • 2
  • 7
-4
votes
2 answers

go mod subdirectories structure

I'm using the following struct on my project, but it feels hacky App ├── go.mod ├── app.go └── src └── foo | └── foo.go └── bar └── bar.go Is there a way to organize it like that? App ├── go.mod └── src ├── app.go └──…
Lordie
  • 178
  • 10
-6
votes
1 answer

How to develop and test a local go module

I have this script: #!/usr/bin/env bash set -eo pipefail cd "$(dirname "$BASH_SOURCE")"; pth_to_make="$GOPATH/src/ores/json-logging" mkdir -p "$pth_to_make"; rm -rf "$pth_to_make"; ln -sf "$PWD" "$pth_to_make"; however this module is not declared…
user12861522
1 2 3
37
38