Created
November 23, 2015 17:44
-
-
Save d-smith/a6b68dbfc498f03160f9 to your computer and use it in GitHub Desktop.
multiroute code - prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Package multiroute defines an interface needed for plugins that support routes with multiple backends. | |
| package plugin | |
| import ( | |
| "net/http" | |
| "errors" | |
| ) | |
| type MultiRouteHandler struct { | |
| backendMap map[string]http.Handler | |
| } | |
| func NewMultiRouteHandler() *MultiRouteHandler { | |
| return &MultiRouteHandler{} | |
| } | |
| func (m *MultiRouteHandler) GetHandlerForBackend(backendName string) (http.Handler,error) { | |
| handler, ok := m.backendMap[backendName] | |
| if !ok { | |
| return errors.New("No handler for backend " + backendName) | |
| } | |
| return handler | |
| } | |
| func (m *MultiRouteHandler) AddHandlerForBackend(backendName string, handler http.Handler) { | |
| m.backendMap[backendName] = handler | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment