Created
December 24, 2018 12:27
-
-
Save stapelberg/0159353c646fb33ce3211a6877c7f20f to your computer and use it in GitHub Desktop.
Temporarily replacing a module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ % mkdir /tmp/apt | |
~ % cd /tmp/apt | |
/tmp/apt % cat > apt.go <<'EOT' | |
package main | |
import ( | |
"bytes" | |
"log" | |
"github.com/stapelberg/godebiancontrol" | |
) | |
const ctrlfile = ` | |
Package: quake | |
` | |
func main() { | |
paragraph, err := godebiancontrol.Parse(bytes.NewReader([]byte(ctrlfile))) | |
if err != nil { | |
log.Fatalf("apt: %v", err) | |
} | |
log.Printf("paragraph: %+v", paragraph) | |
} | |
EOT | |
/tmp/apt % go build | |
go: finding github.com/stapelberg/godebiancontrol v0.0.0-20180408134423-8c93e189186a | |
go: downloading github.com/stapelberg/godebiancontrol v0.0.0-20180408134423-8c93e189186a | |
go: extracting github.com/stapelberg/godebiancontrol v0.0.0-20180408134423-8c93e189186a | |
# Let’s do a change which we want to evaluate. In this case, a re-implementation of godebiancontrol: | |
/tmp/apt % mkdir /tmp/debctrl | |
/tmp/apt % cd /tmp/debctrl | |
/tmp/debctrl % go mod init github.com/stapelberg/godebiancontrol | |
/tmp/debctrl % cat > ctrl.go <<'EOT' | |
package godebiancontrol | |
import ( | |
"fmt" | |
"io" | |
) | |
type Paragraph map[string]string | |
func Parse(input io.Reader) (paragraphs []Paragraph, err error) { | |
return nil, fmt.Errorf("my custom change is broken!") | |
} | |
EOT | |
# Let’s evaluate this change: | |
/tmp/debctrl % cd /tmp/apt | |
/tmp/apt % go mod edit -replace=github.com/stapelberg/godebiancontrol=/tmp/debctrl | |
/tmp/apt % go build && ./apt | |
2018/12/24 13:24:56 apt: my custom change is broken! | |
/tmp/apt % go mod edit -dropreplace=github.com/stapelberg/godebiancontrol | |
# Just to verify that our build is not broken by the temporary module replacement: | |
/tmp/apt % go build | |
/tmp/apt % ./apt | |
2018/12/24 13:25:46 paragraph: [map[Package:quake]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment