Skip to content

Instantly share code, notes, and snippets.

@netologist
Last active April 30, 2026 11:57
Show Gist options
  • Select an option

  • Save netologist/16cce3c356a5795bbf8c62fa5ab33d78 to your computer and use it in GitHub Desktop.

Select an option

Save netologist/16cce3c356a5795bbf8c62fa5ab33d78 to your computer and use it in GitHub Desktop.
golang project initial files
.git
.gitignore
Dockerfile
Taskfile.yml
lefthook.yml
.editorconfig
bin/
dist/
*.test
*.out
.idea/
.vscode/
.env
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
end_of_line = lf
[*.go]
indent_style = tab
indent_size = 4
[*.{yml,yaml}]
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab
# Binaries
bin/
dist/
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test ve Coverage
*.test
*.out
# Go Workspace ve Bağımlılıklar
go.work
go.work.sum
# vendor/ # Genelde ignore edilir, ihtiyaca göre açılabilir
# IDE ve OS Dosyaları
.idea/
.vscode/
*.swp
.DS_Store
# Gizli Değişkenler
.env
.env.local
run:
timeout: 5m
modules-download-mode: readonly
linters:
disable-all: true
enable:
- errcheck # Hata kontrollerinin unutulup unutulmadığına bakar
- gosimple # Kodu daha basit yazma önerileri sunar
- govet # Go'nun standart analiz aracı
- ineffassign # Gereksiz değişken atamalarını bulur
- staticcheck # Gelişmiş statik analiz yapar
- unused # Kullanılmayan kodları bulur
- revive # Stil hatalarını yakalar (golint'in modern hali)
- goconst # Tekrar eden string'leri bulur, "const yap" der
- bodyclose # HTTP yanıt gövdelerinin kapatılıp kapatılmadığını kontrol eder
issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
# 1. Aşama: Build (Derleme)
FROM golang:1.22-alpine AS builder
# Gerekli sistem araçlarını yükle
RUN apk add --no-cache git ca-certificates
# Çalışma dizinini ayarla
WORKDIR /app
# Bağımlılıkları kopyala ve indir (Docker katman önbellekleme için önce bu yapılır)
COPY go.mod go.sum ./
RUN go mod download
# Kaynak kodunu kopyala
COPY . .
# Uygulamayı derle (CGO_ENABLED=0 statik bir binary oluşturur, alpine'da sorunsuz çalışır)
# Not: Giriş noktanız main.go ise yolu ona göre güncelleyin.
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/main .
# 2. Aşama: Final (Çalıştırma)
FROM alpine:latest
RUN apk --no-cache add ca-certificates
# Güvenlik için kök olmayan (non-root) bir kullanıcı oluştur
RUN adduser -D appuser
WORKDIR /home/appuser
# Builder aşamasından sadece derlenmiş binary dosyasını kopyala
COPY --from=builder /app/main .
# Kullanıcıyı değiştir (Root yetkisiyle çalıştırmamak güvenlik için önemlidir)
USER appuser
# Uygulamanızın kullandığı port (Örn: 8080)
EXPOSE 8080
# Uygulamayı çalıştır
CMD ["./main"]
# Git commit öncesi yapılacaklar
pre-commit:
parallel: true
commands:
# Sadece değişen dosyalarda linter çalıştırır (performans için)
linter:
run: golangci-lint run --fast
# Go dosyalarını formatlar
fmt:
glob: "*.go"
run: gofmt -w {staged_files} && git add {staged_files}
# go.mod tutarlılığını kontrol eder
mod-check:
run: go mod verify
# Git push öncesi yapılacaklar
pre-push:
commands:
# Push etmeden önce tüm testlerin geçtiğinden emin olalım
unit-tests:
run: go test ./...
version: '3'
vars:
BINARY_NAME: my-app
GO_FILES:
sh: find . -name '*.go' -not -path "./vendor/*"
tasks:
build:
desc: Uygulamayı derler
cmds:
- go build -o bin/{{.BINARY_NAME}} main.go
run:
desc: Uygulamayı çalıştırır
cmds:
- go run main.go
test:
desc: Testleri çalıştırır
cmds:
- go test -v ./...
lint:
desc: Linter'ı çalıştırır (golangci-lint)
cmds:
- golangci-lint run
tidy:
desc: go.mod dosyasını temizler
cmds:
- go mod tidy
clean:
desc: Derleme çıktılarını temizler
cmds:
- rm -rf bin/
//go:build tools
// This file tracks development tool dependencies.
// Install all tools with: go generate ./tools.go
// Or manually: go install <tool>@latest
package tools
// gopls: Official Go language server, provides IDE features (autocomplete, go-to-def, hover docs)
//go:generate go install golang.org/x/tools/cmd/gopls@latest
// golangci-lint: Fast, configurable linter aggregator — runs many linters in parallel
//go:generate go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
// goimports: Automatically adds/removes imports and formats code (superset of gofmt)
//go:generate go install golang.org/x/tools/cmd/goimports@latest
// gotestsum: Better test runner output — human-friendly formatting and JUnit XML reports
//go:generate go install gotest.tools/gotestsum@latest
// mockery: Generates type-safe mock implementations from Go interfaces for unit testing
//go:generate go install github.com/vektra/mockery/v2@latest
// dlv (Delve): Full-featured Go debugger — supports breakpoints, goroutine inspection, etc.
//go:generate go install github.com/go-delve/delve/cmd/dlv@latest
// govulncheck: Official Go vulnerability scanner — checks your deps against the Go vuln DB
//go:generate go install golang.org/x/vuln/cmd/govulncheck@latest
// protoc-gen-go: Protobuf compiler plugin — generates Go structs from .proto files
//go:generate go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
// protoc-gen-go-grpc: gRPC compiler plugin — generates Go server/client stubs from .proto files
//go:generate go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
// sqlc: Generates type-safe Go code from raw SQL queries and schema definitions
//go:generate go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
// pprof: CPU and memory profiling tool — visualises performance bottlenecks
//go:generate go install github.com/google/pprof@latest
// gqlgen: GraphQL server code generator — generates resolvers and models from GraphQL schema
//go:generate go install github.com/99designs/gqlgen@latest
// air: Live reload for Go apps — watches for file changes and auto-restarts the server
//go:generate go install github.com/air-verse/air@latest
// buf: Modern Protobuf toolchain — linting, breaking change detection, and code generation
//go:generate go install github.com/bufbuild/buf/cmd/buf@latest
// lefthook: Fast, polyglot git hooks manager — run linters/tests on commit or push
//go:generate go install github.com/evilmartians/lefthook/v2@latest
// task: Modern Makefile alternative — define and run tasks via a simple YAML Taskfile
//go:generate go install github.com/go-task/task/v3/cmd/task@latest
// oapi-codegen: Generates Go server boilerplate and types from OpenAPI 3.x specs
//go:generate go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
// goose: Database migration tool — supports SQL and Go migrations with versioning
//go:generate go install github.com/pressly/goose/v3/cmd/goose@latest
// staticcheck: Advanced static analysis — catches bugs and performance issues beyond golangci-lint
//go:generate go install honnef.co/go/tools/cmd/staticcheck@latest
import (
_ "github.com/99designs/gqlgen"
_ "github.com/air-verse/air"
_ "github.com/bufbuild/buf/cmd/buf"
_ "github.com/evilmartians/lefthook/v2"
_ "github.com/go-delve/delve/cmd/dlv"
_ "github.com/go-task/task/v3/cmd/task"
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "github.com/google/pprof"
_ "github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen"
_ "github.com/pressly/goose/v3/cmd/goose"
_ "github.com/sqlc-dev/sqlc/cmd/sqlc"
_ "github.com/vektra/mockery/v2"
_ "golang.org/x/tools/cmd/goimports"
_ "golang.org/x/tools/cmd/gopls"
_ "golang.org/x/vuln/cmd/govulncheck"
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
_ "gotest.tools/gotestsum"
_ "honnef.co/go/tools/cmd/staticcheck"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment