feat: optimization

This commit is contained in:
sajadMRjl
2026-01-28 03:42:36 +03:30
parent 55d198a387
commit d48a7750cc
10 changed files with 299 additions and 60 deletions

38
internal/sink/writer.go Normal file
View File

@@ -0,0 +1,38 @@
package sink
import (
"encoding/json"
"find-me-internet/internal/model"
"os"
"sync"
)
type JSONLWriter struct {
file *os.File
mu sync.Mutex
}
func NewJSONL(path string) (*JSONLWriter, error) {
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}
return &JSONLWriter{file: f}, nil
}
func (w *JSONLWriter) Write(p *model.Proxy) error {
w.mu.Lock()
defer w.mu.Unlock()
data, err := json.Marshal(p)
if err != nil {
return err
}
_, err = w.file.Write(append(data, '\n'))
return err
}
func (w *JSONLWriter) Close() {
w.file.Close()
}