├── go.sum ├── Dockerfile ├── config └── config.yaml ├── static └── img.jpg ├── docs └── Getting Started.md ├── cmd └── server │ └── main.go ├── internal ├── utils │ └── utils.go └── handlers │ └── handlers.go ├── go.mod ├── .env.example ├── scripts ├── PushaG.sh └── creator.sh ├── .gitignore ├── Makefile ├── .github └── workflows │ └── build.yaml ├── LICENSE └── README.md /go.sum: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/config.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /static/img.jpg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/Getting Started.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cmd/server/main.go: -------------------------------------------------------------------------------- 1 | package server 2 | -------------------------------------------------------------------------------- /internal/utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | -------------------------------------------------------------------------------- /internal/handlers/handlers.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module MyGoWebAppTemplate 2 | 3 | go 1.20 4 | 5 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | DB_HOST= 2 | DB_PORT= 3 | DB_USERNAME= 4 | DB_PASSWORD= 5 | DB_NAME= 6 | SSL_MODE= 7 | -------------------------------------------------------------------------------- /scripts/PushaG.sh: -------------------------------------------------------------------------------- 1 | # helper script for pushing code to GitHub 2 | 3 | 4 | git add . 5 | echo -n "🔊 What's the commit message 👉 " 6 | read response 7 | git commit -m "$response" 8 | git push origin main -------------------------------------------------------------------------------- /scripts/creator.sh: -------------------------------------------------------------------------------- 1 | # helper file for recreating the project structure without any file content 2 | 3 | mkdir -p cmd/server config internal/handlers internal/utils scripts static docs 4 | 5 | touch .gitignore LICENSE Makefile README.md Dockerfile .env.example go.mod go.sum scripts/PushaG.sh 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .env 3 | # If you prefer the allow list template instead of the deny list, see community template: 4 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 5 | # 6 | # Binaries for programs and plugins 7 | *.exe 8 | *.exe~ 9 | *.dll 10 | *.so 11 | *.dylib 12 | 13 | # Test binary, built with `go test -c` 14 | *.test 15 | 16 | # Output of the go coverage tool, specifically when used with LiteIDE 17 | *.out 18 | 19 | # Dependency directories (remove the comment below to include it) 20 | # vendor/ 21 | 22 | # Go workspace file 23 | go.work -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for the Golang project 2 | 3 | # Variables 4 | BINARY_NAME=server 5 | PACKAGE=cmd/server 6 | DOCS_DIR=docs 7 | 8 | .PHONY: all build run test clean docs 9 | 10 | # Default target to run when executing 'make' 11 | all: build 12 | 13 | # Build the project 14 | build: 15 | @echo "Building..." 16 | go build -o $(BINARY_NAME) ./$(PACKAGE) 17 | 18 | # Run the server 19 | run: 20 | @echo "Running server..." 21 | go run ./$(PACKAGE) 22 | 23 | # Run tests 24 | test: 25 | @echo "Running tests..." 26 | go test -v ./... 27 | 28 | # Remove build artifacts 29 | clean: 30 | @echo "Cleaning up..." 31 | go clean 32 | rm $(BINARY_NAME) -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | build: 13 | name: Build and Test 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Checkout code 18 | uses: actions/checkout@v3 19 | 20 | - name: Set up Node.js 21 | uses: actions/setup-node@v3 22 | with: 23 | node-version: 16 24 | 25 | - name: Set up Go 1.19 26 | uses: actions/setup-go@v3 27 | with: 28 | go-version: 1.19 29 | id: go 30 | 31 | - name: Install dependencies 32 | run: | 33 | go mod download 34 | 35 | - name: Build 36 | run: go build -v ./... 37 | 38 | - name: Test 39 | run: go test -v ./... 40 | 41 | - name: Vet 42 | run: go vet ./... 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2023 Ukeje Chukwuemeriwo Goodness 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MyGoWebAppTemplate 2 | 3 |

4 | 5 | made-with-Go 6 | GoReportCard 7 | Go.mod version 8 | LICENSE 9 |

