10.12.2018
This commit is contained in:
parent
4091075186
commit
83a5778208
8
bower_components/css/app.css
vendored
8
bower_components/css/app.css
vendored
@ -0,0 +1,8 @@
|
|||||||
|
body {
|
||||||
|
padding-top: 65px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 200px;
|
||||||
|
}
|
32
main.go
32
main.go
@ -4,9 +4,26 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/blog/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var posts map[string]*models.Post
|
||||||
|
|
||||||
func index(w http.ResponseWriter, r *http.Request) {
|
func index(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Println(posts)
|
||||||
|
t, err := template.ParseFiles(
|
||||||
|
"views/write.html",
|
||||||
|
"views/header.html",
|
||||||
|
"views/footer.html",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(w, err.Error())
|
||||||
|
}
|
||||||
|
t.ExecuteTemplate(w, "write", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func write(w http.ResponseWriter, r *http.Request) {
|
||||||
t, err := template.ParseFiles(
|
t, err := template.ParseFiles(
|
||||||
"views/index.html",
|
"views/index.html",
|
||||||
"views/header.html",
|
"views/header.html",
|
||||||
@ -18,11 +35,24 @@ func index(w http.ResponseWriter, r *http.Request) {
|
|||||||
t.ExecuteTemplate(w, "index", nil)
|
t.ExecuteTemplate(w, "index", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func savePost(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id := r.FormValue("id")
|
||||||
|
title := r.FormValue("title")
|
||||||
|
content := r.FormValue("content")
|
||||||
|
|
||||||
|
post := models.NewPost(id, title, content)
|
||||||
|
post[post.Id] = post
|
||||||
|
http.Redirect(w, r, "/", 302)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
posts = make(map[string]*models.Post, 0)
|
||||||
fmt.Println("Listening port 8080")
|
fmt.Println("Listening port 8080")
|
||||||
|
|
||||||
http.Handle("/bower_components", http.StripPrefix("/bower_components/", http.FileServer(http.Dir("./bower_components"))))
|
http.Handle("/bower_components/", http.StripPrefix("/bower_components/", http.FileServer(http.Dir("./bower_components/"))))
|
||||||
http.HandleFunc("/", index)
|
http.HandleFunc("/", index)
|
||||||
|
http.HandleFunc("/write", write)
|
||||||
|
http.HandleFunc("/savePost", savePost)
|
||||||
|
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="active"><a href="/">Home</a></li>
|
<li class="active"><a href="/">Home</a></li>
|
||||||
|
<li><a href="/write">New Post</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
11
views/models/post.go
Normal file
11
views/models/post.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
type Psot struct {
|
||||||
|
Id string
|
||||||
|
Title string
|
||||||
|
Content string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPost(id, title, content string) *Post {
|
||||||
|
return &Post{id, title, content}
|
||||||
|
}
|
27
views/write.html
Normal file
27
views/write.html
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{{ define "write" }}
|
||||||
|
|
||||||
|
{{ template "header" }}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-4"></div>
|
||||||
|
<div class="col-xs-4">
|
||||||
|
<form action="/savePost" method="POST" role="form">
|
||||||
|
<input type="hidden" name="id"/>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="title">Tytul</label>
|
||||||
|
<input type="text" class="form-control" id="title" name="title"/>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="content">Content</label>
|
||||||
|
<textarea name="content" id="content"></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-default">Submit</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-4">
|
||||||
|
<a href="deletePost">Usun</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ template "footer" }}
|
||||||
|
|
||||||
|
{{ end }}
|
Loading…
Reference in New Issue
Block a user