Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# Dependency directories (remove the comment below to include it)
vendor/

# Go workspace file
go.work
# Go workspace checksum file
go.work.sum

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
Expand All @@ -37,4 +37,4 @@ bin/
logging/protoc-gen-go-redact/protoc-gen-go-redact

# cursor
.cursor
.cursor
56 changes: 56 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: "3"

vars:
GO_MODULES:
sh: find . -name go.mod -not -path './.git/*' -exec dirname {} \; | sort

tasks:
default:
desc: Run all repository verification checks.
cmds:
- task: all

all:
desc: Run all repository verification checks.
deps:
- test
- vet
- proto

test:
desc: Run tests for all Go modules.
cmds:
- for: { var: GO_MODULES }
task: test:module
vars:
MODULE: "{{.ITEM}}"

test:module:
internal: true
dir: "{{.MODULE}}"
cmds:
- go test ./...

vet:
desc: Run go vet for all Go modules.
cmds:
- for: { var: GO_MODULES }
task: vet:module
vars:
MODULE: "{{.ITEM}}"

vet:module:
internal: true
dir: "{{.MODULE}}"
cmds:
- go vet ./...

proto:
desc: Lint proto files with buf.
cmds:
- buf lint

verify:
desc: Run all repository verification checks.
cmds:
- task: all
6 changes: 6 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/googleapis/googleapis
commit: c17df5b2beca46928cc87d5656bd5343
digest: b5:648a01e0170d4512dea7d564016165decd1ed6e34bef79fe54753e51ad7e27545709ad9157d7551270147d551155c595a2fb0bf5bb33b1c83040ddbce915c604
6 changes: 4 additions & 2 deletions proto/buf.yaml → buf.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version: v2
name: buf.build/crypto-zero/go-kit
modules:
- path: proto
name: buf.build/crypto-zero/go-kit
deps:
- buf.build/googleapis/googleapis:main
lint:
Expand All @@ -10,4 +12,4 @@ lint:
breaking:
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
- FIELD_SAME_DEFAULT
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ A protoc plugin that generates `Redact()` methods for Protocol Buffer messages t
## Installation

```bash
go install github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact@latest
go install github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact@latest
```

Or build from source:

```bash
cd logging/protoc-gen-go-redact
cd cmd/protoc-gen-go-redact
go build -o protoc-gen-go-redact .
```

Expand Down Expand Up @@ -273,7 +273,7 @@ type Redacter interface {
Use with the logging middleware:

```go
import "github.com/crypto-zero/go-kit/logging/kratos"
import "github.com/crypto-zero/go-kit/kratos/logging"

// Server middleware
srv := http.NewServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact/internal/redact/testdata"
"github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact/internal/redact/testdata"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand All @@ -22,8 +22,7 @@ func BenchmarkRedact_SimpleMessage(b *testing.B) {
Age: 30,
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = user.Redact()
}
}
Expand All @@ -49,8 +48,7 @@ func BenchmarkRedact_NestedMessage(b *testing.B) {
},
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = account.Redact()
}
}
Expand All @@ -69,8 +67,7 @@ func BenchmarkRedact_DeepNested(b *testing.B) {
},
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = level1.Redact()
}
}
Expand Down Expand Up @@ -110,15 +107,14 @@ func BenchmarkRedact_AllScalarTypes(b *testing.B) {
RedactBytes: []byte("secret-bytes"),
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = scalar.Redact()
}
}

func BenchmarkRedact_RepeatedMessages(b *testing.B) {
users := make([]*testdata.User, 100)
for i := 0; i < 100; i++ {
for i := range 100 {
users[i] = &testdata.User{
Id: "user-" + string(rune(i)),
Name: "User " + string(rune(i)),
Expand All @@ -131,20 +127,19 @@ func BenchmarkRedact_RepeatedMessages(b *testing.B) {
Users: users,
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = repeated.Redact()
}
}

func BenchmarkRedact_MapWithStringKey(b *testing.B) {
stringMap := make(map[string]string, 100)
for i := 0; i < 100; i++ {
for i := range 100 {
stringMap["key"+string(rune(i))] = "value" + string(rune(i))
}

userMap := make(map[string]*testdata.User, 10)
for i := 0; i < 10; i++ {
for i := range 10 {
userMap["user"+string(rune(i))] = &testdata.User{
Id: "id-" + string(rune(i)),
Email: "email@test.com",
Expand All @@ -156,8 +151,7 @@ func BenchmarkRedact_MapWithStringKey(b *testing.B) {
UserMap: userMap,
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = m.Redact()
}
}
Expand Down Expand Up @@ -195,17 +189,15 @@ func BenchmarkRedact_ComplexMessage(b *testing.B) {
SecretExtra: &testdata.ComplexMessage_SecretNote{SecretNote: "secret note"},
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = complex.Redact()
}
}

func BenchmarkRedact_NilMessage(b *testing.B) {
var user *testdata.User

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = user.Redact()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact/internal/redact/testdata"
"github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact/internal/redact/testdata"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -639,7 +639,7 @@ func TestSpecialCharacters_Redact(t *testing.T) {
t.Logf("SpecialCharacters.Redact(): %s", result)

// Verify the output is valid JSON
var parsed map[string]interface{}
var parsed map[string]any
if err := json.Unmarshal([]byte(result), &parsed); err != nil {
t.Errorf("Result should be valid JSON: %v", err)
}
Expand Down Expand Up @@ -853,7 +853,7 @@ func TestCustomMaskTypes_AllFields(t *testing.T) {
assertContains(t, result, "publicStatus", "2")

// Verify it's valid JSON
var parsed map[string]interface{}
var parsed map[string]any
if err := json.Unmarshal([]byte(result), &parsed); err != nil {
t.Errorf("Result should be valid JSON: %v", err)
}
Expand All @@ -879,7 +879,7 @@ func TestAllMessages_ValidJSON(t *testing.T) {

for i, msg := range messages {
result := msg.Redact()
var parsed map[string]interface{}
var parsed map[string]any
if err := json.Unmarshal([]byte(result), &parsed); err != nil {
t.Errorf("Message %d produced invalid JSON: %v\nResult: %s", i, err, result)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
syntax = "proto3";

package testdata.crossfile;
option go_package = "github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact/internal/redact/testdata/crossfile";
option go_package = "github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact/internal/redact/testdata/crossfile";

import "crossfile/sensitive.proto";

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
syntax = "proto3";

package testdata.crossfile;
option go_package = "github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact/internal/redact/testdata/crossfile";
option go_package = "github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact/internal/redact/testdata/crossfile";

import "kit/redact/v1/redact.proto";

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";
import "kit/redact/v1/redact.proto";

option go_package = "github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact/testdata";
option go_package = "github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact/testdata";

// ============================================================================
// Enum Definitions
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"
"fmt"

"github.com/crypto-zero/go-kit/logging/protoc-gen-go-redact/internal/redact"
"github.com/crypto-zero/go-kit/cmd/protoc-gen-go-redact/internal/redact"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
)
Expand Down
Loading