Permalink
Browse files

Database URL, Travis cache fix, readme tweaks, and more (#178)

* Simplify main

* Show warning

* Alias DATABASE_URL

* Grab Postgres connection string from DATABASE_URL env var

* Have Travis remove dotfiles before cache

* Remove deprecation warning

* Remove Go Report Card badge

* Reword intro

* Add gometalinter deadline config

* Check errors

* Fix log package name grabbing

* Test that DATABASE_URL works

* Document DATABASE_URL

* Clean up and add links

* Remove unused bower config file
  • Loading branch information...
kochman authored and garoller committed Nov 5, 2018
1 parent 134aa0d commit b5fc7eb4a3b701c240119cff54a3e60ab07d13b0
Showing with 65 additions and 29 deletions.
  1. +0 −3 .bowerrc
  2. +3 −0 .gometalinter.json
  3. +1 −1 .travis.yml
  4. +8 −6 README.md
  5. +6 −1 config/config.go
  6. +2 −16 log/log.go
  7. +9 −2 postgres/postgres.go
  8. +36 −0 postgres/postgres_test.go
View

This file was deleted.

Oops, something went wrong.
View
@@ -0,0 +1,3 @@
{
"Deadline": "1m"
}
View
@@ -44,5 +44,5 @@ cache:
- $GOPATH/pkg
before_cache:
- rm -rf $GOPATH/src/github.com/wtg/shuttletracker/*
- rm -rf $GOPATH/src/github.com/wtg/shuttletracker/{*,.*}
- rm -rf $GOPATH/pkg/**/github.com/wtg/shuttletracker/*
View
@@ -1,8 +1,6 @@
# Shuttle Tracker [![Build Status](https://travis-ci.org/wtg/shuttletracker.svg?branch=master)](https://travis-ci.org/wtg/shuttletracker) [![codecov](https://codecov.io/gh/wtg/shuttletracker/branch/master/graph/badge.svg)](https://codecov.io/gh/wtg/shuttletracker) [![GoDoc](https://godoc.org/github.com/wtg/shuttletracker?status.svg)](https://godoc.org/github.com/wtg/shuttletracker) [![Go Report Card](https://goreportcard.com/badge/github.com/wtg/shuttletracker)](https://goreportcard.com/report/github.com/wtg/shuttletracker)
# Shuttle Tracker [![Build Status](https://travis-ci.org/wtg/shuttletracker.svg?branch=master)](https://travis-ci.org/wtg/shuttletracker) [![codecov](https://codecov.io/gh/wtg/shuttletracker/branch/master/graph/badge.svg)](https://codecov.io/gh/wtg/shuttletracker) [![GoDoc](https://godoc.org/github.com/wtg/shuttletracker?status.svg)](https://godoc.org/github.com/wtg/shuttletracker)
Tracking and mapping RPI's shuttles with [Go](https://golang.org/), [Vue.js](https://vuejs.org/), and [Postgres](https://www.postgresql.org).
Check it out in action at [shuttles.rpi.edu](https://shuttles.rpi.edu).
Tracks and maps RPI's shuttles with [Go](https://golang.org/), [Postgres](https://www.postgresql.org), [Vue.js](https://vuejs.org/), [TypeScript](https://www.typescriptlang.org), and [Leaflet](https://leafletjs.com). Check it out in action at [shuttles.rpi.edu](https://shuttles.rpi.edu).
## Setting up
@@ -25,7 +23,7 @@ Check it out in action at [shuttles.rpi.edu](https://shuttles.rpi.edu).
- _Note: if you are working on the frontend, you may instead use `npx vue-cli-service build --mode development --watch` in another terminal to continuously watch for changes and rebuild._
15. Go back up to the project root directory and build Shuttle Tracker by running `go build -o shuttletracker cmd/shuttletracker/main.go`
16. Start the app by running `./shuttletracker` in the project root directory.
17. You can add yourself as an administrator by using `./shuttletracker admins --add RCS_ID`, replacing `RCS_ID` with your RCS ID. See the "Administrators" section below for more information.
17. Add yourself as an administrator by using `./shuttletracker admins --add RCS_ID`, replacing `RCS_ID` with your RCS ID. See the "Administrators" section below for more information.
18. Visit http://localhost:8080/ to view the tracking application and http://localhost:8080/admin to view the administration panel.
## Configuration
@@ -36,7 +34,11 @@ Shuttle Tracker needs configuration to run properly. The preferred method during
### Environment variables
Most keys can be overridden with environment variables. The variables names usually take the format `SECTION_KEY`. For example, overriding database's Mongo URL could be done with a variable named `POSTGRES_URL`.
Most keys can be overridden with environment variables. The variables names usually take the format `PACKAGE_KEY`. For example, overriding the iTRAK updater's update interval could be done with a variable named `UPDATER_UPDATEINTERVAL`.
#### Database URL
The database URL is a special case. Following the above convention, it can be set with `POSTGRES_URL`. However, for ease of deployment on Dokku, it can also be set with `DATABASE_URL`.
## Administrators
View
@@ -32,7 +32,12 @@ func New() (*Config, error) {
cfg.API = api.NewConfig(v)
cfg.Updater = updater.NewConfig(v)
cfg.Log = log.NewConfig()
cfg.Postgres = postgres.NewConfig(v)
pgCfg, err := postgres.NewConfig(v)
if err != nil {
return nil, err
}
cfg.Postgres = pgCfg
log.Debugf("All settings: %+v", v.AllSettings())
View
@@ -44,22 +44,8 @@ func contextFields(lvl ...int) Fields {
}
pc, file, line, _ := runtime.Caller(level)
_, fileName := path.Split(file)
parts := strings.Split(runtime.FuncForPC(pc).Name(), ".")
pl := len(parts)
packageName := ""
if len(parts) >= 0 && pl-2 < len(parts) {
if len(parts[pl-2]) > 0 && parts[pl-2][0] == '(' {
packageName = strings.Join(parts[0:pl-2], ".")
} else {
packageName = strings.Join(parts[0:pl-1], ".")
}
pkgs := strings.Split(packageName, "/shuttletracker/")
if len(pkgs) > 1 {
packageName = pkgs[1]
}
}
pkgs := strings.Split(runtime.FuncForPC(pc).Name(), "/shuttletracker/")
packageName := strings.Split(pkgs[1], ".")[0]
return Fields{
"package": packageName,
View
@@ -68,10 +68,17 @@ func New(cfg Config) (*Postgres, error) {
}
// NewConfig creates a new Config.
func NewConfig(v *viper.Viper) *Config {
func NewConfig(v *viper.Viper) (*Config, error) {
cfg := &Config{
URL: "postgres://localhost/shuttletracker?sslmode=disable",
}
v.SetDefault("postgres.url", cfg.URL)
return cfg
// Allow DATABASE_URL to set the Postgres connection string for ease of deployment.
err := v.BindEnv("postgres.url", "DATABASE_URL")
if err != nil {
return nil, err
}
return cfg, nil
}
View
@@ -0,0 +1,36 @@
package postgres
import (
"os"
"testing"
"github.com/spf13/viper"
)
func TestConfigDatabaseURL(t *testing.T) {
// this is what we want URL to be set to
testVal := "this is a test haha"
// first make sure it doesn't work
v := viper.New()
cfg, err := NewConfig(v)
if err != nil {
t.Fatal("unexpected error:", err)
}
res := v.GetString("postgres.url")
if res == testVal {
t.Errorf("URL is %s", cfg.URL)
}
// now see if it works
os.Setenv("DATABASE_URL", testVal)
v = viper.New()
cfg, err = NewConfig(v)
if err != nil {
t.Fatal("unexpected error:", err)
}
res = v.GetString("postgres.url")
if res != testVal {
t.Errorf("URL is %s; expected %s", cfg.URL, testVal)
}
}

0 comments on commit b5fc7eb

Please sign in to comment.