-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
141 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"html/template" | ||
"fmt" | ||
|
||
"github.com/tst_martini/models" | ||
"github.com/go-martini/martini" | ||
) | ||
|
||
var discounts map[string]*models.discounts | ||
var discounts map[string]*models.Discounts | ||
|
||
func main() { | ||
discounts := make(map[string]*models.discounts,0) | ||
discounts = make(map[string]*models.Discounts,0) | ||
m := martini.Classic() | ||
|
||
staticOptions := martini.StaticOptions{Prefix:"static"} | ||
m.Use(martini.Static("static", staticOptions)) | ||
m.Get("/", indexHandler) | ||
m.Get("/write", writeHandler) | ||
m.Get("/Save", saveDiscountsHandler) | ||
m.Get("/test", func()string{ | ||
return "That's ok!" | ||
}) | ||
|
||
m.Run() | ||
} | ||
|
||
func indexHandler( ){ | ||
func indexHandler(w http.ResponseWriter, r *http.Request){ | ||
t, err := template.ParseFiles("templates/index.html", "templates/header.html", "templates/footer.html") | ||
if err != nil{ | ||
fmt.Fprintf(w, err.Error()) | ||
} | ||
t.ExecuteTemplate(w, "index", nil) | ||
} | ||
|
||
func writeHandler(w http.ResponseWriter, r *http.Request){ | ||
t, err := template.ParseFiles("templates/index.html", "templates/header.html", "templates/footer.html") | ||
if err != nil{ | ||
fmt.Fprintf(w, err.Error()) | ||
} | ||
t.ExecuteTemplate(w, "write", nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ define "footer" }} | ||
<!-- Include all compiled plugins (below), or include individual files as needed --> | ||
<script src="static/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{{ define "header" }} | ||
|
||
<!--<!DOCTYPE html>--> | ||
<html lang="en"> | ||
<head> | ||
<h1>Hello world!</h1> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Go Blog Example</title> | ||
|
||
<!-- Bootstrap --> | ||
<link href="static/css/bootstrap.min.css" rel="stylesheet"> | ||
|
||
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> | ||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | ||
<!--[if lt IE 9]> | ||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> | ||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> | ||
<![endif]--> | ||
|
||
<link href="static/css/app.css" rel="stylesheet"> | ||
|
||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | ||
<script src="static/js/jquery-2.1.0.min.js"></script> | ||
</head> | ||
<body> | ||
|
||
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> | ||
<div class="container"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> | ||
<span class="sr-only">Toggle navigation</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="/">Go Blog Example</a> | ||
</div> | ||
<div class="collapse navbar-collapse"> | ||
<ul class="nav navbar-nav"> | ||
<li class="active"><a href="/">Home</a></li> | ||
<li><a href="/write">New Post</a></li> | ||
</ul> | ||
</div><!--/.nav-collapse --> | ||
</div> | ||
</div> | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
<div> | ||
{{ range $value := .Posts }} | ||
<div class="row"> | ||
<div class="col-xs-2"> | ||
</div> | ||
<div class="col-xs-8"> | ||
{{if $.IsAuthorized}} | ||
<h1><a href="/edit/{{$value.Id}}">{{ $value.Title }}</a></h1> | ||
{{else}} | ||
<h1><a href="/view/{{$value.Id}}">{{ $value.Title }}</a></h1> | ||
{{end}} | ||
</div> | ||
<div class="col-xs-2"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-xs-2"> | ||
</div> | ||
<div class="col-xs-8"> | ||
{{ $value.ContentHtml | unescape }} | ||
</div> | ||
<div class="col-xs-2"> | ||
</div> | ||
</div> | ||
{{ end }} | ||
{{ define "index" }} | ||
|
||
{{ template "header" }} | ||
|
||
{{ range $key, $value := . }} | ||
<div class="row"> | ||
<div class="col-xs-2"> | ||
</div> | ||
<div class="col-xs-8"> | ||
<h1><a href="/edit?id={{$key}}">{{ $value.description }}</a></h1> | ||
</div> | ||
<div class="col-xs-2"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-xs-2"> | ||
</div> | ||
<div class="col-xs-8"> | ||
<!--{{ $value.Content }}--> | ||
</div> | ||
<div class="col-xs-2"> | ||
</div> | ||
</div> | ||
{{ end }} | ||
|
||
{{ template "footer" }} | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{ define "write" }} | ||
|
||
{{ template "header" }} | ||
|
||
<div class="row"> | ||
<div class="col-xs-4"> | ||
</div> | ||
<div class="col-xs-4"> | ||
<form role="form" method="POST" action="/Save"> | ||
<input type="hidden" name="id" value="{{.Id}}" /> | ||
<div class="form-group"> | ||
<label>Title</label> | ||
<input type="text" class="form-control" id="title" name="title" value="{{.Title}}" /> | ||
</div> | ||
<div class="form-group"> | ||
<label>Description</label> | ||
<textarea id="content" name="content">{{.Content}}</textarea> | ||
</div> | ||
<button type="submit" class="btn btn-default">Submit</button> | ||
</form> | ||
|
||
</div> | ||
<div class="col-xs-4"> | ||
{{ if .Id }} | ||
<a href="/delete?id={{.Id}}">Delete</a> | ||
{{ end }} | ||
</div> | ||
</div> | ||
|
||
{{ template "footer" }} | ||
|
||
{{ end }} |