Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Admin GUI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekn committed Sep 12, 2017
1 parent 51cd8cf commit 932eabc
Show file tree
Hide file tree
Showing 18 changed files with 755 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/gui/.tmp
/gui/yarn.lock
/gui/node_modules
/gui/dist
32 changes: 24 additions & 8 deletions src/github.com/stellar/gateway/bridge/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"os"
"time"

"github.com/elazarl/go-bindata-assetfs"
"github.com/facebookgo/inject"
"github.com/stellar/gateway/bridge/config"
"github.com/stellar/gateway/bridge/gui"
"github.com/stellar/gateway/bridge/handlers"
"github.com/stellar/gateway/db"
"github.com/stellar/gateway/db/drivers/mysql"
Expand Down Expand Up @@ -218,14 +220,28 @@ func (a *App) Serve() {
bridge.Get("/admin/received-payments/:id", a.requestHandler.AdminReceivedPayment)
bridge.Get("/admin/sent-transactions", a.requestHandler.AdminSentTransactions)

// Create a proxy server to localhost:3000 where GUI development server lives.
staticAdminURL, err := url.Parse("http://localhost:3000")
if err != nil {
panic(err)
}
bridge.Get("/*", httputil.NewSingleHostReverseProxy(staticAdminURL))

err = graceful.ListenAndServe(portString, bridge)
if a.config.Develop {
// Create a proxy server to localhost:3000 where GUI development server lives.
staticAdminURL, err := url.Parse("http://localhost:3000")
if err != nil {
panic(err)
}
bridge.Get("/*", httputil.NewSingleHostReverseProxy(staticAdminURL))
} else {
// Load go-bindata files
fileServerHandler := http.FileServer(
&assetfs.AssetFS{
Asset: gui.Asset,
AssetDir: gui.AssetDir,
AssetInfo: gui.AssetInfo,
})
bridge.Get("/admin", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/admin/", http.StatusPermanentRedirect)
})
bridge.Get("/admin/*", http.StripPrefix("/admin/", fileServerHandler))
}

