summaryrefslogtreecommitdiff
path: root/plugin/singbox
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-10-31 10:51:58 +0800
committerLoyalsoldier <[email protected]>2024-10-31 11:21:57 +0800
commit883184cbdc5fff0763c56aae7b08b0605dc08a9b (patch)
treeb1def962ecffe4c2d4be37e77597dd4772ae3e1f /plugin/singbox
parent1e26c9803d42d3601c75c4db2ee3ff565b6388d8 (diff)
Feat: export input & output converters
Diffstat (limited to 'plugin/singbox')
-rw-r--r--plugin/singbox/srs_in.go38
-rw-r--r--plugin/singbox/srs_out.go34
2 files changed, 36 insertions, 36 deletions
diff --git a/plugin/singbox/srs_in.go b/plugin/singbox/srs_in.go
index f38c53cd..13dd51af 100644
--- a/plugin/singbox/srs_in.go
+++ b/plugin/singbox/srs_in.go
@@ -15,16 +15,16 @@ import (
)
const (
- typeSRSIn = "singboxSRS"
- descSRSIn = "Convert sing-box SRS data to other formats"
+ TypeSRSIn = "singboxSRS"
+ DescSRSIn = "Convert sing-box SRS data to other formats"
)
func init() {
- lib.RegisterInputConfigCreator(typeSRSIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
+ lib.RegisterInputConfigCreator(TypeSRSIn, func(action lib.Action, data json.RawMessage) (lib.InputConverter, error) {
return newSRSIn(action, data)
})
- lib.RegisterInputConverter(typeSRSIn, &srsIn{
- Description: descSRSIn,
+ lib.RegisterInputConverter(TypeSRSIn, &SRSIn{
+ Description: DescSRSIn,
})
}
@@ -44,11 +44,11 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
if tmp.Name == "" && tmp.URI == "" && tmp.InputDir == "" {
- return nil, fmt.Errorf("❌ [type %s | action %s] missing inputdir or name or uri", typeSRSIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] missing inputdir or name or uri", TypeSRSIn, action)
}
if (tmp.Name != "" && tmp.URI == "") || (tmp.Name == "" && tmp.URI != "") {
- return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", typeSRSIn, action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] name & uri must be specified together", TypeSRSIn, action)
}
// Filter want list
@@ -59,10 +59,10 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
}
- return &srsIn{
- Type: typeSRSIn,
+ return &SRSIn{
+ Type: TypeSRSIn,
Action: action,
- Description: descSRSIn,
+ Description: DescSRSIn,
Name: tmp.Name,
URI: tmp.URI,
InputDir: tmp.InputDir,
@@ -71,7 +71,7 @@ func newSRSIn(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}, nil
}
-type srsIn struct {
+type SRSIn struct {
Type string
Action lib.Action
Description string
@@ -82,19 +82,19 @@ type srsIn struct {
OnlyIPType lib.IPType
}
-func (s *srsIn) GetType() string {
+func (s *SRSIn) GetType() string {
return s.Type
}
-func (s *srsIn) GetAction() lib.Action {
+func (s *SRSIn) GetAction() lib.Action {
return s.Action
}
-func (s *srsIn) GetDescription() string {
+func (s *SRSIn) GetDescription() string {
return s.Description
}
-func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
+func (s *SRSIn) Input(container lib.Container) (lib.Container, error) {
entries := make(map[string]*lib.Entry)
var err error
@@ -146,7 +146,7 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
return container, nil
}
-func (s *srsIn) walkDir(dir string, entries map[string]*lib.Entry) error {
+func (s *SRSIn) walkDir(dir string, entries map[string]*lib.Entry) error {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
@@ -165,7 +165,7 @@ func (s *srsIn) walkDir(dir string, entries map[string]*lib.Entry) error {
return err
}
-func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error {
+func (s *SRSIn) walkLocalFile(path, name string, entries map[string]*lib.Entry) error {
entryName := ""
name = strings.TrimSpace(name)
if name != "" {
@@ -203,7 +203,7 @@ func (s *srsIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
return nil
}
-func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error {
+func (s *SRSIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry) error {
resp, err := http.Get(url)
if err != nil {
return err
@@ -221,7 +221,7 @@ func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
return nil
}
-func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error {
+func (s *SRSIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error {
name = strings.ToUpper(name)
if len(s.Want) > 0 && !s.Want[name] {
diff --git a/plugin/singbox/srs_out.go b/plugin/singbox/srs_out.go
index a17e1fa7..e613b993 100644
--- a/plugin/singbox/srs_out.go
+++ b/plugin/singbox/srs_out.go
@@ -16,8 +16,8 @@ import (
)
const (
- typeSRSOut = "singboxSRS"
- descSRSOut = "Convert data to sing-box SRS format"
+ TypeSRSOut = "singboxSRS"
+ DescSRSOut = "Convert data to sing-box SRS format"
)
var (
@@ -25,11 +25,11 @@ var (
)
func init() {
- lib.RegisterOutputConfigCreator(typeSRSOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
+ lib.RegisterOutputConfigCreator(TypeSRSOut, func(action lib.Action, data json.RawMessage) (lib.OutputConverter, error) {
return newSRSOut(action, data)
})
- lib.RegisterOutputConverter(typeSRSOut, &srsOut{
- Description: descSRSOut,
+ lib.RegisterOutputConverter(TypeSRSOut, &SRSOut{
+ Description: DescSRSOut,
})
}
@@ -51,10 +51,10 @@ func newSRSOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, er
tmp.OutputDir = defaultOutputDir
}
- return &srsOut{
- Type: typeSRSOut,
+ return &SRSOut{
+ Type: TypeSRSOut,
Action: action,
- Description: descSRSOut,
+ Description: DescSRSOut,
OutputDir: tmp.OutputDir,
Want: tmp.Want,
Exclude: tmp.Exclude,
@@ -62,7 +62,7 @@ func newSRSOut(action lib.Action, data json.RawMessage) (lib.OutputConverter, er
}, nil
}
-type srsOut struct {
+type SRSOut struct {
Type string
Action lib.Action
Description string
@@ -72,19 +72,19 @@ type srsOut struct {
OnlyIPType lib.IPType
}
-func (s *srsOut) GetType() string {
+func (s *SRSOut) GetType() string {
return s.Type
}
-func (s *srsOut) GetAction() lib.Action {
+func (s *SRSOut) GetAction() lib.Action {
return s.Action
}
-func (s *srsOut) GetDescription() string {
+func (s *SRSOut) GetDescription() string {
return s.Description
}
-func (s *srsOut) Output(container lib.Container) error {
+func (s *SRSOut) Output(container lib.Container) error {
for _, name := range s.filterAndSortList(container) {
entry, found := container.GetEntry(name)
if !found {
@@ -100,7 +100,7 @@ func (s *srsOut) Output(container lib.Container) error {
return nil
}
-func (s *srsOut) filterAndSortList(container lib.Container) []string {
+func (s *SRSOut) filterAndSortList(container lib.Container) []string {
excludeMap := make(map[string]bool)
for _, exclude := range s.Exclude {
if exclude = strings.ToUpper(strings.TrimSpace(exclude)); exclude != "" {
@@ -136,7 +136,7 @@ func (s *srsOut) filterAndSortList(container lib.Container) []string {
return list
}
-func (s *srsOut) generate(entry *lib.Entry) error {
+func (s *SRSOut) generate(entry *lib.Entry) error {
ruleset, err := s.marshalRuleSet(entry)
if err != nil {
return err
@@ -150,7 +150,7 @@ func (s *srsOut) generate(entry *lib.Entry) error {
return nil
}
-func (s *srsOut) marshalRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error) {
+func (s *SRSOut) marshalRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error) {
var entryCidr []string
var err error
switch s.OnlyIPType {
@@ -183,7 +183,7 @@ func (s *srsOut) marshalRuleSet(entry *lib.Entry) (*option.PlainRuleSet, error)
return nil, fmt.Errorf("❌ [type %s | action %s] entry %s has no CIDR", s.Type, s.Action, entry.GetName())
}
-func (s *srsOut) writeFile(filename string, ruleset *option.PlainRuleSet) error {
+func (s *SRSOut) writeFile(filename string, ruleset *option.PlainRuleSet) error {
if err := os.MkdirAll(s.OutputDir, 0755); err != nil {
return err
}