wip
This commit is contained in:
parent
04c101982f
commit
13d0b15fd9
15 changed files with 507 additions and 1246 deletions
21
main.go
21
main.go
|
|
@ -26,6 +26,7 @@ const VERSION = "v1"
|
|||
const CONTEXT_USER = 1
|
||||
|
||||
var (
|
||||
FlagGenerate bool
|
||||
FlagDev bool
|
||||
FlagConfig string
|
||||
FlagCreateUser string
|
||||
|
|
@ -56,6 +57,7 @@ func init() { // {{{
|
|||
|
||||
flag.StringVar(&FlagConfig, "config", cfgFilename, "Configuration file")
|
||||
flag.BoolVar(&FlagDev, "dev", false, "Use local files instead of embedded files")
|
||||
flag.BoolVar(&FlagGenerate, "generate", false, "Generate test data")
|
||||
flag.StringVar(&FlagCreateUser, "create-user", "", "Username for creating a new user")
|
||||
flag.StringVar(&FlagChangePassword, "change-password", "", "Change the password for the given username")
|
||||
flag.Parse()
|
||||
|
|
@ -85,6 +87,16 @@ func main() { // {{{
|
|||
// The session manager contains authentication, authorization and session settings.
|
||||
AuthManager, err = authentication.NewManager(db, Log, config.JWT.Secret, config.JWT.ExpireDays)
|
||||
|
||||
// Generate test data?
|
||||
if FlagGenerate {
|
||||
err := TestData()
|
||||
if err != nil {
|
||||
fmt.Printf("%s\n", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// A new user?
|
||||
if FlagCreateUser != "" {
|
||||
createNewUser(FlagCreateUser)
|
||||
|
|
@ -111,7 +123,7 @@ func main() { // {{{
|
|||
http.HandleFunc("/user/authenticate", AuthManager.AuthenticationHandler)
|
||||
|
||||
http.HandleFunc("/node/tree/{timestamp}/{offset}", authenticated(actionNodeTree))
|
||||
http.HandleFunc("/node/retrieve/{id}", authenticated(actionNodeRetrieve))
|
||||
http.HandleFunc("/node/retrieve/{uuid}", authenticated(actionNodeRetrieve))
|
||||
|
||||
http.HandleFunc("/service_worker.js", pageServiceWorker)
|
||||
|
||||
|
|
@ -241,17 +253,14 @@ func actionNodeTree(w http.ResponseWriter, r *http.Request) { // {{{
|
|||
MaxSeq uint64
|
||||
Continue bool
|
||||
}{true, nodes, maxSeq, moreRowsExist})
|
||||
Log.Debug("tree", "nodes", nodes)
|
||||
w.Write(j)
|
||||
} // }}}
|
||||
func actionNodeRetrieve(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
user := getUser(r)
|
||||
var err error
|
||||
|
||||
idStr := r.PathValue("id")
|
||||
id, _ := strconv.Atoi(idStr)
|
||||
|
||||
node, err := RetrieveNode(user.ID, id)
|
||||
uuid := r.PathValue("uuid")
|
||||
node, err := RetrieveNode(user.ID, uuid)
|
||||
if err != nil {
|
||||
responseError(w, err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue