types.go 754 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import "sort"
  3. type Functions []Function
  4. var _ sort.Interface = Functions{}
  5. // Len implements sort.Interface.
  6. func (f Functions) Len() int {
  7. return len(f)
  8. }
  9. // Less implements sort.Interface.
  10. func (f Functions) Less(i int, j int) bool {
  11. if f[i].File < f[j].File {
  12. return true
  13. } else if f[i].File > f[j].File {
  14. return false
  15. }
  16. return f[i].Line.From < f[j].Line.From
  17. }
  18. // Swap implements sort.Interface.
  19. func (f Functions) Swap(i int, j int) {
  20. f[i], f[j] = f[j], f[i]
  21. }
  22. type Function struct {
  23. ID uint64 `json:"id"`
  24. Name string `json:"name"`
  25. File string `json:"file"`
  26. Code string `json:"code"`
  27. Line FunctionPos `json:"line"`
  28. }
  29. type FunctionPos struct {
  30. From int `json:"from"`
  31. To int `json:"to"`
  32. }