Dmitry Yu Okunev лет назад: 6
Сommit
178f85e76f

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+test-results/
+tmp/
+routes/

+ 1 - 0
README.md

@@ -0,0 +1 @@
+Code of https://api.cps.mephi.ru/

+ 13 - 0
app/controllers/app.go

@@ -0,0 +1,13 @@
+package controllers
+
+import (
+	"github.com/revel/revel"
+)
+
+type App struct {
+	*revel.Controller
+}
+
+func (c App) Index() revel.Result {
+	return c.Render()
+}

+ 59 - 0
app/init.go

@@ -0,0 +1,59 @@
+package app
+
+import (
+	"github.com/revel/revel"
+)
+
+var (
+	// AppVersion revel app version (ldflags)
+	AppVersion string
+
+	// BuildTime revel app build-time (ldflags)
+	BuildTime string
+)
+
+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
+	// 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)
+}
+
+// HeaderFilter adds common security headers
+// 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) {
+	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.
+}
+
+//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
+//	}
+//}

+ 21 - 0
app/views/App/Index.html

@@ -0,0 +1,21 @@
+{{set . "title" "Home"}}
+{{template "header.html" .}}
+
+<header class="jumbotron" style="background-color:#A9F16C">
+  <div class="container">
+    <div class="row">
+      <h1>It works!</h1>
+      <p></p>
+    </div>
+  </div>
+</header>
+
+<div class="container">
+  <div class="row">
+    <div class="span6">
+      {{template "flash.html" .}}
+    </div>
+  </div>
+</div>
+
+{{template "footer.html" .}}

+ 64 - 0
app/views/debug.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="glyphicon glyphicon-chevron-left"></i></a>
+
+<script>
+	$sidebar = 0;
+	$('#toggleSidebar').click(function() {
+		if ($sidebar === 1) {
+			$('#sidebar').hide();
+			$('#toggleSidebar i').addClass('glyphicon-chevron-left');
+			$('#toggleSidebar i').removeClass('glyphicon-chevron-right');
+			$sidebar = 0;
+		}
+		else {
+			$('#sidebar').show();
+			$('#toggleSidebar i').addClass('glyphicon-chevron-right');
+			$('#toggleSidebar i').removeClass('glyphicon-chevron-left');
+			$sidebar = 1;
+		}
+
+    return false;
+	});
+</script>

+ 20 - 0
app/views/errors/404.html

@@ -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>

+ 16 - 0
app/views/errors/500.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>

+ 18 - 0
app/views/flash.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-danger">
+	{{if .flash.error}}
+		{{.flash.error}}
+	{{end}}
+	<ul style="margin-top:10px;">
+		{{range .errors}}
+			<li>{{.}}</li>
+		{{end}}
+	</ul>
+</div>
+{{end}}

+ 5 - 0
app/views/footer.html

@@ -0,0 +1,5 @@
+  {{if eq .RunMode "dev"}}
+    {{template "debug.html" .}}
+  {{end}}
+  </body>
+</html>

+ 19 - 0
app/views/header.html

@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+
+<html>
+  <head>
+    <title>{{.title}}</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <link rel="stylesheet" type="text/css" href="/public/css/bootstrap-3.3.6.min.css">
+    <link rel="shortcut icon" type="image/png" href="/public/img/favicon.png">
+    <script src="/public/js/jquery-2.2.4.min.js"></script>
+    <script src="/public/js/bootstrap-3.3.6.min.js"></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>

+ 258 - 0
conf/app.conf

