Last active
April 19, 2025 16:12
-
-
Save CypherpunkSamurai/e9df70d6d30613f183706a4a69d24cd2 to your computer and use it in GitHub Desktop.
Golang Makefile Revised for GraphQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Golang Platform Independent Makefile | |
# This Makefile is designed to work on both Windows and Unix-like systems. | |
# Author: CyberPunkSamurai @github.com/CyberPunkSamurai | |
# License: MIT License (https://opensource.org/licenses/MIT) | |
# https://gist.github.com/CypherpunkSamurai/e9df70d6d30613f183706a4a69d24cd2 | |
# Go parameters | |
GOCMD=go | |
GOBUILD=$(GOCMD) build | |
GOCLEAN=$(GOCMD) clean | |
GOTEST=$(GOCMD) test | |
GOGET=$(GOCMD) get | |
GOMOD=$(GOCMD) mod | |
BINARY_NAME=GoFiberGQL | |
MAIN_FILE=server.go | |
MAIN_FILE_PATH=cmd/$(MAIN_FILE) | |
# Define main file path with platform-specific separators | |
ifeq ($(OS),Windows_NT) | |
MAIN_FILE_PATH=cmd\$(MAIN_FILE) | |
endif | |
# Platform-specific settings | |
ifeq ($(OS),Windows_NT) | |
BINARY_SUFFIX=.exe | |
RM=del /Q | |
else | |
BINARY_SUFFIX= | |
RM=rm -f | |
endif | |
# Add target to install binary | |
BINARY=$(BINARY_NAME)$(BINARY_SUFFIX) | |
.PHONY: all build clean test run tidy | |
all: clean tidy test build | |
build: clean tidy | |
@echo "Building the binary..." | |
$(GOBUILD) -o $(BINARY) $(MAIN_FILE_PATH) | |
clean: | |
rm -f $(BINARY) | |
$(GOCLEAN) | |
test: | |
$(GOTEST) -v ./... | |
run: build | |
./$(BINARY) | |
tidy: | |
$(GOMOD) tidy | |
generate: | |
@echo "Running all code generation tasks..." | |
@$(GOCMD) generate ./... | |
@echo "Code generation tasks completed." | |
# Additional targets for GraphQL | |
gqlinit: | |
@echo "Initializing GraphQL..." | |
@$(GOCMD) run github.com/99designs/gqlgen init | |
@echo "GraphQL initialized." | |
gqlgen: | |
@echo "Generating GraphQL binding code..." | |
@$(GOCMD) run github.com/99designs/gqlgen generate | |
@echo "GraphQL binding code updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment