generated from alecodes/base-template
feat: implement platform handler creation
also refactor public and internal api to support transaction between multiple methods #2
This commit is contained in:
parent
b2d8dadcee
commit
01086d12c9
7 changed files with 423 additions and 253 deletions
|
|
@ -1,6 +1,25 @@
|
|||
package synchronizator
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type default_collection struct {
|
||||
platform_name string
|
||||
}
|
||||
|
||||
func (collection *default_collection) ToNode() (string, []byte, error) {
|
||||
platform_name := strings.ToUpper(collection.platform_name)
|
||||
return platform_name + "_DEFAULT", nil, nil
|
||||
}
|
||||
|
||||
func (collection *default_collection) FromNode(_class string, name string, metadata []byte) error {
|
||||
if _class != "DEFAULT" {
|
||||
return fmt.Errorf("invalid class %s", _class)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Utility struct to represent a collection of nodes, it's a [Node] itself so all
|
||||
// the node's functionality is available.
|
||||
|
|
@ -35,3 +54,16 @@ func (collection *Collection) AddChild(node *Node) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Allows to retreive the saved information back into the user struct. This
|
||||
// method will call the [NodeClass.FromNode] of the provided struct.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// data := &Library{}
|
||||
// if err := node.Unmarshall(data); err != nil {
|
||||
// println(err)
|
||||
// }
|
||||
func (collection *Collection) Unmarshall(dst StandardNode) error {
|
||||
return dst.FromNode("COLLECTION", collection.name, collection.metadata)
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue