From 016b14ac214cf6db883998d314b2f45c393400ef Mon Sep 17 00:00:00 2001 From: asandikci Date: Mon, 24 Jul 2023 10:22:51 +0300 Subject: [PATCH] add package structure example --- README.md | 19 +++++++++++-------- simple-structure/go.mod | 3 +++ simple-structure/package-str/example/main.go | 12 ++++++++++++ simple-structure/package-str/great/great.go | 10 ++++++++++ 4 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 simple-structure/go.mod create mode 100644 simple-structure/package-str/example/main.go create mode 100644 simple-structure/package-str/great/great.go diff --git a/README.md b/README.md index 09fec04..aa21c93 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,18 @@ # go-organization -Understand project structure of GO. Go Modules, GOPATH, efficent development environment... +Understand project structure of GO. Go Modules, GOPATH, efficent development environment... This repo contains lots of trash folder/file! Just trying to understand structure with trying lots of unnecessary things too ### Base Resources -- https://github.com/golang/go/wiki/Modules -- https://go.dev/blog/using-go-modules -- https://github.com/golang-standards/project-layout -- https://go.dev/doc/code -- https://tutorialedge.net/golang/go-project-structure-best-practices/ -- https://www.digitalocean.com/community/tutorials/how-to-use-go-modules -- https://go.dev/ref/mod +| Resource | Explanation | Implementation | +| -------- | ----------- | -------------- | +| https://github.com/golang/go/wiki/Modules | - | - | +| https://go.dev/blog/using-go-modules | - | - | +| https://github.com/golang-standards/project-layout | - | - | +| https://go.dev/doc/code | - | - | +| https://tutorialedge.net/golang/go-project-structure-best-practices/ | - | - | +| https://www.digitalocean.com/community/tutorials/how-to-use-go-modules | Modules | - | +| https://www.digitalocean.com/community/tutorials/how-to-write-packages-in-go | Packages | [package-str](simple-structure/package-str/) | +| https://go.dev/ref/mod | - | - | ### FAQ
diff --git a/simple-structure/go.mod b/simple-structure/go.mod new file mode 100644 index 0000000..d206945 --- /dev/null +++ b/simple-structure/go.mod @@ -0,0 +1,3 @@ +module Liderahenk/go-organization/simple-structure + +go 1.20 diff --git a/simple-structure/package-str/example/main.go b/simple-structure/package-str/example/main.go new file mode 100644 index 0000000..0907b98 --- /dev/null +++ b/simple-structure/package-str/example/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "Liderahenk/go-organization/simple-structure/package-str/great" + "fmt" +) + +func main() { + great.Hello() + fmt.Println(great.Name) + // fmt.Println(great.name2) // ERROR lowercase variables cannot be used outside of package itself +} diff --git a/simple-structure/package-str/great/great.go b/simple-structure/package-str/great/great.go new file mode 100644 index 0000000..e91fb58 --- /dev/null +++ b/simple-structure/package-str/great/great.go @@ -0,0 +1,10 @@ +package great + +import "fmt" + +var Name = "deniz" +var name2 = "deniz2" + +func Hello() { + fmt.Println("Hello World (go-organization/simple-structure/package-str/great/great.go)") +}