MT

mpyw/txbypass

Developer tools

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기

4 stars 품질 58 트렌드 25MIT

Go linter that reports a database handle used from inside a transaction it bypasses

개요

Go linter that reports a database handle used inside a transaction it opened. The callback receives the transaction as tx. r.db is the pool the transaction came from, so the audit log is written outside the transaction. The code compiles. A test where nothing fails passes too. txbypass finds it from the source. Every report ends with the name of its rule. That name is what //txbypass:ignore takes. Pin a version, run through go vet or golangci-lint, or install from an archive mise use pins the version in the project's mise.toml, so every checkout and CI run the same one. Add -g to install it for every project on your machine instead. Through go vet, which runs it with the same package loading as the rest of your vet checks, and caches it: From a release archive, verified against the published checksums:

README

원문 README의 일부입니다. 원문 보기.

Go linter that reports a database handle used inside a transaction it opened.

Overview

package app

import (
	"context"

	"gorm.io/gorm"
)

func (r *OrderRepo) Place(
	ctx context.Context,
	o *Order,
) error {
	return r.db.WithContext(ctx).Transaction(
		func(tx *gorm.DB) error {
			if err := tx.Create(o).Error; err != nil {
				return err
			}
			log := &AuditLog{OrderID: o.ID}
			return r.db.Create(log).Error
		},
	)
}
$ txbypass ./...
order.go:19:11: r.db bypasses the transaction opened with Transaction; use tx instead [outer-handle]

The callback receives the transaction as tx. r.db is the pool the transaction came from, so the audit log is written outside the transaction.

The code compiles. A test where nothing fails passes too. txbypass finds it from the source.

Every report of a rule ends with the rule’s name. That name is what //txbypass:ignore takes. A report about a directive itself names no rule, and no ignore silences it.

Install

Method Command Needs
mise (recommended) mise use "github:mpyw/[email protected]" Nothing. Installs the prebuilt binary
go tool go get -tool github.com/mpyw/txbypass/cmd/txbypass@latest Go 1.26+
go install go install github.com/mpyw/txbypass/cmd/txbypass@latest Go 1.26+
Release archive See below Nothing
txbypass ./...
GitHub에서 전체 README 보기

추천 도구

다른 키워드를 입력하거나 필터를 제거해 보세요.

설치

npx skillfish add mpyw/txbypass
MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →