forked from upspin/upspin
/
cache.go
39 lines (34 loc) · 877 Bytes
/
cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2016 The Upspin Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rpc
import (
"strings"
"upspin.io/errors"
"upspin.io/rpc/local"
"upspin.io/upspin"
)
func CacheEndpoint(cfg upspin.Config) (*upspin.Endpoint, error) {
const op errors.Op = "rpc.CacheEndpoint"
v := cfg.Value("cache")
switch v {
case "", "n", "no", "false":
return nil, nil
case "y", "yes", "true":
name := "remote," + local.LocalName(cfg, "cacheserver") + ":80"
ep, err := upspin.ParseEndpoint(name)
if err != nil {
return nil, errors.E(op, errors.Internal, err)
}
return ep, nil
default:
if !strings.Contains(v, ",") {
v = "remote," + v
}
ep, err := upspin.ParseEndpoint(v)
if err != nil {
return nil, errors.E(op, errors.Invalid, err)
}
return ep, nil
}
}