2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 13:17:42 +00:00
restic/internal/backend/rest/config.go

49 lines
986 B
Go
Raw Normal View History

package rest
import (
"net/url"
"strings"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/options"
)
// Config contains all configuration necessary to connect to a REST server.
type Config struct {
2017-06-05 22:25:22 +00:00
URL *url.URL
Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
2017-06-05 22:25:22 +00:00
}
func init() {
options.Register("rest", Config{})
}
// NewConfig returns a new Config with the default values filled in.
func NewConfig() Config {
return Config{
Connections: 5,
2017-06-05 22:25:22 +00: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:]
if !strings.HasSuffix(s, "/") {
s += "/"
}
u, err := url.Parse(s)
if err != nil {
2016-08-29 19:54:50 +00:00
return nil, errors.Wrap(err, "url.Parse")
}
2017-06-05 22:25:22 +00:00
cfg := NewConfig()
cfg.URL = u
return cfg, nil
}