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.

string_lock_target.go 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package lockprovider
  2. import "gitlink.org.cn/cloudream/common/utils/serder"
  3. type StringLockTarget struct {
  4. Components []StringLockTargetComponet `json:"components"`
  5. }
  6. // IsConflict 判断两个锁对象是否冲突。注:只有相同的结构的Target才有意义
  7. func (t *StringLockTarget) IsConflict(other *StringLockTarget) bool {
  8. if len(t.Components) != len(other.Components) {
  9. return false
  10. }
  11. for i := 0; i < len(t.Components); i++ {
  12. if t.Components[i].IsEquals(&other.Components[i]) {
  13. return true
  14. }
  15. }
  16. return false
  17. }
  18. type StringLockTargetComponet struct {
  19. Values []string `json:"values"`
  20. }
  21. // IsEquals 判断两个Component是否相同。注:只有相同的结构的Component才有意义
  22. func (t *StringLockTargetComponet) IsEquals(other *StringLockTargetComponet) bool {
  23. if len(t.Values) != len(other.Values) {
  24. return false
  25. }
  26. for i := 0; i < len(t.Values); i++ {
  27. if t.Values[i] != other.Values[i] {
  28. return false
  29. }
  30. }
  31. return true
  32. }
  33. func StringLockTargetToString(target *StringLockTarget) (string, error) {
  34. data, err := serder.ObjectToJSON(target)
  35. if err != nil {
  36. return "", err
  37. }
  38. return string(data), nil
  39. }
  40. func StringLockTargetFromString(str string) (StringLockTarget, error) {
  41. var ret StringLockTarget
  42. err := serder.JSONToObject([]byte(str), &ret)
  43. return ret, err
  44. }

公共库

Contributors (1)