From 855939d995c3e19d000e571a1f1ddfb941ebd415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Wed, 28 Jan 2026 18:41:34 +0200 Subject: [PATCH] working commit --- app/router/router.go | 11 +++++++++++ app/service/path.go | 14 -------------- app/service/service.go | 13 +++++++++++-- cmd/mstorectl/file.go | 1 + 4 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 app/service/path.go diff --git a/app/router/router.go b/app/router/router.go index ca942c5..a446905 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -26,6 +26,10 @@ func NewRouter() *Router { } } +func (rout *Router) Selector() *Selector { + return rout.routeHandler +} + func (rout *Router) AddRoute(method, path string, handlerFunc HandlerFunc) { rout.routeHandler.AddRoute(method, path, handlerFunc) } @@ -46,6 +50,10 @@ func (rout *Router) Put(path string, handlerFunc HandlerFunc) { rout.routeHandler.AddRoute("PUT", path, handlerFunc) } +func (rout *Router) Patch(path string, handlerFunc HandlerFunc) { + rout.routeHandler.AddRoute("PATCH", path, handlerFunc) +} + func (rout *Router) Delete(path string, handlerFunc HandlerFunc) { rout.routeHandler.AddRoute("DELETE", path, handlerFunc) } @@ -78,6 +86,7 @@ const globalRoutePattern = `^%s$` func (hand *Selector) AddRoute(method, path string, handlerFunc HandlerFunc) error { var err error + rawPath := path path, err = pathCompiler(path) if err != nil { return err @@ -92,6 +101,7 @@ func (hand *Selector) AddRoute(method, path string, handlerFunc HandlerFunc) err route := &Route{ Method: method, Path: path, + RawPath: rawPath, Handler: handlerFunc, Regexp: re, } @@ -124,6 +134,7 @@ type Route struct { Method string Regexp *regexp.Regexp Path string + RawPath string Handler HandlerFunc } diff --git a/app/service/path.go b/app/service/path.go deleted file mode 100644 index f7966f7..0000000 --- a/app/service/path.go +++ /dev/null @@ -1,14 +0,0 @@ -package service - -import ( - "fmt" -) - -var ( - filepathRegexp = `{path:[a-zA-Z_][\-a-zA-Z0-9_\/\.%~]+}` - fileApiPrefix = `/v3/file` - - FileExistsPath = fmt.Sprintf("%s/%s", fileApiPrefix, filepathRegexp) - - ServiceHelloPath = "/service/hello" -) diff --git a/app/service/service.go b/app/service/service.go index 0b9bc5d..4196d2f 100644 --- a/app/service/service.go +++ b/app/service/service.go @@ -43,8 +43,17 @@ func (svc *Service) Build() error { svc.logg.Infof("Service build ") svc.rout = router.NewRouter() - svc.rout.Get(ServiceHelloPath, svc.hand.SendHello) - svc.rout.Get(FileExistsPath, svc.hand.FileExists) + svc.rout.Get("/v3/api/service/hello", svc.hand.SendHello) + + svc.rout.Head("/v3/api/file/{filepath}", svc.hand.FileExists) + svc.rout.Put("/v3/api/file/{filepath}", svc.hand.PutFile) + svc.rout.Get("/v3/api/file/{filepath}", svc.hand.GetFile) + svc.rout.Delete("/v3/api/file/{filepath}", svc.hand.DeleteFile) + + selector := svc.rout.Selector() + for _, item := range selector.Routes { + svc.logg.Infof("%s\t%s", item.Method, item.RawPath) + } listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum) svc.listen, err = net.Listen(protocol, listenAddress) diff --git a/cmd/mstorectl/file.go b/cmd/mstorectl/file.go index 728f2e6..987cb2e 100644 --- a/cmd/mstorectl/file.go +++ b/cmd/mstorectl/file.go @@ -51,6 +51,7 @@ type FileExistsParams struct { } func (util *Util) FileExists(cmd *cobra.Command, args []string) { + } // Put file