move config to internal

This commit is contained in:
Joel Wetzell
2025-12-06 22:42:38 -06:00
parent 2c6502b622
commit 07108918f1
19 changed files with 79 additions and 51 deletions

View File

@@ -1,6 +0,0 @@
package showbridge
type Config struct {
Modules []ModuleConfig `json:"modules"`
Routes []RouteConfig `json:"routes"`
}

View File

@@ -5,10 +5,12 @@ import (
"log/slog"
"net/http"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
)
type HTTPClient struct {
config ModuleConfig
config config.ModuleConfig
router *Router
client *http.Client
}
@@ -16,7 +18,7 @@ type HTTPClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.http.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
return &HTTPClient{config: config}, nil
},

View File

@@ -5,10 +5,12 @@ import (
"fmt"
"log/slog"
"net/http"
"github.com/jwetzell/showbridge-go/internal/config"
)
type HTTPServer struct {
config ModuleConfig
config config.ModuleConfig
Port uint16
router *Router
}
@@ -21,7 +23,7 @@ type ResponseData struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.http.server",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {

20
internal/config/config.go Normal file
View File

@@ -0,0 +1,20 @@
package config
import "github.com/jwetzell/showbridge-go/internal/processing"
type Config struct {
Modules []ModuleConfig `json:"modules"`
Routes []RouteConfig `json:"routes"`
}
type ModuleConfig struct {
Id string `json:"id"`
Type string `json:"type"`
Params map[string]any `json:"params"`
}
type RouteConfig struct {
Input string `json:"input"`
Processors []processing.ProcessorConfig `json:"processors"`
Output string `json:"output"`
}

View File

