Skip to content

Commit

Permalink
Added type field in status file
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Feb 20, 2023
1 parent 94cd991 commit c0ddac1
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions types/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"encoding/json"
"io/ioutil"
"os"
)

Expand All @@ -19,27 +18,29 @@ type Service interface {
}

type Status struct {
From string `json:"from"`
ID uint64 `json:"id"`
IFace string `json:"iface"`
To string `json:"to"`
From string `json:"from"`
ID uint64 `json:"id"`
To string `json:"to"`
Type uint64 `json:"type"`
Info []byte `json:"info"`
}

func NewStatus() *Status {
return &Status{}
}

func (s *Status) WithFrom(v string) *Status { s.From = v; return s }
func (s *Status) WithID(v uint64) *Status { s.ID = v; return s }
func (s *Status) WithIFace(v string) *Status { s.IFace = v; return s }
func (s *Status) WithTo(v string) *Status { s.To = v; return s }
func (s *Status) WithFrom(v string) *Status { s.From = v; return s }
func (s *Status) WithID(v uint64) *Status { s.ID = v; return s }
func (s *Status) WithInfo(v []byte) *Status { s.Info = v; return s }
func (s *Status) WithTo(v string) *Status { s.To = v; return s }
func (s *Status) WithType(v uint64) *Status { s.Type = v; return s }

func (s *Status) LoadFromPath(path string) error {
if _, err := os.Stat(path); err != nil {
return nil
}

data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -56,5 +57,5 @@ func (s *Status) SaveToPath(path string) error {
return err
}

return ioutil.WriteFile(path, bytes, 0600)
return os.WriteFile(path, bytes, 0600)
}

0 comments on commit c0ddac1

Please sign in to comment.