You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dataset.go 1.5 kB

3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/casbin/casbase/object"
  5. "github.com/casbin/casbase/util"
  6. )
  7. func (c *ApiController) GetGlobalDatasets() {
  8. c.Data["json"] = object.GetGlobalDatasets()
  9. c.ServeJSON()
  10. }
  11. func (c *ApiController) GetDatasets() {
  12. owner := c.Input().Get("owner")
  13. c.Data["json"] = object.GetDatasets(owner)
  14. c.ServeJSON()
  15. }
  16. func (c *ApiController) GetDataset() {
  17. id := c.Input().Get("id")
  18. c.Data["json"] = object.GetDataset(id)
  19. c.ServeJSON()
  20. }
  21. func (c *ApiController) GetDatasetGraph() {
  22. id := c.Input().Get("id")
  23. clusterNumber := util.ParseInt(c.Input().Get("clusterNumber"))
  24. distanceLimit := util.ParseInt(c.Input().Get("distanceLimit"))
  25. c.Data["json"] = object.GetDatasetGraph(id, clusterNumber, distanceLimit)
  26. c.ServeJSON()
  27. }
  28. func (c *ApiController) UpdateDataset() {
  29. id := c.Input().Get("id")
  30. var dataset object.Dataset
  31. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataset)
  32. if err != nil {
  33. panic(err)
  34. }
  35. c.Data["json"] = object.UpdateDataset(id, &dataset)
  36. c.ServeJSON()
  37. }
  38. func (c *ApiController) AddDataset() {
  39. var dataset object.Dataset
  40. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataset)
  41. if err != nil {
  42. panic(err)
  43. }
  44. c.Data["json"] = object.AddDataset(&dataset)
  45. c.ServeJSON()
  46. }
  47. func (c *ApiController) DeleteDataset() {
  48. var dataset object.Dataset
  49. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataset)
  50. if err != nil {
  51. panic(err)
  52. }
  53. c.Data["json"] = object.DeleteDataset(&dataset)
  54. c.ServeJSON()
  55. }

基于Casbin的开源AI领域知识库平台

Contributors (1)