feat: initial commit

This commit is contained in:
2023-02-02 10:55:24 +01:00
commit d3c238fa3d
86 changed files with 6855 additions and 0 deletions

5
internal/spec/error.go Normal file
View File

@ -0,0 +1,5 @@
package spec
import "errors"
var ErrSchemaUnknown = errors.New("schema unknown")

35
internal/spec/gateway.go Normal file
View File

@ -0,0 +1,35 @@
package spec
const NameGateway Name = "gateway.emissary.cadoles.com"
type GatewayID string
type Gateway struct {
Revision int
Gateways map[GatewayID]GatewayEntry
}
type GatewayEntry struct {
Address string
Target string
}
func (g *Gateway) SpecName() Name {
return NameGateway
}
func (g *Gateway) SpecRevision() int {
return g.Revision
}
func (g *Gateway) SpecData() any {
return struct {
Gateways map[GatewayID]GatewayEntry
}{Gateways: g.Gateways}
}
func NewGatewaySpec() *Gateway {
return &Gateway{
Gateways: make(map[GatewayID]GatewayEntry),
}
}

3
internal/spec/name.go Normal file
View File

@ -0,0 +1,3 @@
package spec
type Name string

25
internal/spec/spec.go Normal file
View File

@ -0,0 +1,25 @@
package spec
type Spec interface {
SpecName() Name
SpecRevision() int
SpecData() any
}
type RawSpec struct {
Name Name
Revision int
Data any
}
func (s *RawSpec) SpecName() Name {
return s.Name
}
func (s *RawSpec) SpecRevision() int {
return s.Revision
}
func (s *RawSpec) SpecData() any {
return s.Data
}

28
internal/spec/uci.go Normal file
View File

@ -0,0 +1,28 @@
package spec
import "forge.cadoles.com/Cadoles/emissary/internal/openwrt/uci"
const NameUCI Name = "uci.emissary.cadoles.com"
type UCI struct {
Revision int
Config *uci.UCI
}
func (u *UCI) SpecName() Name {
return NameUCI
}
func (u *UCI) SpecRevision() int {
return u.Revision
}
func (u *UCI) SpecData() any {
return struct {
Config *uci.UCI
}{Config: u.Config}
}
func NewUCISpec() *UCI {
return &UCI{}
}