2 Commits

Author SHA1 Message Date
Hadi 61a112a302 add logs
Signed-off-by: Hadi <hadi@example.com>
2026-05-29 13:41:09 +02:00
Hadi 677223c9b0 change logs fmt
Signed-off-by: Hadi <hadi@example.com>
2026-05-29 11:54:26 +02:00
8 changed files with 27 additions and 14 deletions
+5 -1
View File
@@ -81,7 +81,11 @@ func scanEntries(rows *sql.Rows) ([]Entry, error) {
if err := rows.Scan(&e.ID, &ts, &e.Method, &e.Host, &e.Path, &e.StatusCode, &e.RequestRaw, &e.ResponseRaw, &flagged); err != nil {
return nil, err
}
e.Timestamp, _ = time.Parse(time.RFC3339, ts)
var tsErr error
e.Timestamp, tsErr = time.Parse(time.RFC3339, ts)
if tsErr != nil {
log.Printf("db: parse timestamp %q: %v", ts, tsErr)
}
e.Flagged = flagged != 0
entries = append(entries, e)
}
+6 -1
View File
@@ -1,6 +1,7 @@
package db
import (
"log"
"time"
)
@@ -59,7 +60,11 @@ func (d *DB) ListReplayEntries() ([]ReplayEntry, error) {
&e.OriginalRaw, &e.RequestRaw, &e.ResponseRaw, &e.StatusCode, &e.ErrorMsg); err != nil {
return nil, err
}
e.Timestamp, _ = time.Parse(time.RFC3339, ts)
var tsErr error
e.Timestamp, tsErr = time.Parse(time.RFC3339, ts)
if tsErr != nil {
log.Printf("db: parse replay timestamp %q: %v", ts, tsErr)
}
entries = append(entries, e)
}
return entries, rows.Err()
+4 -4
View File
@@ -46,7 +46,7 @@ func newLuaState(mgr *Manager, p *Plugin) *lua.LState {
func registerUtilities(L *lua.LState, mgr *Manager, p *Plugin) {
L.SetGlobal("log", L.NewFunction(func(L *lua.LState) int {
msg := L.CheckString(1)
log.Printf("[plugin:%s] %s", p.Name, msg)
log.Printf("plugin %s: %s", p.Name, msg)
return 0
}))
@@ -85,7 +85,7 @@ func registerUtilities(L *lua.LState, mgr *Manager, p *Plugin) {
CreatedAt: time.Now(),
})
if err != nil {
log.Printf("[plugin:%s] create_finding error: %v", p.Name, err)
log.Printf("plugin %s: create_finding error: %v", p.Name, err)
return 0
}
_ = inserted
@@ -337,7 +337,7 @@ func luaTableString(t *lua.LTable, key string) string {
return ""
}
func pushRequest(L *lua.LState, f *goproxy.Flow) *lua.LTable {
func pushRequest(L *lua.LState, p *Plugin, f *goproxy.Flow) *lua.LTable {
t := L.NewTable()
r := f.Request
L.SetField(t, "method", lua.LString(r.Method))
@@ -377,7 +377,7 @@ func pushRequest(L *lua.LState, f *goproxy.Flow) *lua.LTable {
L.SetField(t, "set_url", L.NewFunction(func(L *lua.LState) int {
parsed, err := url.Parse(L.CheckString(2))
if err != nil {
log.Printf("[plugin] set_url: %v", err)
log.Printf("plugin %s: set_url: %v", p.Name, err)
return 0
}
r.URL = parsed
+4 -4
View File
@@ -395,25 +395,25 @@ func (m *Manager) runAsyncForPlugins(hookName string, argsFor func(*Plugin) []lu
func (m *Manager) RunSyncOnRequest(f *goproxy.Flow) intercept.Decision {
return m.runSyncDecisionForPlugins("on_request", func(p *Plugin) []lua.LValue {
return []lua.LValue{pushRequest(p.L, f)}
return []lua.LValue{pushRequest(p.L, p, f)}
})
}
func (m *Manager) RunAsyncOnRequest(f *goproxy.Flow) {
m.runAsyncForPlugins("on_request", func(p *Plugin) []lua.LValue {
return []lua.LValue{pushRequest(p.L, f)}
return []lua.LValue{pushRequest(p.L, p, f)}
})
}
func (m *Manager) RunSyncOnResponse(f *goproxy.Flow) intercept.Decision {
return m.runSyncDecisionForPlugins("on_response", func(p *Plugin) []lua.LValue {
return []lua.LValue{pushRequest(p.L, f), pushResponse(p.L, f)}
return []lua.LValue{pushRequest(p.L, p, f), pushResponse(p.L, f)}
})
}
func (m *Manager) RunAsyncOnResponse(f *goproxy.Flow) {
m.runAsyncForPlugins("on_response", func(p *Plugin) []lua.LValue {
return []lua.LValue{pushRequest(p.L, f), pushResponse(p.L, f)}
return []lua.LValue{pushRequest(p.L, p, f), pushResponse(p.L, f)}
})
}
+4 -1
View File
@@ -1,6 +1,7 @@
package plugins
import (
"log"
"os"
"path/filepath"
@@ -76,7 +77,9 @@ func (pf *PluginsFile) register(id string, defaultEnabled bool, configText strin
}
}
pf.data.Plugins[id] = entry
_ = pf.save()
if err := pf.save(); err != nil {
log.Printf("plugin %s: register save: %v", id, err)
}
}
}
+1 -3
View File
@@ -1,7 +1,6 @@
package app
import (
"fmt"
"log"
"os"
"path/filepath"
@@ -97,8 +96,7 @@ func New(broker *intercept.Broker, name, path string) Model {
d, err := db.Open(path)
if err != nil {
fmt.Fprintf(os.Stderr, "db: %v\n", err)
os.Exit(1)
log.Fatalf("db: %v", err)
}
m.database = d
broker.SetDB(d)
+2
View File
@@ -74,6 +74,7 @@ func (m Model) handleSelection() (tea.Model, tea.Cmd) {
case kindTemp:
dir := tempDir()
if err := os.MkdirAll(dir, 0o750); err != nil {
log.Printf("home: create temp dir: %v", err)
return m, nil
}
initProjectFiles(dir)
@@ -117,6 +118,7 @@ func (m Model) updateNaming(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
m.nameInput.Blur()
dir := filepath.Join(m.projectDir, name)
if err := os.MkdirAll(dir, 0o750); err != nil {
log.Printf("home: create project dir %q: %v", name, err)
return m, nil
}
initProjectFiles(dir)
+1
View File
@@ -29,6 +29,7 @@ func resolveEditor() string {
func openWithEditor(content string, callback func(string, error) tea.Msg) tea.Cmd {
f, err := os.CreateTemp("", "spilltea-*.http")
if err != nil {
log.Printf("editor: create temp file: %v", err)
return nil
}
tmpPath := f.Name()