Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename from Play to Revel -- cant use someone elses name after all. A…

…lso, make the installation procedure go get instead of git clone, despite the much longer paths
  • Loading branch information...
commit caa8b9abf8da2a22a673655f73baa87b9b17b6bc 1 parent 4fb3916
@robfig robfig authored
View
8 .travis.yml
@@ -8,11 +8,11 @@ install:
- mkdir -p $HOME/pkg || true
- export GOPATH=$HOME
- export PATH=$PATH:$HOME/go/bin
- - ln -s $HOME/builds/robfig/go-play $HOME/src/go-play
+ - ln -s $HOME/builds/robfig/revel $HOME/src/github.com/robfig/revel
- go get -v github.com/howeyc/fsnotify
- go get -v github.com/kless/goconfig/config
- - git clone git://github.com/robfig/go-play.git $HOME/src/play
+ - git clone git://github.com/robfig/revel.git $HOME/src/github.com/robfig/revel
script:
- - cd $HOME/src/play && go build -v .
- - cd $HOME/src/play && go test -v .
+ - cd $HOME/src/github.com/robfig/revel && go build -v .
+ - cd $HOME/src/github.com/robfig/revel && go test -v .
View
33 README.md
@@ -1,10 +1,10 @@
-# Go Play!
+# Revel!
This is a port of the amazing [Play! framework](http://www.playframework.org) to the [Go language](http://www.golang.org).
It is a high productivity web framework
-[![Build Status](https://secure.travis-ci.org/robfig/go-play.png?branch=master)](http://travis-ci.org/robfig/go-play)
+[![Build Status](https://secure.travis-ci.org/robfig/revel.png?branch=master)](http://travis-ci.org/robfig/revel)
# Simple Example
@@ -24,17 +24,17 @@ Declare a Controller:
```go
// app/controllers/app.go
package controllers
-import "play"
+import "github.com/robfig/revel"
type Application struct {
- *play.Controller
+ *rev.Controller
}
-func (c Application) Index() play.Result {
+func (c Application) Index() rev.Result {
return c.Render()
}
-func (c Application) ShowApp(id int) play.Result {
+func (c Application) ShowApp(id int) rev.Result {
return c.Render(id)
}
```
@@ -58,7 +58,7 @@ This is an example Controller method that processes a Login request. It demonst
- Setting a cookie
```go
-func (c Login) DoLogin(username, password string) play.Result {
+func (c Login) DoLogin(username, password string) rev.Result {
// Validate parameters.
c.Validation.Required(username).Message("Please enter a username.")
c.Validation.Required(password).Message("Please enter a password.")
@@ -124,9 +124,11 @@ There are also helpers to make validation errors easy to surface in the template
From your GOPATH base:
```
-go get github.com/robfig/go-play
-go build -o /bin/play play/cmd
-./bin/play play/samples/booking
+go get github.com/howeyc/fsnotify \
+ github.com/kless/goconfig/config \
+ github.com/robfig/revel
+go build -o /bin/rev github.com/robfig/revel/cmd
+./bin/rev github.com/robfig/revel/samples/booking
```
# How it works
@@ -195,28 +197,29 @@ There is a large list of things left to do.
- Extract default error messages to resource file
- Examples: Regular web page, JSON return, streaming return, comet, websocket
- Clean up stack traces
-- Allow access to requestwriter and make it easy to get Play out of the way when necessary
+- Allow access to requestwriter and make it easy to get Revel out of the way when necessary
- Make it not hard to do this: https://gist.github.com/2328236
- BigDecimal replacement (for currency / that works with MySQL)
- Fixtures
- How to do moreStyles / moreScripts equivalent.
+- Reflection magic does not work if app code imports revel with a modified identifier.
# File layout
-Go Play! depends on the GOPATH layout prescribed by the go command line tool. A description is at the end.
+Revel depends on the GOPATH layout prescribed by the go command line tool. A description is at the end.
-Note that Play must be installed in the same GOPATH as the user app -- it uses that assumption to find its own source, e.g. for finding templates.
+Note that Revel must be installed in the same GOPATH as the user app -- it uses that assumption to find its own source, e.g. for finding templates.
## Example layout
-Here is the default layout of a Go Play application called `sample`, within a
+Here is the default layout of a Revel application called `sample`, within a
typical Go installation.
```
gocode GOPATH root
src GOPATH src directory
- play Go Play source code
+ revel Revel source code
sample
app App sources
controllers App controllers
View
2  binder.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"reflect"
View
2  binder_test.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"fmt"
View
16 cmd/play.go → cmd/rev.go
@@ -7,8 +7,8 @@ import (
"log"
"os"
- "play"
- "play/harness"
+ "github.com/robfig/revel"
+ "github.com/robfig/revel/harness"
)
func main() {
@@ -21,24 +21,24 @@ func main() {
usage()
}
- mode := play.DEV
+ mode := rev.DEV
if len(args) == 2 && args[1] == "prod" {
- mode = play.PROD
+ mode = rev.PROD
}
// Find and parse app.conf
- play.Init(args[0], mode)
- log.Printf("Running app (%s): %s (%s)\n", mode, play.AppName, play.BasePath)
+ rev.Init(args[0], mode)
+ log.Printf("Running app (%s): %s (%s)\n", mode, rev.AppName, rev.BasePath)
harness.Run(mode)
}
const header = `~
-~ go play! http://www.github.com/robfig/go-play
+~ revel! http://www.github.com/robfig/revel
~
`
-const usageText = `~ Usage: play import_path [mode]
+const usageText = `~ Usage: rev import_path [mode]
`
func usage() {
View
2  config.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"github.com/kless/goconfig/config"
View
4 errors.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"bytes"
@@ -60,7 +60,7 @@ func (e *Error) Html() string {
func RenderError(buffer io.Writer, data interface{}) {
if errorTemplate == nil {
errorTemplate = template.Must(template.ParseFiles(
- path.Join(PlayTemplatePath, "500.html")))
+ path.Join(RevelTemplatePath, "500.html")))
}
errorTemplate.Execute(buffer, &data)
}
View
86 harness/harness.go
@@ -1,4 +1,4 @@
-// The Harness for a GoPlay! program.
+// The Harness for a Revel program.
//
// It has a couple responsibilities:
// 1. Parse the user program, generating a main.go file that registers
@@ -25,7 +25,7 @@ import (
"os/exec"
"path"
"path/filepath"
- "play"
+ "github.com/robfig/revel"
"regexp"
"strconv"
"strings"
@@ -39,7 +39,7 @@ package main
import (
"flag"
"reflect"
- "play"
+ "github.com/robfig/revel"
{{range .ImportPaths}}
"{{.}}"
{{end}}
@@ -54,16 +54,16 @@ var (
)
func main() {
- play.LOG.Println("Running play server")
+ rev.LOG.Println("Running revel server")
flag.Parse()
- play.Init(*importPath, "{{.RunMode}}")
+ rev.Init(*importPath, "{{.RunMode}}")
{{range $i, $c := .Controllers}}
- play.RegisterController((*{{.PackageName}}.{{.StructName}})(nil),
- []*play.MethodType{
- {{range .MethodSpecs}}&play.MethodType{
+ rev.RegisterController((*{{.PackageName}}.{{.StructName}})(nil),
+ []*rev.MethodType{
+ {{range .MethodSpecs}}&rev.MethodType{
Name: "{{.Name}}",
- Args: []*play.MethodArg{ {{range .Args}}
- &play.MethodArg{Name: "{{.Name}}", Type: reflect.TypeOf((*{{.TypeName}})(nil)) },{{end}}
+ Args: []*rev.MethodArg{ {{range .Args}}
+ &rev.MethodArg{Name: "{{.Name}}", Type: reflect.TypeOf((*{{.TypeName}})(nil)) },{{end}}
},
RenderArgNames: map[int][]string{ {{range .RenderCalls}}
{{.Line}}: []string{ {{range .Names}}
@@ -74,7 +74,7 @@ func main() {
{{end}}
})
{{end}}
- play.Run(*port)
+ rev.Run(*port)
}
`
@@ -117,10 +117,10 @@ func (hp *harnessProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) {
func serveError(wr http.ResponseWriter, req *http.Request, err error) {
switch e := err.(type) {
- case *play.Error:
- play.RenderError(wr, e)
+ case *rev.Error:
+ rev.RenderError(wr, e)
default:
- play.RenderError(wr, map[string]string{
+ rev.RenderError(wr, map[string]string{
"Title": "Unexpected error",
"Path": "(unknown)",
"Description": "An unexpected error occurred: " + err.Error(),
@@ -147,7 +147,7 @@ func startReverseProxy(port int) *harnessProxy {
}
func getAppPort() int {
- port, err := play.Config.Int("http.port")
+ port, err := rev.Config.Int("http.port")
if err != nil {
log.Println("Parsing http.port failed:", err)
return 9000
@@ -160,10 +160,10 @@ var (
DoNotWatch = []string{"tmp", "views"}
)
-func Run(mode play.RunMode) {
+func Run(mode rev.RunMode) {
// If we are in prod mode, just build and run the application.
- if mode == play.PROD {
+ if mode == rev.PROD {
log.Println("Building...")
if err := rebuild(getAppPort()); err != nil {
log.Fatalln(err)
@@ -185,25 +185,25 @@ func Run(mode play.RunMode) {
}
// Listen to all app subdirectories (except /views)
- filepath.Walk(play.AppPath, func(path string, info os.FileInfo, err error) error {
+ filepath.Walk(rev.AppPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
- play.LOG.Println("error walking app:", err)
+ rev.LOG.Println("error walking app:", err)
return nil
}
if info.IsDir() {
- if play.ContainsString(DoNotWatch, info.Name()) {
+ if rev.ContainsString(DoNotWatch, info.Name()) {
return filepath.SkipDir
}
err = watcher.Watch(path)
- play.LOG.Println("Watching:", path)
+ rev.LOG.Println("Watching:", path)
if err != nil {
- play.LOG.Println("Failed to watch", path, ":", err)
+ rev.LOG.Println("Failed to watch", path, ":", err)
}
}
return nil
})
- // Define an exit handler that kills the play server (since it won't die on
+ // Define an exit handler that kills the revel server (since it won't die on
// its own, if the harness exits)
defer func() {
if cmd != nil {
@@ -257,33 +257,33 @@ func Run(mode play.RunMode) {
var cmd *exec.Cmd
-// Rebuild the Play! application and run it on the given port.
-func rebuild(port int) (compileError *play.Error) {
- controllerSpecs, compileError := ScanControllers(path.Join(play.AppPath, "controllers"))
+// Rebuild the Revel application and run it on the given port.
+func rebuild(port int) (compileError *rev.Error) {
+ controllerSpecs, compileError := ScanControllers(path.Join(rev.AppPath, "controllers"))
if compileError != nil {
return compileError
}
tmpl := template.New("RegisterControllers")
tmpl = template.Must(tmpl.Parse(REGISTER_CONTROLLERS))
- var registerControllerSource string = play.ExecuteTemplate(tmpl, map[string]interface{}{
- "AppName": play.AppName,
+ var registerControllerSource string = rev.ExecuteTemplate(tmpl, map[string]interface{}{
+ "AppName": rev.AppName,
"Controllers": controllerSpecs,
"ImportPaths": uniqueImportPaths(controllerSpecs),
- "RunMode": play.AppMode,
+ "RunMode": rev.AppMode,
})
// Terminate the server if it's already running.
if cmd != nil && (cmd.ProcessState == nil || !cmd.ProcessState.Exited()) {
- log.Println("Killing play server pid", cmd.Process.Pid)
+ log.Println("Killing revel server pid", cmd.Process.Pid)
err := cmd.Process.Kill()
if err != nil {
- log.Fatalln("Failed to kill play server:", err)
+ log.Fatalln("Failed to kill revel server:", err)
}
}
// Create a fresh temp dir.
- tmpPath := path.Join(play.AppPath, "tmp")
+ tmpPath := path.Join(rev.AppPath, "tmp")
err := os.RemoveAll(tmpPath)
if err != nil {
log.Println("Failed to remove tmp dir:", err)
@@ -311,12 +311,12 @@ func rebuild(port int) (compileError *play.Error) {
}
ctx := build.Default
- pkg, err := ctx.Import(play.ImportPath, "", build.FindOnly)
+ pkg, err := ctx.Import(rev.ImportPath, "", build.FindOnly)
if err != nil {
- log.Fatalf("Failure importing", play.ImportPath)
+ log.Fatalf("Failure importing", rev.ImportPath)
}
- binName := path.Join(pkg.BinDir, play.AppName)
- buildCmd := exec.Command(goPath, "build", "-o", binName, path.Join(play.ImportPath, "app", "tmp"))
+ binName := path.Join(pkg.BinDir, rev.AppName)
+ buildCmd := exec.Command(goPath, "build", "-o", binName, path.Join(rev.ImportPath, "app", "tmp"))
output, err := buildCmd.CombinedOutput()
// If we failed to build, parse the error message.
@@ -327,7 +327,7 @@ func rebuild(port int) (compileError *play.Error) {
// Run the server, via tmp/main.go.
cmd = exec.Command(binName,
fmt.Sprintf("-port=%d", port),
- fmt.Sprintf("-importPath=%s", play.ImportPath))
+ fmt.Sprintf("-importPath=%s", rev.ImportPath))
listeningWriter := startupListeningWriter{os.Stdout, make(chan bool)}
cmd.Stdout = listeningWriter
cmd.Stderr = os.Stderr
@@ -341,7 +341,7 @@ func rebuild(port int) (compileError *play.Error) {
}
// A io.Writer that copies to the destination, and listens for "Listening on.."
-// in the stream. (Which tells us when the play server has finished starting up)
+// in the stream. (Which tells us when the revel server has finished starting up)
// This is super ghetto, but by far the simplest thing that should work.
type startupListeningWriter struct {
dest io.Writer
@@ -393,12 +393,12 @@ func uniqueImportPaths(specs []*ControllerSpec) (paths []string) {
// Parse the output of the "go build" command.
// Return a detailed Error.
-func newCompileError(output []byte) *play.Error {
+func newCompileError(output []byte) *rev.Error {
errorMatch := regexp.MustCompile(`(?m)^([^:#]+):(\d+):(\d+:)? (.*)$`).
FindSubmatch(output)
if errorMatch == nil {
log.Println("Failed to parse build errors:\n", string(output))
- return &play.Error{
+ return &rev.Error{
SourceType: "Go code",
Title: "Go Compilation Error",
Description: "See console for build error.",
@@ -407,11 +407,11 @@ func newCompileError(output []byte) *play.Error {
// Read the source for the offending file.
var (
- relFilename = string(errorMatch[1]) // e.g. "src/play/sample/app/controllers/app.go"
+ relFilename = string(errorMatch[1]) // e.g. "src/revel/sample/app/controllers/app.go"
absFilename, _ = filepath.Abs(relFilename)
line, _ = strconv.Atoi(string(errorMatch[2]))
description = string(errorMatch[4])
- compileError = &play.Error{
+ compileError = &rev.Error{
SourceType: "Go code",
Title: "Go Compilation Error",
Path: relFilename,
@@ -420,7 +420,7 @@ func newCompileError(output []byte) *play.Error {
}
)
- fileStr, err := play.ReadLines(absFilename)
+ fileStr, err := rev.ReadLines(absFilename)
if err != nil {
compileError.MetaError = absFilename + ": " + err.Error()
log.Println(compileError.MetaError)
View
30 harness/reflect.go
@@ -10,7 +10,7 @@ import (
"go/token"
"log"
"os"
- "play"
+ "github.com/robfig/revel"
"strings"
"unicode"
)
@@ -21,7 +21,7 @@ type ControllerSpec struct {
ImportPath string
MethodSpecs []*MethodSpec
- // Used internally to identify controllers that indirectly embed *play.Controller.
+ // Used internally to identify controllers that indirectly embed *rev.Controller.
embeddedTypes []*embeddedTypeName
}
@@ -54,7 +54,7 @@ type methodMap map[string][]*MethodSpec
// Parse the app directory and return a list of the controller types found.
// Returns a CompileError if the parsing fails.
-func ScanControllers(path string) (specs []*ControllerSpec, compileError *play.Error) {
+func ScanControllers(path string) (specs []*ControllerSpec, compileError *rev.Error) {
// Parse files within the path.
var pkgs map[string]*ast.Package
fset := token.NewFileSet()
@@ -62,14 +62,14 @@ func ScanControllers(path string) (specs []*ControllerSpec, compileError *play.E
if err != nil {
if errList, ok := err.(scanner.ErrorList); ok {
var pos token.Position = errList[0].Pos
- return nil, &play.Error{
+ return nil, &rev.Error{
SourceType: ".go source",
Title: "Go Compilation Error",
Path: pos.Filename,
Description: errList[0].Msg,
Line: pos.Line,
Column: pos.Column,
- SourceLines: play.MustReadLines(pos.Filename),
+ SourceLines: rev.MustReadLines(pos.Filename),
}
}
ast.Print(nil, err)
@@ -98,7 +98,7 @@ func ScanControllers(path string) (specs []*ControllerSpec, compileError *play.E
}
}
- // Filter the struct specs to just the ones that embed play.Controller.
+ // Filter the struct specs to just the ones that embed rev.Controller.
structSpecs = filterControllers(structSpecs)
// Add the method specs to them.
@@ -148,7 +148,7 @@ func appendStruct(specs []*ControllerSpec, pkg *ast.Package, decl ast.Decl) []*C
}
if len(genDecl.Specs) != 1 {
- play.LOG.Printf("Surprising: Decl does not have 1 Spec: %v", genDecl)
+ rev.LOG.Printf("Surprising: Decl does not have 1 Spec: %v", genDecl)
return specs
}
@@ -164,7 +164,7 @@ func appendStruct(specs []*ControllerSpec, pkg *ast.Package, decl ast.Decl) []*C
controllerSpec := &ControllerSpec{
PackageName: pkg.Name,
StructName: spec.Name.Name,
- ImportPath: play.ImportPath + "/app/" + pkg.Name,
+ ImportPath: rev.ImportPath + "/app/" + pkg.Name,
}
for _, field := range structType.Fields.List {
@@ -175,7 +175,7 @@ func appendStruct(specs []*ControllerSpec, pkg *ast.Package, decl ast.Decl) []*C
// A direct "sub-type" has an ast.Field as either:
// Ident { "AppController" }
- // SelectorExpr { "play", "Controller" }
+ // SelectorExpr { "rev", "Controller" }
// Additionally, that can be wrapped by StarExprs.
fieldType := field.Type
pkgName, typeName := func() (string, string) {
@@ -236,7 +236,7 @@ func appendMethod(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgName stri
return
}
- // Does it return a play.Result?
+ // Does it return a rev.Result?
if funcDecl.Type.Results == nil || len(funcDecl.Type.Results.List) != 1 {
return
}
@@ -244,7 +244,7 @@ func appendMethod(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgName stri
if !ok {
return
}
- if pkgIdent, ok := selExpr.X.(*ast.Ident); !ok || pkgIdent.Name != "play" {
+ if pkgIdent, ok := selExpr.X.(*ast.Ident); !ok || pkgIdent.Name != "rev" {
return
}
if selExpr.Sel.Name != "Result" {
@@ -340,15 +340,15 @@ func (s *embeddedTypeName) SimpleName() string {
return s.PackageName + "." + s.StructName
}
-// Remove any types that do not (directly or indirectly) embed *play.Controller.
+// Remove any types that do not (directly or indirectly) embed *rev.Controller.
func filterControllers(specs []*ControllerSpec) (filtered []*ControllerSpec) {
- // Do a search in the "embedded type graph", starting with play.Controller.
- nodeQueue := []string{"play.Controller"}
+ // Do a search in the "embedded type graph", starting with rev.Controller.
+ nodeQueue := []string{"rev.Controller"}
for len(nodeQueue) > 0 {
controllerSimpleName := nodeQueue[0]
nodeQueue = nodeQueue[1:]
for _, spec := range specs {
- if play.ContainsString(nodeQueue, spec.SimpleName()) {
+ if rev.ContainsString(nodeQueue, spec.SimpleName()) {
continue // Already added
}
View
20 intercept.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"log"
@@ -29,13 +29,13 @@ import (
//
// Func Interceptors may apply to any / all Controllers.
//
-// func example(*play.Controller) play.Result
+// func example(*rev.Controller) rev.Result
//
// Method Interceptors are provided so that properties can be set on application
// controllers.
//
-// func (c AppController) example() play.Result
-// func (c *AppController) example() play.Result
+// func (c AppController) example() rev.Result
+// func (c *AppController) example() rev.Result
//
type InterceptorFunc func(*Controller) Result
type InterceptorMethod interface{}
@@ -91,7 +91,7 @@ var interceptors []*Interception
// Install a general interceptor.
// This can be applied to any Controller.
// It must have the signature of:
-// func example(c *play.Controller) play.Result
+// func example(c *rev.Controller) rev.Result
func InterceptFunc(intc InterceptorFunc, when InterceptTime, target interface{}) {
interceptors = append(interceptors, &Interception{
When: when,
@@ -103,13 +103,13 @@ func InterceptFunc(intc InterceptorFunc, when InterceptTime, target interface{})
}
// Install an interceptor method that applies to its own Controller.
-// func (c AppController) example() play.Result
-// func (c *AppController) example() play.Result
+// func (c AppController) example() rev.Result
+// func (c *AppController) example() rev.Result
func InterceptMethod(intc InterceptorMethod, when InterceptTime) {
methodType := reflect.TypeOf(intc)
if methodType.Kind() != reflect.Func || methodType.NumOut() != 1 || methodType.NumIn() != 1 {
log.Fatalln("Interceptor method should have signature like",
- "'func (c *AppController) example() play.Result' but was", methodType)
+ "'func (c *AppController) example() rev.Result' but was", methodType)
}
interceptors = append(interceptors, &Interception{
When: when,
@@ -137,7 +137,7 @@ func getInterceptors(when InterceptTime, val reflect.Value) []*Interception {
// Also, convert between any difference in indirection.
// If the target couldn't be found, the returned Value will have IsValid() == false
func findTarget(val reflect.Value, target reflect.Type) reflect.Value {
- // Look through the embedded types (until we reach the *play.Controller at the top).
+ // Look through the embedded types (until we reach the *rev.Controller at the top).
for {
// Check if val is of a similar type to the target type.
if val.Type() == target {
@@ -150,7 +150,7 @@ func findTarget(val reflect.Value, target reflect.Type) reflect.Value {
return val.Addr()
}
- // If we reached the *play.Controller and still didn't find what we were
+ // If we reached the *rev.Controller and still didn't find what we were
// looking for, give up.
if val.Type() == controllerPtrType {
break
View
2  intercept_test.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"reflect"
View
2  libs.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"crypto/hmac"
View
22 mvc.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"database/sql"
@@ -118,12 +118,12 @@ func NewAppController(w http.ResponseWriter, r *http.Request, controllerName, me
// This is a helper that initializes (zeros) a new app controller value.
// Generally, everything is set to its zero value, except:
// 1. Embedded controller pointers are newed up.
-// 2. The play.Controller embedded type is set to the value provided.
+// 2. The rev.Controller embedded type is set to the value provided.
// Returns a value representing a pointer to the new app controller.
func initNewAppController(appControllerType reflect.Type, c *Controller) reflect.Value {
// It might be a multi-level embedding, so we have to create new controllers
// at every level of the hierarchy.
- // ASSUME: the first field in each type is the way up to play.Controller.
+ // ASSUME: the first field in each type is the way up to rev.Controller.
appControllerPtr := reflect.New(appControllerType)
ptr := appControllerPtr
for {
@@ -132,7 +132,7 @@ func initNewAppController(appControllerType reflect.Type, c *Controller) reflect
embeddedFieldType reflect.Type = embeddedField.Type()
)
- // Check if it's the Play! controller.
+ // Check if it's the controller.
if embeddedFieldType == controllerType {
embeddedField.Set(reflect.ValueOf(c).Elem())
break
@@ -208,7 +208,7 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
flashValue += "\x00" + key + ":" + value + "\x00"
}
c.SetCookie(&http.Cookie{
- Name: "PLAY_FLASH",
+ Name: "REVEL_FLASH",
Value: url.QueryEscape(flashValue),
Path: "/",
})
@@ -223,7 +223,7 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
}
}
c.SetCookie(&http.Cookie{
- Name: "PLAY_ERRORS",
+ Name: "REVEL_ERRORS",
Value: url.QueryEscape(errorsValue),
Path: "/",
})
@@ -235,7 +235,7 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
}
sessionData := url.QueryEscape(sessionValue)
c.SetCookie(&http.Cookie{
- Name: "PLAY_SESSION",
+ Name: "REVEL_SESSION",
Value: Sign(sessionData) + "-" + sessionData,
Path: "/",
})
@@ -250,7 +250,7 @@ func handleInvocationPanic(c *Controller, err interface{}) {
plugins.OnException(c, err)
// Parse the filename and line from the originating line of app code.
- // /Users/robfig/code/gocode/src/play/samples/booking/app/controllers/hotels.go:191 (0x44735)
+ // /Users/robfig/code/gocode/src/revel/samples/booking/app/controllers/hotels.go:191 (0x44735)
stack := string(debug.Stack())
appFrame := strings.Index(stack, BasePath)
if appFrame == -1 {
@@ -365,7 +365,7 @@ func restoreFlash(req *http.Request) Flash {
Data: make(map[string]string),
Out: make(map[string]string),
}
- if cookie, err := req.Cookie("PLAY_FLASH"); err == nil {
+ if cookie, err := req.Cookie("REVEL_FLASH"); err == nil {
ParseKeyValueCookie(cookie.Value, func(key, val string) {
flash.Data[key] = val
})
@@ -376,7 +376,7 @@ func restoreFlash(req *http.Request) Flash {
// Restore Validation.Errors from a request.
func restoreValidationErrors(req *http.Request) []*ValidationError {
errors := make([]*ValidationError, 0, 5)
- if cookie, err := req.Cookie("PLAY_ERRORS"); err == nil {
+ if cookie, err := req.Cookie("REVEL_ERRORS"); err == nil {
ParseKeyValueCookie(cookie.Value, func(key, val string) {
errors = append(errors, &ValidationError{
Key: key,
@@ -389,7 +389,7 @@ func restoreValidationErrors(req *http.Request) []*ValidationError {
func restoreSession(req *http.Request) Session {
session := make(map[string]string)
- cookie, err := req.Cookie("PLAY_SESSION")
+ cookie, err := req.Cookie("REVEL_SESSION")
if err != nil {
return Session(session)
}
View
2  mvc_test.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"fmt"
View
2  plugin.go
@@ -1,4 +1,4 @@
-package play
+package rev
// An plugin that allows the user to inject behavior at various points in the request cycle.
type Plugin interface {
View
2  results.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"bytes"
View
28 play.go → revel.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"go/build"
@@ -18,21 +18,21 @@ const (
var (
// App details
AppName string // e.g. "sample"
- BasePath string // e.g. "/Users/robfig/gocode/src/play/sample"
- AppPath string // e.g. "/Users/robfig/gocode/src/play/sample/app"
- ViewsPath string // e.g. "/Users/robfig/gocode/src/play/sample/app/views"
- ImportPath string // e.g. "play/sample"
+ BasePath string // e.g. "/Users/robfig/gocode/src/revel/sample"
+ AppPath string // e.g. "/Users/robfig/gocode/src/revel/sample/app"
+ ViewsPath string // e.g. "/Users/robfig/gocode/src/revel/sample/app/views"
+ ImportPath string // e.g. "revel/sample"
Config *MergedConfig
AppMode RunMode // DEV or PROD
- // Play installation details
- PlayTemplatePath string // e.g. "/Users/robfig/gocode/src/play/templates"
+ // Revel installation details
+ RevelTemplatePath string // e.g. "/Users/robfig/gocode/src/revel/templates"
LOG = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile)
// Private
- playInit bool = false
+ revelInit bool = false
secretKey []byte
)
@@ -52,11 +52,11 @@ func Init(importPath string, mode RunMode) {
ImportPath = importPath
// Find the provided resources.
- playPkg, err := build.Import("play", "", build.FindOnly)
+ revelPkg, err := build.Import("github.com/robfig/revel", "", build.FindOnly)
if err != nil {
- log.Fatalf("Failed to find play code.")
+ log.Fatalf("Failed to find revel code.")
}
- PlayTemplatePath = path.Join(playPkg.Dir, "templates")
+ RevelTemplatePath = path.Join(revelPkg.Dir, "templates")
// Load application.conf
Config, err = LoadConfig(
@@ -71,11 +71,11 @@ func Init(importPath string, mode RunMode) {
}
secretKey = []byte(secretStr)
- playInit = true
+ revelInit = true
}
func CheckInit() {
- if !playInit {
- panic("Play has not been initialized!")
+ if !revelInit {
+ panic("Revel has not been initialized!")
}
}
View
2  router.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"io/ioutil"
View
2  router_test.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"fmt"
View
22 samples/booking/app/controllers/app.go
@@ -1,18 +1,18 @@
package controllers
import (
- "play"
- "play/samples/booking/app/models"
+ "github.com/robfig/revel"
+ "github.com/robfig/revel/samples/booking/app/models"
)
-func addUser(c *play.Controller) play.Result {
+func addUser(c *rev.Controller) rev.Result {
if user := connected(c); user != nil {
c.RenderArgs["user"] = user
}
return nil
}
-func connected(c *play.Controller) *models.User {
+func connected(c *rev.Controller) *models.User {
if c.RenderArgs["user"] != nil {
return c.RenderArgs["user"].(*models.User)
}
@@ -39,10 +39,10 @@ select UserId, Password, Name
}
type Application struct {
- *play.Controller
+ *rev.Controller
}
-func (c Application) Index() play.Result {
+func (c Application) Index() rev.Result {
if connected(c.Controller) != nil {
return c.Redirect(Hotels.Index)
}
@@ -51,12 +51,12 @@ func (c Application) Index() play.Result {
return c.Render(title)
}
-func (c Application) Register() play.Result {
+func (c Application) Register() rev.Result {
title := "Register"
return c.Render(title)
}
-func (c Application) SaveUser(user models.User, verifyPassword string) play.Result {
+func (c Application) SaveUser(user models.User, verifyPassword string) rev.Result {
c.Validation.Required(verifyPassword).Key("verifyPassword")
c.Validation.Required(verifyPassword == user.Password).Key("verifyPassword").
Message("Password does not match")
@@ -79,7 +79,7 @@ func (c Application) SaveUser(user models.User, verifyPassword string) play.Resu
return c.Redirect(Hotels.Index)
}
-func (c Application) Login(username, password string) play.Result {
+func (c Application) Login(username, password string) rev.Result {
rows, err := c.Txn.Query(
"select 1 from User where Username = ? and Password = ?",
username, password)
@@ -98,7 +98,7 @@ func (c Application) Login(username, password string) play.Result {
return c.Redirect(Application.Index)
}
-func (c Application) Logout() play.Result {
+func (c Application) Logout() rev.Result {
for k := range c.Session {
delete(c.Session, k)
}
@@ -106,5 +106,5 @@ func (c Application) Logout() play.Result {
}
func init() {
- play.InterceptFunc(addUser, play.BEFORE, &Application{})
+ rev.InterceptFunc(addUser, rev.BEFORE, &Application{})
}
View
14 samples/booking/app/controllers/db.go
@@ -4,13 +4,13 @@ import (
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
- "play"
+ "github.com/robfig/revel"
)
// This plugin manages transaction-per-request for any controllers that embed
// GorpController.
type GorpController struct {
- *play.Controller
+ *rev.Controller
}
var (
@@ -18,7 +18,7 @@ var (
)
type DbPlugin struct {
- play.EmptyPlugin
+ rev.EmptyPlugin
}
func (p DbPlugin) OnAppStart() {
@@ -95,7 +95,7 @@ create table Hotel (
}
}
-func (p DbPlugin) BeforeRequest(c *play.Controller) {
+func (p DbPlugin) BeforeRequest(c *rev.Controller) {
txn, err := db.Begin()
if err != nil {
panic(err)
@@ -103,7 +103,7 @@ func (p DbPlugin) BeforeRequest(c *play.Controller) {
c.Txn = txn
}
-func (p DbPlugin) AfterRequest(c *play.Controller) {
+func (p DbPlugin) AfterRequest(c *rev.Controller) {
if err := c.Txn.Commit(); err != nil {
if err != sql.ErrTxDone {
panic(err)
@@ -112,7 +112,7 @@ func (p DbPlugin) AfterRequest(c *play.Controller) {
c.Txn = nil
}
-func (p DbPlugin) OnException(c *play.Controller, err interface{}) {
+func (p DbPlugin) OnException(c *rev.Controller, err interface{}) {
if err := c.Txn.Rollback(); err != nil {
if err != sql.ErrTxDone {
panic(err)
@@ -121,5 +121,5 @@ func (p DbPlugin) OnException(c *play.Controller, err interface{}) {
}
func init() {
- play.RegisterPlugin(DbPlugin{})
+ rev.RegisterPlugin(DbPlugin{})
}
View
26 samples/booking/app/controllers/hotels.go
@@ -3,13 +3,13 @@ package controllers
import (
"database/sql"
"fmt"
- "play"
- "play/samples/booking/app/models"
+ "github.com/robfig/revel"
+ "github.com/robfig/revel/samples/booking/app/models"
"strings"
"time"
)
-func checkUser(c *play.Controller) play.Result {
+func checkUser(c *rev.Controller) rev.Result {
if user := connected(c); user == nil {
c.Flash.Error("Please log in first")
return c.Redirect(Application.Index)
@@ -18,10 +18,10 @@ func checkUser(c *play.Controller) play.Result {
}
type Hotels struct {
- *play.Controller
+ *rev.Controller
}
-func (c Hotels) Index() play.Result {
+func (c Hotels) Index() rev.Result {
title := "Search"
rows, err := c.Txn.Query(`
select BookingId, UserId, HotelId, CheckInDate, CheckOutDate,
@@ -53,7 +53,7 @@ select BookingId, UserId, HotelId, CheckInDate, CheckOutDate,
return c.Render(title, bookings)
}
-func (c Hotels) List(search string, size, page int) play.Result {
+func (c Hotels) List(search string, size, page int) rev.Result {
title := "List"
if page == 0 {
page = 1
@@ -108,7 +108,7 @@ select HotelId, Name, Address, City, State, Zip, Country, Price
return hotels[0]
}
-func (c Hotels) Show(id int) play.Result {
+func (c Hotels) Show(id int) rev.Result {
var title string
hotel := c.loadHotelById(id)
if hotel == nil {
@@ -120,12 +120,12 @@ func (c Hotels) Show(id int) play.Result {
return c.Render(title, hotel)
}
-func (c Hotels) Settings() play.Result {
+func (c Hotels) Settings() rev.Result {
title := "Settings"
return c.Render(title)
}
-func (c Hotels) SaveSettings(password, verifyPassword string) play.Result {
+func (c Hotels) SaveSettings(password, verifyPassword string) rev.Result {
user := connected(c.Controller)
user.Password = password
user.Validate(c.Validation)
@@ -144,7 +144,7 @@ func (c Hotels) SaveSettings(password, verifyPassword string) play.Result {
return c.Redirect(Hotels.Index)
}
-func (c Hotels) ConfirmBooking(id int, booking models.Booking) play.Result {
+func (c Hotels) ConfirmBooking(id int, booking models.Booking) rev.Result {
hotel := c.loadHotelById(id)
title := fmt.Sprintf("Confirm %s booking", hotel.Name)
booking.Hotel = hotel
@@ -186,7 +186,7 @@ insert into Booking (
return c.Render(title, hotel, booking)
}
-func (c Hotels) CancelBooking(id int) play.Result {
+func (c Hotels) CancelBooking(id int) rev.Result {
_, err := c.Txn.Exec("delete from Booking where BookingId = ?", id)
if err != nil {
panic(err)
@@ -195,7 +195,7 @@ func (c Hotels) CancelBooking(id int) play.Result {
return c.Redirect(Hotels.Index)
}
-func (c Hotels) Book(id int) play.Result {
+func (c Hotels) Book(id int) rev.Result {
hotel := c.loadHotelById(id)
title := "Book " + hotel.Name
// if hotel == nil {
@@ -205,5 +205,5 @@ func (c Hotels) Book(id int) play.Result {
}
func init() {
- play.InterceptFunc(checkUser, play.BEFORE, &Hotels{})
+ rev.InterceptFunc(checkUser, rev.BEFORE, &Hotels{})
}
View
4 samples/booking/app/models/booking.go
@@ -2,7 +2,7 @@ package models
import (
"fmt"
- "play"
+ "github.com/robfig/revel"
"regexp"
"time"
)
@@ -26,7 +26,7 @@ type Booking struct {
// TODO: Make an interface for Validate() and then validation can pass in the
// key prefix ("booking.")
-func (b Booking) Validate(v *play.Validation) {
+func (b Booking) Validate(v *rev.Validation) {
v.Required(b.User).Key("booking.User")
v.Required(b.Hotel).Key("booking.Hotel")
v.Required(b.CheckInDate).Key("booking.CheckInDate")
View
4 samples/booking/app/models/hotel.go
@@ -1,7 +1,7 @@
package models
import (
- "play"
+ "github.com/robfig/revel"
)
type Hotel struct {
@@ -12,7 +12,7 @@ type Hotel struct {
Price int
}
-func (h *Hotel) Validate(v *play.Validation) {
+func (h *Hotel) Validate(v *rev.Validation) {
v.Required(h.Name).Key("hotel.Name")
v.MaxSize(h.Name, 50).Key("hotel.Name")
View
4 samples/booking/app/models/user.go
@@ -2,7 +2,7 @@ package models
import (
"fmt"
- "play"
+ "github.com/robfig/revel"
"regexp"
)
@@ -17,7 +17,7 @@ func (u *User) String() string {
var userRegex = regexp.MustCompile("^\\w*$")
-func (u *User) Validate(v *play.Validation) {
+func (u *User) Validate(v *rev.Validation) {
v.Required(u.Username).Key("user.Username")
v.MaxSize(u.Username, 15).Key("user.Username")
v.MinSize(u.Username, 4).Key("user.Username")
View
2  samples/booking/app/views/footer.html
@@ -1,7 +1,7 @@
</div>
<div id="footer">
- Created with the <a href="http://github.com/robfig/go-play">Go Play framework</a> and really inspirated from the booking sample application provided by <a href="http://www.playframework.org">play framework</a>, which was really inspired by the booking sample application provided by the <a href="http://seamframework.org/">seam framework</a>.
+ Created with the <a href="http://github.com/robfig/revel">Revel framework</a> and really inspirated from the booking sample application provided by <a href="http://www.playframework.org">play framework</a>, which was really inspired by the booking sample application provided by the <a href="http://seamframework.org/">seam framework</a>.
</div>
</body>
View
2  samples/booking/app/views/header.html
@@ -12,7 +12,7 @@
<body>
<div id="header">
- <h1>play framework booking demo</h1>
+ <h1>revel framework booking demo</h1>
{{if .user}}
<div id="options">
Connected as {{.user.Username}}
View
2  server.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"fmt"
View
4 tmpl.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"errors"
@@ -241,7 +241,7 @@ type GoTemplate struct {
loader *TemplateLoader
}
-// return a 'play.Template' from Go's template.
+// return a 'rev.Template' from Go's template.
func (gotmpl GoTemplate) Render(wr io.Writer, arg interface{}) error {
return gotmpl.Execute(wr, arg)
}
View
5 util.go
@@ -1,7 +1,4 @@
-// Various utility functions to make the standard library a bit easier to deal
-// with.
-
-package play
+package rev
import (
"bytes"
View
2  validation.go
@@ -1,4 +1,4 @@
-package play
+package rev
import (
"fmt"
Please sign in to comment.
Something went wrong with that request. Please try again.