Skip to content

Instantly share code, notes, and snippets.

@JesseObrien
Created May 29, 2013 01:30
Show Gist options
  • Save JesseObrien/5667377 to your computer and use it in GitHub Desktop.
Save JesseObrien/5667377 to your computer and use it in GitHub Desktop.
Revel Hello World app
package controllers
import "github.com/robfig/revel"
type App struct {
*revel.Controller
}
func (c App) Index() revel.Result {
greeting := "Hello woooooorld!"
return c.Render(greeting)
}
func (c App) Hello(myName string) revel.Result {
c.Validation.Required(myName).Message("Your name is required!")
c.Validation.MinSize(myName, 3).Message("Your name is not long enough.")
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
return c.Redirect(App.Index)
}
return c.Render(myName)
}
{{set . "title" "Home"}}
{{template "header.html" .}}
<h1>Hello {{.myName}}</h1>
<a href="/">Back to form</a>
{{template "footer.html" .}}
{{set . "title" "Home"}}
{{template "header.html" .}}
<h1>{{ .greeting }}</h1>
{{range .errors}}
<p class="alert">{{.Message}}</p>
{{end}}
<form action="/App/Hello" method="GET">
<input id="" name="myName" type="text" />
<input type="submit" value="Say Hello!" />
</form>
{{template "footer.html" .}}
@otiai10
Copy link

otiai10 commented Sep 17, 2013

Would you mind telling me how to run this app.go?
I tried

% revel run app.go
% revel run app

both of these failed with following message

ERROR 2013/09/18 03:14:16 revel.go:239: Failed to import app with error: cannot find package "app" in any of:
        /home/hiromu/go/src/pkg/app (from $GOROOT)
        /home/hiromu/go/.packages/src/app (from $GOPATH)

Do I have to set this app in $GOPATH?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment