-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from kareemmahlees:refactor_arch
Architectural changes
- Loading branch information
Showing
45 changed files
with
2,290 additions
and
1,895 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
args_bin = ["sqlite3", "-f", ".\\test.db" ] | ||
bin = "tmp\\main.exe" | ||
cmd = "go build -o ./tmp/main.exe ." | ||
delay = 1000 | ||
exclude_dir = ["assets", "tmp", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html"] | ||
include_file = [] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
poll = false | ||
poll_interval = 0 | ||
post_cmd = [] | ||
pre_cmd = [] | ||
rerun = false | ||
rerun_delay = 500 | ||
send_interrupt = false | ||
stop_on_error = false | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
main_only = false | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[screen] | ||
clear_on_rebuild = false | ||
keep_scroll = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kareemmahlees/meta-x/internal" | ||
"github.com/kareemmahlees/meta-x/internal/db" | ||
"github.com/kareemmahlees/meta-x/lib" | ||
|
||
"github.com/go-sql-driver/mysql" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/kareemmahlees/meta-x/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var mysqlCommand = &cobra.Command{ | ||
Use: "mysql", | ||
Short: "use mysql as the database provider", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var cfg string | ||
var mysqlConfig *utils.MySQLConfig | ||
|
||
port, _ := cmd.Flags().GetInt("port") | ||
|
||
connUrl, _ := cmd.Flags().GetString("url") | ||
if connUrl != "" { | ||
cfg = connUrl | ||
mysqlConfig = utils.NewMySQLConfig(&connUrl, nil) | ||
} else { | ||
dbUsername, _ := cmd.Flags().GetString("username") | ||
dbHost, _ := cmd.Flags().GetString("host") | ||
dbPort, _ := cmd.Flags().GetInt("dbPort") | ||
dbName, _ := cmd.Flags().GetString("db") | ||
|
||
dbPassword, _ := cmd.Flags().GetString("password") | ||
if dbPassword == "" { | ||
fmt.Println("Enter password: ") | ||
fmt.Scanln(&dbPassword) | ||
} | ||
|
||
conf := mysql.Config{ | ||
User: dbUsername, | ||
Passwd: dbPassword, | ||
DBName: dbName, | ||
Net: "tcp", | ||
Addr: fmt.Sprintf("%s:%d", dbHost, dbPort), | ||
} | ||
cfg = conf.FormatDSN() | ||
mysqlConfig = utils.NewMySQLConfig(nil, &utils.MySQLConnectionParams{ | ||
DBUsername: dbUsername, | ||
DBPassword: dbPassword, | ||
DBHost: dbHost, | ||
DBPort: dbPort, | ||
DBName: dbName, | ||
}) | ||
} | ||
|
||
port, _ := cmd.Flags().GetInt("port") | ||
|
||
app := fiber.New(fiber.Config{DisableStartupMessage: true}) | ||
conn, err := db.InitDBConn(lib.MYSQL, mysqlConfig) | ||
if err != nil { | ||
return err | ||
} | ||
provider := db.NewMySQLProvider(conn) | ||
server := internal.NewServer(provider, port, make(chan bool, 1)) | ||
|
||
if err := internal.InitDBAndServer(app, lib.MYSQL, cfg, port, make(chan bool, 1)); err != nil { | ||
if err := server.Serve(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
|
||
mysqlCommand.Flags().String("username", "", "db username") | ||
mysqlCommand.Flags().String("username", "root", "db username") | ||
mysqlCommand.Flags().String("password", "", "db password") | ||
mysqlCommand.Flags().String("host", "localhost", "db host") | ||
mysqlCommand.Flags().Int("dbPort", 3306, "db port") | ||
mysqlCommand.Flags().String("db", "mysql", "db name") | ||
mysqlCommand.Flags().String("url", "", "connection url/string") | ||
|
||
mysqlCommand.MarkFlagsMutuallyExclusive("username", "url") | ||
mysqlCommand.MarkFlagsMutuallyExclusive("password", "url") | ||
|
||
rootCmd.AddCommand(mysqlCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kareemmahlees/meta-x/internal" | ||
"github.com/kareemmahlees/meta-x/internal/db" | ||
"github.com/kareemmahlees/meta-x/lib" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/lib/pq" | ||
|
||
"github.com/kareemmahlees/meta-x/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var pgCommand = &cobra.Command{ | ||
Use: "pg", | ||
Short: "use postgres as the database provider", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var cfg string | ||
var pgConfig *utils.PgConfig | ||
|
||
port, _ := cmd.Flags().GetInt("port") | ||
|
||
connUrl, _ := cmd.Flags().GetString("url") | ||
if connUrl != "" { | ||
cfg = connUrl | ||
pgConfig = utils.NewPGConfig(&connUrl, nil) | ||
} else { | ||
dbUsername, _ := cmd.Flags().GetString("username") | ||
dbHost, _ := cmd.Flags().GetString("host") | ||
dbPort, _ := cmd.Flags().GetInt("dbPort") | ||
dbName, _ := cmd.Flags().GetString("db") | ||
dbSslMode, _ := cmd.Flags().GetString("sslmode") | ||
|
||
dbPassword, _ := cmd.Flags().GetString("password") | ||
if dbPassword == "" { | ||
fmt.Println("Enter password: ") | ||
fmt.Scanln(&dbPassword) | ||
} | ||
|
||
cfg, _ = pq.ParseURL(fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s", dbUsername, dbPassword, dbHost, dbPort, dbName, dbSslMode)) | ||
pgConfig = utils.NewPGConfig(nil, &utils.PgConnectionParams{ | ||
DBUsername: dbUsername, | ||
DBPassword: dbPassword, | ||
DBHost: dbHost, | ||
DBPort: dbPort, | ||
DBName: dbName, | ||
DBSslMode: dbSslMode, | ||
}) | ||
} | ||
conn, err := db.InitDBConn(lib.PSQL, pgConfig) | ||
if err != nil { | ||
return err | ||
} | ||
provider := db.NewPgProvider(conn) | ||
server := internal.NewServer(provider, port, make(chan bool, 1)) | ||
|
||
port, _ := cmd.Flags().GetInt("port") | ||
|
||
app := fiber.New(fiber.Config{DisableStartupMessage: true}) | ||
|
||
if err := internal.InitDBAndServer(app, lib.PSQL, cfg, port, make(chan bool, 1)); err != nil { | ||
if err := server.Serve(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
|
||
pgCommand.Flags().String("username", "", "db username") | ||
pgCommand.Flags().String("username", "postgres", "db username") | ||
pgCommand.Flags().String("password", "", "db password") | ||
pgCommand.Flags().String("host", "localhost", "db host") | ||
pgCommand.Flags().Int("dbPort", 5432, "db port") | ||
pgCommand.Flags().String("db", "postgres", "db name") | ||
pgCommand.Flags().String("url", "", "connection url/string") | ||
pgCommand.Flags().String("sslmode", "disable", "db sslmode") | ||
pgCommand.MarkFlagsMutuallyExclusive("username", "url") | ||
pgCommand.MarkFlagsMutuallyExclusive("password", "url") | ||
|
||
rootCmd.AddCommand(pgCommand) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "A RESTFull and GraphQL API to manage your MySQL DB", | ||
"description": "A RESTFull and GraphQL API to supercharge your database", | ||
"title": "MetaX", | ||
"contact": { | ||
"name": "Kareem Ebrahim", | ||
"email": "[email protected]" | ||
}, | ||
"version": "1.0" | ||
"version": "0.1.1" | ||
}, | ||
"host": "localhost:5522", | ||
"basePath": "/", | ||
|
@@ -331,6 +331,31 @@ | |
} | ||
}, | ||
"definitions": { | ||
"handlers.APIInfoResult": { | ||
"type": "object", | ||
"properties": { | ||
"author": { | ||
"type": "string" | ||
}, | ||
"contact": { | ||
"type": "string" | ||
}, | ||
"repo": { | ||
"type": "string" | ||
}, | ||
"year": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"handlers.HealthCheckResult": { | ||
"type": "object", | ||
"properties": { | ||
"date": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"models.AddModifyColumnPayload": { | ||
"type": "object", | ||
"required": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
basePath: / | ||
definitions: | ||
handlers.APIInfoResult: | ||
properties: | ||
author: | ||
type: string | ||
contact: | ||
type: string | ||
repo: | ||
type: string | ||
year: | ||
type: integer | ||
type: object | ||
handlers.HealthCheckResult: | ||
properties: | ||
date: | ||
type: string | ||
type: object | ||
models.AddModifyColumnPayload: | ||
properties: | ||
column_name: | ||
|
@@ -93,9 +109,9 @@ info: | |
contact: | ||
email: [email protected] | ||
name: Kareem Ebrahim | ||
description: A RESTFull and GraphQL API to manage your MySQL DB | ||
description: A RESTFull and GraphQL API to supercharge your database | ||
title: MetaX | ||
version: "1.0" | ||
version: 0.1.1 | ||
paths: | ||
/: | ||
get: | ||
|
Oops, something went wrong.