mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
shift Get method to only key/value modules add Set method to redis.client
This commit is contained in:
@@ -11,3 +11,8 @@ type Module interface {
|
||||
Stop()
|
||||
Output(context.Context, any) error
|
||||
}
|
||||
|
||||
type KeyValueModule interface {
|
||||
Get(key string) (any, error)
|
||||
Set(key string, value any) error
|
||||
}
|
||||
|
||||
@@ -205,7 +205,3 @@ func (hs *HTTPServer) Output(ctx context.Context, payload any) error {
|
||||
func (hs *HTTPServer) Stop() {
|
||||
hs.cancel()
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) Get(key string) (any, error) {
|
||||
return nil, errors.New("http.server does not support Get")
|
||||
}
|
||||
|
||||
@@ -89,12 +89,3 @@ func (mi *MIDIInput) Output(ctx context.Context, payload any) error {
|
||||
func (mi *MIDIInput) Stop() {
|
||||
mi.cancel()
|
||||
}
|
||||
|
||||
func (mi *MIDIInput) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "port":
|
||||
return mi.Port, nil
|
||||
default:
|
||||
return nil, errors.New("midi.input key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,12 +96,3 @@ func (mo *MIDIOutput) Output(ctx context.Context, payload any) error {
|
||||
func (mo *MIDIOutput) Stop() {
|
||||
mo.cancel()
|
||||
}
|
||||
|
||||
func (mo *MIDIOutput) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "port":
|
||||
return mo.Port, nil
|
||||
default:
|
||||
return nil, errors.New("midi.output key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +125,3 @@ func (mc *MQTTClient) Output(ctx context.Context, payload any) error {
|
||||
func (mc *MQTTClient) Stop() {
|
||||
mc.cancel()
|
||||
}
|
||||
|
||||
func (mc *MQTTClient) Get(key string) (any, error) {
|
||||
return nil, errors.New("mqtt.client does not support Get")
|
||||
}
|
||||
|
||||
@@ -116,7 +116,3 @@ func (nc *NATSClient) Output(ctx context.Context, payload any) error {
|
||||
func (nc *NATSClient) Stop() {
|
||||
nc.cancel()
|
||||
}
|
||||
|
||||
func (nc *NATSClient) Get(key string) (any, error) {
|
||||
return nil, errors.New("nats.client does not support Get")
|
||||
}
|
||||
|
||||
@@ -112,7 +112,3 @@ func (ns *NATSServer) Stop() {
|
||||
ns.server.Shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *NATSServer) Get(key string) (any, error) {
|
||||
return nil, errors.New("nats.server does not support Get")
|
||||
}
|
||||
|
||||
@@ -112,14 +112,3 @@ func (pc *PSNClient) Output(ctx context.Context, payload any) error {
|
||||
func (pc *PSNClient) Stop() {
|
||||
pc.cancel()
|
||||
}
|
||||
|
||||
func (pc *PSNClient) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "trackers":
|
||||
return pc.decoder.Trackers, nil
|
||||
case "name":
|
||||
return pc.decoder.SystemName, nil
|
||||
default:
|
||||
return nil, errors.New("psn.client key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,20 +89,20 @@ func (rc *RedisClient) Stop() {
|
||||
}
|
||||
|
||||
func (rc *RedisClient) Get(key string) (any, error) {
|
||||
|
||||
switch key {
|
||||
case "host":
|
||||
return rc.Host, nil
|
||||
case "port":
|
||||
return rc.Port, nil
|
||||
default:
|
||||
if rc.client != nil {
|
||||
val, err := rc.client.Get(rc.ctx, key).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return val, nil
|
||||
if rc.client != nil {
|
||||
val, err := rc.client.Get(rc.ctx, key).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, errors.New("redis.client key not found")
|
||||
return val, nil
|
||||
}
|
||||
return nil, errors.New("redis.client not setup")
|
||||
}
|
||||
|
||||
func (rc *RedisClient) Set(key string, value any) error {
|
||||
if rc.client != nil {
|
||||
status := rc.client.Set(rc.ctx, key, value, 0)
|
||||
return status.Err()
|
||||
}
|
||||
return errors.New("redis.client not setup")
|
||||
}
|
||||
|
||||
@@ -169,12 +169,3 @@ func (sc *SerialClient) Output(ctx context.Context, payload any) error {
|
||||
func (sc *SerialClient) Stop() {
|
||||
sc.cancel()
|
||||
}
|
||||
|
||||
func (sc *SerialClient) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "port":
|
||||
return sc.Port, nil
|
||||
default:
|
||||
return nil, errors.New("serial.client key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,3 @@ func (scs *SIPCallServer) Output(ctx context.Context, payload any) error {
|
||||
func (scs *SIPCallServer) Stop() {
|
||||
scs.cancel()
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) Get(key string) (any, error) {
|
||||
return nil, errors.New("sip.call.server does not support Get")
|
||||
}
|
||||
|
||||
@@ -249,7 +249,3 @@ func (sds *SIPDTMFServer) Output(ctx context.Context, payload any) error {
|
||||
func (sds *SIPDTMFServer) Stop() {
|
||||
sds.cancel()
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Get(key string) (any, error) {
|
||||
return nil, errors.New("sip.dtmf.server does not support Get")
|
||||
}
|
||||
|
||||
@@ -163,20 +163,3 @@ func (tc *TCPClient) Output(ctx context.Context, payload any) error {
|
||||
func (tc *TCPClient) Stop() {
|
||||
tc.cancel()
|
||||
}
|
||||
|
||||
func (tc *TCPClient) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "host":
|
||||
host, err := tc.config.Params.GetString("host")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("net.tcp.client host error: %w", err)
|
||||
}
|
||||
return host, nil
|
||||
case "ip":
|
||||
return tc.Addr.IP.String(), nil
|
||||
case "port":
|
||||
return tc.Addr.Port, nil
|
||||
default:
|
||||
return nil, errors.New("net.tcp.client key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,14 +232,3 @@ func (ts *TCPServer) Stop() {
|
||||
ts.cancel()
|
||||
ts.wg.Wait()
|
||||
}
|
||||
|
||||
func (ts *TCPServer) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "ip":
|
||||
return ts.Addr.IP.String(), nil
|
||||
case "port":
|
||||
return ts.Addr.Port, nil
|
||||
default:
|
||||
return nil, errors.New("net.tcp.server key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,6 @@ func (m *TestModule) Id() string {
|
||||
return "test"
|
||||
}
|
||||
|
||||
func (m *TestModule) Get(key string) (any, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func TestModuleBadRegistrationNoType(t *testing.T) {
|
||||
defer func() {
|
||||
if r := recover(); r == nil {
|
||||
|
||||
@@ -82,12 +82,3 @@ func (i *TimeInterval) Output(ctx context.Context, payload any) error {
|
||||
func (i *TimeInterval) Stop() {
|
||||
i.cancel()
|
||||
}
|
||||
|
||||
func (i *TimeInterval) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "duration":
|
||||
return i.Duration, nil
|
||||
default:
|
||||
return nil, errors.New("time.interval key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,12 +81,3 @@ func (t *TimeTimer) Output(ctx context.Context, payload any) error {
|
||||
func (t *TimeTimer) Stop() {
|
||||
t.cancel()
|
||||
}
|
||||
|
||||
func (t *TimeTimer) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "duration":
|
||||
return t.Duration, nil
|
||||
default:
|
||||
return nil, errors.New("time.timer key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,20 +106,3 @@ func (uc *UDPClient) Output(ctx context.Context, payload any) error {
|
||||
func (uc *UDPClient) Stop() {
|
||||
uc.cancel()
|
||||
}
|
||||
|
||||
func (uc *UDPClient) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "host":
|
||||
host, err := uc.config.Params.GetString("host")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("net.udp.client host error: %w", err)
|
||||
}
|
||||
return host, nil
|
||||
case "ip":
|
||||
return uc.Addr.IP.String(), nil
|
||||
case "port":
|
||||
return uc.Addr.Port, nil
|
||||
default:
|
||||
return nil, errors.New("net.udp.client key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,14 +124,3 @@ func (um *UDPMulticast) Output(ctx context.Context, payload any) error {
|
||||
func (um *UDPMulticast) Stop() {
|
||||
um.cancel()
|
||||
}
|
||||
|
||||
func (um *UDPMulticast) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "ip":
|
||||
return um.Addr.IP.String(), nil
|
||||
case "port":
|
||||
return um.Addr.Port, nil
|
||||
default:
|
||||
return nil, errors.New("net.udp.multicast key not found")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +123,3 @@ func (us *UDPServer) Output(ctx context.Context, payload any) error {
|
||||
func (us *UDPServer) Stop() {
|
||||
us.cancel()
|
||||
}
|
||||
|
||||
func (us *UDPServer) Get(key string) (any, error) {
|
||||
switch key {
|
||||
case "ip":
|
||||
return us.Addr.IP.String(), nil
|
||||
case "port":
|
||||
return us.Addr.Port, nil
|
||||
default:
|
||||
return nil, errors.New("net.udp.server key not found")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user