Пример #1
0
func main() {
	fs, err := filestore.New("s3")
	if err != nil {
		log.Fatal(err)
	}

	port := os.Getenv("PORT")
	m := martini.Classic()
	m.Map(fs)
	m.Use(martini.Static("../web/public"))
	m.Use(render.Renderer(render.Options{
		Directory: "../web/templates",
		Layout:    "layout",
	}))
	m.Get("/", func(fs *filestore.S3, r render.Render) {
		files, err := fs.List("builds")
		sort.Sort(ByTime(files))
		if err != nil {
			log.Fatal(err)
		}

		r.HTML(200, "home", files)
	})

	log.Printf("starting server at %s", port)
	err = http.ListenAndServe(":"+port, m)
	if err != nil {
		log.Fatal(err)
	}
}
Пример #2
0
func uploadZipfile(outzip string) error {
	zipfile, err := os.Open(outzip)
	if err != nil {
		return err
	}
	defer zipfile.Close()

	filename := fmt.Sprintf("/builds/%s", filepath.Base(outzip))
	ds, err := filestore.New("s3")
	if err != nil {
		return err
	}
	err = ds.Upload(filename, "application/zip", zipfile)
	if err != nil {
		return err
	}

	log.Printf("uploaded to s3 %s", filename)

	return nil
}