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"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
//"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
//"log"
|
"log"
|
||||||
|
|
||||||
//"launchpad.net/goamz/aws"
|
"launchpad.net/goamz/aws"
|
||||||
//"launchpad.net/goamz/s3"
|
"launchpad.net/goamz/s3"
|
||||||
|
|
||||||
"github.com/flosch/pongo2"
|
"github.com/flosch/pongo2"
|
||||||
"github.com/go-martini/martini"
|
"github.com/go-martini/martini"
|
||||||
|
@ -20,19 +20,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var templates = make(map[string]*pongo2.Template)
|
var templates = make(map[string]*pongo2.Template)
|
||||||
|
var s3Storage *s3.Bucket
|
||||||
//var s3Storage *s3.Bucket
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
preloadTemplates()
|
preloadTemplates()
|
||||||
|
|
||||||
// Initialize S3 storage
|
// Initialize S3 storage
|
||||||
//awsAuth, err := aws.EnvAuth()
|
awsAuth, err := aws.EnvAuth()
|
||||||
//if err != nil {
|
if err != nil {
|
||||||
// log.Fatal(err)
|
log.Fatal(err)
|
||||||
//}
|
}
|
||||||
//s3Conn := s3.New(awsAuth, aws.USEast)
|
s3Conn := s3.New(awsAuth, aws.USEast)
|
||||||
//s3Storage = s3Conn.Bucket(os.Getenv("S3Bucket"))
|
s3Storage = s3Conn.Bucket(os.Getenv("S3Bucket"))
|
||||||
|
|
||||||
m := martini.Classic()
|
m := martini.Classic()
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"launchpad.net/goamz/s3"
|
||||||
//"launchpad.net/goamz/s3"
|
|
||||||
"log"
|
"log"
|
||||||
//"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -19,7 +17,7 @@ type dashboard struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadDashboard(dashid string) (*dashboard, error) {
|
func loadDashboard(dashid string) (*dashboard, error) {
|
||||||
data, err := ioutil.ReadFile(dashid + ".txt")
|
data, err := s3Storage.Get(dashid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &dashboard{}, errors.New("Dashboard not found")
|
return &dashboard{}, errors.New("Dashboard not found")
|
||||||
}
|
}
|
||||||
|
@ -36,8 +34,7 @@ func (d *dashboard) Save() {
|
||||||
log.Printf("Error while marshalling dashboard: %s", err)
|
log.Printf("Error while marshalling dashboard: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(d.DashboardID+".txt", data, 0600)
|
err = s3Storage.Put(d.DashboardID, data, "application/json", s3.Private)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error while storing dashboard: %s", err)
|
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) {
|
func handleCreateRandomDashboard(res http.ResponseWriter, req *http.Request) {
|
||||||
urlProposal := generateAPIKey()[0:20]
|
urlProposal := generateAPIKey()[0:20]
|
||||||
_, err := ioutil.ReadFile(urlProposal + ".txt")
|
_, err := s3Storage.Get(urlProposal)
|
||||||
for err == nil {
|
for err == nil {
|
||||||
urlProposal = generateAPIKey()[0:20]
|
urlProposal = generateAPIKey()[0:20]
|
||||||
_, err = ioutil.ReadFile(urlProposal + ".txt")
|
_, err = s3Storage.Get(urlProposal)
|
||||||
}
|
}
|
||||||
http.Redirect(res, req, fmt.Sprintf("/%s", urlProposal), http.StatusTemporaryRedirect)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//_ = s3Storage.Del(params["dashid"])
|
_ = s3Storage.Del(params["dashid"])
|
||||||
http.Error(res, "OK", http.StatusOK)
|
http.Error(res, "OK", http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue