Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/revel_example/myapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-results/
tmp/
routes/
43 changes: 43 additions & 0 deletions examples/revel_example/myapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Welcome to Revel

A high-productivity web framework for the [Go language](http://www.golang.org/).


### Start the web server:

revel run myapp

### Go to http://localhost:9000/ and you'll see:

"It works"

## Code Layout

The directory structure of a generated Revel application:

conf/ Configuration directory
app.conf Main app configuration file
routes Routes definition file

app/ App sources
init.go Interceptor registration
controllers/ App controllers go here
views/ Templates directory

messages/ Message files

public/ Public static assets
css/ CSS files
js/ Javascript files
images/ Image files

tests/ Test suites


## Help

* The [Getting Started with Revel](http://revel.github.io/tutorial/gettingstarted.html).
* The [Revel guides](http://revel.github.io/manual/index.html).
* The [Revel sample apps](http://revel.github.io/examples/index.html).
* The [API documentation](https://godoc.org/github.com/revel/revel).

43 changes: 43 additions & 0 deletions examples/revel_example/myapp/app/controllers/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package controllers

import (
"github.com/amplitude/Amplitude-Go/amplitude"
"github.com/revel/revel"
"myapp/app"
)

type App struct {
*revel.Controller
}

type payload struct {
EventType string `json:"event_type"`
UserProperties map[amplitude.IdentityOp]map[string]interface{} `json:"user_properties,omitempty"`
DeviceID string `json:"device_id,omitempty"`
UserID string `json:"user_id,omitempty"`
SessionID int `json:"session_id,omitempty"`
}

func (c App) Index() revel.Result {
return c.Render()
}

func (c App) Analytics() revel.Result {
jsonData := payload{}
//config.Logger.Debug("string(c.Params.JSON): ", string(c.Params.JSON))
c.Params.BindJSON(&jsonData)
//config.Logger.Debug("jsonData: ", jsonData)

event := amplitude.Event{
EventOptions: amplitude.EventOptions{
UserID: jsonData.UserID,
DeviceID: jsonData.DeviceID,
SessionID: jsonData.SessionID,
},
EventType: jsonData.EventType,
UserProperties: jsonData.UserProperties,
}
app.Client.Track(event)

return c.Render()
}
69 changes: 69 additions & 0 deletions examples/revel_example/myapp/app/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package app

import (
"github.com/amplitude/Amplitude-Go/amplitude"
_ "github.com/revel/modules"
"github.com/revel/revel"
)

var (
// AppVersion revel app version (ldflags)
AppVersion string

// BuildTime revel app build-time (ldflags)
BuildTime string

Client amplitude.Client
)

func InitAmplitude() {
Config := amplitude.NewConfig("your-api-key")
Client = amplitude.NewClient(Config)
}

func init() {
// Filters is the default set of global filters.
revel.Filters = []revel.Filter{
revel.PanicFilter, // Recover from panics and display an error page instead.
revel.RouterFilter, // Use the routing table to select the right Action
revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
revel.ParamsFilter, // Parse parameters into Controller.Params.
revel.SessionFilter, // Restore and write the session cookie.
revel.FlashFilter, // Restore and write the flash cookie.
revel.ValidationFilter, // Restore kept validation errors and save new ones from cookie.
revel.I18nFilter, // Resolve the requested language
HeaderFilter, // Add some security based headers
revel.InterceptorFilter, // Run interceptors around the action.
revel.CompressFilter, // Compress the result.
revel.BeforeAfterFilter, // Call the before and after filter functions
revel.ActionInvoker, // Invoke the action.
}

// Register startup functions with OnAppStart
// revel.DevMode and revel.RunMode only work inside of OnAppStart. See Example Startup Script
// ( order dependent )
// revel.OnAppStart(ExampleStartupScript)
// revel.OnAppStart(InitDB)
// revel.OnAppStart(FillCache)
revel.OnAppStart(InitAmplitude)
}

// HeaderFilter adds common security headers
// There is a full implementation of a CSRF filter in
// https://github.com/revel/modules/tree/master/csrf
var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) {
c.Response.Out.Header().Add("X-Frame-Options", "SAMEORIGIN")
c.Response.Out.Header().Add("X-XSS-Protection", "1; mode=block")
c.Response.Out.Header().Add("X-Content-Type-Options", "nosniff")
c.Response.Out.Header().Add("Referrer-Policy", "strict-origin-when-cross-origin")

fc[0](c, fc[1:]) // Execute the next filter stage.
}

//func ExampleStartupScript() {
// // revel.DevMod and revel.RunMode work here
// // Use this script to check for dev mode and set dev/prod startup scripts here!
// if revel.DevMode == true {
// // Dev mode
// }
//}
119 changes: 119 additions & 0 deletions examples/revel_example/myapp/app/routes/routes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// GENERATED CODE - DO NOT EDIT
// This file provides a way of creating URL's based on all the actions
// found in all the controllers.
package routes

import "github.com/revel/revel"


type tStatic struct {}
var Static tStatic


func (_ tStatic) Serve(
prefix string,
filepath string,
) string {
args := make(map[string]string)

revel.Unbind(args, "prefix", prefix)
revel.Unbind(args, "filepath", filepath)
return revel.MainRouter.Reverse("Static.Serve", args).URL
}

func (_ tStatic) ServeDir(
prefix string,
filepath string,
) string {
args := make(map[string]string)

revel.Unbind(args, "prefix", prefix)
revel.Unbind(args, "filepath", filepath)
return revel.MainRouter.Reverse("Static.ServeDir", args).URL
}

func (_ tStatic) ServeModule(
moduleName string,
prefix string,
filepath string,
) string {
args := make(map[string]string)

revel.Unbind(args, "moduleName", moduleName)
revel.Unbind(args, "prefix", prefix)
revel.Unbind(args, "filepath", filepath)
return revel.MainRouter.Reverse("Static.ServeModule", args).URL
}

func (_ tStatic) ServeModuleDir(
moduleName string,
prefix string,
filepath string,
) string {
args := make(map[string]string)

revel.Unbind(args, "moduleName", moduleName)
revel.Unbind(args, "prefix", prefix)
revel.Unbind(args, "filepath", filepath)
return revel.MainRouter.Reverse("Static.ServeModuleDir", args).URL
}


type tTestRunner struct {}
var TestRunner tTestRunner


func (_ tTestRunner) Index(
) string {
args := make(map[string]string)

return revel.MainRouter.Reverse("TestRunner.Index", args).URL
}

func (_ tTestRunner) Suite(
suite string,
) string {
args := make(map[string]string)

revel.Unbind(args, "suite", suite)
return revel.MainRouter.Reverse("TestRunner.Suite", args).URL
}

func (_ tTestRunner) Run(
suite string,
test string,
) string {
args := make(map[string]string)

revel.Unbind(args, "suite", suite)
revel.Unbind(args, "test", test)
return revel.MainRouter.Reverse("TestRunner.Run", args).URL
}

func (_ tTestRunner) List(
) string {
args := make(map[string]string)

return revel.MainRouter.Reverse("TestRunner.List", args).URL
}


type tApp struct {}
var App tApp


func (_ tApp) Index(
) string {
args := make(map[string]string)

return revel.MainRouter.Reverse("App.Index", args).URL
}

func (_ tApp) Analytics(
) string {
args := make(map[string]string)

return revel.MainRouter.Reverse("App.Analytics", args).URL
}


25 changes: 25 additions & 0 deletions examples/revel_example/myapp/app/tmp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// GENERATED CODE - DO NOT EDIT
// This file is the main file for Revel.
// It registers all the controllers and provides details for the Revel server engine to
// properly inject parameters directly into the action endpoints.
package main

import (
"flag"
"myapp/app/tmp/run"
"github.com/revel/revel"
)

var (
runMode *string = flag.String("runMode", "", "Run mode.")
port *int = flag.Int("port", 0, "By default, read from app.conf")
importPath *string = flag.String("importPath", "", "Go Import Path for the app.")
srcPath *string = flag.String("srcPath", "", "Path to the source root.")

)

func main() {
flag.Parse()
revel.Init(*runMode, *importPath, *srcPath)
run.Run(*port)
}
Loading