| 
									
										
										
										
											2016-02-20 22:05:48 +01:00
										 |  |  | package rest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"net/url" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2016-08-21 17:46:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:17:37 +02:00
										 |  |  | 	"restic/errors" | 
					
						
							| 
									
										
										
										
											2017-06-06 00:25:22 +02:00
										 |  |  | 	"restic/options" | 
					
						
							| 
									
										
										
										
											2016-02-20 22:05:48 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Config contains all configuration necessary to connect to a REST server. | 
					
						
							|  |  |  | type Config struct { | 
					
						
							| 
									
										
										
										
											2017-06-06 00:25:22 +02:00
										 |  |  | 	URL         *url.URL | 
					
						
							| 
									
										
										
										
											2017-06-11 13:46:54 +02:00
										 |  |  | 	Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"` | 
					
						
							| 
									
										
										
										
											2017-06-06 00:25:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func init() { | 
					
						
							|  |  |  | 	options.Register("rest", Config{}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NewConfig returns a new Config with the default values filled in. | 
					
						
							|  |  |  | func NewConfig() Config { | 
					
						
							|  |  |  | 	return Config{ | 
					
						
							| 
									
										
										
										
											2017-06-11 13:46:54 +02:00
										 |  |  | 		Connections: 5, | 
					
						
							| 
									
										
										
										
											2017-06-06 00:25:22 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-02-20 22:05:48 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ParseConfig parses the string s and extracts the REST server URL. | 
					
						
							|  |  |  | func ParseConfig(s string) (interface{}, error) { | 
					
						
							|  |  |  | 	if !strings.HasPrefix(s, "rest:") { | 
					
						
							|  |  |  | 		return nil, errors.New("invalid REST backend specification") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s = s[5:] | 
					
						
							|  |  |  | 	u, err := url.Parse(s) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2016-08-29 21:54:50 +02:00
										 |  |  | 		return nil, errors.Wrap(err, "url.Parse") | 
					
						
							| 
									
										
										
										
											2016-02-20 22:05:48 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-06 00:25:22 +02:00
										 |  |  | 	cfg := NewConfig() | 
					
						
							|  |  |  | 	cfg.URL = u | 
					
						
							| 
									
										
										
										
											2016-02-20 22:05:48 +01:00
										 |  |  | 	return cfg, nil | 
					
						
							|  |  |  | } |