mirror of
https://github.com/Luzifer/mondash.git
synced 2024-12-23 04:21:18 +00:00
parent
55386a5eab
commit
36fc6ede75
3 changed files with 17 additions and 21 deletions
23
main.go
23
main.go
|
@ -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,19 +20,18 @@ 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()
|
||||
|
||||
|
|
|
@ -3,10 +3,8 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
//"launchpad.net/goamz/s3"
|
||||
"launchpad.net/goamz/s3"
|
||||
"log"
|
||||
//"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -19,7 +17,7 @@ type dashboard struct {
|
|||
}
|
||||
|
||||
func loadDashboard(dashid string) (*dashboard, error) {
|
||||
data, err := ioutil.ReadFile(dashid + ".txt")
|
||||
data, err := s3Storage.Get(dashid)
|
||||
if err != nil {
|
||||
return &dashboard{}, errors.New("Dashboard not found")
|
||||
}
|
||||
|
@ -36,8 +34,7 @@ func (d *dashboard) Save() {
|
|||
log.Printf("Error while marshalling dashboard: %s", err)
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(d.DashboardID+".txt", data, 0600)
|
||||
|
||||
err = s3Storage.Put(d.DashboardID, data, "application/json", s3.Private)
|
||||
if err != nil {
|
||||
log.Printf("Error while storing dashboard: %s", err)
|
||||
}
|
||||
|
|
|
@ -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 := ioutil.ReadFile(urlProposal + ".txt")
|
||||
_, err := s3Storage.Get(urlProposal)
|
||||
for err == nil {
|
||||
urlProposal = generateAPIKey()[0:20]
|
||||
_, err = ioutil.ReadFile(urlProposal + ".txt")
|
||||
_, err = s3Storage.Get(urlProposal)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue