Files
Igor Sirotin f3e4363808 refactor: move protocol to internal/protocol
Part of the Go project layout migration, item 27.

Pure move plus import-path rewrite across 502 files. No API or behaviour
change. `internal/` keeps the messaging application logic unimportable
from outside the module, which is what the issue asks for -- status-go is
consumed through the C-bindings in mobile/, not as a Go library.

Things that had to follow the move, beyond the Go imports:

- tools/generate-handlers/template.txt. messenger_handlers.go is
  generated, and the template hard-codes the imports it emits, so the
  generated file kept importing protocol/common and failed typecheck.
- .gitignore. The ignore rule for that generated file was pinned to the
  old path; without moving it, a 1486-line generated file starts being
  tracked.
- Makefile: the logosstorage and torrent test targets (both the archive
  packages and ./protocol itself), the archive README, migration-protocol.
- scripts/run_unit_tests.sh, which names the protocol package explicitly
  to shard its tests.
- scripts/cleanup_generated_files.sh and .golangci.yml.

scripts/migration_check.sh also needed a fix that is not specific to this
move: it validated every file the branch touched under a migration dir
against the timestamp naming rule, and a directory rename makes every
migration in it look newly added. It now excludes renames, so moving a
migration is not mistaken for adding one.

refs #7067
2026-08-21 10:11:05 +02:00

82 lines
2.1 KiB
Go

package zaputil
import (
"encoding/hex"
"sync"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type jsonHexEncoder struct {
zapcore.Encoder
}
// NewJSONHexEncoder creates a JSON logger based on zapcore.NewJSONEncoder
// but overwrites encoding of byte slices. Instead encoding them with base64,
// jsonHexEncoder uses hex-encoding.
// Each hex-encoded value is prefixed with 0x so that it's clear it's a hex string.
func NewJSONHexEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder {
jsonEncoder := zapcore.NewJSONEncoder(cfg)
return &jsonHexEncoder{
Encoder: jsonEncoder,
}
}
func (enc *jsonHexEncoder) AddBinary(key string, val []byte) {
enc.AddString(key, "0x"+hex.EncodeToString(val))
}
func (enc *jsonHexEncoder) Clone() zapcore.Encoder {
encoderClone := enc.Encoder.Clone()
return &jsonHexEncoder{Encoder: encoderClone}
}
var (
registerJSONHexEncoderOnce sync.Once
registerConsoleHexEncodeOnce sync.Once
)
// RegisterJSONHexEncoder registers a jsonHexEncoder under "json-hex" name.
// Later, this name can be used as a value for zap.Config.Encoding to enable
// jsonHexEncoder.
func RegisterJSONHexEncoder() error {
var err error
registerJSONHexEncoderOnce.Do(func() {
err = zap.RegisterEncoder("json-hex", func(cfg zapcore.EncoderConfig) (zapcore.Encoder, error) {
return NewJSONHexEncoder(cfg), nil
})
})
return err
}
type consoleHexEncoder struct {
zapcore.Encoder
}
func NewConsoleHexEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder {
consoleEncoder := zapcore.NewConsoleEncoder(cfg)
return &consoleHexEncoder{
Encoder: consoleEncoder,
}
}
func (enc *consoleHexEncoder) AddBinary(key string, val []byte) {
enc.AddString(key, "0x"+hex.EncodeToString(val))
}
func (enc *consoleHexEncoder) Clone() zapcore.Encoder {
encoderClone := enc.Encoder.Clone()
return &consoleHexEncoder{Encoder: encoderClone}
}
func RegisterConsoleHexEncoder() error {
var err error
registerConsoleHexEncodeOnce.Do(func() {
err = zap.RegisterEncoder("console-hex", func(cfg zapcore.EncoderConfig) (zapcore.Encoder, error) {
return NewConsoleHexEncoder(cfg), nil
})
})
return err
}