Skip to content

Commit

Permalink
Make it easier to add other storage systems
Browse files Browse the repository at this point in the history
  • Loading branch information
codemage66 committed Sep 2, 2016
1 parent c101f09 commit d874aed
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 239 deletions.
14 changes: 10 additions & 4 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/blue-jay/blueprint/controller"
"github.com/blue-jay/blueprint/controller/status"
"github.com/blue-jay/blueprint/lib/asset"
"github.com/blue-jay/blueprint/lib/database"
"github.com/blue-jay/blueprint/lib/email"
"github.com/blue-jay/blueprint/lib/flash"
"github.com/blue-jay/blueprint/lib/form"
Expand All @@ -29,6 +28,7 @@ import (
"github.com/blue-jay/blueprint/viewmodify/authlevel"
"github.com/blue-jay/blueprint/viewmodify/uri"

"github.com/blue-jay/core/storage/driver/mysql"
"github.com/gorilla/context"
"github.com/gorilla/csrf"
)
Expand All @@ -40,12 +40,14 @@ import (
// Info contains the application settings.
type Info struct {
Asset asset.Info `json:"Asset"`
Database database.Info `json:"Database"`
Email email.Info `json:"Email"`
Form form.Info `json:"Form"`
MySQL mysql.Info `json:"MySQL"`
Server server.Info `json:"Server"`
Session session.Info `json:"Session"`
Template view.Template `json:"Template"`
View view.Info `json:"View"`
Path string
}

// ParseJSON unmarshals bytes to structs
Expand Down Expand Up @@ -74,6 +76,9 @@ func LoadConfig(configFile string) *Info {
// Load the configuration file
jsonconfig.LoadOrFatal(configFile, config)

// Store the path of the file
config.Path = configFile

// Return the configuration
return config
}
Expand All @@ -90,10 +95,11 @@ func RegisterServices(config *Info) {
})

// Connect to database
database.Connect(config.Database, true)
mysql.SetConfig(config.MySQL)
mysql.Connect(true)

// Configure form handling
form.SetConfig(form.Info{config.Database.FileStorage})
form.SetConfig(config.Form)

// Load the controller routes
controller.LoadRoutes()
Expand Down
11 changes: 0 additions & 11 deletions database/migration/20160630_020000.000000_init.down.sql

This file was deleted.

11 changes: 11 additions & 0 deletions database/mysql/20160630_020000.000000_init.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ******************************************************************************
# Settings
# ******************************************************************************
SET foreign_key_checks = 0;

# ******************************************************************************
# Remove tables
# ******************************************************************************
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS user_status;
DROP TABLE IF EXISTS note;
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* *****************************************************************************
// Settings
// ****************************************************************************/
# ******************************************************************************
# Settings
# ******************************************************************************
SET foreign_key_checks = 1;
SET time_zone = '+00:00';

/* *****************************************************************************
// Create new tables
// ****************************************************************************/
# ******************************************************************************
# Create new tables
# ******************************************************************************
# CREATE DATABASE IF NOT EXISTS blueprint DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
# USE blueprint;

/* *****************************************************************************
// Create tables
// ****************************************************************************/
# ******************************************************************************
# Create tables
# ******************************************************************************
CREATE TABLE user_status (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,

Expand Down
29 changes: 15 additions & 14 deletions env.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@
"Asset":{
"Folder":"asset"
},
"Database":{
"FileStorage":"database/filestorage",
"Type":"MySQL",
"MySQL":{
"Username":"root",
"Password":"",
"Database":"blueprint",
"Charset":"utf8mb4",
"Collation":"utf8mb4_unicode_ci",
"Hostname":"127.0.0.1",
"Port":3306,
"Parameter":"parseTime=true"
}
},
"Email":{
"Username":"",
"Password":"",
"Hostname":"",
"Port":25,
"From":""
},
"Form":{
"FileStorageFolder":"database/filestorage"
},
"MySQL":{
"Username":"root",
"Password":"",
"Database":"blueprint",
"Charset":"utf8mb4",
"Collation":"utf8mb4_unicode_ci",
"Hostname":"127.0.0.1",
"Port":3306,
"Parameter":"parseTime=true",
"MigrationFolder":"database/mysql",
"Extension":"sql"
},
"Server":{
"Hostname":"",
"UseHTTP":true,
Expand Down
2 changes: 1 addition & 1 deletion generate/model/default.gen
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"database/sql"
"fmt"

"github.com/blue-jay/blueprint/lib/database"
"github.com/blue-jay/blueprint/model"
database "github.com/blue-jay/storage/driver/mysql"
"github.com/go-sql-driver/mysql"
)

Expand Down
196 changes: 0 additions & 196 deletions lib/database/database.go

This file was deleted.

4 changes: 2 additions & 2 deletions lib/form/form.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

// Info holds the details for the form handling.
type Info struct {
FileStorage string
FileStorageFolder string `json:"FileStorageFolder"`
}

// SetConfig stores the config.
Expand Down Expand Up @@ -90,7 +90,7 @@ func UploadFile(r *http.Request, name string, maxSize int64) (string, string, er
return "", "", err
}

f, err := os.OpenFile(filepath.Join(Config().FileStorage, fileID), os.O_WRONLY|os.O_CREATE, 0644)
f, err := os.OpenFile(filepath.Join(Config().FileStorageFolder, fileID), os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return "", "", err
}
Expand Down
3 changes: 2 additions & 1 deletion model/note/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"database/sql"
"fmt"

"github.com/blue-jay/blueprint/lib/database"
"github.com/blue-jay/blueprint/model"

database "github.com/blue-jay/core/storage/driver/mysql"
"github.com/go-sql-driver/mysql"
)

Expand Down
Loading

0 comments on commit d874aed

Please sign in to comment.