MCPcopy
hub / github.com/thanos-io/thanos / parseGroupcacheConfig

Function parseGroupcacheConfig

pkg/cache/groupcache.go:79–102  ·  view source on GitHub ↗

parseGroupcacheConfig unmarshals a buffer into a GroupcacheConfig with default values.

(conf []byte)

Source from the content-addressed store, hash-verified

77
78// parseGroupcacheConfig unmarshals a buffer into a GroupcacheConfig with default values.
79func 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.
105func NewGroupcache(logger log.Logger, reg prometheus.Registerer, conf []byte, basepath string, r *route.Router, bucket objstore.Bucket, cfg *CachingBucketConfig) (*Groupcache, error) {

Callers 1

NewGroupcacheFunction · 0.85

Calls 2

ErrorfMethod · 0.80
UnmarshalMethod · 0.65

Tested by

no test coverage detected