Add description field to routes and redirects

This commit is contained in:
Melon 2023-10-28 22:20:04 +01:00
parent c91f1dd2fc
commit 69670e068b
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
4 changed files with 10 additions and 6 deletions

View File

@ -3,6 +3,7 @@ CREATE TABLE IF NOT EXISTS routes
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
source TEXT UNIQUE, source TEXT UNIQUE,
destination TEXT, destination TEXT,
description TEXT,
flags INTEGER DEFAULT 0, flags INTEGER DEFAULT 0,
active INTEGER DEFAULT 1 active INTEGER DEFAULT 1
); );
@ -12,6 +13,7 @@ CREATE TABLE IF NOT EXISTS redirects
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
source TEXT UNIQUE, source TEXT UNIQUE,
destination TEXT, destination TEXT,
description TEXT,
flags INTEGER DEFAULT 0, flags INTEGER DEFAULT 0,
code INTEGER DEFAULT 0, code INTEGER DEFAULT 0,
active INTEGER DEFAULT 1 active INTEGER DEFAULT 1

View File

@ -148,14 +148,14 @@ func (m *Manager) GetAllRoutes(hosts []string) ([]target.RouteWithActive, error)
s := make([]target.RouteWithActive, 0) 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 { if err != nil {
return nil, err return nil, err
} }
for query.Next() { for query.Next() {
var a target.RouteWithActive 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 return nil, err
} }
@ -172,7 +172,7 @@ func (m *Manager) GetAllRoutes(hosts []string) ([]target.RouteWithActive, error)
} }
func (m *Manager) InsertRoute(route target.Route) 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 return err
} }
@ -188,14 +188,14 @@ func (m *Manager) GetAllRedirects(hosts []string) ([]target.RedirectWithActive,
s := make([]target.RedirectWithActive, 0) 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 { if err != nil {
return nil, err return nil, err
} }
for query.Next() { for query.Next() {
var a target.RedirectWithActive 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 return nil, err
} }
@ -212,7 +212,7 @@ func (m *Manager) GetAllRedirects(hosts []string) ([]target.RedirectWithActive,
} }
func (m *Manager) InsertRedirect(redirect target.Redirect) error { 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 return err
} }

View File

@ -14,6 +14,7 @@ import (
type Redirect struct { type Redirect struct {
Src string `json:"src"` // request source Src string `json:"src"` // request source
Dst string `json:"dst"` // redirect destination Dst string `json:"dst"` // redirect destination
Desc string `json:"desc"` // description for admin panel use
Flags Flags `json:"flags"` // extra flags Flags Flags `json:"flags"` // extra flags
Code int `json:"code"` // status code used to redirect Code int `json:"code"` // status code used to redirect
} }

View File

@ -39,6 +39,7 @@ var serveApiCors = cors.New(cors.Options{
type Route struct { type Route struct {
Src string `json:"src"` // request source Src string `json:"src"` // request source
Dst string `json:"dst"` // proxy destination Dst string `json:"dst"` // proxy destination
Desc string `json:"desc"` // description for admin panel use
Flags Flags `json:"flags"` // extra flags Flags Flags `json:"flags"` // extra flags
Headers http.Header `json:"-"` // extra headers Headers http.Header `json:"-"` // extra headers
Proxy *proxy.HybridTransport `json:"-"` // reverse proxy handler Proxy *proxy.HybridTransport `json:"-"` // reverse proxy handler