working commit

This commit is contained in:
2026-01-23 19:26:56 +02:00
parent 772657d9be
commit d704a76bee
10 changed files with 161 additions and 76 deletions
+8 -3
View File
@@ -8,7 +8,12 @@ import (
func (hand *Handler) FileExists(rctx *router.Context) {
hand.logg.Debugf("handle FileExists")
params := &operator.FileExistsParams{}
res, _ := hand.oper.FileExists(params)
rctx.SetStatus(res.Code)
filepath := rctx.PathMap["filepath"]
params := &operator.FileExistsParams{
Filepath: filepath,
}
hand.logg.Debugf("filepath: %s", filepath)
code, _, _ := hand.oper.FileExists(params)
rctx.SetStatus(code)
}
+52 -9
View File
@@ -1,19 +1,62 @@
package operator
import (
"io"
"net/http"
)
type FileExistsParams struct{}
type FileExistsResult struct {
Code int
// File exists
type FileExistsParams struct {
Filepath string
Source string
Dest string
}
type FileExistsResult struct{}
func (oper *Operator) FileExists(param *FileExistsParams) (*FileExistsResult, error) {
func (oper *Operator) FileExists(param *FileExistsParams) (int, *FileExistsResult, error) {
var err error
res := &FileExistsResult{
Code: http.StatusOK,
}
return res, err
res := &FileExistsResult{}
code := http.StatusOK
return code, res, err
}
// Put file
type PutFileParams struct {
Filepath string
Source string
}
type PutFileResult struct{}
func (oper *Operator) PutFile(param *PutFileParams) (int, *PutFileResult, error) {
var err error
res := &PutFileResult{}
code := http.StatusOK
return code, res, err
}
// Get file
type GetFileParams struct {
Filepath string
Dest io.Writer
}
type GetFileResult struct{}
func (oper *Operator) GetFile(param *GetFileParams) (int, *GetFileResult, error) {
var err error
res := &GetFileResult{}
code := http.StatusOK
return code, res, err
}
// Delete file
type DeleteFileParams struct {
Filepath string
}
type DeleteFileResult struct{}
func (oper *Operator) DeleteFile(param *DeleteFileParams) (int, *DeleteFileResult, error) {
var err error
res := &DeleteFileResult{}
code := http.StatusOK
return code, res, err
}
+1 -1
View File
@@ -56,7 +56,7 @@ func pathCompiler(path string) (string, error) {
}
const (
defaultRegexp = `[a-zA-Z0-9_][\-\.a-zA-Z0-9_%%=:~]+`
defaultRegexp = `[a-zA-Z0-9_][/\-\.a-zA-Z0-9_%%=:~]+`
)
func convertRegexp(src []byte) []byte {
+8
View File
@@ -30,6 +30,10 @@ func (rout *Router) AddRoute(method, path string, handlerFunc HandlerFunc) {
rout.routeHandler.AddRoute(method, path, handlerFunc)
}
func (rout *Router) Head(path string, handlerFunc HandlerFunc) {
rout.routeHandler.AddRoute("HEAD", path, handlerFunc)
}
func (rout *Router) Get(path string, handlerFunc HandlerFunc) {
rout.routeHandler.AddRoute("GET", path, handlerFunc)
}
@@ -38,6 +42,10 @@ func (rout *Router) Post(path string, handlerFunc HandlerFunc) {
rout.routeHandler.AddRoute("POST", path, handlerFunc)
}
func (rout *Router) Put(path string, handlerFunc HandlerFunc) {
rout.routeHandler.AddRoute("PUT", path, handlerFunc)
}
func (rout *Router) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
rctx := NewContext(writer, req)
rout.routeHandler.ServeHTTP(rctx)
+5 -7
View File
@@ -4,13 +4,11 @@ import (
"fmt"
)
const (
PathServiceHello = "/service/hello"
)
var (
pathRegexp = `{path:[a-zA-Z_][\-a-zA-Z0-9_\/\.%~]+}`
fileOperPrefix = "/v3/file"
filepathRegexp = `{path:[a-zA-Z_][\-a-zA-Z0-9_\/\.%~]+}`
fileApiPrefix = `/v3/file`
PathFileExists = fmt.Sprintf("%s/%s", fileOperPrefix, pathRegexp)
FileExistsPath = fmt.Sprintf("%s/%s", fileApiPrefix, filepathRegexp)
ServiceHelloPath = "/service/hello"
)
+2 -2
View File
@@ -43,8 +43,8 @@ func (svc *Service) Build() error {
svc.logg.Infof("Service build ")
svc.rout = router.NewRouter()
svc.rout.Get(PathServiceHello, svc.hand.SendHello)
svc.rout.Get(PathFileExists, svc.hand.FileExists)
svc.rout.Get(ServiceHelloPath, svc.hand.SendHello)
svc.rout.Get(FileExistsPath, svc.hand.FileExists)
listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum)
svc.listen, err = net.Listen(protocol, listenAddress)