forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support storeView impl * chore: add const storeType * chore: use const in test * feat: add interface for storeView
- Loading branch information
1 parent
c6f1589
commit 9237ddf
Showing
5 changed files
with
500 additions
and
0 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
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,124 @@ | ||
package sls | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
) | ||
|
||
func (c *Client) CreateStoreView(project string, storeView *StoreView) error { | ||
body, err := json.Marshal(storeView) | ||
if err != nil { | ||
return NewClientError(err) | ||
} | ||
h := map[string]string{ | ||
"Content-Type": "application/json", | ||
"x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), | ||
} | ||
uri := "/storeviews" | ||
r, err := c.request(project, "POST", uri, h, body) | ||
if err != nil { | ||
return err | ||
} | ||
r.Body.Close() | ||
return nil | ||
} | ||
|
||
func (c *Client) UpdateStoreView(project string, storeView *StoreView) error { | ||
body, err := json.Marshal(storeView) | ||
if err != nil { | ||
return NewClientError(err) | ||
} | ||
h := map[string]string{ | ||
"Content-Type": "application/json", | ||
"x-log-bodyrawsize": fmt.Sprintf("%v", len(body)), | ||
} | ||
uri := "/storeviews/" + storeView.Name | ||
r, err := c.request(project, "PUT", uri, h, body) | ||
if err != nil { | ||
return err | ||
} | ||
r.Body.Close() | ||
return nil | ||
} | ||
|
||
func (c *Client) DeleteStoreView(project string, storeViewName string) error { | ||
h := map[string]string{ | ||
"Content-Type": "application/json", | ||
"x-log-bodyrawsize": "0", | ||
} | ||
uri := "/storeviews/" + storeViewName | ||
r, err := c.request(project, "DELETE", uri, h, nil) | ||
if err != nil { | ||
return err | ||
} | ||
r.Body.Close() | ||
return nil | ||
} | ||
|
||
func (c *Client) GetStoreView(project string, storeViewName string) (*StoreView, error) { | ||
h := map[string]string{ | ||
"Content-Type": "application/json", | ||
"x-log-bodyrawsize": "0", | ||
} | ||
uri := "/storeviews/" + storeViewName | ||
r, err := c.request(project, "GET", uri, h, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer r.Body.Close() | ||
buf, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := &StoreView{} | ||
if err = json.Unmarshal(buf, res); err != nil { | ||
return nil, NewClientError(err) | ||
} | ||
res.Name = storeViewName | ||
return res, nil | ||
} | ||
|
||
func (c *Client) ListStoreViews(project string, req *ListStoreViewsRequest) (*ListStoreViewsResponse, error) { | ||
h := map[string]string{ | ||
"Content-Type": "application/json", | ||
"x-log-bodyrawsize": "0", | ||
} | ||
uri := fmt.Sprintf("/storeviews?offset=%d&line=%d", req.Offset, req.Size) | ||
r, err := c.request(project, "GET", uri, h, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer r.Body.Close() | ||
buf, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := &ListStoreViewsResponse{} | ||
if err = json.Unmarshal(buf, res); err != nil { | ||
return nil, NewClientError(err) | ||
} | ||
return res, nil | ||
} | ||
|
||
func (c *Client) GetStoreViewIndex(project string, storeViewName string) (*GetStoreViewIndexResponse, error) { | ||
h := map[string]string{ | ||
"Content-Type": "application/json", | ||
"x-log-bodyrawsize": "0", | ||
} | ||
uri := fmt.Sprintf("/storeviews/%s/index", storeViewName) | ||
r, err := c.request(project, "GET", uri, h, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer r.Body.Close() | ||
buf, err := ioutil.ReadAll(r.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res := &GetStoreViewIndexResponse{} | ||
if err = json.Unmarshal(buf, res); err != nil { | ||
return nil, NewClientError(err) | ||
} | ||
return res, nil | ||
} |
Oops, something went wrong.