rename.sh respects gitea host url
This commit is contained in:
parent
ba96926176
commit
9c79b250ef
@ -13,6 +13,6 @@ dir: "mocks/{{.PackageName}}"
|
|||||||
# Packages whose interfaces should be mocked.
|
# Packages whose interfaces should be mocked.
|
||||||
# Add entries here whenever you define an interface that other packages depend on.
|
# Add entries here whenever you define an interface that other packages depend on.
|
||||||
packages:
|
packages:
|
||||||
github.com/your-org/go-template/internal/greeter:
|
gitea.djmil.dev/djmil/go-template/internal/greeter:
|
||||||
interfaces:
|
interfaces:
|
||||||
Greeter:
|
Greeter:
|
||||||
|
|||||||
@ -11,7 +11,7 @@ Go 1.24 template / PoC starter. Demonstrates: structured logging (zap),
|
|||||||
config (viper), interfaces + mocks (mockery), linting (golangci-lint),
|
config (viper), interfaces + mocks (mockery), linting (golangci-lint),
|
||||||
security scanning (gosec, govulncheck), git hooks, devcontainer, VSCode tasks.
|
security scanning (gosec, govulncheck), git hooks, devcontainer, VSCode tasks.
|
||||||
|
|
||||||
Module: `github.com/your-org/go-template` — update this when you fork.
|
Module: `gitea.djmil.dev/djmil/go-template` — update this when you fork.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ tools.go Tool version pinning (build tag: tools)
|
|||||||
|
|
||||||
## Project rules
|
## Project rules
|
||||||
|
|
||||||
- **Module imports** — always use the full module path `github.com/your-org/go-template/...`
|
- **Module imports** — always use the full module path `gitea.djmil.dev/djmil/go-template/...`
|
||||||
- **Packages** — keep `cmd/` thin (wiring only); business logic belongs in `internal/`
|
- **Packages** — keep `cmd/` thin (wiring only); business logic belongs in `internal/`
|
||||||
- **Interfaces** — define interfaces where they are *used*, not where they are *implemented*
|
- **Interfaces** — define interfaces where they are *used*, not where they are *implemented*
|
||||||
- **Errors** — wrap with `fmt.Errorf("context: %w", err)`; never swallow errors silently
|
- **Errors** — wrap with `fmt.Errorf("context: %w", err)`; never swallow errors silently
|
||||||
|
|||||||
@ -157,7 +157,7 @@ In production (`app.env != dev`) the output is JSON. In development, use
|
|||||||
Generated mocks support type-safe EXPECT() call chains:
|
Generated mocks support type-safe EXPECT() call chains:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import mocks "github.com/you/my-project/mocks/greeter"
|
import mocks "gitea.djmil.dev/djmil/go-template/mocks/greeter"
|
||||||
|
|
||||||
func TestSomething(t *testing.T) {
|
func TestSomething(t *testing.T) {
|
||||||
g := mocks.NewMockGreeter(t)
|
g := mocks.NewMockGreeter(t)
|
||||||
|
|||||||
@ -7,9 +7,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/your-org/go-template/internal/config"
|
"gitea.djmil.dev/djmil/go-template/internal/config"
|
||||||
"github.com/your-org/go-template/internal/greeter"
|
"gitea.djmil.dev/djmil/go-template/internal/greeter"
|
||||||
"github.com/your-org/go-template/internal/logger"
|
"gitea.djmil.dev/djmil/go-template/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module github.com/your-org/go-template
|
module gitea.djmil.dev/djmil/go-template
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package greeter
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/your-org/go-template/internal/logger"
|
"gitea.djmil.dev/djmil/go-template/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate mockery --name=Greeter
|
//go:generate mockery --name=Greeter
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/your-org/go-template/internal/greeter"
|
"gitea.djmil.dev/djmil/go-template/internal/greeter"
|
||||||
"github.com/your-org/go-template/internal/logger"
|
"gitea.djmil.dev/djmil/go-template/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ── Service (unit tests) ──────────────────────────────────────────────────────
|
// ── Service (unit tests) ──────────────────────────────────────────────────────
|
||||||
@ -39,7 +39,7 @@ func TestGreet(t *testing.T) {
|
|||||||
|
|
||||||
func TestMockUsageExample(t *testing.T) {
|
func TestMockUsageExample(t *testing.T) {
|
||||||
// Import path when used in another package:
|
// Import path when used in another package:
|
||||||
// mocks "github.com/your-org/go-template/mocks/greeter"
|
// mocks "gitea.djmil.dev/djmil/go-template/mocks/greeter"
|
||||||
//
|
//
|
||||||
// mock := mocks.NewMockGreeter(t)
|
// mock := mocks.NewMockGreeter(t)
|
||||||
// mock.EXPECT().Greet("Alice").Return("Hello, Alice!", nil)
|
// mock.EXPECT().Greet("Alice").Return("Hello, Alice!", nil)
|
||||||
|
|||||||
18
rename.sh
18
rename.sh
@ -25,6 +25,10 @@ warn() { echo -e "${YELLOW}!${RESET} $*"; }
|
|||||||
error() { echo -e "${RED}✗${RESET} $*" >&2; }
|
error() { echo -e "${RED}✗${RESET} $*" >&2; }
|
||||||
heading() { echo -e "\n${BOLD}$*${RESET}"; }
|
heading() { echo -e "\n${BOLD}$*${RESET}"; }
|
||||||
|
|
||||||
|
# ── Default Git host ──────────────────────────────────────────────────────────
|
||||||
|
# Change this if you ever migrate to a different server.
|
||||||
|
DEFAULT_HOST="gitea.djmil.dev"
|
||||||
|
|
||||||
# ── Validation ────────────────────────────────────────────────────────────────
|
# ── Validation ────────────────────────────────────────────────────────────────
|
||||||
validate_slug() {
|
validate_slug() {
|
||||||
local val="$1" label="$2"
|
local val="$1" label="$2"
|
||||||
@ -54,7 +58,7 @@ if [[ ! -f go.mod ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
CURRENT_MODULE=$(grep '^module ' go.mod | awk '{print $2}')
|
CURRENT_MODULE=$(grep '^module ' go.mod | awk '{print $2}')
|
||||||
TEMPLATE_MODULE="github.com/your-org/go-template"
|
TEMPLATE_MODULE="${DEFAULT_HOST}/djmil/go-template"
|
||||||
|
|
||||||
if [[ "$CURRENT_MODULE" != "$TEMPLATE_MODULE" ]]; then
|
if [[ "$CURRENT_MODULE" != "$TEMPLATE_MODULE" ]]; then
|
||||||
warn "Module is already '$CURRENT_MODULE' (not the default template value)."
|
warn "Module is already '$CURRENT_MODULE' (not the default template value)."
|
||||||
@ -72,11 +76,11 @@ if [[ $# -ge 2 ]]; then
|
|||||||
NEW_PROJECT="$2"
|
NEW_PROJECT="$2"
|
||||||
else
|
else
|
||||||
while true; do
|
while true; do
|
||||||
read -rp "GitHub org or username (e.g. acme-corp): " NEW_ORG
|
read -rp "Org / username (e.g. djmil): " NEW_ORG
|
||||||
validate_slug "$NEW_ORG" "Org/username" && break
|
validate_slug "$NEW_ORG" "Org/username" && break
|
||||||
done
|
done
|
||||||
while true; do
|
while true; do
|
||||||
read -rp "Project / repo name (e.g. my-service): " NEW_PROJECT
|
read -rp "Project name (e.g. my-service): " NEW_PROJECT
|
||||||
validate_slug "$NEW_PROJECT" "Project name" && break
|
validate_slug "$NEW_PROJECT" "Project name" && break
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
@ -84,7 +88,7 @@ fi
|
|||||||
validate_slug "$NEW_ORG" "Org/username"
|
validate_slug "$NEW_ORG" "Org/username"
|
||||||
validate_slug "$NEW_PROJECT" "Project name"
|
validate_slug "$NEW_PROJECT" "Project name"
|
||||||
|
|
||||||
NEW_MODULE="github.com/${NEW_ORG}/${NEW_PROJECT}"
|
NEW_MODULE="${DEFAULT_HOST}/${NEW_ORG}/${NEW_PROJECT}"
|
||||||
OLD_MODULE="$CURRENT_MODULE"
|
OLD_MODULE="$CURRENT_MODULE"
|
||||||
OLD_PROJECT=$(basename "$OLD_MODULE") # e.g. go-template
|
OLD_PROJECT=$(basename "$OLD_MODULE") # e.g. go-template
|
||||||
NEW_DISPLAY=$(to_title "$NEW_PROJECT") # e.g. My Service
|
NEW_DISPLAY=$(to_title "$NEW_PROJECT") # e.g. My Service
|
||||||
@ -161,12 +165,8 @@ fi
|
|||||||
|
|
||||||
# 6. README.md — heading + all module path occurrences
|
# 6. README.md — heading + all module path occurrences
|
||||||
if [[ -f README.md ]]; then
|
if [[ -f README.md ]]; then
|
||||||
# Top-level heading
|
|
||||||
sedi "s|^# ${OLD_PROJECT}$|# ${NEW_PROJECT}|g" README.md
|
sedi "s|^# ${OLD_PROJECT}$|# ${NEW_PROJECT}|g" README.md
|
||||||
# Any leftover template module paths (including the 'github.com/you/my-project' placeholder)
|
|
||||||
sedi "s|${OLD_MODULE}|${NEW_MODULE}|g" README.md
|
sedi "s|${OLD_MODULE}|${NEW_MODULE}|g" README.md
|
||||||
sedi "s|github\.com/you/my-project|${NEW_MODULE}|g" README.md
|
|
||||||
# app.name reference in the config block
|
|
||||||
sedi "s|name: \"${OLD_PROJECT}\"|name: \"${NEW_PROJECT}\"|g" README.md
|
sedi "s|name: \"${OLD_PROJECT}\"|name: \"${NEW_PROJECT}\"|g" README.md
|
||||||
info "README.md"
|
info "README.md"
|
||||||
fi
|
fi
|
||||||
@ -188,4 +188,4 @@ echo " make build # verify it compiles"
|
|||||||
echo " make test # verify tests pass"
|
echo " make test # verify tests pass"
|
||||||
echo
|
echo
|
||||||
warn "If you renamed the directory on disk, update git remote too:"
|
warn "If you renamed the directory on disk, update git remote too:"
|
||||||
echo " git remote set-url origin git@github.com:${NEW_ORG}/${NEW_PROJECT}.git"
|
echo " git remote set-url origin git@${DEFAULT_HOST}:${NEW_ORG}/${NEW_PROJECT}.git"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user