Skip to content

Commit 647c8ac

Browse files
committed
renamed private functions.
1 parent ba313d4 commit 647c8ac

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

ditto.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ func getCacheFilePath(endpoint string) string {
1717
return filepath.Join(".ditto", hashedEndpoint)
1818
}
1919

20-
func loadCache(endpoint string) ([]byte, error) {
20+
func retrieve(endpoint string) ([]byte, error) {
2121
cacheFilePath := getCacheFilePath(endpoint)
2222
if _, err := os.Stat(cacheFilePath); os.IsNotExist(err) {
2323
return nil, err
2424
}
2525
return os.ReadFile(cacheFilePath)
2626
}
2727

28-
func saveCache(endpoint string, data []byte) error {
28+
func cache(endpoint string, data []byte) error {
2929
cacheFilePath := getCacheFilePath(endpoint)
3030
os.MkdirAll(filepath.Dir(cacheFilePath), os.ModePerm)
3131
return os.WriteFile(cacheFilePath, data, 0644)
@@ -38,7 +38,7 @@ type CachingHTTPClient struct {
3838
func (c *CachingHTTPClient) RoundTrip(req *http.Request) (*http.Response, error) {
3939
endpoint := req.URL.String()
4040

41-
data, err := loadCache(endpoint)
41+
data, err := retrieve(endpoint)
4242
if err == nil {
4343
reader := io.NopCloser(bytes.NewReader(data))
4444
return &http.Response{
@@ -57,7 +57,7 @@ func (c *CachingHTTPClient) RoundTrip(req *http.Request) (*http.Response, error)
5757
return nil, err
5858
}
5959

60-
err = saveCache(endpoint, data)
60+
err = cache(endpoint, data)
6161
if err != nil {
6262
return nil, err
6363
}

ditto_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ func TestGetCacheFilePath(t *testing.T) {
2121
t.Errorf("Expected` %s, but got %s", expected, result)
2222
}
2323
}
24-
func TestSaveCache(t *testing.T) {
24+
func TestCache(t *testing.T) {
2525
endpoint := "https://example.com/api"
2626
data := []byte("test data")
2727
expectedFilePath := getCacheFilePath(endpoint)
2828

29-
err := saveCache(endpoint, data)
29+
err := cache(endpoint, data)
3030
if err != nil {
3131
t.Errorf("Unexpected error: %v", err)
3232
}
@@ -43,7 +43,7 @@ func TestSaveCache(t *testing.T) {
4343
t.Errorf("Failed to remove cache file: %v", err)
4444
}
4545
}
46-
func TestLoadCache(t *testing.T) {
46+
func TestRetrieve(t *testing.T) {
4747
endpoint := "https://example.com/api"
4848
expectedData := []byte("test data")
4949
expectedFilePath := getCacheFilePath(endpoint)
@@ -56,7 +56,7 @@ func TestLoadCache(t *testing.T) {
5656
defer os.Remove(expectedFilePath)
5757

5858
// Test loading cache
59-
result, err := loadCache(endpoint)
59+
result, err := retrieve(endpoint)
6060
if err != nil {
6161
t.Errorf("Unexpected error: %v", err)
6262
}

0 commit comments

Comments
 (0)