No Description

Darko Luketic 30d8d4d193 renamed package, added defer ms.Close() 5 years ago
README.md 2551d12e21 update README.md 5 years ago
file.go 30d8d4d193 renamed package, added defer ms.Close() 5 years ago
helpers.go 831310875d initial 5 years ago

README.md

file

Upload, Download, Delete and list files (optional) as JSON

How

package main

import (
        "github.com/gomango/auth"
        "github.com/gomango/mblog/blog"
        "gopkg.in/mgo.v2"
        "log"
        "net/http"
)

func main() {
        ms, e := mgo.Dial("localhost")
        if e != nil {
                log.Fatalln(e.Error())
        }
        authopts := auth.Options{
                Host:             "file.dev.luketic",
                MailFrom:         "root@localhost",
                MailSupport:      "postmaster@localhost",
                TemplatePath:     "/home/darko/go/src/github.com/gomango/authtemplates",
                MailTemplatePath: "/home/darko/go/src/github.com/gomango/authemailtemplates/pongo2",
                XSRFkey:          auth.GenKey(128),
                Database:         "testmblog",
                Account:          "account",
                Resetcode:        "resetcode",
                Profile:          "profile",
                AESkey:           auth.GenKey(32),
                HMACkey:          auth.GenKey(512),
                BcryptPasswordCost: 12,
        }
        ah := auth.NewAuthHandler(ms, authopts)
        http.Handle("/account/", http.StripPrefix("/account/", ah))
        fileopts := blog.FileHandlerOptions{
                Prefix:         "images",
                DB:             "testfile",
                MS:             ms,
                AllowDuplicate: false,
                DisplayIndex:   true,
        }
        fh := blog.NewFileHandler(fileopts)
        http.Handle("/images/", http.StripPrefix("/images/", fh))
        log.Fatal(http.ListenAndServe(":8080", nil))
}

Interface

PUT and DELETE methods require either

  • a cookie with the JWT token acquired by logging in ("token=JWT")
  • a HTTP Header Authorization: Bearer JWT

Where JWT is the JWT string

AllowDuplicate: true

GET /

PUT /

DELETE /{bsonId:[a-fA-F0-9]{24}}

AllowDuplicate: false

GET /

PUT /

DELETE /{filename:.*}

Other

For auth methods see https://github.com/gomango/auth

TODO

  • Thumbnails