feat: implement StoreWithFallbacks#46
Conversation
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #46 +/- ##
==========================================
- Coverage 78.32% 77.67% -0.65%
==========================================
Files 3 4 +1
Lines 203 224 +21
==========================================
+ Hits 159 174 +15
- Misses 33 37 +4
- Partials 11 13 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
|
|
||
| // NewStoreWithFallbacks returns a new store based on the given stores. | ||
| // The second and the subsequent stores will be used as fallbacks for the first store. | ||
| func NewStoreWithFallbacks(store Store, fallbacks ...Store) Store { |
There was a problem hiding this comment.
I'm still struggling between
NewStoreWithFallbacks(store Store, fallbacks ...Store) Storeand
NewStoreWithFallbacks(stores ...Store) StoreLater we will have a docker store which is based on the docker configuration file at the default location. I'm wondering how we should use it together with StoreWithFallbacks.
If we go for option 1, the experience would be:
ns := NewNativeStore()
store := NewStoreWithFallbacks(ns, NewStoreFromDocker())or
dockerStore := NewStoreFromDocker()
store := NewStoreWithFallbacks(dockerStore)If we go for option 2, we should have the docker store to be the default store when no store is passed.
So
dockerStore := NewStoreFromDocker()
store := NewStoreWithFallbacks(dockerStore)is equivalent to
store := NewStoreWithFallbacks()There was a problem hiding this comment.
I think I still prefer option 1.
Good advice. Added more detailed documentations for |
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
| } | ||
|
|
||
| // NewStoreWithFallbacks returns a new store based on the given stores. | ||
| // The first store in the array is used as the primary store. The second |
There was a problem hiding this comment.
The first store in the array is used as the primary store
This looks a bit strange as this function does not accept an array of stores for the primary store.
There was a problem hiding this comment.
removed the description about the array.
| } | ||
|
|
||
| // Get retrieves credentials from the StoreWithFallbacks for the given server. | ||
| // It searches the array of stores for the credentials of serverAddress |
There was a problem hiding this comment.
The array of stores is invisible to users.
There was a problem hiding this comment.
removed the description about the array.
There was a problem hiding this comment.
Can we put everything in store.go instead of having a new file?
| // StoreWithFallbacks is a store that has multiple fallback stores. | ||
| // Please use the NewStoreWithFallbacks to create new instances of | ||
| // StoreWithFallbacks. | ||
| type StoreWithFallbacks struct { |
There was a problem hiding this comment.
Do we need to export this struct? Can we make it private?
There was a problem hiding this comment.
Made it private.
| func NewStoreWithFallbacks(store Store, fallbacks ...Store) Store { | ||
| return &StoreWithFallbacks{ | ||
| stores: append([]Store{store}, fallbacks...), | ||
| } | ||
| } |
There was a problem hiding this comment.
If len(fallbacks) == 0, should we just return store?
There was a problem hiding this comment.
changed it.
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
| // Please use the NewStoreWithFallbacks to create new instances of | ||
| // storeWithFallbacks. |
| // The first store is used as the primary store. The second and the | ||
| // subsequent stores will be used as fallbacks for the first store. | ||
| func NewStoreWithFallbacks(store Store, fallbacks ...Store) Store { | ||
| if fallbacks == nil { |
There was a problem hiding this comment.
| if fallbacks == nil { | |
| if len(fallbacks) == 0 { |
fallbacks can be not-nil but empty.
| // It searches the primary and the fallback stores for the credentials of serverAddress | ||
| // and returns when it finds the credentials in any of the stores. |
There was a problem hiding this comment.
I'm wondering if users can see these comments. We may need to move them to NewStoreWithFallbacks.
| } | ||
|
|
||
| // Put saves credentials into the StoreWithFallbacks. It puts | ||
| // the credentials into the primary store. |
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Resolves #35