10 | 11 | ## 🗞️ Introduction 12 | 13 | This is a template for initializing Go apps with the hexagonal structure according to the best practices as overviewed 14 | through the community. 15 | 16 | You're going to find this useful if you're building an app that you intend to use and support over a long period of 17 | time. 18 | 19 | ## ⚠️ Understanding the Structure 20 | 21 | First, you're going to tweak this structure for your app's use case. This template simply eliminates the overhead of 22 | manually initializing a project. 23 | 24 | 25 | 1. **[cmd](./cmd)**: This directory contains the main entry point for your server application. 26 | - **[server](./cmd/server)**: Subdirectory for the server application. 27 | - **[main.go](./cmd/server/main.go)**: The main Go source code file for your server application. 28 | 29 | 2. **[config](./config)**: This directory stores configuration files for your application. 30 | - **[config.yaml](./config/config.yaml)**: Configuration settings and parameters. 31 | 32 | 3. **[docs](./docs)**: Documentation related to your project. 33 | - **[Getting Started.md](./docs/Getting%20Started.md)**: Instructions on how to get started with your application. 34 | 35 | 4. **[internal](./internal)**: Contains internal application code not meant to be exposed as a public API. 36 | - **[handlers](./internal/handlers)**: Subdirectory for request handlers. 37 | - **[handlers.go](./internal/handlers/handlers.go)**: Code for defining and implementing request handlers. 38 | - **[utils](./internal/utils)**: Subdirectory for utility functions. 39 | - **[utils.go](./internal/utils/utils.go)**: Utility functions used within the application. 40 | 41 | 5. **[scripts](./scripts)**: Contains scripts for automating various tasks. 42 | - **[PushaG.sh](./scripts/PushaG.sh)**: A script for a task named "PushaG." 43 | - **[creator.sh](./scripts/creator.sh)**: A script that might be related to creating something for your application. 44 | 45 | 6. **[static](./static)**: Contains static assets like images. 46 | - **[img.jpg](./static/img.jpg)**: An image file used in your application. 47 | 48 | Each of these subdirectories serves a specific purpose in organizing your application's code and resources. The 49 | structure helps keep your codebase modular and maintainable by separating concerns and functionalities into different 50 | directories. 51 | 52 | ## 🏁 Getting Started 53 | 54 | You can use the `gonew` command or the bash [creator.sh](./scripts/creator.sh) script to initialize this project. 55 | 56 | ### 🤩 Using Gonew 57 | 58 | Using `gonew` will ensure that you also get additional files and file content. Google `gonew` and check the LogRocket 59 | blog for a tutorial I wrote on how you can use `gonew` to streamline your apps' development. 60 | 61 | 62 | First, Install `gonew` with this command line 63 | 64 | 65 | ```shell 66 | go install golang.org/x/tools/cmd/gonew@latest 67 | ``` 68 | 69 | Next, run this command to complete the setup with `gonew` and start building. 70 | 71 | 72 | ```shell 73 | 74 | gonew -dir -v github.com/Goodnessuc/MyGoWebAppTemplate 75 | 76 | ``` 77 | 78 | 79 | The command will create the exact structure of the project as is on GitHub. 80 | 81 | ### ⚙️ Using the Bash Script 82 | 83 | Using the [creator.sh](./scripts/creator.sh) bash script is a fast alternative to getting started. 84 | 85 | The bash script also affords you more control over the contents of your app files in a minimalistic manner 86 | 87 | Run this command in the terminal of your project's working directory to create the directory structure and files 88 | 89 | 90 | ```bash 91 | mkdir -p cmd/server config internal/handlers internal/utils scripts static docs 92 | 93 | touch .gitignore LICENSE Makefile README.md Dockerfile .env.example go.mod go.sum scripts/PushaG.sh 94 | 95 | ``` 96 | 97 | 98 | You've successfully set up your project's structure with the Bash Script. 99 | 100 | 101 | ## 🛠️ Technologies and Tools 102 | Go - The programming language used 103 | 104 | GitHub Actions - GitHub CI/CD tool 105 | 106 | Make - Build automation tool 107 | 108 | 109 | 110 | ## 👏 Contributing 111 | Contributions are welcome! Feel free to open a pull request right away. 112 | 113 | ## 📃 License 114 | This project is licensed under the MIT License - see the LICENSE.md file for details --------------------------------------------------------------------------------