Skip to content

Commit 8720761

Browse files
committed
add Mux#AbsPath to return the current SubMux path starting from root
1 parent 920ec04 commit 8720761

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div align="center">
1616
<!-- Release -->
1717
<a href="https://github.com/kataras/muxie/releases">
18-
<img src="https://img.shields.io/badge/release%20-v1.0.5-0077b3.svg?style=flat-squaree"
18+
<img src="https://img.shields.io/badge/release%20-v1.0.6-0077b3.svg?style=flat-squaree"
1919
alt="Release/stability" />
2020
</a>
2121
<!-- Godocs -->

_examples/10_fileserver/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
7+
"github.com/kataras/muxie"
8+
)
9+
10+
func main() {
11+
mux := muxie.NewMux()
12+
mux.Handle("/static/*file", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
13+
14+
log.Println("Server started at http://localhost:8080\nGET: http://localhost:8080/static/\nGET: http://localhost:8080/static/js/empty.js")
15+
http.ListenAndServe(":8080", mux)
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
body {
2+
background-color: black;
3+
}
4+
5+
h1 {
6+
color: white;
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html><head><link rel="stylesheet" href="./css/main.css"><title>Index</title></head>
2+
<body>
3+
<h1>Hello index</h1>
4+
</body>
5+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* empty js file */

mux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ type SubMux interface {
211211
Use(middlewares ...Wrapper)
212212
Handle(pattern string, handler http.Handler)
213213
HandleFunc(pattern string, handlerFunc func(http.ResponseWriter, *http.Request))
214+
AbsPath() string
214215
}
215216

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

253+
// AbsPath returns the absolute path of the router for this Mux group.
254+
func (m *Mux) AbsPath() string {
255+
if m.root == "" {
256+
return "/"
257+
}
258+
return m.root
259+
}
260+
252261
/* Notes:
253262
254263
Four options to solve optionally "inherition" of parent's middlewares but dismissed:

0 commit comments

Comments
 (0)