Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f36e3bb840 | ||
|
|
fff3f28ba4 | ||
|
|
2e30da54e2 | ||
|
|
f67d57fedf |
10
Makefile
10
Makefile
@@ -1,9 +1,9 @@
|
|||||||
.PHONY: *
|
.PHONY: *
|
||||||
|
|
||||||
help: ## This help dialog.
|
help:
|
||||||
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 | "sort -u"}' $(MAKEFILE_LIST)
|
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 | "sort -u"}' $(MAKEFILE_LIST)
|
||||||
|
|
||||||
check-docker: ## Verify Docker CLI is available
|
check-docker: ## Verify Docker CLI available
|
||||||
@command -v docker >/dev/null 2>&1 || { \
|
@command -v docker >/dev/null 2>&1 || { \
|
||||||
echo "Error: docker not found."; \
|
echo "Error: docker not found."; \
|
||||||
echo "Install Docker Desktop: https://docs.docker.com/desktop/setup/install/mac-install/"; \
|
echo "Install Docker Desktop: https://docs.docker.com/desktop/setup/install/mac-install/"; \
|
||||||
@@ -17,20 +17,20 @@ run: check-docker ## Start the application with Docker Compose
|
|||||||
run-local: ## Start the application locally (without Docker)
|
run-local: ## Start the application locally (without Docker)
|
||||||
go run ./cmd/app
|
go run ./cmd/app
|
||||||
|
|
||||||
down: check-docker ## Stop the application
|
down: check-docker
|
||||||
docker compose down --remove-orphans
|
docker compose down --remove-orphans
|
||||||
|
|
||||||
setup-local: copy-config install-dependencies ## Install config and Go dependencies
|
setup-local: copy-config install-dependencies ## Install config and Go dependencies
|
||||||
|
|
||||||
setup-docker: setup-local run ## Install dependencies and start with Docker Compose
|
setup-docker: setup-local run ## Install dependencies and start with Docker Compose
|
||||||
|
|
||||||
install-lint: ## Install Go lint
|
install-lint:
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||||
|
|
||||||
install-dependencies: ## Install Go project dependencies
|
install-dependencies: ## Install Go project dependencies
|
||||||
go mod download
|
go mod download
|
||||||
|
|
||||||
copy-config: ## Copy config file if missing
|
copy-config:
|
||||||
@test -f .env || cp .env.dist .env
|
@test -f .env || cp .env.dist .env
|
||||||
|
|
||||||
lint: install-lint ## Run lint
|
lint: install-lint ## Run lint
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Go HTTP server
|
# Go HTTP server
|
||||||
|
|
||||||
A simple Go HTTP server boilerplate with Echo, structured logging, graceful shutdown, and Docker support.
|
A simple Go HTTP server boilerplate with Echo, structured logging, and Docker support.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
|
|||||||
BIN
bin/server
BIN
bin/server
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
package httpjson
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package httpjson
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package httpjson
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package httpjson
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/kjannette/go_http_server/cmd/app/handler/httpjson"
|
"github.com/kjannette/go_http_server/cmd/app/handler"
|
||||||
"github.com/kjannette/go_http_server/internal/config"
|
"github.com/kjannette/go_http_server/internal/config"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@@ -14,7 +14,7 @@ func run(ctx context.Context, cfg *config.Config) error {
|
|||||||
lg := zap.L().With(zap.String("app_name", appName), zap.String("app_version", appVersion))
|
lg := zap.L().With(zap.String("app_name", appName), zap.String("app_version", appVersion))
|
||||||
|
|
||||||
eg, ctx := errgroup.WithContext(ctx)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
app, h := httpjson.New(lg)
|
app, h := handler.New(lg)
|
||||||
serverLog := lg.Named("run_server")
|
serverLog := lg.Named("run_server")
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config represents the application configuration.
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
API struct {
|
API struct {
|
||||||
Port int `envconfig:"API_PORT" default:"3000"`
|
Port int `envconfig:"API_PORT" default:"3000"`
|
||||||
@@ -16,7 +15,6 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig creates a new initialised application Config.
|
|
||||||
func NewConfig() (*Config, error) {
|
func NewConfig() (*Config, error) {
|
||||||
var config Config
|
var config Config
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
)
|
)
|
||||||
|
|
||||||
// init initializes zap's global loggers (i.e. zap.L() and zap.S()).
|
|
||||||
// Log level is retrieved from environment variable LOG_LEVEL, defaulting to "info" otherwise.
|
// Log level is retrieved from environment variable LOG_LEVEL, defaulting to "info" otherwise.
|
||||||
// To activate this facility, add a blank import to this package.
|
// To activate this facility, add a blank import to this package.
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
Reference in New Issue
Block a user