From 97b2901e7da38e76bf820f14d0cd7e5c38670b4e Mon Sep 17 00:00:00 2001 From: Sangbum Kim Date: Thu, 10 Mar 2016 00:28:35 +0900 Subject: [PATCH] adding template engine --- asset/template/index.html | 1351 +--------------------------- asset/template/index__.html | 1349 +++++++++++++++++++++++++++ asset/template/layout/base.html | 18 + asset/template/layout/header.html | 8 +- asset/template/layout/sidebar.html | 235 ++--- main.go | 11 +- util/ginrus.go | 51 ++ 7 files changed, 1549 insertions(+), 1474 deletions(-) create mode 100644 asset/template/index__.html create mode 100644 asset/template/layout/base.html create mode 100644 util/ginrus.go diff --git a/asset/template/index.html b/asset/template/index.html index 0947731..9e78227 100755 --- a/asset/template/index.html +++ b/asset/template/index.html @@ -1,1349 +1,6 @@ - - +{% extends "layout/base.html" %} - - - - - - +{% block content %} +

hello

- Gentallela Alela! | - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
- -
-
- - -
- - -
-
- ... -
-
- Welcome, -

Anthony Fernando

-
-
- - -
- - - - - - - - -
-
- - - - - - - -
- - -
-
-
-
- Total Users -
2500
- 4% From last Week -
-
-
-
-
- Average Time -
123.50
- 3% From last Week -
-
-
-
-
- Total Males -
2,500
- 34% From last Week -
-
-
-
-
- Total Females -
4,567
- 12% From last Week -
-
-
-
-
- Total Collections -
2,315
- 34% From last Week -
-
-
-
-
- Total Connections -
7,325
- 34% From last Week -
-
- -
- - -
-
-
- -
-
-

Network Activities Graph title sub-title

-
-
-
- - December 30, 2014 - January 28, 2015 -
-
-
- -
- -
-
-
-
-
-
-

Top Campaign Performance

-
-
- -
-
-

Facebook Campaign

-
-
-
-
-
-
-
-

Twitter Campaign

-
-
-
-
-
-
-
-
-
-

Conventional Media

-
-
-
-
-
-
-
-

Bill boards

-
-
-
-
-
-
-
- -
- -
-
-
- -
-
- -
- - -
-
-
-

App Versions

- -
-
-
-

App Usage across versions

-
-
- 0.1.5.2 -
-
-
-
- 60% Complete -
-
-
-
- 123k -
-
-
- -
-
- 0.1.5.3 -
-
-
-
- 60% Complete -
-
-
-
- 53k -
-
-
-
-
- 0.1.5.4 -
-
-
-
- 60% Complete -
-
-
-
- 23k -
-
-
-
-
- 0.1.5.5 -
-
-
-
- 60% Complete -
-
-
-
- 3k -
-
-
-
-
- 0.1.5.6 -
-
-
-
- 60% Complete -
-
-
-
- 1k -
-
-
- -
-
-
- -
-
-
-

Device Usage

- -
-
-
- - - - - - - - - - -
-

Top 5

-
-
-

Device

-
-
-

Progress

-
-
- - - - - - - - - - - - - - - - - - - - - - - -
-

IOS

-
30%
-

Android

-
10%
-

Blackberry

-
20%
-

Symbian

-
15%
-

Others

-
30%
-
-
-
-
- - -
-
-
-

Quick Settings

- -
-
-
-
- - - -
-
-
-
- -
- - -
-
-
-
-

Recent Activities Sessions

- -
-
-
-
- - -
-
-
-
- - -
- - - -
- -
-
-
-

Visitors location geo-presentation

- -
-
-
-
-
-

125.7k Views from 60 countries

- - - - - - - - - - - - - - - - - - - - - - - - -
United States33%
France27%
Germany16%
Spain11%
Britain10%
-
-
-
-
-
-
- -
-
- - - -
-
-
-

To Do List Sample tasks

- -
-
-
- -
-
    -
  • -

    - Schedule meeting with new client

    -
  • -
  • -

    - Create email address for new intern

    -
  • -
  • -

    - Have IT fix the network printer

    -
  • -
  • -

    - Copy backups to offsite location

    -
  • -
  • -

    - Food truck fixie locavors mcsweeney

    -
  • -
  • -

    - Food truck fixie locavors mcsweeney

    -
  • -
  • -

    - Create email address for new intern

    -
  • -
  • -

    - Have IT fix the network printer

    -
  • -
  • -

    - Copy backups to offsite location

    -
  • -
-
-
-
-
- - - - -
-
-
-

Daily active users Sessions

- -
-
-
-
-
-
Monday, 07:30 AM - F - C - -
-
-
-
-
-
- - - - -
-
-
-
-

Texas -
Partly Cloudy Day -

-
-
-
-
-
-

23

-
-
-
- - -
-
-
-

