Skip to content

Commit

Permalink
🔥 wip: enhance structure
Browse files Browse the repository at this point in the history
  • Loading branch information
zcubbs committed Oct 15, 2023
1 parent 4b19718 commit 7d143b9
Show file tree
Hide file tree
Showing 110 changed files with 611 additions and 144 deletions.
5 changes: 0 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
indent_style = tab
indent_size = 4

[*.md]
indent_size = 4
trim_trailing_whitespace = false

[Taskfile.yaml]
indent_size = 2
indent_style = tab

[Dockerfile]
indent_size = 4
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters-settings:
gosec:
# To specify a set of rules to explicitly exclude.
# Available rules: https://github.com/securego/gosec#available-rules
excludes: []
105 changes: 105 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---

project_name: tlz
before:
hooks:
- go mod tidy
builds:
- env: [CGO_ENABLED=0]
binary: tlz
goos:
- linux
goarch:
- amd64
- arm64
id: "cli"
dir: .
main: ./cmd/server/main.go
ldflags:
- -s -w -X main.Version={{.Version}} -X main.Commit={{.Commit}} -X main.Date={{.Date}}

archives:
- id: cli-archive
format: tar.gz
files:
- none*
builds:
- cli
format_overrides:
- goos: windows
format: zip
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
dockers:
- use: buildx
goos: linux
goarch: amd64
image_templates:
- "ghcr.io/zcubbs/{{ .ProjectName }}:{{ .Version }}-amd64"
- "ghcr.io/zcubbs/{{ .ProjectName }}:latest-amd64"
build_flag_templates:
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- use: buildx
goos: linux
goarch: arm64
image_templates:
- "ghcr.io/zcubbs/{{ .ProjectName }}:{{ .Version }}-arm64"
- "ghcr.io/zcubbs/{{ .ProjectName }}:latest-arm64"
build_flag_templates:
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
docker_manifests:
- name_template: ghcr.io/zcubbs/{{ .ProjectName }}:{{ .Version }}
image_templates:
- ghcr.io/zcubbs/{{ .ProjectName }}:{{ .Version }}-amd64
- ghcr.io/zcubbs/{{ .ProjectName }}:{{ .Version }}-arm64
- name_template: ghcr.io/zcubbs/{{ .ProjectName }}:latest
image_templates:
- ghcr.io/zcubbs/{{ .ProjectName }}:latest-amd64
- ghcr.io/zcubbs/{{ .ProjectName }}:latest-arm64
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^conf:'
snapshot:
name_template: SNAPSHOT-{{ .Commit }}
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
signs:
- cmd: gpg
args:
- --output
- $signature
- --detach-sig
- $artifact
signature: ${artifact}.sig
artifacts: none
release:
gittlz:
owner: zcubbs
name: tlz
draft: false
prerelease: auto
header: |
## ({{ .Date }})
Welcome to this new release!
footer: |
## Thanks!
Those were the changes on {{ .Tag }}!
name_template: "{{.Tag}}"
2 changes: 1 addition & 1 deletion .gosec.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"global": {
"exclude": "G404,G402"
"exclude": "G203"
}
}
126 changes: 36 additions & 90 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
version: '3'

includes:
bootstrap_tasks: .taskfiles/bootstrap.yaml
container_tasks: .taskfiles/containers.yaml
build_tasks: .taskfiles/build.yaml
test_tasks: .taskfiles/test.yaml
gen_tasks: .taskfiles/gen.yaml

env:
GOOS: "{{OS}}"

Expand All @@ -15,114 +8,67 @@ vars:
LOCAL_HOST: 127.0.0.1

tasks:

################################################################
# Bootstrap tasks
################################################################
bootstrap:
desc: Install all necessary tools and CLI dependencies
cmds:
- task: bootstrap_tasks:local

boostrap:gh:
desc: Install all necessary tools and CLI dependencies for GitHub Actions
test:
cmds:
- task: bootstrap_tasks:gh

- go test ./...

################################################################
# Build tasks
################################################################
build:
cmds:
- task: build_tasks:build
- task: build:{{OS}}

build:pack:
build:windows:
cmds:
- task: build_tasks:build:pack
- go env -w GOOS=windows GOARCH=amd64
- go build -o bin/server.exe ./cmd/server/main.go

build:pack:gh:
build:darwin:
cmds:
- task: build_tasks:build:pack:gh
- go env -w GOOS=darwin GOARCH=amd64
- go build -o bin/server ./cmd/server/main.go