err := graceful.ListenAndServe(portString, bridge)
if err != nil {
log.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions src/github.com/stellar/gateway/bridge/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
MACKey string `mapstructure:"mac_key"`
APIKey string `mapstructure:"api_key"`
NetworkPassphrase string `mapstructure:"network_passphrase"`
Develop bool
Assets []Asset
Database struct {
Type string
Expand Down
327 changes: 327 additions & 0 deletions src/github.com/stellar/gateway/bridge/gui/bindata.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/github.com/stellar/gateway/bridge/gui/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Package gui contains templates and static files used in bridge admin GUI.
package gui

//go:generate go-bindata -ignore .+\.go$ -pkg gui -o bindata.go -prefix ../../../../../../gui/dist ../../../../../../gui/dist
2 changes: 1 addition & 1 deletion src/github.com/stellar/gateway/db/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ type Driver interface {
Delete(object entities.Entity) (err error)

GetOne(object entities.Entity, where string, params ...interface{}) (entities.Entity, error)
GetMany(slice interface{}, where, order, limit *string, params ...interface{}) (err error)
GetMany(slice interface{}, where, order, offset, limit *string, params ...interface{}) (err error)
}
8 changes: 4 additions & 4 deletions src/github.com/stellar/gateway/db/drivers/mysql/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/github.com/stellar/gateway/db/drivers/mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (d *Driver) GetOne(object entities.Entity, where string, params ...interfac
}

// GetMany returns many entities
func (d *Driver) GetMany(slice interface{}, where, order, limit *string, params ...interface{}) (err error) {
func (d *Driver) GetMany(slice interface{}, where, order, offset, limit *string, params ...interface{}) (err error) {
_, tableName, err := getTypeData(slice)
if err != nil {
return
Expand All @@ -188,7 +188,9 @@ func (d *Driver) GetMany(slice interface{}, where, order, limit *string, params
query.WriteString(" ORDER BY " + *order)
}

if limit != nil {
if limit != nil && offset != nil {
query.WriteString(fmt.Sprintf(" LIMIT %s, %s", *offset, *limit))
} else if limit != nil {
query.WriteString(" LIMIT " + *limit)
}

Expand Down
8 changes: 4 additions & 4 deletions src/github.com/stellar/gateway/db/drivers/postgres/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/github.com/stellar/gateway/db/drivers/postgres/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package postgres
import (
"bytes"
"fmt"
"log"
"reflect"
"strings"

Expand Down Expand Up @@ -168,8 +167,9 @@ func (d *Driver) GetOne(object entities.Entity, where string, params ...interfac
return nil, err
}

sql := "SELECT * FROM " + tableName + " WHERE " + where + " LIMIT 1"
log.Println(sql)
sql := "SELECT * FROM " + tableName + " WHERE " + where + " LIMIT 1;"
sql = sqlx.Rebind(sqlx.DOLLAR, sql)

err = d.database.Get(object, sql, params...)
if err != nil {
if err.Error() == "sql: no rows in result set" {
Expand All @@ -182,7 +182,7 @@ func (d *Driver) GetOne(object entities.Entity, where string, params ...interfac
}

// GetMany returns many entities
func (d *Driver) GetMany(slice interface{}, where, order, limit *string, params ...interface{}) (err error) {
func (d *Driver) GetMany(slice interface{}, where, order, offset, limit *string, params ...interface{}) (err error) {
_, tableName, err := getTypeData(slice)
if err != nil {
return
Expand All @@ -200,6 +200,10 @@ func (d *Driver) GetMany(slice interface{}, where, order, limit *string, params
query.WriteString(" ORDER BY " + *order)
}

if offset != nil {
query.WriteString(" OFFSET " + *offset)
}

if limit != nil {
query.WriteString(" LIMIT " + *limit)
}
Expand Down
12 changes: 8 additions & 4 deletions src/github.com/stellar/gateway/db/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ func (r Repository) GetReceivedPayments(page, limit int) ([]*entities.ReceivedPa

offset := (page - 1) * limit

limitQuery := fmt.Sprintf("%d, %d", offset, limit)
limitQuery := fmt.Sprintf("%d", limit)
offsetQuery := fmt.Sprintf("%d", offset)
orderQuery := "id desc"
err := r.driver.GetMany(&payments, nil, &orderQuery, &limitQuery)

err := r.driver.GetMany(&payments, nil, &orderQuery, &offsetQuery, &limitQuery)
return payments, err
}

Expand All @@ -167,9 +169,11 @@ func (r Repository) GetSentTransactions(page, limit int) ([]*entities.SentTransa

offset := (page - 1) * limit

limitQuery := fmt.Sprintf("%d, %d", offset, limit)
limitQuery := fmt.Sprintf("%d", limit)
offsetQuery := fmt.Sprintf("%d", offset)
orderQuery := "id desc"
err := r.driver.GetMany(&transactions, nil, &orderQuery, &limitQuery)

err := r.driver.GetMany(&transactions, nil, &orderQuery, &offsetQuery, &limitQuery)
return transactions, err
}

Expand Down
14 changes: 14 additions & 0 deletions src/github.com/stellar/gateway/server/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"net/http"
"strings"
)

// StripTrailingSlashMiddleware strips trailing slash.
Expand All @@ -10,6 +11,13 @@ func StripTrailingSlashMiddleware() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path

// Do not change /admin paths
if strings.HasPrefix(path, "/admin") {
next.ServeHTTP(w, r)
return
}

l := len(path)

// if the path is longer than 1 char (i.e., not '/')
Expand All @@ -28,6 +36,12 @@ func StripTrailingSlashMiddleware() func(next http.Handler) http.Handler {
func HeadersMiddleware() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
// Do not change admin home
if r.URL.Path == "/admin/" {
next.ServeHTTP(w, r)
return
}

w.Header().Set("Content-Type", "application/json")
next.ServeHTTP(w, r)
}
Expand Down
6 changes: 6 additions & 0 deletions vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
"revision": "4623535a2b1c4a613d7a75899b1422d8186fe9b7",
"branch": "master"
},
{
"importpath": "github.com/elazarl/go-bindata-assetfs",
"repository": "https://github.com/elazarl/go-bindata-assetfs",
"revision": "30f82fa23fd844bd5bb1e5f216db87fd77b5eb43",
"branch": "master"
},
{
"importpath": "github.com/facebookgo/inject",
"repository": "https://github.com/facebookgo/inject",
Expand Down
23 changes: 23 additions & 0 deletions vendor/src/github.com/elazarl/go-bindata-assetfs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2014, Elazar Leibovich
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 changes: 46 additions & 0 deletions vendor/src/github.com/elazarl/go-bindata-assetfs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# go-bindata-assetfs

Serve embedded files from [jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata) with `net/http`.

[GoDoc](http://godoc.org/github.com/elazarl/go-bindata-assetfs)

### Installation

Install with

$ go get github.com/jteeuwen/go-bindata/...
$ go get github.com/elazarl/go-bindata-assetfs/...

### Creating embedded data

Usage is identical to [jteeuwen/go-bindata](https://github.com/jteeuwen/go-bindata) usage,
instead of running `go-bindata` run `go-bindata-assetfs`.

The tool will create a `bindata_assetfs.go` file, which contains the embedded data.

A typical use case is

$ go-bindata-assetfs data/...

### Using assetFS in your code

The generated file provides an `assetFS()` function that returns a `http.Filesystem`
wrapping the embedded files. What you usually want to do is:

http.Handle("/", http.FileServer(assetFS()))

This would run an HTTP server serving the embedded files.

## Without running binary tool

You can always just run the `go-bindata` tool, and then

use

import "github.com/elazarl/go-bindata-assetfs"
...
http.Handle("/",
http.FileServer(
&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: "data"}))

to serve files embedded from the `data` directory.
Loading

0 comments on commit 932eabc

Please sign in to comment.