Files
EvoBGP/internal/repository/postgres_module_doh.go
T
Denozordec 34ecc5c235
CI / changes (push) Successful in 6s
CI / openapi (push) Successful in 1m2s
CI / go (push) Successful in 27s
CI / docker-web (push) Successful in 1m27s
CI / docker-bird (push) Has been skipped
CI / bird2 (push) Successful in 16s
CI / docker-go (push) Successful in 8m5s
feat: enhance DoH profile management and resolver policy in modules
- Added `DohResolverPolicy` schema to OpenAPI documentation, defining policies for domain resolution.
- Updated module handling to support multiple DoH profiles via `doh_profile_ids` and introduced `doh_resolver_policy` in the API.
- Refactored related functions to accommodate the new DoH profile structure, ensuring backward compatibility with existing `doh_profile_id`.
- Enhanced UI components to allow selection and management of DoH profiles and policies in the web interface.
- Updated database interactions to handle new fields and ensure proper data normalization.
2026-05-19 14:57:50 +07:00

68 lines
1.7 KiB
Go

package repository
import (
"context"
"evobgp/internal/store"
)
func (p *Postgres) fillModuleDohFields(ctx context.Context, m *store.Module) error {
if m == nil {
return nil
}
rows, err := p.pool.Query(ctx, `
SELECT doh_profile_id::text
FROM module_doh_profile
WHERE module_id = $1
ORDER BY sort_order, doh_profile_id`, m.ID)
if err != nil {
return err
}
defer rows.Close()
var ids []string
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
return err
}
ids = append(ids, id)
}
if err := rows.Err(); err != nil {
return err
}
m.DohProfileIDs = store.NormalizeDohProfileIDList(ids)
m.SyncLegacyDohProfileID()
return nil
}
func (p *Postgres) setModuleDohProfiles(ctx context.Context, moduleID string, ids []string) error {
ids = store.NormalizeDohProfileIDList(ids)
if _, err := p.pool.Exec(ctx, `DELETE FROM module_doh_profile WHERE module_id = $1`, moduleID); err != nil {
return err
}
for i, id := range ids {
if _, err := p.pool.Exec(ctx, `
INSERT INTO module_doh_profile (module_id, doh_profile_id, sort_order)
VALUES ($1, $2, $3)`, moduleID, id, i); err != nil {
return err
}
}
var dohArg any
if len(ids) > 0 {
dohArg = ids[0]
}
_, err := p.pool.Exec(ctx, `UPDATE module SET doh_profile_id = $2, updated_at = now() WHERE id = $1`, moduleID, dohArg)
return err
}
func (p *Postgres) moduleDohProfileInUse(ctx context.Context, dohProfileID string) (bool, error) {
var n int
if err := p.pool.QueryRow(ctx, `
SELECT COUNT(*) FROM module_doh_profile mdp
JOIN module m ON m.id = mdp.module_id
WHERE mdp.doh_profile_id = $1::uuid AND m.deleted_at IS NULL`, dohProfileID).Scan(&n); err != nil {
return false, err
}
return n > 0, nil
}