working commit
This commit is contained in:
@@ -26,6 +26,10 @@ func NewRouter() *Router {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rout *Router) Selector() *Selector {
|
||||||
|
return rout.routeHandler
|
||||||
|
}
|
||||||
|
|
||||||
func (rout *Router) AddRoute(method, path string, handlerFunc HandlerFunc) {
|
func (rout *Router) AddRoute(method, path string, handlerFunc HandlerFunc) {
|
||||||
rout.routeHandler.AddRoute(method, path, 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)
|
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) {
|
func (rout *Router) Delete(path string, handlerFunc HandlerFunc) {
|
||||||
rout.routeHandler.AddRoute("DELETE", path, handlerFunc)
|
rout.routeHandler.AddRoute("DELETE", path, handlerFunc)
|
||||||
}
|
}
|
||||||
@@ -78,6 +86,7 @@ const globalRoutePattern = `^%s$`
|
|||||||
|
|
||||||
func (hand *Selector) AddRoute(method, path string, handlerFunc HandlerFunc) error {
|
func (hand *Selector) AddRoute(method, path string, handlerFunc HandlerFunc) error {
|
||||||
var err error
|
var err error
|
||||||
|
rawPath := path
|
||||||
path, err = pathCompiler(path)
|
path, err = pathCompiler(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -92,6 +101,7 @@ func (hand *Selector) AddRoute(method, path string, handlerFunc HandlerFunc) err
|
|||||||
route := &Route{
|
route := &Route{
|
||||||
Method: method,
|
Method: method,
|
||||||
Path: path,
|
Path: path,
|
||||||
|
RawPath: rawPath,
|
||||||
Handler: handlerFunc,
|
Handler: handlerFunc,
|
||||||
Regexp: re,
|
Regexp: re,
|
||||||
}
|
}
|
||||||
@@ -124,6 +134,7 @@ type Route struct {
|
|||||||
Method string
|
Method string
|
||||||
Regexp *regexp.Regexp
|
Regexp *regexp.Regexp
|
||||||
Path string
|
Path string
|
||||||
|
RawPath string
|
||||||
Handler HandlerFunc
|
Handler HandlerFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
|
||||||
)
|
|
||||||
+11
-2
@@ -43,8 +43,17 @@ func (svc *Service) Build() error {
|
|||||||
svc.logg.Infof("Service build ")
|
svc.logg.Infof("Service build ")
|
||||||
|
|
||||||
svc.rout = router.NewRouter()
|
svc.rout = router.NewRouter()
|
||||||
svc.rout.Get(ServiceHelloPath, svc.hand.SendHello)
|
svc.rout.Get("/v3/api/service/hello", svc.hand.SendHello)
|
||||||
svc.rout.Get(FileExistsPath, svc.hand.FileExists)
|
|
||||||
|
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)
|
listenAddress := fmt.Sprintf("%s:%d", svc.address, svc.portnum)
|
||||||
svc.listen, err = net.Listen(protocol, listenAddress)
|
svc.listen, err = net.Listen(protocol, listenAddress)
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ type FileExistsParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *Util) FileExists(cmd *cobra.Command, args []string) {
|
func (util *Util) FileExists(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put file
|
// Put file
|
||||||
|
|||||||
Reference in New Issue
Block a user