Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
24579d86
Commit
24579d86
authored
Aug 12, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated
parent
71573fb5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
backend/api/api.go
+22
-6
No files found.
backend/api/api.go
View file @
24579d86
...
...
@@ -5,6 +5,7 @@ import (
log
"github.com/alecthomas/log4go"
"github.com/gin-gonic/gin"
"github.com/gorilla/sessions"
"github.com/torkelo/grafana-pro/backend/components"
"github.com/torkelo/grafana-pro/backend/stores"
)
...
...
@@ -17,6 +18,12 @@ type HttpServer struct {
router
*
gin
.
Engine
}
var
sessionStore
=
sessions
.
NewCookieStore
([]
byte
(
"something-very-secret"
))
// var hashKey = []byte("very-secret")
// var blockKey = []byte("a-lot-secret")
// var s = securecookie.New(hashKey, blockKey)
func
NewHttpServer
(
port
string
,
store
stores
.
Store
)
*
HttpServer
{
self
:=
&
HttpServer
{}
self
.
port
=
port
...
...
@@ -26,18 +33,13 @@ func NewHttpServer(port string, store stores.Store) *HttpServer {
return
self
}
func
CacheHeadersMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
c
.
Writer
.
Header
()
.
Add
(
"Cache-Control"
,
"max-age=0, public, must-revalidate, proxy-revalidate"
)
}
}
func
(
self
*
HttpServer
)
ListenAndServe
()
{
log
.
Info
(
"Starting Http Listener on port %v"
,
self
.
port
)
defer
func
()
{
self
.
shutdown
<-
true
}()
self
.
router
=
gin
.
Default
()
self
.
router
.
Use
(
CacheHeadersMiddleware
())
self
.
router
.
Use
(
self
.
AuthMiddleware
())
// register & parse templates
templates
:=
template
.
New
(
"templates"
)
...
...
@@ -62,6 +64,20 @@ func (self *HttpServer) index(c *gin.Context) {
c
.
HTML
(
200
,
"index.html"
,
&
indexViewModel
{
title
:
"hello from go"
})
}
func
(
self
*
HttpServer
)
AuthMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
session
.
Values
[
"asd"
]
=
1
session
.
Save
(
c
.
Request
,
c
.
Writer
)
}
}
func
CacheHeadersMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
c
.
Writer
.
Header
()
.
Add
(
"Cache-Control"
,
"max-age=0, public, must-revalidate, proxy-revalidate"
)
}
}
// Api Handler Registration
var
routeHandlers
=
make
([]
routeHandlerRegisterFn
,
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment