Commit 10c57b29 authored by Ronny Bangsund's avatar Ronny Bangsund

Added mutex.

parent 6968a570
......@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/hoisie/web"
"html/template"
"sync"
"time"
)
......@@ -27,6 +28,7 @@ type ScrapLink struct {
var indexTemplate, indexerr = template.ParseFiles("tpl/index.tpl")
var links = []ScrapLink{}
var share sync.Mutex
func initWeb() {
info("Launching web service.")
......@@ -61,7 +63,6 @@ func get_index(ctx *web.Context, arg string) {
var lang string
if arg != "" {
s = loadScrap(sane(arg))
info("Links: %d (%d)", len(links), len(scraps))
if !s.hasExpired() {
view = true
lang = s.Language
......@@ -126,13 +127,14 @@ func post_scrap(ctx *web.Context) {
func buildLinks() {
i := 0
share.Lock()
links = []ScrapLink{}
for _, v := range scraps {
links = append(links, ScrapLink{v.Hash, v.Title, v.User})
info("Title %d:%s", i, v.Title)
i++
if i > 9 {
break
}
}
share.Unlock()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment