Actual behavior
Explicit implementation of OnGetByKey handler within the node, causes the library panic during DELETE request handling if, OnDeleteByKey is not explicit implemented.
Expected behavior
Explicit implementation of OnGetByKey handler within the node, does NOT cause the library panic during DELETE request handling, if OnDeleteByKey is not explicit implemented
Reproduction stepsCode used to reproduce the bug can be found in the section below
Start restconf server - go run main.go
Create more than 1 resource within the books Yang node (it is already done, by configuration within startup.json file)
Perform a DELETE request to delete 1 resource within the books node
Request:
curl -X DELETE http://localhost:8080/restconf/data/library:books=0
Response:
curl: (52) Empty reply from server
Server logs:
module library {
revision 2024-10-03;
list books {
key book-id;
leaf book-id {
description "unique id for book";
type int32;
}
leaf title {
description "title of the book";
type string;
}
}
}
The only way I found to avoid it, is to implement an explicit OnDeleteByKey handler too. After that requested DELETE request is performed with no issues.
package main
import (
"github.com/freeconf/restconf"
"github.com/freeconf/restconf/device"
"github.com/freeconf/yang/fc"
"github.com/freeconf/yang/node"
"github.com/freeconf/yang/nodeutil"
"github.com/freeconf/yang/source"
)
type Book struct {
BookId int
Title string
}
type Library struct {
Books []*Book
}
type Model struct {
Library *Library
}
func NewLibrary() *Library {
lib := &Library{
Books: []*Book{},
}
return lib
}
func getByKey(n *nodeutil.Node, r node.ListRequest) (node.Node, error) {
// node processing...
return n.DoGetByKey(r)
}
func deleteByKey(n *nodeutil.Node, r node.ListRequest) error {
return n.DoDeleteByKey(r)
}
func main() {
fc.DebugLog(true)
ypath := source.Any(source.Path("yang"), restconf.InternalYPath)
d := device.New(ypath)
rootNode := &nodeutil.Node{
Object: NewLibrary(),
OnGetByKey: getByKey,
OnDeleteByKey: deleteByKey,
}
d.Add("library", rootNode)
restconf.NewServer(d)
d.ApplyStartupConfigFile("./startup.json")
select {}
}
Actual behavior Explicit implementation of
OnGetByKey
handler within the node, causes the library panic duringDELETE
request handling if,OnDeleteByKey
is not explicit implemented.Expected behavior Explicit implementation of
OnGetByKey
handler within the node, does NOT cause the library panic duringDELETE
request handling, ifOnDeleteByKey
is not explicit implementedReproduction steps Code used to reproduce the bug can be found in the section below
go run main.go
books
Yang node (it is already done, by configuration withinstartup.json
file)Perform a DELETE request to delete 1 resource within the
books
node Request:curl -X DELETE http://localhost:8080/restconf/data/library:books=0
Response:curl: (52) Empty reply from server
Server logs:Code used to reproduce a bug
yang/library.yang
main.go
import ( "github.com/freeconf/restconf" "github.com/freeconf/restconf/device" "github.com/freeconf/yang/fc" "github.com/freeconf/yang/node" "github.com/freeconf/yang/nodeutil" "github.com/freeconf/yang/source" )
type Book struct { BookId int Title string }
type Library struct { Books []*Book }
type Model struct { Library *Library }
func NewLibrary() Library { lib := &Library{ Books: []Book{}, } return lib }
func getByKey(n *nodeutil.Node, r node.ListRequest) (node.Node, error) { // node processing... return n.DoGetByKey(r) }
func main() { fc.DebugLog(true) ypath := source.Any(source.Path("yang"), restconf.InternalYPath) d := device.New(ypath) rootNode := &nodeutil.Node{ Object: NewLibrary(), OnGetByKey: getByKey, } d.Add("library", rootNode) restconf.NewServer(d) d.ApplyStartupConfigFile("./startup.json") select {} }
Additional informations
go.mod
content:The only way I found to avoid it, is to implement an explicit
OnDeleteByKey
handler too. After that requestedDELETE
request is performed with no issues.