Move wisski instance code to separate package

This commit is contained in:
Tom Wiesing 2022-10-17 14:20:15 +02:00
parent 7c3c84e116
commit 063f3f9b7d
No known key found for this signature in database
67 changed files with 533 additions and 409 deletions

View file

@ -0,0 +1,36 @@
package wisski
import (
_ "embed"
"golang.org/x/exp/slices"
)
//go:embed php/export_pathbuilder.php
var exportPathbuilderPHP string
// Pathbuilders returns the ids of all pathbuilders in consistent order.
//
// server is the server to fetch the pathbuilders from, any may be nil.
func (wisski *WissKI) Pathbuilders(server *PHPServer) (ids []string, err error) {
err = wisski.ExecPHPScript(server, &ids, exportPathbuilderPHP, "all_list")
slices.Sort(ids)
return
}
// Pathbuilder returns a single pathbuilder as xml.
// If it does not exist, it returns the empty string and nil error.
//
// server is the server to fetch the pathbuilders from, any may be nil.
func (wisski *WissKI) Pathbuilder(server *PHPServer, id string) (xml string, err error) {
err = wisski.ExecPHPScript(server, &xml, exportPathbuilderPHP, "one_xml", id)
return
}
// AllPathbuilders returns all pathbuilders serialized as xml
//
// server is the server to fetch the pathbuilders from, any may be nil.
func (wisski *WissKI) AllPathbuilders(server *PHPServer) (pathbuilders map[string]string, err error) {
err = wisski.ExecPHPScript(server, &pathbuilders, exportPathbuilderPHP, "all_xml")
return
}