-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from iquzart/hexagonal_structure
Restructure
- Loading branch information
Showing
1,218 changed files
with
399,480 additions
and
53,711 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.DEFAULT_GOAL := help | ||
.PHONY: help clean build run docker-build docker-run docker-stop | ||
|
||
# Define variables | ||
BINARY_NAME := go-app | ||
DOCKER_IMAGE := make-go-app | ||
DOCKER_CONTAINER := make-go-app | ||
MAIN_FILE := cmd/app/main.go | ||
LDFLAGS := -ldflags="-s -w" | ||
|
||
help: ## Display this help message | ||
@echo "Usage: make <command>" | ||
@echo "" | ||
@echo "Commands:" | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
||
clean: ## Remove binary file and container resources | ||
rm -f $(BINARY_NAME) | ||
docker stop $(DOCKER_CONTAINER) || true | ||
docker rm $(DOCKER_CONTAINER) || true | ||
docker rmi $(DOCKER_IMAGE) || true | ||
|
||
build: ## Build the binary file | ||
go build $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_FILE) | ||
|
||
run: ## Build and run the binary file | ||
go run $(LDFLAGS) $(MAIN_FILE) | ||
|
||
docker-build: ## Build Docker image | ||
docker build -t $(DOCKER_IMAGE) . -f ./Containerfile | ||
|
||
docker-run: ## Run Docker container | ||
@if ! docker image inspect $(DOCKER_IMAGE) >/dev/null 2>&1; then \ | ||
make docker-build; \ | ||
fi | ||
docker run -d -p 8080:8080 --name $(DOCKER_CONTAINER) $(DOCKER_IMAGE) | ||
|
||
|
||
docker-stop: ## Stop Docker container | ||
docker stop $(DOCKER_CONTAINER) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
|
||
import "go-app/pkg/server" | ||
|
||
func main() { | ||
// Start the server | ||
server.Run() | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
// Server contains the HTTP server configurations. | ||
type ServerConfigs struct { | ||
Port string | ||
GracefulShutdown bool | ||
ServiceName string | ||
} | ||
|
||
// NewServer creates a new Server instance with default values. | ||
func GetServerConfigs() *ServerConfigs { | ||
return &ServerConfigs{ | ||
Port: fmt.Sprintf(":%s", getEnvOrDefault("PORT", "8080")), | ||
GracefulShutdown: getEnvOrDefaultBool("ENABLE_GRACEFUL_SHUTDOWN", true), | ||
ServiceName: getEnvOrDefault("SERVICE_NAME", "go-app"), | ||
} | ||
} | ||
|
||
func getEnvOrDefault(key, defaultValue string) string { | ||
value := os.Getenv(key) | ||
if value == "" { | ||
return defaultValue | ||
} | ||
return value | ||
} | ||
|
||
func getEnvOrDefaultBool(key string, defaultValue bool) bool { | ||
value, err := strconv.ParseBool(os.Getenv(key)) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return value | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.