Implement lifecycle

This commit is contained in:
d1slike committed 2024-05-06 09:43:11 +03:00
1 parent 2e23e882bb
commit 8a2a65d8ed
14 files changed
+594 -38

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
package entity
import (
"github.com/txix-open/isp-kit/cluster"
)
type Backend struct {
ModuleId string `json:"module_id"`
Address string `json:"address"`
Version string `json:"version"`
LibVersion string `json:"lib_version"`
Endpoints JsonValue[[]cluster.EndpointDescriptor] `json:"endpoints"`
RequiredModules JsonValue[cluster.ModuleRequirements] `json:"required_modules"`
//CreatedAt time.Time `json:"created_at"`
//UpdatedAt time.Time `json:"updated_at"`
}
+34
View File
@@ -0,0 +1,34 @@
package entity
import (
"time"
)
type Config struct {
Id string `json:"id"`
Name string `json:"name"`
ModuleId string `json:"module_id"`
Data []byte `json:"data"`
Version int `json:"version"`
Active int `json:"active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type ConfigHistory struct {
Id string `json:"id"`
ConfigId string `json:"config_id"`
Data []byte `json:"data"`
Version int `json:"version"`
AdminId int `json:"admin_id"`
CreatedAt time.Time `json:"created_at"`
}
type ConfigSchema struct {
Id string `json:"id"`
ModuleId string `json:"module_id"`
Data []byte `json:"data"`
ModuleVersion string `json:"module_version"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
+45
View File
@@ -0,0 +1,45 @@
package entity
import (
"encoding/base64"
"strconv"
"github.com/txix-open/isp-kit/json"
)
type JsonValue[T any] struct {
Value T
}
func (l JsonValue[T]) MarshalJSON() ([]byte, error) {
data, err := l.MarshalText()
if err != nil {
return nil, err
}
return []byte(strconv.Quote(string(data))), nil
}
func (l *JsonValue[T]) UnmarshalJSON(data []byte) error {
s, err := strconv.Unquote(string(data))
if err != nil {
return err
}
return l.UnmarshalText([]byte(s))
}
func (l JsonValue[T]) MarshalText() ([]byte, error) {
data, err := json.Marshal(l.Value)
if err != nil {
return nil, err
}
s := base64.StdEncoding.EncodeToString(data)
return []byte(s), nil
}
func (l *JsonValue[T]) UnmarshalText(data []byte) error {
arr, err := base64.StdEncoding.DecodeString(string(data))
if err != nil {
return err
}
return json.Unmarshal(arr, &l.Value)
}
+5 -5
View File
@@ -5,9 +5,9 @@ import (
)
type Module struct {
Id string
Name string
LastConnectedAt time.Time
LastDisconnectedAt time.Time
Created time.Time
Id string `json:"id"`
Name string `json:"name"`
LastConnectedAt *time.Time `json:"last_connected_at"`
LastDisconnectedAt *time.Time `json:"last_disconnected_at"`
CreatedAt time.Time `json:"created_at"`
}