-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e1e6f8
commit f3d4739
Showing
13 changed files
with
207 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
.DS_Store | ||
.DS_Store | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package models | ||
|
||
import ( | ||
pb "github.com/momentohq/client-sdk-go/internal/protos" | ||
) | ||
|
||
type CreateCacheRequest struct { | ||
CacheName string | ||
} | ||
|
||
type DeleteCacheRequest struct { | ||
CacheName string | ||
} | ||
|
||
type ListCachesRequest struct { | ||
NextToken string | ||
} | ||
|
||
type ListCachesResponse struct { | ||
NextToken string | ||
Caches []CacheInfo | ||
} | ||
|
||
func NewListCacheResponse(resp *pb.ListCachesResponse) *ListCachesResponse { | ||
var caches = []CacheInfo{} | ||
for _, cache := range resp.Cache { | ||
caches = append(caches, NewCacheInfo(cache)) | ||
} | ||
return &ListCachesResponse{NextToken: resp.NextToken, Caches: caches} | ||
} | ||
|
||
type CacheInfo struct { | ||
Name string | ||
} | ||
|
||
func NewCacheInfo(cache *pb.Cache) CacheInfo { | ||
return CacheInfo{Name: cache.CacheName} | ||
} | ||
|
||
const ( | ||
HIT string = "HIT" | ||
MISS string = "MISS" | ||
) | ||
|
||
type CacheGetRequest struct { | ||
CacheName string | ||
Key interface{} | ||
} | ||
|
||
type GetCacheResponse struct { | ||
Value []byte | ||
Result string | ||
} | ||
|
||
func NewGetCacheResponse(resp *pb.GetResponse) (*GetCacheResponse, error) { | ||
var result string | ||
if resp.Result == pb.ECacheResult_Hit { | ||
result = HIT | ||
} else if resp.Result == pb.ECacheResult_Miss { | ||
result = MISS | ||
} else { | ||
return nil, ConvertEcacheResult(ConvertEcacheResultRequest{ | ||
ECacheResult: resp.Result, | ||
Message: resp.Message, | ||
OpName: "GET", | ||
}) | ||
} | ||
return &GetCacheResponse{Value: resp.CacheBody, Result: result}, nil | ||
} | ||
|
||
type CacheSetRequest struct { | ||
CacheName string | ||
Key interface{} | ||
Value interface{} | ||
TtlSeconds uint32 | ||
} | ||
|
||
type SetCacheResponse struct { | ||
Value []byte | ||
} | ||
|
||
func NewSetCacheResponse(resp *pb.SetResponse, value []byte) *SetCacheResponse { | ||
return &SetCacheResponse{Value: value} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
package utility | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
internalRequests "github.com/momentohq/client-sdk-go/internal/requests" | ||
) | ||
|
||
func IsCacheNameValid(cacheName string) bool { | ||
return len(strings.TrimSpace(cacheName)) != 0 | ||
} | ||
|
||
func ConvertEcacheResult(request internalRequests.ConvertEcacheResultRequest) error { | ||
return fmt.Errorf("CacheService returned an unexpected result: %v for operation: %s with message: %s", request.ECacheResult, request.OpName, request.Message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.