@@ -4,10 +4,12 @@ import (
"fmt"
"log/slog"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
)
type Interval struct {
config ModuleConfig
config config.ModuleConfig
Duration uint32
router *Router
ticker *time.Ticker
@@ -16,7 +18,7 @@ type Interval struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "gen.interval",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
duration, ok := params["duration"]

View File

@@ -6,12 +6,13 @@ import (
"fmt"
"log/slog"
"github.com/jwetzell/showbridge-go/internal/config"
"gitlab.com/gomidi/midi/v2"
_ "gitlab.com/gomidi/midi/v2/drivers/rtmididrv"
)
type MIDIClient struct {
config ModuleConfig
config config.ModuleConfig
router *Router
InputPort string
OutputPort string
@@ -22,7 +23,7 @@ func init() {
RegisterModule(ModuleRegistration{
//TODO(jwetzell): find a better namespace than "misc"
Type: "misc.midi.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
input, ok := params["input"]

View File

@@ -3,11 +3,13 @@ package showbridge
import (
"fmt"
"sync"
"github.com/jwetzell/showbridge-go/internal/config"
)
type ModuleError struct {
Index int
Config ModuleConfig
Config config.ModuleConfig
Error error
}
@@ -19,15 +21,9 @@ type Module interface {
Output(any) error
}
type ModuleConfig struct {
Id string `json:"id"`
Type string `json:"type"`
Params map[string]any `json:"params"`
}
type ModuleRegistration struct {
Type string `json:"type"`
New func(ModuleConfig) (Module, error)
New func(config.ModuleConfig) (Module, error)
}
func RegisterModule(mod ModuleRegistration) {

View File

@@ -5,11 +5,12 @@ import (
"log/slog"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processing"
)
type MQTTClient struct {
config ModuleConfig
config config.ModuleConfig
router *Router
Broker string
ClientID string
@@ -20,7 +21,7 @@ type MQTTClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.mqtt.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
broker, ok := params["broker"]

View File

@@ -4,12 +4,13 @@ import (
"fmt"
"log/slog"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processing"
"github.com/nats-io/nats.go"
)
type NATSClient struct {
config ModuleConfig
config config.ModuleConfig
router *Router
URL string
Subject string
@@ -19,7 +20,7 @@ type NATSClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.nats.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
url, ok := params["url"]

View File

@@ -7,10 +7,11 @@ import (
"time"
"github.com/jwetzell/psn-go"
"github.com/jwetzell/showbridge-go/internal/config"
)
type PSNClient struct {
config ModuleConfig
config config.ModuleConfig
conn *net.UDPConn
router *Router
decoder *psn.Decoder
@@ -19,7 +20,7 @@ type PSNClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.psn.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
return &PSNClient{config: config, decoder: psn.NewDecoder()}, nil
},

View File

@@ -3,12 +3,13 @@ package showbridge
import (
"fmt"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processing"
)
type RouteError struct {
Index int
Config RouteConfig
Config config.RouteConfig
Error error
}
@@ -20,13 +21,7 @@ type Route struct {
router *Router
}
type RouteConfig struct {
Input string `json:"input"`
Processors []processing.ProcessorConfig `json:"processors"`
Output string `json:"output"`
}
func NewRoute(index int, config RouteConfig, router *Router) (*Route, error) {
func NewRoute(index int, config config.RouteConfig, router *Router) (*Route, error) {
processors := []processing.Processor{}
if len(config.Processors) > 0 {

View File

@@ -6,6 +6,8 @@ import (
"log/slog"
"os"
"sync"
"github.com/jwetzell/showbridge-go/internal/config"
)
type RoutingError struct {
@@ -21,7 +23,7 @@ type Router struct {
moduleWait sync.WaitGroup
}
func NewRouter(ctx context.Context, config Config) (*Router, []ModuleError, []RouteError) {
func NewRouter(ctx context.Context, config config.Config) (*Router, []ModuleError, []RouteError) {
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: slog.LevelInfo,

View File

@@ -7,12 +7,13 @@ import (
"log/slog"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/framing"
"go.bug.st/serial"
)
type SerialClient struct {
config ModuleConfig
config config.ModuleConfig
router *Router
Port string
Framer framing.Framer
@@ -24,7 +25,7 @@ func init() {
RegisterModule(ModuleRegistration{
//TODO(jwetzell): find a better namespace than "misc"
Type: "misc.serial.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]

View File

@@ -6,11 +6,12 @@ import (
"net"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/framing"
)
type TCPClient struct {
config ModuleConfig
config config.ModuleConfig
framer framing.Framer
conn *net.TCPConn
router *Router
@@ -20,7 +21,7 @@ type TCPClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.tcp.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
host, ok := params["host"]

View File

@@ -10,11 +10,12 @@ import (
"syscall"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/framing"
)
type TCPServer struct {
config ModuleConfig
config config.ModuleConfig
Addr *net.TCPAddr
Framer framing.Framer
router *Router
@@ -27,7 +28,7 @@ type TCPServer struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.tcp.server",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {

View File

@@ -4,10 +4,12 @@ import (
"fmt"
"log/slog"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
)
type Timer struct {
config ModuleConfig
config config.ModuleConfig
Duration uint32
router *Router
timer *time.Timer
@@ -16,7 +18,7 @@ type Timer struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "gen.timer",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
duration, ok := params["duration"]

View File

@@ -4,10 +4,12 @@ import (
"fmt"
"log/slog"
"net"
"github.com/jwetzell/showbridge-go/internal/config"
)
type UDPClient struct {
config ModuleConfig
config config.ModuleConfig
Addr *net.UDPAddr
Port uint16
conn *net.UDPConn
@@ -17,7 +19,7 @@ type UDPClient struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.udp.client",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
host, ok := params["host"]

View File

@@ -5,10 +5,12 @@ import (
"log/slog"
"net"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
)
type UDPMulticast struct {
config ModuleConfig
config config.ModuleConfig
conn *net.UDPConn
router *Router
Addr *net.UDPAddr
@@ -17,7 +19,7 @@ type UDPMulticast struct {
func init() {
RegisterModule(ModuleRegistration{
Type: "net.udp.multicast",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
ip, ok := params["ip"]

View File

@@ -6,18 +6,20 @@ import (
"log/slog"
"net"
"time"
"github.com/jwetzell/showbridge-go/internal/config"
)
type UDPServer struct {
Addr *net.UDPAddr
config ModuleConfig
config config.ModuleConfig
router *Router
}
func init() {
RegisterModule(ModuleRegistration{
Type: "net.udp.server",
New: func(config ModuleConfig) (Module, error) {
New: func(config config.ModuleConfig) (Module, error) {
params := config.Params
port, ok := params["port"]
if !ok {