Files
api-gateway/app/server/host.go
2026-02-05 23:58:47 +01:00

42 lines
686 B
Go

package server
import (
"net/http/httputil"
"net/url"
"git.secnex.io/secnex/api-gateway/config"
)
type Hosts map[string]*Host
type Host struct {
ID string
Name string
Domain string
proxy *httputil.ReverseProxy
}
func NewHosts(cfg *config.Configuration) Hosts {
hosts := make(Hosts)
for _, host := range cfg.Hosts {
hosts[host.ID] = NewHost(&host)
}
return hosts
}
func NewHost(host *config.Host) *Host {
return &Host{
ID: host.ID,
Name: host.Name,
Domain: host.Domain,
proxy: httputil.NewSingleHostReverseProxy(&url.URL{
Scheme: "https",
Host: host.Domain,
}),
}
}
func (hs Hosts) GetHost(domain string) *Host {
return hs[domain]
}