Skip to content

Add RouterNode.Path()#193

Merged
devfeel merged 3 commits intomasterfrom
develop
Feb 13, 2019
Merged

Add RouterNode.Path()#193
devfeel merged 3 commits intomasterfrom
develop

Conversation

@devfeel
Copy link
Owner

@devfeel devfeel commented Feb 12, 2019

  • New Feature: RouterNode add RouterNode.Path() to get routing path for the request
  • Detail:
    • you can use ctx.RouterNode().Path() to get routing path for the request
    • you can use ctx.HttpServer().Router().MatchPath to match request and routing path
  • Demo:
    func main() {
    	app := dotweb.Classic("/home/logs/wwwroot/")
    
      // if use this, all router will auto add "HEAD" method support
      // default is false
      app.HttpServer.SetEnabledAutoHEAD(true)
    
    	app.HttpServer.GET("/index", func(ctx dotweb.Context) error{
    	    flag := ctx.HttpServer().Router().MatchPath(ctx, "/index")
    		return ctx.WriteString("welcome to my first web!" + ctx.RouterNode().Path() + " - " + fmt.Sprint(flag))
    	})
    
    	err := app.StartServer(80)
        fmt.Println("dotweb.StartServer error => ", err)
    }
  • 2019-02-12 16:00

* New Feature: RouterNode add RouterNode.Path() to get routing path for the request
* Detail:
    - you can use ctx.RouterNode().Path() to get routing path for the request
    - you can use ctx.HttpServer().Router().MatchPath to match request and routing path
* Demo:
  ~~~go
  func main() {
  	app := dotweb.Classic("/home/logs/wwwroot/")

    // if use this, all router will auto add "HEAD" method support
    // default is false
    app.HttpServer.SetEnabledAutoHEAD(true)

  	app.HttpServer.GET("/index", func(ctx dotweb.Context) error{
  	    flag := ctx.HttpServer().Router().MatchPath(ctx, "/index")
  		return ctx.WriteString("welcome to my first web!" + ctx.RouterNode().Path() + " - " + fmt.Sprint(flag))
  	})

  	err := app.StartServer(80)
      fmt.Println("dotweb.StartServer error => ", err)
  }
  ~~~
* 2019-02-12 16:00
* New Feature: RouterNode add RouterNode.Path() to get routing path for the request
* Detail:
    - you can use ctx.RouterNode().Path() to get routing path for the request
    - you can use ctx.HttpServer().Router().MatchPath to match request and routing path
* Demo:
  ~~~go
  func main() {
  	app := dotweb.Classic("/home/logs/wwwroot/")

    // if use this, all router will auto add "HEAD" method support
    // default is false
    app.HttpServer.SetEnabledAutoHEAD(true)

  	app.HttpServer.GET("/index", func(ctx dotweb.Context) error{
  	    flag := ctx.HttpServer().Router().MatchPath(ctx, "/index")
  		return ctx.WriteString("welcome to my first web!" + ctx.RouterNode().Path() + " - " + fmt.Sprint(flag))
  	})

  	err := app.StartServer(80)
      fmt.Println("dotweb.StartServer error => ", err)
  }
  ~~~
* 2019-02-12 16:00
* New Feature: RouterNode add RouterNode.Path() to get routing path for the request
* Detail:
    - you can use ctx.RouterNode().Path() to get routing path for the request
    - you can use ctx.HttpServer().Router().MatchPath to match request and routing path
* Demo:
  ~~~go
  func main() {
  	app := dotweb.Classic("/home/logs/wwwroot/")

    // if use this, all router will auto add "HEAD" method support
    // default is false
    app.HttpServer.SetEnabledAutoHEAD(true)

  	app.HttpServer.GET("/index", func(ctx dotweb.Context) error{
  	    flag := ctx.HttpServer().Router().MatchPath(ctx, "/index")
  		return ctx.WriteString("welcome to my first web!" + ctx.RouterNode().Path() + " - " + fmt.Sprint(flag))
  	})

  	err := app.StartServer(80)
      fmt.Println("dotweb.StartServer error => ", err)
  }
  ~~~
* 2019-02-12 16:00
@devfeel devfeel merged commit bdf512d into master Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant