constants.go 2.6 KB

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