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

Added mutex.

parent 6968a570
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/hoisie/web" "github.com/hoisie/web"
"html/template" "html/template"
"sync"
"time" "time"
) )
...@@ -27,6 +28,7 @@ type ScrapLink struct { ...@@ -27,6 +28,7 @@ type ScrapLink struct {
var indexTemplate, indexerr = template.ParseFiles("tpl/index.tpl") var indexTemplate, indexerr = template.ParseFiles("tpl/index.tpl")
var links = []ScrapLink{} var links = []ScrapLink{}
var share sync.Mutex
func initWeb() { func initWeb() {
info("Launching web service.") info("Launching web service.")
...@@ -61,7 +63,6 @@ func get_index(ctx *web.Context, arg string) { ...@@ -61,7 +63,6 @@ func get_index(ctx *web.Context, arg string) {
var lang string var lang string
if arg != "" { if arg != "" {
s = loadScrap(sane(arg)) s = loadScrap(sane(arg))
info("Links: %d (%d)", len(links), len(scraps))
if !s.hasExpired() { if !s.hasExpired() {
view = true view = true
lang = s.Language lang = s.Language
...@@ -126,13 +127,14 @@ func post_scrap(ctx *web.Context) { ...@@ -126,13 +127,14 @@ func post_scrap(ctx *web.Context) {
func buildLinks() { func buildLinks() {
i := 0 i := 0
share.Lock()
links = []ScrapLink{} links = []ScrapLink{}
for _, v := range scraps { for _, v := range scraps {
links = append(links, ScrapLink{v.Hash, v.Title, v.User}) links = append(links, ScrapLink{v.Hash, v.Title, v.User})
info("Title %d:%s", i, v.Title)
i++ i++
if i > 9 { if i > 9 {
break 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