@@ -302,29 +302,25 @@ export PROXY_CONVERT_DEFAULT_OUTPUT_FORMAT=v2ray
302302``` tree
303303src/
304304├── main.rs # Entry point
305- ├── core/ # Core modules
306- │ ├── error.rs # Error handling
305+ ├── core/ # Domain and core
307306│ ├── config.rs # Config management
308- │ ├── converter.rs # Core converter
309- │ ├── http_client.rs # HTTP client
310- │ ├── multi_input.rs # Multi-input integration ✨
311- │ └── output.rs # Output management
307+ │ ├── error.rs # Global error type
308+ │ ├── logging.rs # Logging init
309+ │ └── source.rs # SourceMeta, SourceProtocol (domain types)
312310├── protocols/ # Protocol modules
313- │ ├── mod.rs # Protocol registry
314- │ ├── common/ # Common utilities
311+ │ ├── mod.rs # Protocol registry, ProxyServer, ProtocolProcessor
315312│ ├── clash/ # Clash protocol support
316313│ ├── singbox/ # Sing-box protocol support
317314│ └── v2ray/ # V2Ray protocol support
318- ├── commands/ # Command modules
315+ ├── commands/ # CLI commands
319316│ ├── cli.rs # CLI definition
320- │ ├── convert.rs # Convert command ✨
321- │ ├── validate.rs # Validate command
317+ │ ├── convert.rs # Convert command
318+ │ ├── validate.rs # Validate command
322319│ ├── template.rs # Template command
323320│ └── version.rs # Version command
324- └── utils/ # Utility modules
325- ├── file.rs # File operations
326- ├── url.rs # URL processing
327- └── template.rs # Template processing ✨
321+ └── utils/ # Utilities
322+ ├── source/ # Source loader and parser
323+ └── template/ # Template interpolation and engine
328324```
329325
330326## 🔧 Development
@@ -369,53 +365,47 @@ The project supports multi-source integration with unified interpolation rules:
369365### Add New Protocol Support
370366
3713671 . Create a new protocol module under ` src/protocols/ `
372- 2 . Implement the ` ProtocolConverter ` trait
373- 3 . Register the new protocol in ` init_protocol_registry() ` in ` src/main.rs `
368+ 2 . Implement the ` ProtocolProcessor ` trait for template processing
369+ 3 . Register the processor in ` ProtocolRegistry::init() ` in ` src/protocols/mod.rs ` :
370+ ` registry.register("format_name", Box::new(YourProcessor)); `
371+ 4 . Add parsing/conversion in the registry for your format if needed (e.g. ` parse_content ` , subscription/plain)
374372
375373### Example: Add New Protocol
376374
377375``` rust
378376// src/protocols/new_protocol/mod.rs
379- use crate :: utils :: error :: Result ;
380- use crate :: protocols :: {ProtocolConverter , ProxyServer };
377+ use crate :: core :: error :: Result ;
378+ use crate :: protocols :: {ProtocolProcessor , ProxyServer };
379+ use crate :: utils :: template :: interpolation_parser :: InterpolationRule ;
380+ use indexmap :: IndexMap ;
381+ use crate :: utils :: source :: parser :: Source ;
381382
382- pub struct NewProtocolConverter ;
383+ pub struct NewProtocolProcessor ;
383384
384- impl ProtocolConverter for NewProtocolConverter {
385- fn name (& self ) -> & str {
386- " new_protocol "
385+ impl ProtocolProcessor for NewProtocolProcessor {
386+ fn process_rule (& self , _rule : & InterpolationRule , _sources : & IndexMap < String , Source > ) -> Result < String > {
387+ Ok ( String :: new ())
387388 }
388-
389- fn supported_input_formats (& self ) -> & [& str ] {
390- & [" json" , " yaml" ]
391- }
392-
393- fn supported_output_formats (& self ) -> & [& str ] {
394- & [" singbox" , " clash" ]
389+ fn get_nodes_for_rule (& self , rule : & InterpolationRule , sources : & IndexMap <String , Source >) -> Result <Vec <ProxyServer >> {
390+ // ...
395391 }
396-
397- fn detect_format (& self , content : & str ) -> Result <Option <String >> {
398- // Implement format detection logic
399- Ok (None )
392+ fn set_default_values (& self , template : & str , nodes : & [ProxyServer ]) -> Result <String > {
393+ // ...
400394 }
401-
402- fn parse_input (& self , content : & str , format : & str ) -> Result <Vec <ProxyServer >> {
403- // Implement input parsing logic
404- Ok (vec! [])
395+ fn append_nodes (& self , template : & str , nodes : & [ProxyServer ]) -> Result <String > {
396+ // ...
405397 }
406-
407- fn generate_output (& self , servers : & [ProxyServer ], format : & str , template : Option <& str >) -> Result <String > {
408- // Implement output generation logic
409- Ok ("" . to_string ())
410- }
411-
412- fn validate_output (& self , content : & str , format : & str ) -> Result <bool > {
413- // Implement output validation logic
414- Ok (true )
398+ fn create_node_config (& self , node : & ProxyServer ) -> String {
399+ // ...
415400 }
416401}
417402```
418403
404+ Then in ` ProtocolRegistry::init() ` :
405+ ``` rust
406+ registry . register (" new_protocol" , Box :: new (new_protocol :: NewProtocolProcessor ));
407+ ```
408+
419409### Build and Test
420410
421411``` bash
0 commit comments