Skip to content

sss7526/go_maker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go Project Template with Makefile Automation

A template repository for automating Go project setup and management using a Makefile.


Initial Workflow

To get started, follow these steps:

  1. Clone the Repository:

    git clone https://github.com/sss7526/go_maker.git <your-project>
    cd <your-project>

    Replace <your-new-project-name> with the desired name of your new project.

  2. Install Go (if not already installed): Run the following command to ensure the latest version of Go is installed on your system:

    make install
  3. Initialize Your New Project: Use the mod-init command to initialize your project:

    make mod-init

    This will:

    • Generate a go.mod file with your project's name.
    • Create a main.go file with a Hello World program.
    • Generate a main_test.go file to test the Hello World program.
    • Reinitialize the Git repository, unlinking it from the upstream template and starting with a fresh commit history.

You’re now ready to start building your Go project.


Makefile Commands

The repository's Makefile provides several commands to manage and maintain the project. Below is the output of make help

========================================================================================================

                   ██████╗  ██████╗       ███╗   ███╗ █████╗ ██╗  ██╗███████╗██████╗
                  ██╔════╝ ██╔═══██╗      ████╗ ████║██╔══██╗██║ ██╔╝██╔════╝██╔══██╗
                  ██║  ███╗██║   ██║█████╗██╔████╔██║███████║█████╔╝ █████╗  ██████╔╝
                  ██║   ██║██║   ██║╚════╝██║╚██╔╝██║██╔══██║██╔═██╗ ██╔══╝  ██╔══██╗
                  ╚██████╔╝╚██████╔╝      ██║ ╚═╝ ██║██║  ██║██║  ██╗███████╗██║  ██║
                   ╚═════╝  ╚═════╝       ╚═╝     ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝

========================================================================================================
                              COMMANDS FOR GO PROJECT MANAGEMENT
========================================================================================================
  SOURCE: https://github.com/sss7526/go_maker

  SETUP AND MAINTENANCE:
      install       Install the latest Go version (if not installed).
      update        Update Go to the latest version (if needed).
      uninstall     Remove the currently installed Go version.

  MODULE MANAGEMENT:
      mod-init      Initialize a new Go module in the current directory.
      mod-tidy      Ensure go.mod and go.sum are in a tidy state.
      mod-update    Update all project dependencies to their latest versions.

  CODE QUALITY & SECURITY:
      format        Format Go files to a consistent standard (via gofmt).
      lint          Perform rigorous code linting with golangci-lint.
      vulncheck     Analyze dependencies for vulnerabilities (via govulncheck).

  BUILD, RUN, & TEST:
      run           Run the project's main entry point (main.go)
      test          Run all tests recursively across all packages.
      build         Build the project and output the binary to ~/.local/bin/your_project.
      build-dev     Build the project in dev mode and output the binary to ~/.local/bin/your_project.
      ex            Execute the built binary.
      clean         Remove the compiled binary from ~/.local/bin/.

  MISCELLANEOUS:
      fix_certs     Fix TLS certificate issues when working in WSL in Enterprise Windows environments.
      tree          Generate a directory structure summary and save it to tree.txt.
      doctor        Check for missing system utilities.
      help          Display this help screen.

========================================================================================================
                                 INFO: Use 'make <target>' to run a command.
========================================================================================================

Setup and Initialization

Command Description
make install Installs the latest version of Go if it’s not already installed locally.
make update Updates Go to the latest version.
make uninstall Removes the currently installed Go versionn

Module Management

Command Description
make mod-init Initializes a new Go project, generates boilerplate code, and reinitializes Git.
make mod-tidy Ensures go.mod and go.sum are in a tidy, consistent state.
make mod-update Updates all project dependencies to their latest compatible versions.

Code Quality and Security

Command Description
make format Formats Go files using gofmt.
make lint Performs static analysis and linting with golangci-lint.
make vulncheck Checks for vulnerabilities in dependencies using govulncheck.

Build, Test, and Run

Command Description
make build Builds the Go project and places the binary in ~/.local/bin/<project-name>.
make build-dev Builds the Go project in dev mode and places the binary in ~/.local/bin/<project-name>.
make run [ARGS] Runs the main.go file of the project. Accepts arbitrary arguments
make test Executes tests recursively (go test ./...).
make ex Executes the built binary.
make clean Removes the built binary.

Misc

Command Description
make fix_certs Fix TLS certificate issues when working in WSL in Enterprise Windows environments.
make tree Generate a directory structure summary and save it to tree.txt
make doctor Check for missing system utilities
make help Shows help output

Output Example (For make mod-init)

This an example of the terminal output when running make mod-init:

Initializing Go module with name: my-project...
go.mod created.
Creating main.go with a Hello World program...
main.go created.
Creating main_test.go with a basic test...
main_test.go created.
The repository is currently linked to the template upstream (https://github.com/sss7526/go_maker.git).
Resetting .git and initializing a new Git repository...
Git repository has been reset and initialized.

File Structure

After running make mod-init, your project will have the following structure:

<project-name>/
├── Makefile
├── go.mod
├── main.go
├── main_test.go
├── .gitignore
└── .git/

Adding Your First Commit

After running make mod-init, you will have your project's Git repository initialized with an empty commit history. To create your first commit, do the following:

git add .
git commit -m "Initial commit"

If you want to link your project to a remote repository, run:

git remote add origin <your-new-repository-url>
git push -u origin main

Contributing

Contributions to this repository are welcome! If you have suggestions, feature requests, or improvements, please submit an issue or create a pull request.


License

This project is licensed under the MIT License.

About

Template repository for automating Go installation and project setup and management with Makefile. Initializes Go modules, generates boilerplate code (main.go and main_test.go), and reinitializes Git

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors