diff --git a/router/create-tables.sql b/router/create-tables.sql index 7779e67..6f03820 100644 --- a/router/create-tables.sql +++ b/router/create-tables.sql @@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS routes id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT UNIQUE, destination TEXT, + description TEXT, flags INTEGER DEFAULT 0, active INTEGER DEFAULT 1 ); @@ -12,6 +13,7 @@ CREATE TABLE IF NOT EXISTS redirects id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT UNIQUE, destination TEXT, + description TEXT, flags INTEGER DEFAULT 0, code INTEGER DEFAULT 0, active INTEGER DEFAULT 1 diff --git a/router/manager.go b/router/manager.go index a7b4ed4..9553dc9 100644 --- a/router/manager.go +++ b/router/manager.go @@ -148,14 +148,14 @@ func (m *Manager) GetAllRoutes(hosts []string) ([]target.RouteWithActive, error) s := make([]target.RouteWithActive, 0) - query, err := m.db.Query(`SELECT source, destination, flags, active FROM routes `) + query, err := m.db.Query(`SELECT source, destination, description, flags, active FROM routes`) if err != nil { return nil, err } for query.Next() { var a target.RouteWithActive - if query.Scan(&a.Src, &a.Dst, &a.Flags, &a.Active) != nil { + if query.Scan(&a.Src, &a.Dst, &a.Desc, &a.Flags, &a.Active) != nil { return nil, err } @@ -172,7 +172,7 @@ func (m *Manager) GetAllRoutes(hosts []string) ([]target.RouteWithActive, error) } func (m *Manager) InsertRoute(route target.Route) error { - _, err := m.db.Exec(`INSERT INTO routes (source, destination, flags) VALUES (?, ?, ?) ON CONFLICT(source) DO UPDATE SET destination = excluded.destination, flags = excluded.flags, active = 1`, route.Src, route.Dst, route.Flags) + _, err := m.db.Exec(`INSERT INTO routes (source, destination, description, flags) VALUES (?, ?, ?, ?) ON CONFLICT(source) DO UPDATE SET destination = excluded.destination, description = excluded.description, flags = excluded.flags, active = 1`, route.Src, route.Dst, route.Desc, route.Flags) return err } @@ -188,14 +188,14 @@ func (m *Manager) GetAllRedirects(hosts []string) ([]target.RedirectWithActive, s := make([]target.RedirectWithActive, 0) - query, err := m.db.Query(`SELECT source, destination, flags, code, active FROM redirects`) + query, err := m.db.Query(`SELECT source, destination, description, flags, code, active FROM redirects`) if err != nil { return nil, err } for query.Next() { var a target.RedirectWithActive - if query.Scan(&a.Src, &a.Dst, &a.Flags, &a.Code, &a.Active) != nil { + if query.Scan(&a.Src, &a.Dst, &a.Desc, &a.Flags, &a.Code, &a.Active) != nil { return nil, err } @@ -212,7 +212,7 @@ func (m *Manager) GetAllRedirects(hosts []string) ([]target.RedirectWithActive, } func (m *Manager) InsertRedirect(redirect target.Redirect) error { - _, err := m.db.Exec(`INSERT INTO redirects (source, destination, flags, code) VALUES (?, ?, ?, ?) ON CONFLICT(source) DO UPDATE SET destination = excluded.destination, flags = excluded.flags, code = excluded.code, active = 1`, redirect.Src, redirect.Dst, redirect.Flags, redirect.Code) + _, err := m.db.Exec(`INSERT INTO redirects (source, destination, description, flags, code) VALUES (?, ?, ?, ?, ?) ON CONFLICT(source) DO UPDATE SET destination = excluded.destination, description = excluded.description, flags = excluded.flags, code = excluded.code, active = 1`, redirect.Src, redirect.Dst, redirect.Desc, redirect.Flags, redirect.Code) return err } diff --git a/target/redirect.go b/target/redirect.go index e3f7677..a80f438 100644 --- a/target/redirect.go +++ b/target/redirect.go @@ -14,6 +14,7 @@ import ( type Redirect struct { Src string `json:"src"` // request source Dst string `json:"dst"` // redirect destination + Desc string `json:"desc"` // description for admin panel use Flags Flags `json:"flags"` // extra flags Code int `json:"code"` // status code used to redirect } diff --git a/target/route.go b/target/route.go index a79c9d4..f0810f2 100644 --- a/target/route.go +++ b/target/route.go @@ -39,6 +39,7 @@ var serveApiCors = cors.New(cors.Options{ type Route struct { Src string `json:"src"` // request source Dst string `json:"dst"` // proxy destination + Desc string `json:"desc"` // description for admin panel use Flags Flags `json:"flags"` // extra flags Headers http.Header `json:"-"` // extra headers Proxy *proxy.HybridTransport `json:"-"` // reverse proxy handler