From d7f0e206ca2c2771d1bb73c871ba07654a3446e3 Mon Sep 17 00:00:00 2001 From: Robert Jeutter Date: Thu, 30 Dec 2021 20:35:06 +0100 Subject: [PATCH] import remote project --- 3-importremote/go.mod | 5 +++++ 3-importremote/go.sum | 4 ++++ 3-importremote/hello.go | 14 ++++++++++++ 3-importremote/importpackage/reverse.go | 12 ++++++++++ 3-importremote/readme.md | 29 +++++++++++++++++++++++++ 5 files changed, 64 insertions(+) create mode 100644 3-importremote/go.mod create mode 100644 3-importremote/go.sum create mode 100644 3-importremote/hello.go create mode 100644 3-importremote/importpackage/reverse.go create mode 100644 3-importremote/readme.md diff --git a/3-importremote/go.mod b/3-importremote/go.mod new file mode 100644 index 0000000..5bcc82b --- /dev/null +++ b/3-importremote/go.mod @@ -0,0 +1,5 @@ +module example/user/importremote + +go 1.17 + +require github.com/google/go-cmp v0.5.6 diff --git a/3-importremote/go.sum b/3-importremote/go.sum new file mode 100644 index 0000000..03e1a9c --- /dev/null +++ b/3-importremote/go.sum @@ -0,0 +1,4 @@ +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/3-importremote/hello.go b/3-importremote/hello.go new file mode 100644 index 0000000..a951e61 --- /dev/null +++ b/3-importremote/hello.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + + "example/user/importremote/importpackage" + + "github.com/google/go-cmp/cmp" +) + +func main() { + fmt.Println(importpackage.ReverseRunes("!oG ,olleH")) + fmt.Println(cmp.Diff("Hello World", "Hello Go")) +} \ No newline at end of file diff --git a/3-importremote/importpackage/reverse.go b/3-importremote/importpackage/reverse.go new file mode 100644 index 0000000..743724a --- /dev/null +++ b/3-importremote/importpackage/reverse.go @@ -0,0 +1,12 @@ +// Package importpackage implements additional functions to manipulate UTF-8 +// encoded strings, beyond what is provided in the standard "strings" package. +package importpackage + +// ReverseRunes returns its argument string reversed rune-wise left to right. +func ReverseRunes(s string) string { + r := []rune(s) + for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { + r[i], r[j] = r[j], r[i] + } + return string(r) +} \ No newline at end of file diff --git a/3-importremote/readme.md b/3-importremote/readme.md new file mode 100644 index 0000000..1d1a343 --- /dev/null +++ b/3-importremote/readme.md @@ -0,0 +1,29 @@ +# Import package from remote modules +An import path can describe how to obtain the package source code using a revision control system such as Git or Mercurial. The go tool uses this property to automatically fetch packages from remote repositories. + +```bash +cp -r 2-importpackage 3-importremote +# change importpackage to importremote +nano go.mod +nano importpackage/reverse.go +# update modules in hello.go +nano hello.go +> package main +> +> import ( +> "fmt" +> +> "example/user/importremote/importpackage" +> +> "github.com/google/go-cmp/cmp" +> ) +> +> func main() { +> fmt.Println(importpackage.ReverseRunes("!oG ,olleH")) +> fmt.Println(cmp.Diff("Hello World", "Hello Go")) +> } +# get all requirements and download modules +go mod tidy +# run code +go run hello.go +``` \ No newline at end of file