| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | // +build json | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package dokodemo | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2016-06-11 22:52:37 +02:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	v2net "github.com/v2ray/v2ray-core/common/net" | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	"github.com/v2ray/v2ray-core/proxy/internal" | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | func (this *Config) UnmarshalJSON(data []byte) error { | 
					
						
							|  |  |  | 	type DokodemoConfig struct { | 
					
						
							|  |  |  | 		Host         *v2net.AddressJson `json:"address"` | 
					
						
							|  |  |  | 		PortValue    v2net.Port         `json:"port"` | 
					
						
							|  |  |  | 		NetworkList  *v2net.NetworkList `json:"network"` | 
					
						
							|  |  |  | 		TimeoutValue int                `json:"timeout"` | 
					
						
							| 
									
										
										
										
											2016-06-12 01:30:56 +02:00
										 |  |  | 		Redirect     bool               `json:"followRedirect"` | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	rawConfig := new(DokodemoConfig) | 
					
						
							|  |  |  | 	if err := json.Unmarshal(data, rawConfig); err != nil { | 
					
						
							| 
									
										
										
										
											2016-06-11 22:52:37 +02:00
										 |  |  | 		return errors.New("Dokodemo: Failed to parse config: " + err.Error()) | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-12 22:54:33 +02:00
										 |  |  | 	if rawConfig.Host != nil { | 
					
						
							|  |  |  | 		this.Address = rawConfig.Host.Address | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	this.Port = rawConfig.PortValue | 
					
						
							|  |  |  | 	this.Network = rawConfig.NetworkList | 
					
						
							|  |  |  | 	this.Timeout = rawConfig.TimeoutValue | 
					
						
							| 
									
										
										
										
											2016-06-12 01:30:56 +02:00
										 |  |  | 	this.FollowRedirect = rawConfig.Redirect | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	return nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | func init() { | 
					
						
							| 
									
										
										
										
											2016-06-10 22:26:39 +02:00
										 |  |  | 	internal.RegisterInboundConfig("dokodemo-door", func() interface{} { return new(Config) }) | 
					
						
							| 
									
										
										
										
											2016-01-15 12:43:06 +01:00
										 |  |  | } |