Mon

-

25

- - - - - -
15 - km/h -
-
-
-
-
-

Tue

-

25

- -
12 - km/h -
-
-
-
-
-

Wed

-

27

- -
14 - km/h -
-
-
-
-
-

Thu

-

28

- -
15 - km/h -
-
-
-
-
-

Fri

-

28

- -
11 - km/h -
-
-
-
-
-

Sat

-

26

- -
10 - km/h -
-
-
-
-
-
-
- -
- -
- - - - - - - - - -
- -
- - - -
-
-

Gentelella Alela! a Bootstrap 3 template by Colorlib. | - Gentelella Alela! -

-
-
-
- -
- - -
- -
- -
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +{% endblock %} \ No newline at end of file diff --git a/asset/template/index__.html b/asset/template/index__.html new file mode 100644 index 0000000..0947731 --- /dev/null +++ b/asset/template/index__.html @@ -0,0 +1,1349 @@ + + + + + + + + + + + Gentallela Alela! | + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ +
+
+ + +
+ + +
+
+ ... +
+
+ Welcome, +

Anthony Fernando

+
+
+ + +
+ + + + + + + + +
+
+ + + + + + + +
+ + +
+
+
+
+ Total Users +
2500
+ 4% From last Week +
+
+
+
+
+ Average Time +
123.50
+ 3% From last Week +
+
+
+
+
+ Total Males +
2,500
+ 34% From last Week +
+
+
+
+
+ Total Females +
4,567
+ 12% From last Week +
+
+
+
+
+ Total Collections +
2,315
+ 34% From last Week +
+
+
+
+
+ Total Connections +
7,325
+ 34% From last Week +
+
+ +
+ + +
+
+
+ +
+
+

Network Activities Graph title sub-title

+
+
+
+ + December 30, 2014 - January 28, 2015 +
+
+
+ +
+ +
+
+
+
+
+
+

Top Campaign Performance

+
+
+ +
+
+

Facebook Campaign

+
+
+
+
+
+
+
+

Twitter Campaign

+
+
+
+
+
+
+
+
+
+

Conventional Media

+
+
+
+
+
+
+
+

Bill boards

+
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+
+
+

App Versions

+ +
+
+
+

App Usage across versions

+
+
+ 0.1.5.2 +
+
+
+
+ 60% Complete +
+
+
+
+ 123k +
+
+
+ +
+
+ 0.1.5.3 +
+
+
+
+ 60% Complete +
+
+
+
+ 53k +
+
+
+
+
+ 0.1.5.4 +
+
+
+
+ 60% Complete +
+
+
+
+ 23k +
+
+
+
+
+ 0.1.5.5 +
+
+
+
+ 60% Complete +
+
+
+
+ 3k +
+
+
+
+
+ 0.1.5.6 +
+
+
+
+ 60% Complete +
+
+
+
+ 1k +
+
+
+ +
+
+
+ +
+
+
+

Device Usage

+ +
+
+
+ + + + + + + + + + +
+

Top 5

+
+
+

Device

+
+
+

Progress

+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+

IOS

+
30%
+

Android

+
10%
+

Blackberry

+
20%
+

Symbian

+
15%
+

Others

+
30%
+
+
+
+
+ + +
+
+
+

Quick Settings

+ +
+
+
+
+ + + +
+
+
+
+ +
+ + +
+
+
+
+

Recent Activities Sessions

+ +
+
+
+
+ + +
+
+
+
+ + +
+ + + +
+ +
+
+
+

Visitors location geo-presentation

+ +
+
+
+
+
+

125.7k Views from 60 countries

+ + + + + + + + + + + + + + + + + + + + + + + + +
United States33%
France27%
Germany16%
Spain11%
Britain10%
+
+
+
+
+
+
+ +
+
+ + + +
+
+
+

To Do List Sample tasks

+ +
+
+
+ +
+
    +
  • +

    + Schedule meeting with new client

    +
  • +
  • +

    + Create email address for new intern

    +
  • +
  • +

    + Have IT fix the network printer

    +
  • +
  • +

    + Copy backups to offsite location

    +
  • +
  • +

    + Food truck fixie locavors mcsweeney

    +
  • +
  • +

    + Food truck fixie locavors mcsweeney

    +
  • +
  • +

    + Create email address for new intern

    +
  • +
  • +

    + Have IT fix the network printer

    +
  • +
  • +

    + Copy backups to offsite location

    +
  • +
+
+
+
+
+ + + + +
+
+
+

Daily active users Sessions

+ +
+
+
+
+
+
Monday, 07:30 AM + F + C + +
+
+
+
+
+
+ + + + +
+
+
+
+

Texas +
Partly Cloudy Day +

+
+
+
+
+
+

23

+
+
+
+ + +
+
+
+

Mon

+

25

+ + + + + +
15 + km/h +
+
+
+
+
+

