ae6a4d7f4c
Task 9 Фазы 1B: узкий интерфейс TenantStore (внутри store.Account/Template/Domain,
без db.* в api) реализован тонкими обёртками в internal/store/tenant.go; API.Store/
Cipher/Reg добавлены к существующему Svc. Роуты POST/GET/DELETE для accounts/
templates/domains + POST /accounts/{aid}/import (ListZones -> CreateDomain на зону).
accountResponse не содержит секрет ни в каком виде.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/vasyakrg/dns-autoresolver/internal/api"
|
|
"github.com/vasyakrg/dns-autoresolver/internal/config"
|
|
"github.com/vasyakrg/dns-autoresolver/internal/crypto"
|
|
"github.com/vasyakrg/dns-autoresolver/internal/provider/registry"
|
|
"github.com/vasyakrg/dns-autoresolver/internal/provider/selectel"
|
|
"github.com/vasyakrg/dns-autoresolver/internal/service"
|
|
"github.com/vasyakrg/dns-autoresolver/internal/store"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
log.Fatalf("config: %v", err)
|
|
}
|
|
if err := store.Migrate(ctx, cfg.DBDSN); err != nil {
|
|
log.Fatalf("migrate: %v", err)
|
|
}
|
|
pool, err := pgxpool.New(ctx, cfg.DBDSN)
|
|
if err != nil {
|
|
log.Fatalf("pool: %v", err)
|
|
}
|
|
defer pool.Close()
|
|
|
|
cipher, err := crypto.NewCipher(cfg.EncKey)
|
|
if err != nil {
|
|
log.Fatalf("cipher: %v", err)
|
|
}
|
|
st := store.New(pool)
|
|
|
|
reg := registry.New()
|
|
reg.Register(selectel.New())
|
|
|
|
svc := service.New(st, st, reg, cipher)
|
|
a := &api.API{Svc: svc, Store: st, Cipher: cipher, Reg: reg}
|
|
|
|
log.Printf("listening on %s", cfg.ListenAddr)
|
|
if err := http.ListenAndServe(cfg.ListenAddr, api.NewRouter(a)); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|