-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #417 from fabiolb/issue-396-consul-kvpath-prefix
Issue #396: treat registry.consul.kvpath as prefix
- Loading branch information
Showing
13 changed files
with
286 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package api | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/fabiolb/fabio/registry" | ||
) | ||
|
||
type ManualPathsHandler struct { | ||
Prefix string | ||
} | ||
|
||
func (h *ManualPathsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
// we need this for testing. | ||
// under normal circumstances this is never nil | ||
if registry.Default == nil { | ||
return | ||
} | ||
|
||
switch r.Method { | ||
case "GET": | ||
paths, err := registry.Default.ManualPaths() | ||
if err != nil { | ||
log.Print("[ERROR] ", err) | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
for i, p := range paths { | ||
paths[i] = strings.TrimPrefix(p, h.Prefix) | ||
} | ||
writeJSON(w, r, paths) | ||
return | ||
|
||
default: | ||
http.Error(w, "not allowed", http.StatusMethodNotAllowed) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.