update call Hooks && linter
This commit is contained in:
		| @@ -172,7 +172,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error) | |||||||
| 						hdlr := shdlr.(*httpHandler) | 						hdlr := shdlr.(*httpHandler) | ||||||
| 						fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod) | 						fh, mp, err := hdlr.handlers.Search(http.MethodPost, "/"+microMethod) | ||||||
| 						if err == nil { | 						if err == nil { | ||||||
| 							match = true | 							// match = true | ||||||
| 							for k, v := range mp { | 							for k, v := range mp { | ||||||
| 								matches[k] = v | 								matches[k] = v | ||||||
| 							} | 							} | ||||||
| @@ -278,7 +278,7 @@ func (h *Server) HTTPHandlerFunc(handler interface{}) (http.HandlerFunc, error) | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// wrap the handler func | 		// wrap the handler func | ||||||
| 		h.opts.Hooks.EachNext(func(hook options.Hook) { | 		h.opts.Hooks.EachPrev(func(hook options.Hook) { | ||||||
| 			if h, ok := hook.(server.HookHandler); ok { | 			if h, ok := hook.(server.HookHandler); ok { | ||||||
| 				fn = h(fn) | 				fn = h(fn) | ||||||
| 			} | 			} | ||||||
| @@ -646,7 +646,7 @@ func (h *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	h.opts.Hooks.EachNext(func(hook options.Hook) { | 	h.opts.Hooks.EachPrev(func(hook options.Hook) { | ||||||
| 		if h, ok := hook.(server.HookHandler); ok { | 		if h, ok := hook.(server.HookHandler); ok { | ||||||
| 			fn = h(fn) | 			fn = h(fn) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -1,8 +1,6 @@ | |||||||
| package http | package http | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"io" |  | ||||||
|  |  | ||||||
| 	"go.unistack.org/micro/v3/codec" | 	"go.unistack.org/micro/v3/codec" | ||||||
| 	"go.unistack.org/micro/v3/metadata" | 	"go.unistack.org/micro/v3/metadata" | ||||||
| 	"go.unistack.org/micro/v3/server" | 	"go.unistack.org/micro/v3/server" | ||||||
| @@ -14,7 +12,7 @@ var ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type rpcRequest struct { | type rpcRequest struct { | ||||||
| 	rw          io.ReadWriter | 	// rw          io.ReadWriter | ||||||
| 	payload     interface{} | 	payload     interface{} | ||||||
| 	codec       codec.Codec | 	codec       codec.Codec | ||||||
| 	header      metadata.Metadata | 	header      metadata.Metadata | ||||||
|   | |||||||
| @@ -152,7 +152,7 @@ func (s *Server) createSubHandler(sb *httpSubscriber, opts server.Options) broke | |||||||
| 				return nil | 				return nil | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			opts.Hooks.EachNext(func(hook options.Hook) { | 			opts.Hooks.EachPrev(func(hook options.Hook) { | ||||||
| 				if h, ok := hook.(server.HookSubHandler); ok { | 				if h, ok := hook.(server.HookSubHandler); ok { | ||||||
| 					fn = h(fn) | 					fn = h(fn) | ||||||
| 				} | 				} | ||||||
|   | |||||||
							
								
								
									
										41
									
								
								util_test.go
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								util_test.go
									
									
									
									
									
								
							| @@ -3,9 +3,6 @@ package http | |||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" |  | ||||||
| 	"go.unistack.org/micro/v3/options" |  | ||||||
| 	"go.unistack.org/micro/v3/server" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
| @@ -101,41 +98,3 @@ func TestFillrequest(t *testing.T) { | |||||||
| 		t.Fatalf("FillRequest error: %#+v", req) | 		t.Fatalf("FillRequest error: %#+v", req) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func Test_Hook(t *testing.T) { |  | ||||||
| 	opts := server.Options{} |  | ||||||
|  |  | ||||||
| 	var fn server.HandlerFunc = func(fctx context.Context, req server.Request, rsp interface{}) (err error) { |  | ||||||
| 		fmt.Println("1") |  | ||||||
| 		return nil |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	var fn2 server.HandlerWrapper = func(server.HandlerFunc) server.HandlerFunc { |  | ||||||
| 		return func(ctx context.Context, req server.Request, rsp interface{}) error { |  | ||||||
| 			fmt.Println("2") |  | ||||||
| 			return nil |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	var fn3 server.HandlerWrapper = func(server.HandlerFunc) server.HandlerFunc { |  | ||||||
| 		return func(ctx context.Context, req server.Request, rsp interface{}) error { |  | ||||||
| 			fmt.Println("3") |  | ||||||
| 			return nil |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	var fn4 server.HandlerWrapper = func(server.HandlerFunc) server.HandlerFunc { |  | ||||||
| 		return func(ctx context.Context, req server.Request, rsp interface{}) error { |  | ||||||
| 			fmt.Println("4") |  | ||||||
| 			return nil |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	opts.Hooks = append(opts.Hooks, fn2, fn3, fn4) |  | ||||||
|  |  | ||||||
| 	opts.Hooks.EachNext(func(hook options.Hook) { |  | ||||||
| 		if h, ok := hook.(server.HandlerWrapper); ok { |  | ||||||
| 			fn = h(fn) |  | ||||||
| 		} |  | ||||||
| 	}) |  | ||||||
|  |  | ||||||
| 	fn(nil, nil, nil) |  | ||||||
| } |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user