From cb5f3037bb18403433c2cfd0271f6bea76906aca Mon Sep 17 00:00:00 2001
From: Horus_Arch
Date: Wed, 18 Feb 2015 17:03:41 +0100
Subject: Reimplementation with gorilla toolkit.
---
.gitignore | 4 +-
Makefile | 17 +
app/controllers/app.go | 11 -
app/controllers/db.go | 38 -
app/controllers/utilities.go | 96 -
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 -
db.go | 40 +
fetch.go | 9 +
handler.go | 63 +
main.go | 25 +
messages/sample.en | 7 -
public/css/bootstrap.css | 5774 -----------------------------
public/img/favicon.png | Bin 5639 -> 0 bytes
public/img/glyphicons-halflings-white.png | Bin 8777 -> 0 bytes
public/img/glyphicons-halflings.png | Bin 12799 -> 0 bytes
public/js/jquery-1.9.1.min.js | 5 -
struct.go | 37 +
templates/admin/admin.html | 0
templates/footer.html | 16 +
templates/header.html | 19 +
templates/index/index.html | 0
templates/jobs.html | 9 +
templates/login/login.html | 0
templates/navbar.html | 23 +
templates/register/register.html | 0
tests/apptest.go | 21 -
utilities.go | 95 +
36 files changed, 354 insertions(+), 6330 deletions(-)
create mode 100644 Makefile
delete mode 100644 app/controllers/app.go
delete mode 100644 app/controllers/db.go
delete mode 100644 app/controllers/utilities.go
delete mode 100644 app/init.go
delete mode 100644 app/views/App/Index.html
delete mode 100644 app/views/debug.html
delete mode 100644 app/views/errors/404.html
delete mode 100644 app/views/errors/500.html
delete mode 100644 app/views/flash.html
delete mode 100644 app/views/footer.html
delete mode 100644 app/views/header.html
delete mode 100644 conf/app.conf
delete mode 100644 conf/routes
create mode 100644 db.go
create mode 100644 fetch.go
create mode 100644 handler.go
create mode 100644 main.go
delete mode 100644 messages/sample.en
delete mode 100644 public/css/bootstrap.css
delete mode 100644 public/img/favicon.png
delete mode 100644 public/img/glyphicons-halflings-white.png
delete mode 100644 public/img/glyphicons-halflings.png
delete mode 100644 public/js/jquery-1.9.1.min.js
create mode 100644 struct.go
create mode 100644 templates/admin/admin.html
create mode 100644 templates/footer.html
create mode 100644 templates/header.html
create mode 100644 templates/index/index.html
create mode 100644 templates/jobs.html
create mode 100644 templates/login/login.html
create mode 100644 templates/navbar.html
create mode 100644 templates/register/register.html
delete mode 100644 tests/apptest.go
create mode 100644 utilities.go
diff --git a/.gitignore b/.gitignore
index 70a8117..37ab148 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,2 @@
-test-results/
-tmp/
-routes/
*.swp
+*.db
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..64c916d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,17 @@
+export STATUS_DB_DRIVER:=sqlite3
+export STATUS_DB_CREDENTIALS:=status.db
+
+all: kill build run
+
+clean:
+ rm status.db
+ rm statuspage
+
+build:
+ go build
+
+run:
+ ./statuspage &
+
+kill:
+ pkill statuspage || true
diff --git a/app/controllers/app.go b/app/controllers/app.go
deleted file mode 100644
index e76d76b..0000000
--- a/app/controllers/app.go
+++ /dev/null
@@ -1,11 +0,0 @@
-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
deleted file mode 100644
index e96cb63..0000000
--- a/app/controllers/db.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package controllers
-
-import (
- "github.com/jinzhu/gorm"
- _ "github.com/mattn/go-sqlite3"
- "github.com/revel/revel"
- "time"
-)
-
-/* Maybe worth saving uptime history? */
-
-type Hosts struct {
- Id int64
- UserId int64
- Url string
- Protocoll string // e.g. http
- Private bool
- Response int64
- Date time.Time
- Success bool
- Include string // Website must include this string
- Except string // Website must not include this string
- Reason string // Include, Exclude, Connection failure
- Alert bool // True to send alert on failure
- CreatedAt time.Time
- DeletedAt time.Time
- UpdatedAt time.Time
-}
-
-type User struct {
- Id int64
- Name string
- Email string
- Password string
- CreatedAt time.Time
- DeletedAt time.Time
- UpdatedAt time.Time
-}
diff --git a/app/controllers/utilities.go b/app/controllers/utilities.go
deleted file mode 100644
index 99720b8..0000000
--- a/app/controllers/utilities.go
+++ /dev/null
@@ -1,96 +0,0 @@
-package controllers
-
-import (
- "crypto/md5"
- "fmt"
- // "github.com/garyburd/redigo/redis"
- "github.com/revel/revel"
- "golang.org/x/crypto/bcrypt"
- "io"
- "io/ioutil"
- "math/rand"
- "net/http"
- "time"
-)
-
-// Returns the content of a webpage as string
-func HttpGet(url string) (http.Header, string, error) {
- response, err := http.Get(url)
- if err != nil {
- return nil, "Get request failed.", err
- }
-
- defer response.Body.Close()
- contents, err := ioutil.ReadAll(response.Body)
- if err != nil {
- return nil, "Reading body failed.", err
- }
-
- return response.Header, string(contents), nil
-}
-
-// Hashs and returns a string (md5)
-func Hash(content string) string {
- h := md5.New()
- io.WriteString(h, content)
- hash := fmt.Sprintf("%x", h.Sum(nil))
-
- return hash
-}
-
-// Creates a random string
-func RandomKey() string {
- letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
- key := make([]rune, 40)
- for i := range key {
- key[i] = letters[rand.Intn(len(letters))]
- }
-
- return string(key)
-}
-
-var pool = newPool()
-
-/*
-// Creates a pool with connections to Redis
-func newPool() *redis.Pool {
- return &redis.Pool{
- MaxIdle: 3,
- IdleTimeout: 240 * time.Second,
- Dial: func() (redis.Conn, error) {
- //c, err := redis.Dial("tcp", ":6379")
- c, err := redis.Dial("tcp", revel.Config.StringDefault("redis.server", "127.0.0.1")+":"+revel.Config.StringDefault("redis.port", "6379"))
- if err != nil {
- return nil, err
- }
- return c, err
- },
- TestOnBorrow: func(c redis.Conn, t time.Time) error {
- _, err := c.Do("PING")
- return err
- },
- }
-}
-*/
-
-// Hashs password with bcrypt and returns the string
-func HashPassword(password string) (string, error) {
- if password == "" {
- return "", nil
- }
- p := []byte(password)
- hash, err := bcrypt.GenerateFromPassword(p, 10)
- if err != nil {
- return "", err
- }
- return string(hash), nil
-}
-
-// Verify password and hash
-func VerifyPassword(password, hash string) (bool, error) {
- err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
- if err != nil {
- return false, err
- }
- return true, nil
-}
diff --git a/app/init.go b/app/init.go
deleted file mode 100644
index 2305d73..0000000
--- a/app/init.go
+++ /dev/null
@@ -1,38 +0,0 @@
-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
deleted file mode 100644
index deb2304..0000000
--- a/app/views/App/Index.html
+++ /dev/null
@@ -1,23 +0,0 @@
-{{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 deleted file mode 100644 index 0cef4de..0000000 --- a/app/views/errors/500.html +++ /dev/null @@ -1,16 +0,0 @@ - - - -- This exception has been logged. -
- {{end}} - - diff --git a/app/views/flash.html b/app/views/flash.html deleted file mode 100644 index 9c9ade9..0000000 --- a/app/views/flash.html +++ /dev/null @@ -1,18 +0,0 @@ -{{if .flash.success}} -