mirror of
https://github.com/kataras/iris.git
synced 2026-01-23 03:45:56 +00:00
gofmt -s -w .
Former-commit-id: 6cca675303187f10377a7a713b2e7b3cdf16fd18
This commit is contained in:
@@ -18,7 +18,7 @@ func TestProxy(t *testing.T) {
|
||||
unexpectedRoute := "unexpected"
|
||||
|
||||
// proxySrv := iris.New()
|
||||
u, err := url.Parse("https://localhost")
|
||||
u, err := url.Parse("https://localhost:4444")
|
||||
if err != nil {
|
||||
t.Fatalf("%v while parsing url", err)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func TestProxy(t *testing.T) {
|
||||
// proxySrv.Downgrade(p.ServeHTTP)
|
||||
// go proxySrv.Run(iris.Addr(":80"), iris.WithoutBanner, iris.WithoutInterruptHandler)
|
||||
|
||||
go host.NewProxy(":80", u).ListenAndServe()
|
||||
go host.NewProxy(":1193", u).ListenAndServe() // should be localhost/127.0.0.1:80 but travis throws permission denied.
|
||||
|
||||
app := iris.New()
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
@@ -46,14 +46,14 @@ func TestProxy(t *testing.T) {
|
||||
ctx.WriteString(unexpectedRoute)
|
||||
})
|
||||
|
||||
l, err := net.Listen("tcp", "localhost:443")
|
||||
l, err := net.Listen("tcp", "localhost:4444") // should be localhost/127.0.0.1:443 but travis throws permission denied.
|
||||
if err != nil {
|
||||
t.Fatalf("%v while creating tcp4 listener for new tls local test listener", err)
|
||||
}
|
||||
// main server
|
||||
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutBanner)
|
||||
|
||||
e := httptest.NewInsecure(t, httptest.URL("http://localhost"))
|
||||
e := httptest.NewInsecure(t, httptest.URL("http://localhost:1193"))
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedIndex)
|
||||
e.GET("/about").Expect().Status(iris.StatusOK).Body().Equal(expectedAbout)
|
||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().Equal(unexpectedRoute)
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestMuttable(t *testing.T) {
|
||||
|
||||
// map
|
||||
|
||||
p.Set("map", map[string]myTestObject{"key 1": myTestObject{"value 1"}, "key 2": myTestObject{"value 2"}})
|
||||
p.Set("map", map[string]myTestObject{"key 1": {"value 1"}, "key 2": {"value 2"}})
|
||||
vMap := p.Get("map").(map[string]myTestObject)
|
||||
vMap["key 1"] = myTestObject{"modified"}
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestImmutable(t *testing.T) {
|
||||
}
|
||||
|
||||
// map
|
||||
p.SetImmutable("map", map[string]myTestObject{"key 1": myTestObject{"value 1"}, "key 2": myTestObject{"value 2"}})
|
||||
p.SetImmutable("map", map[string]myTestObject{"key 1": {"value 1"}, "key 2": {"value 2"}})
|
||||
vMap := p.Get("map").(map[string]myTestObject)
|
||||
vMap["key 1"] = myTestObject{"modified"}
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ func (r *repository) getAll() []*Route {
|
||||
return r.routes
|
||||
}
|
||||
|
||||
// RoutesProvider should be implemented by
|
||||
// iteral which contains the registered routes.
|
||||
type RoutesProvider interface { // api builder
|
||||
GetRoutes() []*Route
|
||||
GetRoute(routeName string) *Route
|
||||
@@ -177,6 +179,8 @@ func (rb *APIBuilder) Party(relativePath string, handlers ...context.Handler) Pa
|
||||
}
|
||||
}
|
||||
|
||||
// Macros returns the macro map which is responsible
|
||||
// to register custom macro functions for all routes.
|
||||
func (rb *APIBuilder) Macros() *macro.MacroMap {
|
||||
return rb.macros
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ func (h *routerHandler) addRoute(method, subdomain, path string, handlers contex
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewDefaultHandler returns the handler which is responsible
|
||||
// to map the request with a route (aka mux implementation).
|
||||
func NewDefaultHandler() RequestHandler {
|
||||
h := &routerHandler{}
|
||||
return h
|
||||
|
||||
@@ -588,7 +588,7 @@ func TypeByExtension(ext string) (typ string) {
|
||||
return typ
|
||||
}
|
||||
|
||||
// TypeByFilename, saem as TypeByExtension
|
||||
// TypeByFilename same as TypeByExtension
|
||||
// but receives a filename path instead.
|
||||
func TypeByFilename(fullFilename string) string {
|
||||
ext := filepath.Ext(fullFilename)
|
||||
|
||||
@@ -12,6 +12,9 @@ import (
|
||||
"github.com/kataras/iris/core/router/macro"
|
||||
)
|
||||
|
||||
// Route contains the information about a registered Route.
|
||||
// If any of the following fields are changed then the
|
||||
// caller should Refresh the router.
|
||||
type Route struct {
|
||||
Name string // "userRoute"
|
||||
Method string // "GET"
|
||||
@@ -24,6 +27,11 @@ type Route struct {
|
||||
FormattedPath string
|
||||
}
|
||||
|
||||
// NewRoute returns a new route based on its method,
|
||||
// subdomain, the path (unparsed or original),
|
||||
// handlers and the macro container which all routes should share.
|
||||
// It parses the path based on the "macros",
|
||||
// handlers are being changed to validate the macros at serve time, if needed.
|
||||
func NewRoute(method, subdomain, unparsedPath string,
|
||||
handlers context.Handlers, macros *macro.MacroMap) (*Route, error) {
|
||||
|
||||
|
||||
@@ -12,6 +12,12 @@ import (
|
||||
"github.com/kataras/iris/core/errors"
|
||||
)
|
||||
|
||||
// Router is the "director".
|
||||
// Caller should provide a request handler (router implementation or root handler).
|
||||
// Router is responsible to build the received request handler and run it
|
||||
// to serve requests, based on the received context.Pool.
|
||||
//
|
||||
// User can refresh the router with `RefreshRouter` whenever a route's field is changed by him.
|
||||
type Router struct {
|
||||
mu sync.Mutex // for Downgrade, WrapRouter & BuildRouter,
|
||||
// not indeed but we don't to risk its usage by third-parties.
|
||||
|
||||
Reference in New Issue
Block a user