@@ -0,0 +1,258 @@
+################################################################################
+# Revel configuration file
+# More info at http://revel.github.io/manual/appconf.html
+################################################################################
+
+# Sets `revel.AppName` for use in-app.
+# Example:
+#   `if revel.AppName {...}`
+app.name = api.cps
+
+# 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 = yOtGFVHyE7pFj3ZlR03WcM4Wwff0pmysbvgdqXryGEfn8oUPQKzxH5GNG8z4hwC3
+
+# Revel running behind proxy like nginx, haproxy, etc.
+app.behind.proxy = false
+
+
+# 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 =
+
+
+# Timeout specifies a time limit for request (in seconds) made by a single client.
+# A Timeout of zero means no timeout.
+http.timeout.read = 90
+http.timeout.write = 60
+
+
+# For any cookies set by Revel (Session,Flash,Error) these properties will set
+# the fields of:
+# http://golang.org/pkg/net/http/#Cookie
+#
+# 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.
+#
+# Defaults to false. If 'http.ssl' is enabled, this will be defaulted to true.
+# This should only be true when Revel is handling SSL connections. If you are
+# using a proxy in front of revel (Nginx, Apache, etc), then this should be left
+# as false.
+# cookie.secure = false
+
+# Limit cookie access to a given domain.
+#cookie.domain =
+
+# Define when your session cookie expires.
+# 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     = 2006-01-02
+format.datetime = 2006-01-02 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.
+# User can override these prefix values within any section
+# For e.g: [dev], [prod], etc
+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
+
+# The default format when message is missing.
+# The original message shows in %s
+#i18n.unknown_format = "??? %s ???"
+
+
+# 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 `revel.DevMode` for use in-app.
+# Example:
+#   `if revel.DevMode {...}`
+#   or in your templates with
+#   `<no value>`
+# Values:
+# "true"
+#   Sets `DevMode` to `true`.
+# "false"
+#   Sets `DevMode` to `false`.
+mode.dev = true
+
+
+# Pretty print JSON/XML when calling RenderJSON/RenderXML
+# Values:
+# "true"
+#   Enables pretty printing.
+# "false"
+#   Disables pretty printing.
+results.pretty = true
+
+
+# Watch your applicaton files for changes and automatically rebuild
+# Values:
+# "true"
+#   Enables auto rebuilding. 
+# "false"
+#   Disables auto rebuilding.
+watch = true
+
+
+# Define when to rebuild new changes.
+# Values:
+# "normal"
+#   Rebuild when a new request is received and changes have been detected.
+# "eager"
+#   Rebuild as soon as changes are detected.
+watch.mode = normal
+
+# Watch the entire `$GOPATH` for changes.
+# Values:
+# "true"
+#   Includes `$GOPATH` in watch path.
+# "false"
+#   Excludes `$GOPATH` from watch path. Default value.
+#watch.gopath = true
+
+
+# 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
+# Values:
+# "off"
+#   Disable log output.
+# "stdout"
+#   Log to OS's standard output.
+# "stderr"
+#   Log to Os's standard error output. Default value.
+# "relative/path/to/log"
+#   Log to file.
+log.trace.output = off
+log.info.output  = stderr
+log.warn.output  = stderr
+log.error.output = stderr
+
+
+# Revel log flags. Possible flags defined by the Go `log` package. Go log is
+# "Bits OR'ed together to control what's printed
+# See:
+#   https://golang.org/pkg/log/#pkg-constants
+# Values:
+# "0"
+#   Just log the message, turn off the flags.
+# "3"
+#   log.LstdFlags (log.Ldate|log.Ltime)
+# "19"
+#   log.Ldate|log.Ltime|log.Lshortfile
+# "23"
+#   log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile
+log.trace.flags = 19
+log.info.flags  = 19
+log.warn.flags  = 19
+log.error.flags = 19
+
+
+# Revel request access log
+# Access log line format:
+# RequestStartTime ClientIP ResponseStatus RequestLatency HTTPMethod URLPath
+# Sample format:
+# 2016/05/25 17:46:37.112 127.0.0.1 200  270.157µs GET /
+log.request.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  = log/%(app.name)s.log
+log.error.output = log/%(app.name)s.log
+
+# Revel log flags. Possible flags defined by the Go `log` package,
+# please refer https://golang.org/pkg/log/#pkg-constants
+# Go log is "Bits or'ed together to control what's printed"
+# Examples:
+#   0  => just log the message, turn off the flags
+#   3  => log.LstdFlags (log.Ldate|log.Ltime)
+#   19 => log.Ldate|log.Ltime|log.Lshortfile
+#   23 => log.Ldate|log.Ltime|log.Lmicroseconds|log.Lshortfile
+log.trace.flags = 3
+log.info.flags  = 3
+log.warn.flags  = 3
+log.error.flags = 3
+
+
+# Revel request access log
+# Access log line format:
+# RequestStartTime ClientIP ResponseStatus RequestLatency HTTPMethod URLPath
+# Sample format:
+# 2016/05/25 17:46:37.112 127.0.0.1 200  270.157µs GET /
+# Example:
+#   log.request.output = %(app.name)s-request.log
+log.request.output = off

+ 19 - 0
conf/routes

@@ -0,0 +1,19 @@
+# Routes Config
+#
+# This file defines all application routes (Higher priority routes first)
+#
+
+module:testrunner
+# module:jobs
+
+
+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

+ 7 - 0
messages/sample.en

@@ -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
+

Разница между файлами не показана из-за своего большого размера
+ 5 - 0
public/css/bootstrap-3.3.6.min.css


BIN
public/fonts/glyphicons-halflings-regular.ttf


BIN
public/fonts/glyphicons-halflings-regular.woff


BIN
public/fonts/glyphicons-halflings-regular.woff2


BIN
public/img/favicon.png


Разница между файлами не показана из-за своего большого размера
+ 7 - 0
public/js/bootstrap-3.3.6.min.js


Разница между файлами не показана из-за своего большого размера
+ 4 - 0
public/js/jquery-2.2.4.min.js


+ 23 - 0
tests/apptest.go

@@ -0,0 +1,23 @@
+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")
+}