constants.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package deprecated
  2. import (
  3. C "github.com/sagernet/sing-box/constant"
  4. F "github.com/sagernet/sing/common/format"
  5. "golang.org/x/mod/semver"
  6. )
  7. type Note struct {
  8. Name string
  9. Description string
  10. DeprecatedVersion string
  11. ScheduledVersion string
  12. EnvName string
  13. MigrationLink string
  14. }
  15. func (n Note) Impending() bool {
  16. if n.ScheduledVersion == "" {
  17. return false
  18. }
  19. if !semver.IsValid("v" + C.Version) {
  20. return false
  21. }
  22. versionMinor := semver.Compare(semver.MajorMinor("v"+C.Version), "v"+n.ScheduledVersion)
  23. if versionMinor < 0 {
  24. panic("invalid deprecated note: " + n.Name)
  25. }
  26. return versionMinor <= 1
  27. }
  28. func (n Note) Message() string {
  29. return F.ToString(
  30. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  31. " and will be removed in sing-box ", n.ScheduledVersion, ", please checkout documentation for migration.",
  32. )
  33. }
  34. func (n Note) MessageWithLink() string {
  35. return F.ToString(
  36. n.Description, " is deprecated in sing-box ", n.DeprecatedVersion,
  37. " and will be removed in sing-box ", n.ScheduledVersion, ", checkout documentation for migration: ", n.MigrationLink,
  38. )
  39. }
  40. var OptionBadMatchSource = Note{
  41. Name: "bad-match-source",
  42. Description: "legacy match source rule item",
  43. DeprecatedVersion: "1.10.0",
  44. ScheduledVersion: "1.11.0",
  45. MigrationLink: "https://sing-box.sagernet.org/deprecated/#match-source-rule-items-are-renamed",
  46. }
  47. var OptionGEOIP = Note{
  48. Name: "geoip",
  49. Description: "geoip database",
  50. DeprecatedVersion: "1.8.0",
  51. ScheduledVersion: "1.12.0",
  52. EnvName: "GEOIP",
  53. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geoip-to-rule-sets",
  54. }
  55. var OptionGEOSITE = Note{
  56. Name: "geosite",
  57. Description: "geosite database",
  58. DeprecatedVersion: "1.8.0",
  59. ScheduledVersion: "1.12.0",
  60. EnvName: "GEOSITE",
  61. MigrationLink: "https://sing-box.sagernet.org/migration/#migrate-geosite-to-rule-sets",
  62. }
  63. var OptionTUNAddressX = Note{
  64. Name: "tun-address-x",
  65. Description: "legacy tun address fields",
  66. DeprecatedVersion: "1.10.0",
  67. ScheduledVersion: "1.12.0",
  68. MigrationLink: "https://sing-box.sagernet.org/migration/#tun-address-fields-are-merged",
  69. }
  70. var Options = []Note{
  71. OptionBadMatchSource,
  72. OptionGEOIP,
  73. OptionGEOSITE,
  74. OptionTUNAddressX,
  75. }