Skip to content

Commit

Permalink
chore(*): -
Browse files Browse the repository at this point in the history
  • Loading branch information
enenumxela committed Nov 30, 2024
1 parent 7d49a3d commit 5381a75
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Pull requests should target the `dev` branch. Please also reference the issue fr
When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Here are a few points to keep in mind:

* All dependencies must be defined in the `go.mod` file.
* Advanced IDEs and code editors (like VSCode) will take care of that, but to be sure, run `go mod tidy` to validate dependencies.
* Please run `go fmt ./...` before committing to ensure code aligns with go standards.
* We use [`golangci-lint`](https://golangci-lint.run/) for linting Go code, run `golangci-lint run --fix` before submitting PR. Editors such as Visual Studio Code or JetBrains IntelliJ; with Go support plugin will offer `golangci-lint` automatically.
* Advanced IDEs and code editors (like VSCode) will take care of that, but to be sure, run `make go-mod-tidy` to validate dependencies.
* Please run `make go-fmt` before committing to ensure code aligns with go standards.
* We use [`golangci-lint`](https://golangci-lint.run/) for linting Go code, run `make go-lint` before submitting PR. Editors such as Visual Studio Code or JetBrains IntelliJ; with Go support plugin will offer `golangci-lint` automatically.
* For details on the approved style, check out [Effective Go](https://golang.org/doc/effective_go.html).

### License
Expand Down
68 changes: 44 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
# Set the default shell to `/bin/sh` for executing commands in the Makefile.
# `/bin/sh` is used as it is lightweight and widely available across UNIX systems.
SHELL = /bin/sh

# Define the project name for easy reference.
# Define the project name for easy reference throughout the Makefile.
# This helps in maintaining a consistent project name and avoiding hardcoding it in multiple places.
PROJECT = "hq-go-http"

# --- Prepare | Setup -------------------------------------------------------------------------------

.PHONY: prepare
prepare:
@# Install the latest version of Lefthook (a Git hooks manager) and set it up.
go install github.com/evilmartians/lefthook@latest && lefthook install

# --- Go(Golang) ------------------------------------------------------------------------------------

# Define common Go commands with variables for reusability and easier updates.
GOCMD=go # The main Go command.
GOMOD=$(GOCMD) mod # Go mod command for managing modules.
GOGET=$(GOCMD) get # Go get command for retrieving packages.
GOFMT=$(GOCMD) fmt # Go fmt command for formatting Go code.
GOTEST=$(GOCMD) test # Go test command for running tests.
GOCMD=go
GOMOD=$(GOCMD) mod
GOGET=$(GOCMD) get
GOFMT=$(GOCMD) fmt
GOTEST=$(GOCMD) test

# Define Go build flags for verbosity and linking.
GOFLAGS := -v # Verbose flag for Go commands to print detailed output.
LDFLAGS := -s -w # Linker flags to strip debug information (-s) and reduce binary size (-w).

# Set static linking flags for systems that are not macOS (darwin).
# Static linking allows the binary to include all required libraries in the executable.
# Verbose flag for Go commands, helpful for debugging and understanding output.
GOFLAGS := -v
# Linker flags:
# - `-s` removes the symbol table for a smaller binary size.
# - `-w` removes DWARF debugging information.
LDFLAGS := -s -w

# Enable static linking on non-macOS platforms.
# This embeds all dependencies directly into the binary, making it more portable.
ifneq ($(shell go env GOOS),darwin)
LDFLAGS := -extldflags "-static"
endif
Expand All @@ -30,39 +43,42 @@ GOLANGCILINTRUN=$(GOLANGCILINTCMD) run
# --- Go Module Management

# Tidy Go modules
# This target cleans up `go.mod` and `go.sum` files by removing any unused dependencies.
# Use this command to ensure that the module files are in a clean state.
# This cleans up `go.mod` and `go.sum` by removing unused dependencies
# and ensuring that only the required packages are listed.
.PHONY: go-mod-tidy
go-mod-tidy:
$(GOMOD) tidy

# Update Go modules
# This target updates the Go module dependencies to their latest versions.
# It fetches and updates all modules, and any indirect dependencies.
# Updates all Go dependencies to their latest versions, including both direct and indirect dependencies.
# Useful for staying up-to-date with upstream changes and bug fixes.
.PHONY: go-mod-update
go-mod-update:
$(GOGET) -f -t -u ./... # Update test dependencies.
$(GOGET) -f -u ./... # Update other dependencies.
@# Update test dependencies.
$(GOGET) -f -t -u ./...
@# Update all other dependencies.
$(GOGET) -f -u ./...

# --- Go Code Quality and Testing

# Format Go code
# This target formats all Go source files according to Go's standard formatting rules using `go fmt`.
# Formats all Go source files in the current module according to Go's standard rules.
# Consistent formatting is crucial for code readability and collaboration.
.PHONY: go-fmt
go-fmt:
$(GOFMT) ./...

# Lint Go code
# This target lints the Go source code to ensure it adheres to best practices.
# It uses `golangci-lint` to run various static analysis checks on the code.
# It first runs the `go-fmt` target to ensure the code is properly formatted.
# Runs static analysis checks on the Go code using Golangci-lint.
# Ensures the code adheres to best practices and is free from common issues.
# This target also runs `go-fmt` beforehand to ensure the code is formatted.
.PHONY: go-lint
go-lint: go-fmt
$(GOLANGCILINTRUN) $(GOLANGCILINT) ./...

# Run Go tests
# This target runs all Go tests in the current module.
# The `GOFLAGS` flag ensures that tests are run with verbose output, providing more detailed information.
# Executes all unit tests in the module with detailed output.
# The `GOFLAGS` variable is used to enable verbosity, making it easier to debug test results.
.PHONY: go-test
go-test:
$(GOTEST) $(GOFLAGS) ./...
Expand All @@ -83,6 +99,9 @@ help:
@echo ""
@echo "Available commands:"
@echo ""
@echo " Preparation | Setup:"
@echo " prepare .................. prepare repository."
@echo ""
@echo " Go Commands:"
@echo " go-mod-tidy .............. Tidy Go modules."
@echo " go-mod-update ............ Update Go modules."
Expand All @@ -94,5 +113,6 @@ help:
@echo " help ..................... Display this help information"
@echo ""

# Default goal when `make` is run without arguments
# Set the default goal to `help`.
# This ensures that running `make` without arguments will display the help information.
.DEFAULT_GOAL = help
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/hueristiq/hq-go-http

go 1.23.1
go 1.23.3

require (
github.com/hueristiq/hq-go-retrier v0.0.0-20241124123316-75e4987d3cb6
github.com/hueristiq/hq-go-retrier v0.0.0-20241130122723-f060264d9262
github.com/hueristiq/hqgoutils v0.0.0-20231024005153-bd2c47932440
golang.org/x/net v0.31.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hueristiq/hq-go-retrier v0.0.0-20241122195731-385c7d253525 h1:DXsl0OsSlVOHpcZg1zmiH38OPCnM282ryOrt4QJkojI=
github.com/hueristiq/hq-go-retrier v0.0.0-20241122195731-385c7d253525/go.mod h1:YkxIHoJHsL0wmzQ3tc0qz4UTr9q9eCicUt5RvMV//xw=
github.com/hueristiq/hq-go-retrier v0.0.0-20241124123316-75e4987d3cb6 h1:MrT8DTES74Y5l79N6PPPg3q/GbHQWQcats76FBs6Er0=
github.com/hueristiq/hq-go-retrier v0.0.0-20241124123316-75e4987d3cb6/go.mod h1:1SITeMGkM7cJh41P9zMoXqbp5h8fxlF9nuPdynkwjjI=
github.com/hueristiq/hq-go-retrier v0.0.0-20241130122723-f060264d9262 h1:mEJOmRcl2l0mDrk6pwLSYTrcLXWlAGsGMEQGMtcc/C8=
github.com/hueristiq/hq-go-retrier v0.0.0-20241130122723-f060264d9262/go.mod h1:0gJoaPQEgXzuXWxqGS8eMQarow9FFjRuL/zyeTZPyuw=
github.com/hueristiq/hqgoutils v0.0.0-20231024005153-bd2c47932440 h1:dpHAa9c74HgAXkZ2WPd84q2cCiF76eluuSGRw7bk7To=
github.com/hueristiq/hqgoutils v0.0.0-20231024005153-bd2c47932440/go.mod h1:NlZ117o///yWDbRAbgYD7/Y44qce8z1Dj4caUsjunSY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
Expand Down

0 comments on commit 5381a75

Please sign in to comment.