From 647c8ac4ac7896aedb4f2a00277b9c4b1f116262 Mon Sep 17 00:00:00 2001 From: Timothy Stiles Date: Tue, 9 Jan 2024 08:57:45 -0800 Subject: [PATCH] renamed private functions. --- ditto.go | 8 ++++---- ditto_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ditto.go b/ditto.go index 64639a2..a7310b7 100644 --- a/ditto.go +++ b/ditto.go @@ -17,7 +17,7 @@ func getCacheFilePath(endpoint string) string { return filepath.Join(".ditto", hashedEndpoint) } -func loadCache(endpoint string) ([]byte, error) { +func retrieve(endpoint string) ([]byte, error) { cacheFilePath := getCacheFilePath(endpoint) if _, err := os.Stat(cacheFilePath); os.IsNotExist(err) { return nil, err @@ -25,7 +25,7 @@ func loadCache(endpoint string) ([]byte, error) { return os.ReadFile(cacheFilePath) } -func saveCache(endpoint string, data []byte) error { +func cache(endpoint string, data []byte) error { cacheFilePath := getCacheFilePath(endpoint) os.MkdirAll(filepath.Dir(cacheFilePath), os.ModePerm) return os.WriteFile(cacheFilePath, data, 0644) @@ -38,7 +38,7 @@ type CachingHTTPClient struct { func (c *CachingHTTPClient) RoundTrip(req *http.Request) (*http.Response, error) { endpoint := req.URL.String() - data, err := loadCache(endpoint) + data, err := retrieve(endpoint) if err == nil { reader := io.NopCloser(bytes.NewReader(data)) return &http.Response{ @@ -57,7 +57,7 @@ func (c *CachingHTTPClient) RoundTrip(req *http.Request) (*http.Response, error) return nil, err } - err = saveCache(endpoint, data) + err = cache(endpoint, data) if err != nil { return nil, err } diff --git a/ditto_test.go b/ditto_test.go index 21c6c02..2ed85e2 100644 --- a/ditto_test.go +++ b/ditto_test.go @@ -21,12 +21,12 @@ func TestGetCacheFilePath(t *testing.T) { t.Errorf("Expected` %s, but got %s", expected, result) } } -func TestSaveCache(t *testing.T) { +func TestCache(t *testing.T) { endpoint := "https://example.com/api" data := []byte("test data") expectedFilePath := getCacheFilePath(endpoint) - err := saveCache(endpoint, data) + err := cache(endpoint, data) if err != nil { t.Errorf("Unexpected error: %v", err) } @@ -43,7 +43,7 @@ func TestSaveCache(t *testing.T) { t.Errorf("Failed to remove cache file: %v", err) } } -func TestLoadCache(t *testing.T) { +func TestRetrieve(t *testing.T) { endpoint := "https://example.com/api" expectedData := []byte("test data") expectedFilePath := getCacheFilePath(endpoint) @@ -56,7 +56,7 @@ func TestLoadCache(t *testing.T) { defer os.Remove(expectedFilePath) // Test loading cache - result, err := loadCache(endpoint) + result, err := retrieve(endpoint) if err != nil { t.Errorf("Unexpected error: %v", err) }