Skip to content

Commit

Permalink
add Mux#AbsPath to return the current SubMux path starting from root
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Nov 15, 2018
1 parent 920ec04 commit 8720761
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div align="center">
<!-- Release -->
<a href="https://github.com/kataras/muxie/releases">
<img src="https://img.shields.io/badge/release%20-v1.0.5-0077b3.svg?style=flat-squaree"
<img src="https://img.shields.io/badge/release%20-v1.0.6-0077b3.svg?style=flat-squaree"
alt="Release/stability" />
</a>
<!-- Godocs -->
Expand Down
16 changes: 16 additions & 0 deletions _examples/10_fileserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"log"
"net/http"

"github.com/kataras/muxie"
)

func main() {
mux := muxie.NewMux()
mux.Handle("/static/*file", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))

log.Println("Server started at http://localhost:8080\nGET: http://localhost:8080/static/\nGET: http://localhost:8080/static/js/empty.js")
http.ListenAndServe(":8080", mux)
}
7 changes: 7 additions & 0 deletions _examples/10_fileserver/static/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
background-color: black;
}

h1 {
color: white;
}
5 changes: 5 additions & 0 deletions _examples/10_fileserver/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html><head><link rel="stylesheet" href="./css/main.css"><title>Index</title></head>
<body>
<h1>Hello index</h1>
</body>
</html>
1 change: 1 addition & 0 deletions _examples/10_fileserver/static/js/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty js file */
9 changes: 9 additions & 0 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ type SubMux interface {
Use(middlewares ...Wrapper)
Handle(pattern string, handler http.Handler)
HandleFunc(pattern string, handlerFunc func(http.ResponseWriter, *http.Request))
AbsPath() string
}

// Of returns a new Mux which its Handle and HandleFunc will register the path based on given "prefix", i.e:
Expand Down Expand Up @@ -249,6 +250,14 @@ func (m *Mux) Of(prefix string) SubMux {
}
}

// AbsPath returns the absolute path of the router for this Mux group.
func (m *Mux) AbsPath() string {
if m.root == "" {
return "/"
}
return m.root
}

/* Notes:
Four options to solve optionally "inherition" of parent's middlewares but dismissed:
Expand Down

0 comments on commit 8720761

Please sign in to comment.