frontlas: update redis model

This commit is contained in:
singchia
2024-05-16 15:13:08 +08:00
parent 8517dff9ac
commit 2f9ca84dbe
13 changed files with 291 additions and 192 deletions

View File

@@ -1,5 +1,10 @@
package repo
import (
"bytes"
"fmt"
)
// key: serviceID; value: Service
type Service struct {
Service string `json:"service"`
@@ -7,3 +12,25 @@ type Service struct {
Addr string `json:"addr"`
UpdateTime int64 `json:"update_time"`
}
func (service *Service) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString("{")
_, err := buffer.WriteString(fmt.Sprintf("service: %s, ", service.Service))
if err != nil {
return nil, err
}
_, err = buffer.WriteString(fmt.Sprintf("frontierID: %s, ", service.FrontierID))
if err != nil {
return nil, err
}
_, err = buffer.WriteString(fmt.Sprintf("addr: %s, ", service.Addr))
if err != nil {
return nil, err
}
_, err = buffer.WriteString(fmt.Sprintf("update_time: %d", service.UpdateTime))
if err != nil {
return nil, err
}
buffer.WriteString("}")
return buffer.Bytes(), nil
}