common.go 901 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package utils
  4. import (
  5. "fmt"
  6. "github.com/tidwall/gjson"
  7. )
  8. func getKey(content string,keys []string) string{
  9. key := ""
  10. if keys == nil {
  11. return key
  12. }
  13. for _,v := range keys{
  14. key = key+gjson.Get(content, v).String()
  15. }
  16. return key
  17. }
  18. // 获取主键
  19. func GetPrimaryKey(content string,outputSource string ,keys []string ) (string,string) {
  20. key := getKey(content,keys)
  21. if key == ""{
  22. return "",""
  23. }
  24. lockKey := fmt.Sprintf("ads-lock-%s-%s",outputSource,key)
  25. taskKey := fmt.Sprintf("ads-task-%s-%s",outputSource,key)
  26. return lockKey,taskKey
  27. }
  28. // 获取任务主键
  29. func GetTaskKey(content string ,keys []string) string {
  30. key := ""
  31. for _,v := range keys{
  32. key = key+gjson.Get(content, v).String()
  33. }
  34. if key == ""{
  35. return key
  36. }
  37. key = fmt.Sprintf("task-%s",key)
  38. return key
  39. }