feat: initial commit
This commit is contained in:
5
internal/spec/error.go
Normal file
5
internal/spec/error.go
Normal file
@ -0,0 +1,5 @@
|
||||
package spec
|
||||
|
||||
import "errors"
|
||||
|
||||
var ErrSchemaUnknown = errors.New("schema unknown")
|
35
internal/spec/gateway.go
Normal file
35
internal/spec/gateway.go
Normal file
@ -0,0 +1,35 @@
|
||||
package spec
|
||||
|
||||
const NameGateway Name = "gateway.emissary.cadoles.com"
|
||||
|
||||
type GatewayID string
|
||||
|
||||
type Gateway struct {
|
||||
Revision int `json:"revision"`
|
||||
Gateways map[GatewayID]GatewayEntry `json:"gateways"`
|
||||
}
|
||||
|
||||
type GatewayEntry struct {
|
||||
Address string `json:"address"`
|
||||
Target string `json:"target"`
|
||||
}
|
||||
|
||||
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
3
internal/spec/name.go
Normal file
@ -0,0 +1,3 @@
|
||||
package spec
|
||||
|
||||
type Name string
|
25
internal/spec/spec.go
Normal file
25
internal/spec/spec.go
Normal file
@ -0,0 +1,25 @@
|
||||
package spec
|
||||
|
||||
type Spec interface {
|
||||
SpecName() Name
|
||||
SpecRevision() int
|
||||
SpecData() any
|
||||
}
|
||||
|
||||
type RawSpec struct {
|
||||
Name Name `json:"name"`
|
||||
Revision int `json:"revision"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func (s *RawSpec) SpecName() Name {
|
||||
return s.Name
|
||||
}
|
||||
|
||||
func (s *RawSpec) SpecRevision() int {
|
||||
return s.Revision
|
||||
}
|
||||
|
||||
func (s *RawSpec) SpecData() any {
|
||||
return s.Data
|
||||
}
|
37
internal/spec/uci.go
Normal file
37
internal/spec/uci.go
Normal file
@ -0,0 +1,37 @@
|
||||
package spec
|
||||
|
||||
import "forge.cadoles.com/Cadoles/emissary/internal/openwrt/uci"
|
||||
|
||||
const NameUCI Name = "uci.emissary.cadoles.com"
|
||||
|
||||
type UCI struct {
|
||||
Revision int `json:"revisions"`
|
||||
Config *uci.UCI `json:"config"`
|
||||
PostImportCommands []*UCIPostImportCommand `json:"postImportCommands"`
|
||||
}
|
||||
|
||||
type UCIPostImportCommand struct {
|
||||
Command string `json:"command"`
|
||||
Args []string `json:"args"`
|
||||
}
|
||||
|
||||
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 `json:"config"`
|
||||
PostImportCommands []*UCIPostImportCommand `json:"postImportCommands"`
|
||||
}{Config: u.Config, PostImportCommands: u.PostImportCommands}
|
||||
}
|
||||
|
||||
func NewUCISpec() *UCI {
|
||||
return &UCI{
|
||||
PostImportCommands: make([]*UCIPostImportCommand, 0),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user