github.com/mckael/restic@v0.8.3/internal/backend/rest/config.go (about)

     1  package rest
     2  
     3  import (
     4  	"net/url"
     5  	"strings"
     6  
     7  	"github.com/restic/restic/internal/errors"
     8  	"github.com/restic/restic/internal/options"
     9  )
    10  
    11  // Config contains all configuration necessary to connect to a REST server.
    12  type Config struct {
    13  	URL         *url.URL
    14  	Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
    15  }
    16  
    17  func init() {
    18  	options.Register("rest", Config{})
    19  }
    20  
    21  // NewConfig returns a new Config with the default values filled in.
    22  func NewConfig() Config {
    23  	return Config{
    24  		Connections: 5,
    25  	}
    26  }
    27  
    28  // ParseConfig parses the string s and extracts the REST server URL.
    29  func ParseConfig(s string) (interface{}, error) {
    30  	if !strings.HasPrefix(s, "rest:") {
    31  		return nil, errors.New("invalid REST backend specification")
    32  	}
    33  
    34  	s = s[5:]
    35  	u, err := url.Parse(s)
    36  
    37  	if err != nil {
    38  		return nil, errors.Wrap(err, "url.Parse")
    39  	}
    40  
    41  	cfg := NewConfig()
    42  	cfg.URL = u
    43  	return cfg, nil
    44  }