Further consolidate the libraries
This commit is contained in:
		
							
								
								
									
										32
									
								
								proxy/router/http/options.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								proxy/router/http/options.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| package http | ||||
|  | ||||
| import ( | ||||
| 	"github.com/micro/go-micro" | ||||
| 	"github.com/micro/go-micro/server" | ||||
| ) | ||||
|  | ||||
| // WithBackend provides an option to set the http backend url | ||||
| func WithBackend(url string) micro.Option { | ||||
| 	return func(o *micro.Options) { | ||||
| 		// get the router | ||||
| 		r := o.Server.Options().Router | ||||
|  | ||||
| 		// not set | ||||
| 		if r == nil { | ||||
| 			r = DefaultRouter | ||||
| 			o.Server.Init(server.WithRouter(r)) | ||||
| 		} | ||||
|  | ||||
| 		// check its a http router | ||||
| 		if httpRouter, ok := r.(*Router); ok { | ||||
| 			httpRouter.Backend = url | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // WithRouter provides an option to set the http router | ||||
| func WithRouter(r server.Router) micro.Option { | ||||
| 	return func(o *micro.Options) { | ||||
| 		o.Server.Init(server.WithRouter(r)) | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user