Implement api

This commit is contained in:
d1slike committed 2024-05-08 15:40:14 +03:00
1 parent 80a99c425b
commit b2e34c00a4
30 files changed
+708 -69

No files matched your search

+1 -10
View File
@@ -6,17 +6,8 @@ import (
"isp-config-service/entity/xtypes"
)
type EventType int
const (
Unknown EventType = iota
ConfigUpdated
ModuleReady
ModuleDisconnected
)
type Event struct {
RowId int `json:"rowid"`
Id int `json:"id"`
Payload xtypes.Json[EventPayload] `json:"payload"`
}
+3 -5
View File
@@ -1,8 +1,6 @@
package xtypes
type Bool struct {
Value bool
}
type Bool bool
func (l Bool) MarshalJSON() ([]byte, error) {
return l.MarshalText()
@@ -13,13 +11,13 @@ func (l *Bool) UnmarshalJSON(data []byte) error {
}
func (l Bool) MarshalText() ([]byte, error) {
if l.Value {
if l {
return []byte("1"), nil
}
return []byte("0"), nil
}
func (l *Bool) UnmarshalText(data []byte) error {
l.Value = string(data) == "1"
*l = string(data) == "1"
return nil
}
+7 -5
View File
@@ -5,9 +5,7 @@ import (
"time"
)
type Time struct {
Value time.Time
}
type Time time.Time
func (l Time) MarshalJSON() ([]byte, error) {
return l.MarshalText()
@@ -18,15 +16,19 @@ func (l *Time) UnmarshalJSON(data []byte) error {
}
func (l Time) MarshalText() ([]byte, error) {
value := strconv.Itoa(int(l.Value.Unix()))
t := time.Time(l)
value := strconv.Itoa(int(t.Unix()))
return []byte(value), nil
}
func (l *Time) UnmarshalText(data []byte) error {
if string(data) == "null" {
return nil
}
value, err := strconv.Atoi(string(data))
if err != nil {
return err
}
l.Value = time.Unix(int64(value), 0)
*l = Time(time.Unix(int64(value), 0))
return nil
}