Tue

+

25

+ +
12 + km/h +
+
+
+
+
+

Wed

+

27

+ +
14 + km/h +
+
+
+
+
+

Thu

+

28

+ +
15 + km/h +
+
+
+
+
+

Fri

+

28

+ +
11 + km/h +
+
+
+
+
+

Sat

+

26

+ +
10 + km/h +
+
+
+
+
+
+
+ +
+ +
+ + + + + + + + + +
+ +
+ + + +
+
+

Gentelella Alela! a Bootstrap 3 template by Colorlib. | + Gentelella Alela! +

+
+
+
+ +
+ + +
+ +
+ +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/asset/template/layout/base.html b/asset/template/layout/base.html new file mode 100644 index 0000000..97314b6 --- /dev/null +++ b/asset/template/layout/base.html @@ -0,0 +1,18 @@ + + + + {% include "header.html" %} + + + + + +
+ {% block content %}{% endblock %} +
+ + \ No newline at end of file diff --git a/asset/template/layout/header.html b/asset/template/layout/header.html index 62ddd18..3d4b9bc 100644 --- a/asset/template/layout/header.html +++ b/asset/template/layout/header.html @@ -3,14 +3,14 @@ -Gentallela Alela! | +{% block title %}Mnemonics{% endblock %}-Amuz.es - + - - + + - - +
+     
+   +          +   +         
+             
+                 ... +             
+             
+                 Welcome, +                 

Anthony Mutisya

+             
+         
+   +         
+          +   +          +     
+
\ No newline at end of file diff --git a/main.go b/main.go index a970b07..a0e9e2d 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,6 @@ package main import ( "github.com/gin-gonic/gin" "github.com/Sirupsen/logrus" - "github.com/gin-gonic/contrib/ginrus" "runtime" "time" "flag" @@ -31,6 +30,7 @@ import ( var argIp = flag.String("listen_ip", "", "IP to listen on, defaults to all IPs") var argPort = flag.Int("port", 8080, "port to listen") var maxProcs = flag.Int("max_procs", 0, "max number of CPUs that can be used simultaneously. Less than 1 for default (number of cores).") +var logger = logrus.New() func main() { flag.Parse() @@ -38,7 +38,7 @@ func main() { r := gin.New() - r.Use(ginrus.Ginrus(logrus.StandardLogger(), time.RFC3339, true)) + r.Use(util.Ginrus(logrus.StandardLogger(), time.RFC3339, true)) r.Use(gin.Recovery()) @@ -47,10 +47,9 @@ func main() { }) - logger := logrus.New() logger.Level = logrus.ErrorLevel - logger.SetOutput(os.Stderr) - r.Use(ginrus.Ginrus(logger, time.RFC3339, false)) + logger.Out=os.Stderr + r.Use(util.Ginrus(logger, time.RFC3339, false)) r.StaticFS("/static", route.Static("")) r.GET("/api", route.Api) @@ -84,6 +83,6 @@ func setMaxProcs() { // Check if the setting was successful. actualNumProcs := runtime.GOMAXPROCS(0) if actualNumProcs != numProcs { - logger.Warningf("Specified max procs of %v but using %v", numProcs, actualNumProcs) + logger.Warnf("Specified max procs of %v but using %v", numProcs, actualNumProcs) } } diff --git a/util/ginrus.go b/util/ginrus.go new file mode 100644 index 0000000..66abafb --- /dev/null +++ b/util/ginrus.go @@ -0,0 +1,51 @@ +// Package ginrus provides log handling using logrus package. +// +// Based on github.com/stephenmuss/ginerus but adds more options. +package util + +import ( + "time" + + "github.com/Sirupsen/logrus" + "github.com/gin-gonic/gin" +) + +// Ginrus returns a gin.HandlerFunc (middleware) that logs requests using logrus. +// +// Requests with errors are logged using logrus.Error(). +// Requests without errors are logged using logrus.Info(). +// +// It receives: +// 1. A time package format string (e.g. time.RFC3339). +// 2. A boolean stating whether to use UTC time zone or local. +func Ginrus(logger *logrus.Logger, timeFormat string, utc bool) gin.HandlerFunc { + return func(c *gin.Context) { + start := time.Now() + // some evil middlewares modify this values + path := c.Request.URL.Path + c.Next() + + end := time.Now() + latency := end.Sub(start) + if utc { + end = end.UTC() + } + + entry := logger.WithFields(logrus.Fields{ + "status": c.Writer.Status(), + "method": c.Request.Method, + "path": path, + "ip": c.ClientIP(), + "latency": latency, + "user-agent": c.Request.UserAgent(), + "time": end.Format(timeFormat), + }) + + if len(c.Errors) > 0 { + // Append error field if this is an erroneous request. + entry.Error(c.Errors.String()) + } else { + entry.Info() + } + } +}