From af1f4677c685e8a2c4967ffa0350d314a6543db7 Mon Sep 17 00:00:00 2001
From: Horus3
Date: Thu, 5 Feb 2015 02:55:30 +0100
Subject: Init
---
.gitignore | 3 +
README.md | 75 +
app/controllers/app.go | 11 +
app/controllers/db.go | 43 +
app/controllers/url.go | 28 +
app/init.go | 38 +
app/views/App/Index.html | 23 +
app/views/debug.html | 64 +
app/views/errors/404.html | 20 +
app/views/errors/500.html | 16 +
app/views/flash.html | 18 +
app/views/footer.html | 5 +
app/views/header.html | 17 +
conf/app.conf | 158 +
conf/routes | 16 +
messages/sample.en | 7 +
public/css/bootstrap.css | 5774 +++++++++++++++++++++++++++++
public/img/favicon.png | Bin 0 -> 5639 bytes
public/img/glyphicons-halflings-white.png | Bin 0 -> 8777 bytes
public/img/glyphicons-halflings.png | Bin 0 -> 12799 bytes
public/js/jquery-1.9.1.min.js | 5 +
tests/apptest.go | 21 +
22 files changed, 6342 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 app/controllers/app.go
create mode 100644 app/controllers/db.go
create mode 100644 app/controllers/url.go
create mode 100644 app/init.go
create mode 100644 app/views/App/Index.html
create mode 100644 app/views/debug.html
create mode 100644 app/views/errors/404.html
create mode 100644 app/views/errors/500.html
create mode 100644 app/views/flash.html
create mode 100644 app/views/footer.html
create mode 100644 app/views/header.html
create mode 100644 conf/app.conf
create mode 100644 conf/routes
create mode 100644 messages/sample.en
create mode 100644 public/css/bootstrap.css
create mode 100644 public/img/favicon.png
create mode 100644 public/img/glyphicons-halflings-white.png
create mode 100644 public/img/glyphicons-halflings.png
create mode 100644 public/js/jquery-1.9.1.min.js
create mode 100644 tests/apptest.go
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..dae67d0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+test-results/
+tmp/
+routes/
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..246b5ba
--- /dev/null
+++ b/README.md
@@ -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 --help 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)!
diff --git a/app/controllers/app.go b/app/controllers/app.go
new file mode 100644
index 0000000..e76d76b
--- /dev/null
+++ b/app/controllers/app.go
@@ -0,0 +1,11 @@
+package controllers
+
+import "github.com/revel/revel"
+
+type App struct {
+ *revel.Controller
+}
+
+func (c App) Index() revel.Result {
+ return c.Render()
+}
diff --git a/app/controllers/db.go b/app/controllers/db.go
new file mode 100644
index 0000000..9607f24
--- /dev/null
+++ b/app/controllers/db.go
@@ -0,0 +1,43 @@
+package controllers
+
+import (
+ "github.com/jinzhu/gorm"
+ _ "github.com/mattn/go-sqlite3"
+ "github.com/revel/revel"
+)
+
+type User struct {
+ Id int64
+ Email string
+ Name string
+ Password string
+}
+
+type Job struct {
+}
+
+var DB *gorm.DB
+
+func DBInit() *sql.DB {
+ // Open database handler
+ db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
+
+ // Ping database to check if up
+ if err = db.DB().Ping(); err != nil {
+ revel.ERROR.Panicf("Failed to init database. %s \n", err)
+ }
+
+ // Set Pool connections
+ db.DB().SetMaxIdleConns(10)
+ db.DB().SetMaxOpenConns(100)
+
+ // Create tables defined as struct
+ db.CreateTable(&User{})
+ db.CreateTable(&Job{})
+
+ // Add index on email
+ db.Model(&User{}).AddIndex("idx_user_email", "email")
+
+ // Make database handler public
+ DB = db
+}
diff --git a/app/controllers/url.go b/app/controllers/url.go
new file mode 100644
index 0000000..516f6a6
--- /dev/null
+++ b/app/controllers/url.go
@@ -0,0 +1,28 @@
+package controllers
+
+import (
+ "crypto/md5"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+)
+
+func HashUrl(url string) (string, error) {
+ response, err := http.Get(url)
+ if err != nil {
+ return "Get request failed.", err
+ }
+
+ defer response.Body.Close()
+ contents, err := ioutil.ReadAll(response.Body)
+ if er != nil {
+ return "Reading body failed.", err
+ }
+
+ h := md5.New()
+ io.WriteString(h, string(contents))
+ hash := fmt.Sprintf("%x", h.Sum(nil))
+
+ return hash, nil
+}
diff --git a/app/init.go b/app/init.go
new file mode 100644
index 0000000..2305d73
--- /dev/null
+++ b/app/init.go
@@ -0,0 +1,38 @@
+package app
+
+import "github.com/revel/revel"
+
+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(InitDB)
+ // 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.
+}
diff --git a/app/views/App/Index.html b/app/views/App/Index.html
new file mode 100644
index 0000000..deb2304
--- /dev/null
+++ b/app/views/App/Index.html
@@ -0,0 +1,23 @@
+{{set . "title" "Home"}}
+{{template "header.html" .}}
+
+It works!
+
+
+ {{.Description}} +
+ {{end}} +{{end}} + + diff --git a/app/views/errors/500.html b/app/views/errors/500.html new file mode 100644 index 0000000..0cef4de --- /dev/null +++ b/app/views/errors/500.html @@ -0,0 +1,16 @@ + + + ++ This exception has been logged. +
+ {{end}} + + diff --git a/app/views/flash.html b/app/views/flash.html new file mode 100644 index 0000000..9c9ade9 --- /dev/null +++ b/app/views/flash.html @@ -0,0 +1,18 @@ +{{if .flash.success}} +