mirror of https://github.com/ehrudxo/GoMap.git
update for 1st commit of level + postgresql
commit
f4d055c0e2
|
@ -0,0 +1,3 @@
|
|||
test-results/
|
||||
tmp/
|
||||
routes/
|
|
@ -0,0 +1,75 @@
|
|||
# Welcome to Revel
|
||||
|
||||
## Getting Started
|
||||
|
||||
A high-productivity web framework for the [Go language](http://www.golang.org/).
|
||||
|
||||
### Start the web server:
|
||||
|
||||
revel run myapp
|
||||
|
||||
Run with <tt>--help</tt> for options.
|
||||
|
||||
### Go to http://localhost:9000/ and you'll see:
|
||||
|
||||
"It works"
|
||||
|
||||
### Description of Contents
|
||||
|
||||
The default directory structure of a generated Revel application:
|
||||
|
||||
myapp App root
|
||||
app App sources
|
||||
controllers App controllers
|
||||
init.go Interceptor registration
|
||||
models App domain models
|
||||
routes Reverse routes (generated code)
|
||||
views Templates
|
||||
tests Test suites
|
||||
conf Configuration files
|
||||
app.conf Main configuration file
|
||||
routes Routes definition
|
||||
messages Message files
|
||||
public Public assets
|
||||
css CSS files
|
||||
js Javascript files
|
||||
images Image files
|
||||
|
||||
app
|
||||
|
||||
The app directory contains the source code and templates for your application.
|
||||
|
||||
conf
|
||||
|
||||
The conf directory contains the application’s configuration files. There are two main configuration files:
|
||||
|
||||
* app.conf, the main configuration file for the application, which contains standard configuration parameters
|
||||
* routes, the routes definition file.
|
||||
|
||||
|
||||
messages
|
||||
|
||||
The messages directory contains all localized message files.
|
||||
|
||||
public
|
||||
|
||||
Resources stored in the public directory are static assets that are served directly by the Web server. Typically it is split into three standard sub-directories for images, CSS stylesheets and JavaScript files.
|
||||
|
||||
The names of these directories may be anything; the developer need only update the routes.
|
||||
|
||||
test
|
||||
|
||||
Tests are kept in the tests directory. Revel provides a testing framework that makes it easy to write and run functional tests against your application.
|
||||
|
||||
### Follow the guidelines to start developing your application:
|
||||
|
||||
* The README file created within your application.
|
||||
* The [Getting Started with Revel](http://revel.github.io/tutorial/index.html).
|
||||
* The [Revel guides](http://revel.github.io/manual/index.html).
|
||||
* The [Revel sample apps](http://revel.github.io/samples/index.html).
|
||||
* The [API documentation](http://revel.github.io/docs/godoc/index.html).
|
||||
|
||||
## Contributing
|
||||
We encourage you to contribute to Revel! Please check out the [Contributing to Revel
|
||||
guide](https://github.com/revel/revel/blob/master/CONTRIBUTING.md) for guidelines about how
|
||||
to proceed. [Join us](https://groups.google.com/forum/#!forum/revel-framework)!
|
|
@ -0,0 +1,19 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/revel/revel"
|
||||
"github.com/jinzhu/gorm"
|
||||
"map1/app/models"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
*revel.Controller
|
||||
Tx *gorm.DB
|
||||
}
|
||||
|
||||
func (c App) Index() revel.Result {
|
||||
user := &models.User{Username: "keen2"}
|
||||
c.Tx.NewRecord(user)
|
||||
c.Tx.Create(user)
|
||||
return c.Render(user)
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package controllers
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/revel/revel"
|
||||
"map1/app/models"
|
||||
)
|
||||
type GormController struct {
|
||||
*revel.Controller
|
||||
Tx *gorm.DB
|
||||
}
|
||||
var Db gorm.DB
|
||||
func InitDB() {
|
||||
var err error
|
||||
Db, err = gorm.Open("postgres", "user=gouser dbname=postgres password=go1234 sslmode=disable")
|
||||
if err != nil {
|
||||
revel.ERROR.Println("FATAL", err)
|
||||
panic(err)
|
||||
}
|
||||
tab := &models.User{}
|
||||
Db.AutoMigrate(tab)
|
||||
Db.Model(tab).AddUniqueIndex("idx_user__mail", "mail")
|
||||
}
|
||||
func (c *GormController) Begin() revel.Result {
|
||||
txn := Db.Begin()
|
||||
if txn.Error != nil {
|
||||
panic(txn.Error)
|
||||
}
|
||||
c.Tx = txn
|
||||
revel.INFO.Println("c.Tx init", c.Tx)
|
||||
return nil
|
||||
}
|
||||
func (c *GormController) Commit() revel.Result {
|
||||
if c.Tx == nil {
|
||||
return nil
|
||||
}
|
||||
c.Tx.Commit()
|
||||
if err := c.Tx.Error; err != nil && err != sql.ErrTxDone {
|
||||
panic(err)
|
||||
}
|
||||
c.Tx = nil
|
||||
revel.INFO.Println("c.Tx commited (nil)")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *GormController) Rollback() revel.Result {
|
||||
if c.Tx == nil {
|
||||
return nil
|
||||
}
|
||||
c.Tx.Rollback()
|
||||
if err := c.Tx.Error; err != nil && err != sql.ErrTxDone {
|
||||
panic(err)
|
||||
}
|
||||
c.Tx = nil
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"github.com/revel/revel"
|
||||
"map1/app/controllers"
|
||||
)
|
||||
|
||||
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.ActionInvoker, // Invoke the action.
|
||||
}
|
||||
|
||||
// register startup functions with OnAppStart
|
||||
// ( order dependent )
|
||||
revel.OnAppStart(controllers.InitDB)
|
||||
revel.InterceptMethod((*controllers.GormController).Begin, revel.BEFORE)
|
||||
revel.InterceptMethod((*controllers.GormController).Commit, revel.AFTER)
|
||||
revel.InterceptMethod((*controllers.GormController).Rollback, revel.FINALLY)
|
||||
// revel.OnAppStart(FillCache)
|
||||
}
|
||||
|
||||
// TODO turn this into revel.HeaderFilter
|
||||
// should probably also have a filter for CSRF
|
||||
// not sure if it can go in the same filter or not
|
||||
var HeaderFilter = func(c *revel.Controller, fc []revel.Filter) {
|
||||
// Add some common security headers
|
||||
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")
|
||||
|
||||
fc[0](c, fc[1:]) // Execute the next filter stage.
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package models
|
||||
|
||||
type User struct {
|
||||
Seq int64
|
||||
Username string
|
||||
Mail string
|
||||
Password string
|
||||
Description string
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{{set . "title" "Home"}}
|
||||
{{template "header.html" .}}
|
||||
|
||||
<header class="hero-unit" style="background-color:#A9F16C">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="hero-text">
|
||||
<h1>It works!</h1>
|
||||
<p></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="span6">
|
||||
{{.user.Name}}
|
||||
{{template "flash.html" .}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{template "footer.html" .}}
|
|
@ -0,0 +1,64 @@
|
|||
<style type="text/css">
|
||||
#sidebar {
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
top:69px;
|
||||
max-width: 75%;
|
||||
z-index: 1000;
|
||||
background-color: #fee;
|
||||
border: thin solid grey;
|
||||
padding: 10px;
|
||||
}
|
||||
#toggleSidebar {
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
top: 50px;
|
||||
background-color: #fee;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div id="sidebar" style="display:none;">
|
||||
<h4>Available pipelines</h4>
|
||||
<dl>
|
||||
{{ range $index, $value := .}}
|
||||
<dt>{{$index}}</dt>
|
||||
<dd>{{$value}}</dd>
|
||||
{{end}}
|
||||
</dl>
|
||||
<h4>Flash</h4>
|
||||
<dl>
|
||||
{{ range $index, $value := .flash}}
|
||||
<dt>{{$index}}</dt>
|
||||
<dd>{{$value}}</dd>
|
||||
{{end}}
|
||||
</dl>
|
||||
|
||||
<h4>Errors</h4>
|
||||
<dl>
|
||||
{{ range $index, $value := .errors}}
|
||||
<dt>{{$index}}</dt>
|
||||
<dd>{{$value}}</dd>
|
||||
{{end}}
|
||||
</dl>
|
||||
</div>
|
||||
<a id="toggleSidebar" href="#" class="toggles"><i class="icon-chevron-left"></i></a>
|
||||
|
||||
<script>
|
||||
$sidebar = 0;
|
||||
$('#toggleSidebar').click(function() {
|
||||
if ($sidebar === 1) {
|
||||
$('#sidebar').hide();
|
||||
$('#toggleSidebar i').addClass('icon-chevron-left');
|
||||
$('#toggleSidebar i').removeClass('icon-chevron-right');
|
||||
$sidebar = 0;
|
||||
}
|
||||
else {
|
||||
$('#sidebar').show();
|
||||
$('#toggleSidebar i').addClass('icon-chevron-right');
|
||||
$('#toggleSidebar i').removeClass('icon-chevron-left');
|
||||
$sidebar = 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Not found</title>
|
||||
</head>
|
||||
<body>
|
||||
{{if eq .RunMode "dev"}}
|
||||
{{template "errors/404-dev.html" .}}
|
||||
{{else}}
|
||||
{{with .Error}}
|
||||
<h1>
|
||||
{{.Title}}
|
||||
</h1>
|
||||
<p>
|
||||
{{.Description}}
|
||||
</p>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Application error</title>
|
||||
</head>
|
||||
<body>
|
||||
{{if eq .RunMode "dev"}}
|
||||
{{template "errors/500-dev.html" .}}
|
||||
{{else}}
|
||||
<h1>Oops, an error occured</h1>
|
||||
<p>
|
||||
This exception has been logged.
|
||||
</p>
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
{{if .flash.success}}
|
||||
<div class="alert alert-success">
|
||||
{{.flash.success}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if or .errors .flash.error}}
|
||||
<div class="alert alert-error">
|
||||
{{if .flash.error}}
|
||||
{{.flash.error}}
|
||||
{{end}}
|
||||
<ul style="margin-top:10px;">
|
||||
{{range .errors}}
|
||||
<li>{{.}}</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
|
@ -0,0 +1,5 @@
|
|||
{{if eq .RunMode "dev"}}
|
||||
{{template "debug.html" .}}
|
||||
{{end}}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>{{.title}}</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="/public/css/bootstrap.css">
|
||||
<link rel="shortcut icon" type="image/png" href="/public/img/favicon.png">
|
||||
<script src="/public/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
|
||||
{{range .moreStyles}}
|
||||
<link rel="stylesheet" type="text/css" href="/public/{{.}}">
|
||||
{{end}}
|
||||
{{range .moreScripts}}
|
||||
<script src="/public/{{.}}" type="text/javascript" charset="utf-8"></script>
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
|
@ -0,0 +1,160 @@
|
|||
################################################################################
|
||||
# Revel configuration file
|
||||
# See:
|
||||
# http://revel.github.io/manual/appconf.html
|
||||
# for more detailed documentation.
|
||||
################################################################################
|
||||
|
||||
# This sets the `AppName` variable which can be used in your code as
|
||||
# `if revel.AppName {...}`
|
||||
app.name = map1
|
||||
|
||||
# A secret string which is passed to cryptographically sign the cookie to prevent
|
||||
# (and detect) user modification.
|
||||
# Keep this string secret or users will be able to inject arbitrary cookie values
|
||||
# into your application
|
||||
app.secret = VkLLrryCWQWxJPk1StFmHyhVlL9u4HQJPfASH06xznbIHgIYlSVFxCsTGcJRQaoj
|
||||
|
||||
|
||||
# The IP address on which to listen.
|
||||
http.addr =
|
||||
|
||||
# The port on which to listen.
|
||||
http.port = 9000
|
||||
|
||||
# Whether to use SSL or not.
|
||||
http.ssl = false
|
||||
|
||||
# Path to an X509 certificate file, if using SSL.
|
||||
#http.sslcert =
|
||||
|
||||
# Path to an X509 certificate key, if using SSL.
|
||||
#http.sslkey =
|
||||
|
||||
|
||||
# For any cookies set by Revel (Session,Flash,Error) these properties will set
|
||||
# the fields of:
|
||||
# http://golang.org/pkg/net/http/#Cookie
|
||||
#
|
||||
# The HttpOnly attribute is supported by most modern browsers. On a supported
|
||||
# browser, an HttpOnly session cookie will be used only when transmitting HTTP
|
||||
# (or HTTPS) requests, thus restricting access from other, non-HTTP APIs (such
|
||||
# as JavaScript). This restriction mitigates, but does not eliminate the threat
|
||||
# of session cookie theft via cross-site scripting (XSS). This feature applies
|
||||
# only to session-management cookies, and not other browser cookies.
|
||||
cookie.httponly = false
|
||||
|
||||
# Each cookie set by Revel is prefixed with this string.
|
||||
cookie.prefix = REVEL
|
||||
|
||||
# A secure cookie has the secure attribute enabled and is only used via HTTPS,
|
||||
# ensuring that the cookie is always encrypted when transmitting from client to
|
||||
# server. This makes the cookie less likely to be exposed to cookie theft via
|
||||
# eavesdropping.
|
||||
cookie.secure = false
|
||||
|
||||
# Limit cookie access to a given domain
|
||||
#cookie.domain =
|
||||
|
||||
# Define when your session cookie expires. Possible values:
|
||||
# "720h"
|
||||
# A time duration (http://golang.org/pkg/time/#ParseDuration) after which
|
||||
# the cookie expires and the session is invalid.
|
||||
# "session"
|
||||
# Sets a session cookie which invalidates the session when the user close
|
||||
# the browser.
|
||||
session.expires = 720h
|
||||
|
||||
|
||||
# The date format used by Revel. Possible formats defined by the Go `time`
|
||||
# package (http://golang.org/pkg/time/#Parse)
|
||||
format.date = 01/02/2006
|
||||
format.datetime = 01/02/2006 15:04
|
||||
|
||||
|
||||
# Determines whether the template rendering should use chunked encoding.
|
||||
# Chunked encoding can decrease the time to first byte on the client side by
|
||||
# sending data before the entire template has been fully rendered.
|
||||
results.chunked = false
|
||||
|
||||
|
||||
# Prefixes for each log message line
|
||||
log.trace.prefix = "TRACE "
|
||||
log.info.prefix = "INFO "
|
||||
log.warn.prefix = "WARN "
|
||||
log.error.prefix = "ERROR "
|
||||
|
||||
|
||||
# The default language of this application.
|
||||
i18n.default_language = en
|
||||
|
||||
|
||||
# Module to serve static content such as CSS, JavaScript and Media files
|
||||
# Allows Routes like this:
|
||||
# `Static.ServeModule("modulename","public")`
|
||||
module.static=github.com/revel/modules/static
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
# Section: dev
|
||||
# This section is evaluated when running Revel in dev mode. Like so:
|
||||
# `revel run path/to/myapp`
|
||||
[dev]
|
||||
# This sets `DevMode` variable to `true` which can be used in your code as
|
||||
# `if revel.DevMode {...}`
|
||||
# or in your templates with
|
||||
# `<no value>`
|
||||
mode.dev = true
|
||||
|
||||
|
||||
# Pretty print JSON/XML when calling RenderJson/RenderXml
|
||||
results.pretty = true
|
||||
|
||||
|
||||
# Automatically watches your applicaton files and recompiles on-demand
|
||||
watch = true
|
||||
|
||||
|
||||
# If you set watcher.mode = "eager", the server starts to recompile
|
||||
# your application every time your application's files change.
|
||||
watcher.mode = "normal"
|
||||
|
||||
|
||||
# Module to run code tests in the browser
|
||||
# See:
|
||||
# http://revel.github.io/manual/testing.html
|
||||
module.testrunner = github.com/revel/modules/testrunner
|
||||
|
||||
|
||||
# Where to log the various Revel logs
|
||||
log.trace.output = off
|
||||
log.info.output = stderr
|
||||
log.warn.output = stderr
|
||||
log.error.output = stderr
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
# Section: prod
|
||||
# This section is evaluated when running Revel in production mode. Like so:
|
||||
# `revel run path/to/myapp prod`
|
||||
# See:
|
||||
# [dev] section for documentation of the various settings
|
||||
[prod]
|
||||
mode.dev = false
|
||||
|
||||
|
||||
results.pretty = false
|
||||
|
||||
|
||||
watch = false
|
||||
|
||||
|
||||
module.testrunner =
|
||||
|
||||
|
||||
log.trace.output = off
|
||||
log.info.output = off
|
||||
log.warn.output = %(app.name)s.log
|
||||
log.error.output = %(app.name)s.log
|
|
@ -0,0 +1,16 @@
|
|||
# Routes
|
||||
# This file defines all application routes (Higher priority routes first)
|
||||
# ~~~~
|
||||
|
||||
module:testrunner
|
||||
|
||||
GET / App.Index
|
||||
|
||||
# Ignore favicon requests
|
||||
GET /favicon.ico 404
|
||||
|
||||
# Map static resources from the /app/public folder to the /public path
|
||||
GET /public/*filepath Static.Serve("public")
|
||||
|
||||
# Catch all
|
||||
* /:controller/:action :controller.:action
|
|
@ -0,0 +1,7 @@
|
|||
# Sample messages file for the English language (en)
|
||||
# Message file extensions should be ISO 639-1 codes (http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
|
||||
# Sections within each message file can optionally override the defaults using ISO 3166-1 alpha-2 codes (http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
|
||||
# See also:
|
||||
# - http://www.rfc-editor.org/rfc/bcp/bcp47.txt
|
||||
# - http://www.w3.org/International/questions/qa-accept-lang-locales
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,21 @@
|
|||
package tests
|
||||
|
||||
import "github.com/revel/revel/testing"
|
||||
|
||||
type AppTest struct {
|
||||
testing.TestSuite
|
||||
}
|
||||
|
||||
func (t *AppTest) Before() {
|
||||
println("Set up")
|
||||
}
|
||||
|
||||
func (t *AppTest) TestThatIndexPageWorks() {
|
||||
t.Get("/")
|
||||
t.AssertOk()
|
||||
t.AssertContentType("text/html; charset=utf-8")
|
||||
}
|
||||
|
||||
func (t *AppTest) After() {
|
||||
println("Tear down")
|
||||
}
|
Loading…
Reference in New Issue