1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-09 16:10:01 +00:00

Remove S3

S3 storage becomes really expensive. The network latency is also worse
than local file latency.
This commit is contained in:
zainhoda 2015-03-12 01:13:45 -04:00
parent 3f7e71c0c9
commit ba4ccee98c
3 changed files with 21 additions and 17 deletions

23
main.go
View file

@ -5,13 +5,13 @@ import (
"fmt"
"io/ioutil"
"net/http"
"os"
//"os"
"time"
"log"
//"log"
"launchpad.net/goamz/aws"
"launchpad.net/goamz/s3"
//"launchpad.net/goamz/aws"
//"launchpad.net/goamz/s3"
"github.com/flosch/pongo2"
"github.com/go-martini/martini"
@ -20,18 +20,19 @@ import (
)
var templates = make(map[string]*pongo2.Template)
var s3Storage *s3.Bucket
//var s3Storage *s3.Bucket
func main() {
preloadTemplates()
// Initialize S3 storage
awsAuth, err := aws.EnvAuth()
if err != nil {
log.Fatal(err)
}
s3Conn := s3.New(awsAuth, aws.USEast)
s3Storage = s3Conn.Bucket(os.Getenv("S3Bucket"))
//awsAuth, err := aws.EnvAuth()
//if err != nil {
// log.Fatal(err)
//}
//s3Conn := s3.New(awsAuth, aws.USEast)
//s3Storage = s3Conn.Bucket(os.Getenv("S3Bucket"))
m := martini.Classic()

View file

@ -3,8 +3,10 @@ package main
import (
"encoding/json"
"errors"
"launchpad.net/goamz/s3"
"io/ioutil"
//"launchpad.net/goamz/s3"
"log"
//"os"
"sort"
"strconv"
"time"
@ -17,7 +19,7 @@ type dashboard struct {
}
func loadDashboard(dashid string) (*dashboard, error) {
data, err := s3Storage.Get(dashid)
data, err := ioutil.ReadFile(dashid + ".txt")
if err != nil {
return &dashboard{}, errors.New("Dashboard not found")
}
@ -34,7 +36,8 @@ func (d *dashboard) Save() {
log.Printf("Error while marshalling dashboard: %s", err)
return
}
err = s3Storage.Put(d.DashboardID, data, "application/json", s3.Private)
err = ioutil.WriteFile(d.DashboardID+".txt", data, 0600)
if err != nil {
log.Printf("Error while storing dashboard: %s", err)
}

View file

@ -19,10 +19,10 @@ func handleRedirectWelcome(res http.ResponseWriter, req *http.Request) {
func handleCreateRandomDashboard(res http.ResponseWriter, req *http.Request) {
urlProposal := generateAPIKey()[0:20]
_, err := s3Storage.Get(urlProposal)
_, err := ioutil.ReadFile(urlProposal + ".txt")
for err == nil {
urlProposal = generateAPIKey()[0:20]
_, err = s3Storage.Get(urlProposal)
_, err = ioutil.ReadFile(urlProposal + ".txt")
}
http.Redirect(res, req, fmt.Sprintf("/%s", urlProposal), http.StatusTemporaryRedirect)
}
@ -62,7 +62,7 @@ func handleDeleteDashboard(params martini.Params, req *http.Request, res http.Re
return
}
_ = s3Storage.Del(params["dashid"])
//_ = s3Storage.Del(params["dashid"])
http.Error(res, "OK", http.StatusOK)
}