-1

I'm developing a go module, let's call it github.com/spyna/mymodule.

This module is a library and another go project uses it, for example: github.com/spyna/goapp uses github.com/spyna/mymodule.

During the development phase, I don't want to push changes in github.com/spyna/mymodule because they're still under development, but in order to test the changes, I want to use the local version of github.com/spyna/mymodule as a dependency of github.com/spyna/goapp.

For example, this file in github.com/spyna/goapp requires github.com/spyna/mymodule.

//main.go

package main

import (
    "github.com/spyna/mymodule"
)

func main() {
 mymodule.doSomething()
}


If I run this code, the dependency is resolved remotely, but I want to use the local one, to test my changes.

Is this possible in go?

thank you.

Spyna
  • 490
  • 3
  • 12

1 Answers1

0

You can use the replace directives in go.mod. In your go.mod add:

 replace github.com/spyna/mymodule => ../path/to/local/mymodule

See the replace specification

aureliar
  • 1,476
  • 4
  • 16
  • Thank you, this works! Is there any other not manual method to do this? I mean, when the development phase is finished, I need to remember to remove the `replace`. – Spyna Feb 23 '21 at 13:42
  • There a command line tool `go mod edit` (see `go mod help edit`) that can perform these transformations. But you have to remember to roll back. A linter could check that there is no replace directive in `go.mod` – aureliar Feb 23 '21 at 13:52
  • @Spyna: just don't commit the `replace` line, so there's nothing to roll back. – JimB Feb 23 '21 at 14:17