parseGroupcacheConfig unmarshals a buffer into a GroupcacheConfig with default values.
(conf []byte)
| 77 | |
| 78 | // parseGroupcacheConfig unmarshals a buffer into a GroupcacheConfig with default values. |
| 79 | func parseGroupcacheConfig(conf []byte) (GroupcacheConfig, error) { |
| 80 | config := DefaultGroupcacheConfig |
| 81 | if err := yaml.Unmarshal(conf, &config); err != nil { |
| 82 | return GroupcacheConfig{}, err |
| 83 | } |
| 84 | |
| 85 | if len(config.Peers) == 0 { |
| 86 | config.Peers = append(config.Peers, config.SelfURL) |
| 87 | } |
| 88 | |
| 89 | for i, peer := range config.Peers { |
| 90 | // Workaround for https://github.com/thanos-community/galaxycache/blob/master/http/http.go#L205-L210. |
| 91 | // If the peer has a slash at the end then the router redirects |
| 92 | // and then the request fails. |
| 93 | if strings.HasSuffix(peer, "/") { |
| 94 | return GroupcacheConfig{}, fmt.Errorf("peer %d must not have a trailing slash (%s)", i, peer) |
| 95 | } |
| 96 | } |
| 97 | if strings.HasSuffix(config.SelfURL, "/") { |
| 98 | return GroupcacheConfig{}, fmt.Errorf("self URL %s must not have a trailing slash", config.SelfURL) |
| 99 | } |
| 100 | |
| 101 | return config, nil |
| 102 | } |
| 103 | |
| 104 | // NewGroupcache creates a new Groupcache instance. |
| 105 | func NewGroupcache(logger log.Logger, reg prometheus.Registerer, conf []byte, basepath string, r *route.Router, bucket objstore.Bucket, cfg *CachingBucketConfig) (*Groupcache, error) { |
no test coverage detected