LoginSignup
0

More than 5 years have passed since last update.

【Go】RevelのControllerからURLを取得する

Posted at

routes.Controller.Method(aregs...) とすることでアクセスパスを取得できる。
AccountsController内のMeのURLが知りたい場合は以下のように取得できる。

func (c Accounts) Me() revel.Result {
    fmt.Println(routes.Accounts.Me()) // /api/accounts/login
    ...
    return c.Render()
}

内部的には route.go が自動生成され、 revel.MainRouter.Reverse が叩かれているので、直接これを使用することでもURLを取得できそう

route.go
func (_ tAccounts) Login() string {
    return revel.MainRouter.Reverse("Accounts.Login", args).URL
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0