working commit
This commit is contained in:
@@ -17,3 +17,45 @@ func (hand *Handler) FileExists(rctx *router.Context) {
|
||||
code, _, _ := hand.oper.FileExists(params)
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
|
||||
func (hand *Handler) PutFile(rctx *router.Context) {
|
||||
hand.logg.Debugf("handle PutFile")
|
||||
|
||||
filepath := rctx.PathMap["filepath"]
|
||||
params := &operator.PutFileParams{
|
||||
Filepath: filepath,
|
||||
Source: rctx.Request.Body,
|
||||
}
|
||||
hand.logg.Debugf("filepath: %s", filepath)
|
||||
|
||||
code, _, _ := hand.oper.PutFile(params)
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
|
||||
func (hand *Handler) GetFile(rctx *router.Context) {
|
||||
hand.logg.Debugf("handle GetFile")
|
||||
|
||||
filepath := rctx.PathMap["filepath"]
|
||||
params := &operator.GetFileParams{
|
||||
Filepath: filepath,
|
||||
}
|
||||
hand.logg.Debugf("filepath: %s", filepath)
|
||||
|
||||
code, res, _ := hand.oper.GetFile(params)
|
||||
rctx.SetHeader("Content-Type", res.ContentType)
|
||||
rctx.SetHeader("Content-Length", res.ContentLength)
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
|
||||
func (hand *Handler) DeleteFile(rctx *router.Context) {
|
||||
hand.logg.Debugf("handle DeleteFile")
|
||||
|
||||
filepath := rctx.PathMap["filepath"]
|
||||
params := &operator.DeleteFileParams{
|
||||
Filepath: filepath,
|
||||
}
|
||||
hand.logg.Debugf("filepath: %s", filepath)
|
||||
|
||||
code, _, _ := hand.oper.DeleteFile(params)
|
||||
rctx.SetStatus(code)
|
||||
}
|
||||
|
||||
@@ -22,8 +22,10 @@ func (oper *Operator) FileExists(param *FileExistsParams) (int, *FileExistsResul
|
||||
|
||||
// Put file
|
||||
type PutFileParams struct {
|
||||
ContentType string
|
||||
ContentLength string
|
||||
Filepath string
|
||||
Source string
|
||||
Source io.ReadCloser
|
||||
}
|
||||
type PutFileResult struct{}
|
||||
|
||||
@@ -37,9 +39,12 @@ func (oper *Operator) PutFile(param *PutFileParams) (int, *PutFileResult, error)
|
||||
// Get file
|
||||
type GetFileParams struct {
|
||||
Filepath string
|
||||
Dest io.Writer
|
||||
}
|
||||
type GetFileResult struct{}
|
||||
type GetFileResult struct {
|
||||
ContentType string
|
||||
ContentLength string
|
||||
Source io.ReadCloser
|
||||
}
|
||||
|
||||
func (oper *Operator) GetFile(param *GetFileParams) (int, *GetFileResult, error) {
|
||||
var err error
|
||||
|
||||
@@ -24,6 +24,10 @@ func NewContext(writer http.ResponseWriter, request *http.Request) *Context {
|
||||
return rctx
|
||||
}
|
||||
|
||||
func (rctx *Context) SetHeader(key, value string) {
|
||||
rctx.Writer.Header().Set(key, value)
|
||||
}
|
||||
|
||||
func (rctx *Context) SetStatus(httpStatus int) {
|
||||
rctx.Writer.WriteHeader(httpStatus)
|
||||
}
|
||||
@@ -37,3 +41,7 @@ func (rctx *Context) SendText(payload string) {
|
||||
rctx.Writer.Header().Set("Content-Type", "text/plain")
|
||||
rctx.Writer.Write([]byte(payload))
|
||||
}
|
||||
|
||||
func (rctx *Context) GetHeader(key string) string {
|
||||
return rctx.Request.URL.Query().Get(key)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package client
|
||||
|
||||
type Client struct {
|
||||
}
|
||||
|
||||
func (cli *Client) FileExists(path string) (bool, error) {
|
||||
//reqPath = fmt.Sprintf("/v3/api/file/%s", path)
|
||||
//request, err := http.NewRequest("HEAD", reqPath, nil)
|
||||
}
|
||||
+3
-2
@@ -10,6 +10,7 @@ import (
|
||||
"mstore/app/router"
|
||||
"mstore/app/server"
|
||||
"mstore/app/service"
|
||||
//"mstore/pkg/client"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -25,8 +26,8 @@ func TestFileExists(t *testing.T) {
|
||||
err = srv.Build()
|
||||
require.NoError(t, err)
|
||||
|
||||
reqPath := "/api/v3/file/foo/bare/abc123"
|
||||
routePath := `/api/v3/file/{filepath}`
|
||||
reqPath := `/v3/api/file/foo/bare`
|
||||
routePath := `/v3/api/file/{filepath}`
|
||||
|
||||
rout := router.NewRouter()
|
||||
hand := srv.Handler()
|
||||
|
||||
Reference in New Issue
Block a user