################################################################
# Test tasks
################################################################
lint:
build:linux:
cmds:
- task: test_tasks:lint

scan:
cmds:
- task: test_tasks:scan

test:
cmds:
- task: test_tasks:test
- go env -w GOOS=linux GOARCH=amd64
- go build -o bin/server ./cmd/server/main.go

run:
cmds:
- task: test_tasks:run
- task: build:{{OS}}
- task: run:{{OS}}
vars:
ARGS: "{{.CLI_ARGS}}"

preview:
run:darwin:
cmds:
- task: test_tasks:preview

evans:
- bin/server {{.ARGS}}
run:linux:
cmds:
- task: test_tasks:evans

################################################################
# Generate tasks
################################################################
proto:
- bin/server {{.ARGS}}
run:windows:
cmds:
- task: gen_tasks:proto
- bin/server.exe {{.ARGS}}

mock:
cmds:
- task: gen_tasks:mock

sqlc:
cmds:
- task: gen_tasks:sqlc


################################################################
# Container tasks
################################################################
pg:
cmds:
- task: container_tasks:pg

pg:start:
cmds:
- task: container_tasks:pg:start

pg:down:
cmds:
- task: container_tasks:pg:down

redis:
lint:
cmds:
- task: container_tasks:redis
- golangci-lint run ./... -v --timeout 5m

redis:start:
scan:
cmds:
- task: container_tasks:redis:start
- gosec -conf .gosec.config.json "./..."

redis:down:
tools:install:
desc: Install tools
cmds:
- task: container_tasks:redis:down
- task tools:install:golangci-lint
- task tools:install:gosec

mailhog:
tools:install:golangci-lint:
desc: Install golangci-lint
cmds:
- task: container_tasks:mailhog
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

mailhog:start:
tools:install:gosec:
desc: Install gosec
cmds:
- task: container_tasks:mailhog:start
- go install github.com/securego/gosec/v2/cmd/gosec@latest

mailhog:down:
cmds:
- task: container_tasks:mailhog:down
File renamed without changes.
2 changes: 1 addition & 1 deletion api/converter.go → cmd/server/api/converter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/pb"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion api/main_test.go → cmd/server/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"github.com/stretchr/testify/require"
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/internal/util"
"github.com/zcubbs/tlz/worker"
"github.com/zcubbs/x/random"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"github.com/hibiken/asynq"
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/internal/validator"

Check failure on line 7 in cmd/server/api/rpc_create_user.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/zcubbs/tlz/internal/validator; to add it:
"github.com/zcubbs/tlz/pb"
"github.com/zcubbs/tlz/worker"

Check failure on line 9 in cmd/server/api/rpc_create_user.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/zcubbs/tlz/worker; to add it:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"database/sql"
"fmt"
"github.com/stretchr/testify/require"
mockdb "github.com/zcubbs/tlz/db/mock"
db "github.com/zcubbs/tlz/db/sqlc"
mockdb "github.com/zcubbs/tlz/cmd/server/db/mock"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/pb"
"github.com/zcubbs/tlz/worker"
mockwk "github.com/zcubbs/tlz/worker/mock"
Expand Down
2 changes: 1 addition & 1 deletion api/rpc_login_user.go → cmd/server/api/rpc_login_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"errors"
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/pb"
"github.com/zcubbs/x/password"
"google.golang.org/grpc/codes"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"database/sql"
"errors"
"github.com/jackc/pgx/v5/pgtype"
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/internal/validator"
"github.com/zcubbs/tlz/pb"
"github.com/zcubbs/x/password"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"context"
"github.com/google/uuid"
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/internal/validator"
"github.com/zcubbs/tlz/pb"
"google.golang.org/genproto/googleapis/rpc/errdetails"
Expand Down
2 changes: 1 addition & 1 deletion api/server.go → cmd/server/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/charmbracelet/log"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/rs/cors"
db "github.com/zcubbs/tlz/db/sqlc"
db "github.com/zcubbs/tlz/cmd/server/db/sqlc"
"github.com/zcubbs/tlz/internal/util"

Check failure on line 11 in cmd/server/api/server.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/zcubbs/tlz/internal/util; to add it:
"github.com/zcubbs/tlz/pb"
"github.com/zcubbs/tlz/pkg/token"
Expand Down
Loading

0 comments on commit 7d143b9

Please sign in to comment.