Commit 1878789f authored by zauberstuhl's avatar zauberstuhl

Add mysql and postgres support

closes #5
parent e0eaecda
......@@ -9,6 +9,14 @@
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
version = "v1.4.7"
[[projects]]
digest = "1:ec6f9bf5e274c833c911923c9193867f3f18788c461f76f05f62bb1510e0ae65"
name = "github.com/go-sql-driver/mysql"
packages = ["."]
pruneopts = "UT"
revision = "72cd26f257d44c1114970e19afddcd812016007e"
version = "v1.4.1"
[[projects]]
digest = "1:c0d19ab64b32ce9fe5cf4ddceba78d5bc9807f0016db6b1183599da3dcc24d10"
name = "github.com/hashicorp/hcl"
......@@ -29,10 +37,12 @@
version = "v1.0.0"
[[projects]]
digest = "1:27f44b9a8c2995c35ec25a9948ffa96f997f8eedbc5bb34838f10dcf620aaee3"
digest = "1:b0c1770be8c52cf00117b98049de1e4df91c8df588102198364b09669bb60178"
name = "github.com/jinzhu/gorm"
packages = [
".",
"dialects/mysql",
"dialects/postgres",
"dialects/sqlite",
]
pruneopts = "UT"
......@@ -47,6 +57,19 @@
revision = "f5c5f50e6090ae76a29240b61ae2a90dd810112e"
version = "v1.0.0"
[[projects]]
digest = "1:0ead8e64fe356bd9221605e3ec40b4438509868018cbbbaaaff3ebae1b69b78b"
name = "github.com/lib/pq"
packages = [
".",
"hstore",
"oid",
"scram",
]
pruneopts = "UT"
revision = "3427c32cb71afc948325f299f040e53c1dd78979"
version = "v1.2.0"
[[projects]]
digest = "1:5a0ef768465592efca0412f7e838cdc0826712f8447e70e6ccc52eb441e9ab13"
name = "github.com/magiconair/properties"
......@@ -172,6 +195,14 @@
revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"
version = "v0.3.2"
[[projects]]
digest = "1:c25289f43ac4a68d88b02245742347c94f1e108c534dda442188015ff80669b3"
name = "google.golang.org/appengine"
packages = ["cloudsql"]
pruneopts = "UT"
revision = "b2f4a3cf3c67576a2ee09e1fe62656a5086ce880"
version = "v1.6.1"
[[projects]]
digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96"
name = "gopkg.in/yaml.v2"
......@@ -185,6 +216,8 @@
analyzer-version = 1
input-imports = [
"github.com/jinzhu/gorm",
"github.com/jinzhu/gorm/dialects/mysql",
"github.com/jinzhu/gorm/dialects/postgres",
"github.com/jinzhu/gorm/dialects/sqlite",
"github.com/microcosm-cc/bluemonday",
"github.com/robfig/cron",
......
......@@ -27,7 +27,6 @@ import (
"log"
"github.com/spf13/viper"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
const rootUrl = "https://api.untappd.com"
......
#nginxRewrite: "/users/%s"
redirectUrl: http://localhost:8080
# untappd app secret
clientID: 1234
clientSecret: 123456789
# mapbox public key
mapboxKey: 123456789
# development
debug: false
worker: true
# database config
db.driver: sqlite3
#db.user: postgres
#db.password: ""
#db.host: postgres
#db.database: unmappd
## sqlite3
db.url: unmappd.db
## mysql
#db.url: "%s:%s@tcp(%s)/%s?parseTime=true"
## postgres
#db.url: "postgres://%s:%s@%s/%s?sslmode=disable"
......@@ -23,7 +23,6 @@ import (
"log"
"github.com/spf13/viper"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
var CLIENTID, CLIENTSECRET, REDIRECTURL string
......
......@@ -24,8 +24,11 @@ import (
"strings"
"fmt"
"github.com/spf13/viper"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
type User struct {
......@@ -33,8 +36,8 @@ type User struct {
CreatedAt time.Time
UpdatedAt time.Time
Username string `gorm:"unique_index"`
Token string `gorm:"index"`
Username string `gorm:"unique_index;size:191"`
Token string `gorm:"index;size:191"`
TotalBadges int
TotalFriends int
......@@ -88,7 +91,17 @@ func (locations Locations) LatLngJSON() template.JS {
}
func openDatabase() (*gorm.DB, error) {
db, err := gorm.Open("sqlite3", "unmappd.db")
driver := viper.GetString("db.driver")
url := viper.GetString("db.url")
if driver != "sqlite3" {
user := viper.GetString("db.user")
password := viper.GetString("db.password")
host := viper.GetString("db.host")
database := viper.GetString("db.database")
url = fmt.Sprintf(url, user, password, host, database)
}
db, err := gorm.Open(driver, url)
if err != nil {
return db, err
}
......
No preview for this file type
......@@ -26,7 +26,6 @@ import (
"log"
"github.com/spf13/viper"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/microcosm-cc/bluemonday"
)
......
......@@ -24,7 +24,6 @@ import (
"github.com/spf13/viper"
"github.com/robfig/cron"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
func init() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment