Select Git revision
format_ipynb.sh
types.go 1.51 KiB
package helper
import (
"fmt"
)
type Node struct {
Resource Resource `json:"resource"`
Storage Storage `json:"storage"`
}
type Resource struct {
Name string `json:"name"`
Address string `json:"address"`
}
type Storage struct {
Data []StorageElement `json:"data"`
}
type StorageElement struct {
Id int `json:"id"`
Resource `json:"resource"`
}
const (
TRequest = iota
TResponse = iota
TRequestFailed
)
const (
ACTION_QUERY = iota
ACTION_VIEW_STORAGE = iota
)
type Message struct {
Type int `json:"type"`
RequestContent RequestMessage
ResponseContent ResponseMessage
}
type RequestMessage struct {
Query int
Sender Resource
}
type ResponseMessage struct {
QueryFound bool
Location Resource
}
func (r Resource) String() string {
return fmt.Sprintf("Resource{Name=%s,Address=%s}", r.Name, r.Address)
}
func (se StorageElement) String() string {
return fmt.Sprintf("StorageElement{Id=%d,Resource=%s}", se.Id, se.Resource.String())
}
func (s Storage) String() string {
output := "Storage{"
for _, se := range s.Data {
output += fmt.Sprintf("\n\t\t%s", se.String())
}
output += "\n\t}\n"
return output
}
func (n Node) String() string {
return fmt.Sprintf("Node{\n\t%s,\n\t%s}\n", n.Resource, n.Storage)
}
func (req RequestMessage) String() string {
return fmt.Sprintf("RequestMessage{Query=%d,Sender=%s}", req.Query, req.Sender)
}
func (res ResponseMessage) String() string {
return fmt.Sprintf("ResponseMessage{QueryFound=%v,Location=%s}", res.QueryFound, res.Location)
}