refactor: rename module 'err' to 'gperr' in references

This commit is contained in:
yusing
2025-03-28 06:26:36 +08:00
parent e4f6994dfc
commit 361931ed96
38 changed files with 242 additions and 267 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/rs/zerolog"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/logging"
"github.com/yusing/go-proxy/internal/task"
"github.com/yusing/go-proxy/internal/watcher/events"
@@ -24,7 +24,7 @@ type DirWatcher struct {
mu sync.Mutex
eventCh chan Event
errCh chan E.Error
errCh chan gperr.Error
task *task.Task
}
@@ -55,14 +55,14 @@ func NewDirectoryWatcher(parent task.Parent, dirPath string) *DirWatcher {
w: w,
fwMap: make(map[string]*fileWatcher),
eventCh: make(chan Event),
errCh: make(chan E.Error),
errCh: make(chan gperr.Error),
task: parent.Subtask("dir_watcher(" + dirPath + ")"),
}
go helper.start()
return helper
}
func (h *DirWatcher) Events(_ context.Context) (<-chan Event, <-chan E.Error) {
func (h *DirWatcher) Events(_ context.Context) (<-chan Event, <-chan gperr.Error) {
return h.eventCh, h.errCh
}
@@ -78,7 +78,7 @@ func (h *DirWatcher) Add(relPath string) Watcher {
s = &fileWatcher{
relPath: relPath,
eventCh: make(chan Event),
errCh: make(chan E.Error),
errCh: make(chan gperr.Error),
}
h.fwMap[relPath] = s
return s
@@ -162,7 +162,7 @@ func (h *DirWatcher) start() {
return
}
select {
case h.errCh <- E.From(err):
case h.errCh <- gperr.Wrap(err):
default:
}
}

View File

@@ -7,7 +7,7 @@ import (
docker_events "github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
"github.com/yusing/go-proxy/internal/docker"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/watcher/events"
)
@@ -51,13 +51,13 @@ func NewDockerWatcher(host string) DockerWatcher {
return DockerWatcher{host: host}
}
func (w DockerWatcher) Events(ctx context.Context) (<-chan Event, <-chan E.Error) {
func (w *DockerWatcher) Events(ctx context.Context) (<-chan Event, <-chan gperr.Error) {
return w.EventsWithOptions(ctx, optionsDefault)
}
func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerListOptions) (<-chan Event, <-chan E.Error) {
func (w *DockerWatcher) EventsWithOptions(ctx context.Context, options DockerListOptions) (<-chan Event, <-chan gperr.Error) {
eventCh := make(chan Event)
errCh := make(chan E.Error)
errCh := make(chan gperr.Error)
go func() {
defer func() {

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/yusing/go-proxy/internal/common"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/task"
)
@@ -19,7 +19,7 @@ type (
onError OnErrorFunc
}
OnFlushFunc = func(events []Event)
OnErrorFunc = func(err E.Error)
OnErrorFunc = func(err gperr.Error)
)
const eventQueueCapacity = 10
@@ -50,13 +50,13 @@ func NewEventQueue(queueTask *task.Task, flushInterval time.Duration, onFlush On
}
}
func (e *EventQueue) Start(eventCh <-chan Event, errCh <-chan E.Error) {
func (e *EventQueue) Start(eventCh <-chan Event, errCh <-chan gperr.Error) {
origOnFlush := e.onFlush
// recover panic in onFlush when in production mode
e.onFlush = func(events []Event) {
defer func() {
if err := recover(); err != nil {
e.onError(E.New("recovered panic in onFlush").
e.onError(gperr.New("recovered panic in onFlush").
Withf("%v", err).
Subject(e.task.Name()))
if common.IsDebug {

View File

@@ -3,15 +3,15 @@ package watcher
import (
"context"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/gperr"
)
type fileWatcher struct {
relPath string
eventCh chan Event
errCh chan E.Error
errCh chan gperr.Error
}
func (fw *fileWatcher) Events(ctx context.Context) (<-chan Event, <-chan E.Error) {
func (fw *fileWatcher) Events(ctx context.Context) (<-chan Event, <-chan gperr.Error) {
return fw.eventCh, fw.errCh
}

View File

@@ -58,13 +58,9 @@ func (mon *monitor) ContextWithTimeout(cause string) (ctx context.Context, cance
}
// Start implements task.TaskStarter.
func (mon *monitor) Start(parent task.Parent) E.Error {
func (mon *monitor) Start(parent task.Parent) gperr.Error {
if mon.config.Interval <= 0 {
return E.From(ErrNegativeInterval)
}
if common.PrometheusEnabled {
mon.metric = metrics.GetServiceMetrics().HealthStatus.With(metrics.HealthMetricLabels(mon.service))
return gperr.Wrap(ErrNegativeInterval)
}
mon.service = parent.Name()

View File

@@ -3,12 +3,12 @@ package watcher
import (
"context"
E "github.com/yusing/go-proxy/internal/error"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/watcher/events"
)
type Event = events.Event
type Watcher interface {
Events(ctx context.Context) (<-chan Event, <-chan E.Error)
Events(ctx context.Context) (<-chan Event, <-chan gperr.Error)
}