refactor: move http api to a new transport layer
This commit is contained in:
parent
476c4b056f
commit
0448f66ab2
41 changed files with 822 additions and 390 deletions
24
internal/transport/host/client.go
Normal file
24
internal/transport/host/client.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"git.wzray.com/homelab/hivemind/internal/transport"
|
||||
"git.wzray.com/homelab/hivemind/internal/types"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
caller transport.Caller
|
||||
}
|
||||
|
||||
func New(caller transport.Caller) *Client {
|
||||
return &Client{
|
||||
caller: caller,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Dns(endpoint string) (types.HostState, error) {
|
||||
return dnsRoute.CallNoInput(c.caller, endpoint)
|
||||
}
|
||||
|
||||
func (c *Client) Nameserver(endpoint string) (types.HostState, error) {
|
||||
return nsRoute.CallNoInput(c.caller, endpoint)
|
||||
}
|
||||
16
internal/transport/host/handlers.go
Normal file
16
internal/transport/host/handlers.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"git.wzray.com/homelab/hivemind/internal/transport"
|
||||
"git.wzray.com/homelab/hivemind/internal/types"
|
||||
)
|
||||
|
||||
type HostHandlers interface {
|
||||
Dns() (types.HostState, error)
|
||||
Nameserver() (types.HostState, error)
|
||||
}
|
||||
|
||||
func Register(registrator transport.Registrator, h HostHandlers) {
|
||||
dnsRoute.Register(registrator, transport.WithoutInput(h.Dns))
|
||||
nsRoute.Register(registrator, transport.WithoutInput(h.Nameserver))
|
||||
}
|
||||
11
internal/transport/host/routes.go
Normal file
11
internal/transport/host/routes.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"git.wzray.com/homelab/hivemind/internal/transport"
|
||||
"git.wzray.com/homelab/hivemind/internal/types"
|
||||
)
|
||||
|
||||
var (
|
||||
dnsRoute = transport.NewRoute[struct{}, types.HostState]("/host/dns")
|
||||
nsRoute = transport.NewRoute[struct{}, types.HostState]("/host/ns")
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue