Skip to content

Commit

Permalink
Split command line interfaces and http server
Browse files Browse the repository at this point in the history
  • Loading branch information
RobyFerro committed Aug 25, 2021
1 parent 4d09e59 commit c6b95c4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 143 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "Go-web" will be documented in this file.

## [Unreleased]

## [v0.6.0-beta] - 2021-08-25
## Changed
- Split command line interfaces and http server

## [v0.5.3-beta] - 2021-08-20
## Changed
- Updated GWF version
Expand Down
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ go 1.16
//replace github.com/RobyFerro/go-web-framework => <your local gwf path>

require (
github.com/RobyFerro/go-web-framework v0.5.8-beta
github.com/RobyFerro/go-web-framework v0.6.0-beta
github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1
github.com/brianvoe/gofakeit/v4 v4.3.0
github.com/common-nighthawk/go-figure v0.0.0-20200609044655-c4b36f998cf2
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e // indirect
github.com/denisenkom/go-mssqldb v0.10.0 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/elastic/go-elasticsearch/v8 v8.0.0-20200819071622-59b6a186f8dd
github.com/go-redis/redis/v7 v7.4.0
Expand All @@ -29,10 +28,8 @@ require (
github.com/pkg/errors v0.9.1
github.com/tidwall/pretty v1.0.1 // indirect
go.mongodb.org/mongo-driver v1.5.1
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
golang.org/x/tools v0.0.0-20200827010519-17fd2f27a9e3 // indirect
gopkg.in/yaml.v2 v2.3.0
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RobyFerro/dig v1.12.1-0.20210819154643-39ab24cc0b65 h1:H4H+dLG6WQ5M5PuqkleY7PupT4r/z0TR+AgUJXpRmw4=
github.com/RobyFerro/dig v1.12.1-0.20210819154643-39ab24cc0b65/go.mod h1:jfL50cNXPp4gqLYHPyZMyUS9D05UTUJCdkxNU6gftXc=
github.com/RobyFerro/go-web-framework v0.5.7-beta h1:CsJBbvTKiXKX6waRc4Eml3rPWN3TW1kd5fvgjugUmwQ=
github.com/RobyFerro/go-web-framework v0.5.7-beta/go.mod h1:y7Rt1EwseGbKYxSx9ikuhe6/oAePgH13OJLS2+X4nVQ=
github.com/RobyFerro/dig v1.12.1-0.20210820090948-eef4b5ae40c2 h1:RaMKVl0nfJD/neflcaPmWJYyzt43HfX5kmN3gdWGjRw=
github.com/RobyFerro/dig v1.12.1-0.20210820090948-eef4b5ae40c2/go.mod h1:jfL50cNXPp4gqLYHPyZMyUS9D05UTUJCdkxNU6gftXc=
github.com/RobyFerro/go-web-framework v0.6.0-beta h1:7P9UvP+4ypTwEdEKUzGgzuXzDTDfL2iXZC4QVWoiq24=
github.com/RobyFerro/go-web-framework v0.6.0-beta/go.mod h1:wB/7eaLLMAq+y4rGnKxvrRlw+c3RoO6i825jBCd44gU=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1 h1:lnVadil6o8krZE47ms2PCxhXcki/UwoqiB0axOIV3mk=
github.com/auth0/go-jwt-middleware v0.0.0-20200810150920-a32d7af194d1/go.mod h1:mF0ip7kTEFtnhBJbd/gJe62US3jykNN+dcZoZakJCCA=
Expand All @@ -12,15 +12,15 @@ github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/
github.com/brianvoe/gofakeit/v4 v4.3.0 h1:y8octMlc4cmDra6sIst89NHEjZuWYmZDl9H0i5wjTvY=
github.com/brianvoe/gofakeit/v4 v4.3.0/go.mod h1:GC/GhKWdGJ2eskBf4zGdjo3eHj8rX4E9hFLFg0bqK4s=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
github.com/common-nighthawk/go-figure v0.0.0-20200609044655-c4b36f998cf2 h1:tjT4Jp4gxECvsJcYpAMtW2I3YqzBTPuB67OejxXs86s=
github.com/common-nighthawk/go-figure v0.0.0-20200609044655-c4b36f998cf2/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e h1:LzwWXEScfcTu7vUZNlDDWDARoSGEtvlDKK2BYHowNeE=
github.com/denisenkom/go-mssqldb v0.0.0-20200206145737-bbfc9a55622e/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/denisenkom/go-mssqldb v0.10.0 h1:QykgLZBorFE95+gO3u9esLd0BmbvpWp0/waNNZfHBM8=
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/elastic/go-elasticsearch/v8 v8.0.0-20200819071622-59b6a186f8dd h1:kVw29H2M+wai0NQ/W8FzngD80DnHTUfz/8kbfZl10hU=
Expand Down Expand Up @@ -186,8 +186,6 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7Jul
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.mongodb.org/mongo-driver v1.5.1 h1:9nOVLGDfOaZ9R0tBumx/BcuqkbFpyTCU2r/Po7A2azI=
go.mongodb.org/mongo-driver v1.5.1/go.mod h1:gRXCHX4Jo7J0IJ1oDQyUxF7jfy19UfxniMS4xxMmUqw=
go.uber.org/dig v1.12.0 h1:l1GQeZpEbss0/M4l/ZotuBndCrkMdjnygzgcuOjAdaY=
go.uber.org/dig v1.12.0/go.mod h1:X34SnWGr8Fyla9zQNO2GSO2D+TIuqB14OS8JhYocIyw=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand All @@ -196,8 +194,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf h1:B2n+Zi5QeYRDAEodEu72OS36gmTWjgpXr2+cWcBW90o=
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
Expand All @@ -212,8 +210,8 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -234,10 +232,12 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
Expand Down
20 changes: 3 additions & 17 deletions goweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,14 @@ package main
import (
"encoding/gob"
"github.com/RobyFerro/go-web-framework"
"github.com/RobyFerro/go-web/app/http/middleware"
"github.com/RobyFerro/go-web/database/model"
"os"
"github.com/RobyFerro/go-web/register"
)

// Main Go-Web entry point.
func main() {
gob.Register(&model.User{})

entities := baseEntities()
foundation.Start(os.Args[1:], entities)
}

// Returns a filled BaseEntities struct.
func baseEntities() foundation.BaseEntities {
return foundation.BaseEntities{
Commands: Commands,
Controllers: Controllers,
Services: Services,
SingletonServices: SingletonServices,
CommandServices: CommandServices,
Models: Models,
Middlewares: middleware.Middleware{},
}
entities := register.BaseEntities()
foundation.Start(entities)
}
19 changes: 19 additions & 0 deletions register/entities.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package register

import (
"github.com/RobyFerro/go-web-framework"
"github.com/RobyFerro/go-web/app/http/middleware"
)

// BaseEntities returns a struct that contains Go-Web base entities
func BaseEntities() foundation.BaseEntities {
return foundation.BaseEntities{
Commands: Commands,
Controllers: Controllers,
Services: Services,
SingletonServices: SingletonServices,
CommandServices: CommandServices,
Models: Models,
Middlewares: middleware.Middleware{},
}
}
2 changes: 1 addition & 1 deletion register.go → register/register.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package register

import (
"github.com/RobyFerro/go-web-framework/register"
Expand Down
107 changes: 4 additions & 103 deletions tool/alfred.go
Original file line number Diff line number Diff line change
@@ -1,111 +1,12 @@
package main

import (
"fmt"
"github.com/RobyFerro/go-web-framework/cli"
"github.com/RobyFerro/go-web/app"
"github.com/RobyFerro/go-web/service"
"github.com/common-nighthawk/go-figure"
"log"
"github.com/RobyFerro/go-web-framework"
"github.com/RobyFerro/go-web/register"
"os"
)

func main() {
myFigure := figure.NewFigure("GWF-Alfred", "", true)
myFigure.Print()

fmt.Println("\nGo-Web - Alfred CLI tool - Author: [email protected]")

args := os.Args[1:]

if len(args) == 0 {
log.Fatal("Missing arguments, type -h/--help to show available commands")
}

switch args[0] {
case "--help", "-h":
help()
case "--make-controller", "-mC":
if len(args) != 2 {
log.Fatal("Missing controller name")
}
cmd := cli.ControllerCreate{Args: args[1]}
cmd.Run()
case "--make-command", "-mCMD":
if len(args) != 2 {
log.Fatal("Missing command name")
}

cmd := cli.CmdCreate{Args: args[1]}
cmd.Run()
case "--make-model", "-mM":
if len(args) != 2 {
log.Fatal("Missing model name")
}
cmd := cli.ModelCreate{Args: args[1]}
cmd.Run()
case "--make-migration", "-mDBM":
if len(args) != 2 {
log.Fatal("Missing migration name")
}
cmd := cli.MigrationCreate{Args: args[1]}
cmd.Run()
case "--make-job", "-mJ":
if len(args) != 2 {
log.Fatal("Missing migration name")
}
cmd := cli.JobCreate{Args: args[1]}
cmd.Run()
case "--migrate-up", "-mU":
conf, err := app.Configuration()
if err != nil {
log.Fatal(err)
}

db := service.ConnectDB(conf)
cmd := cli.MigrationUp{}
cmd.Run(db)
case "--migrate-rollback", "-mR":
if len(args) != 2 {
log.Fatal("Missing rollback step")
}

conf, err := app.Configuration()
if err != nil {
log.Fatal(err)
}

db := service.ConnectDB(conf)
cmd := cli.MigrateRollback{
Args: args[1],
}
cmd.Run(db)
case "--make-middleware", "-mMW":
if len(args) != 2 {
log.Fatal("Missing middleware name")
}
cmd := cli.MiddlewareCreate{Args: args[1]}
cmd.Run()
case "--generate-key", "-gK":
cmd := cli.GenerateKey{}
cmd.Run()
}
}

func help() {
fmt.Println("Usage: alfred [command] [options]")

fmt.Println("\nBASIC COMMANDS:")
fmt.Println(" --help -h: Shows help menu")

fmt.Println("\nPROJECT COMMANDS - RUNS THIS COMMANDS ONLY IN PROJECT ROOT!")
fmt.Println(" --make-controller, -mC <controller_name>: Creates new Go-Web controller")
fmt.Println(" --make-command, -mCMD <command_name>: Creates new Go-Web command")
fmt.Println(" --make-model, -mM <model_name>: Creates new Go-Web model")
fmt.Println(" --make-migration , -mDBM <migration_name>: Creates new Go-Web SQL migration")
fmt.Println(" --make-middleware , -mMW <middleware_name>: Creates new middleware")
fmt.Println(" --make-job, -mJ <job_name>: Creates new async job")
fmt.Println(" --migrate-up, -mU: Executes migrations")
fmt.Println(" --migrate-rollback, -mR <steps>: Executes migrations rollback")
fmt.Println(" --generate-key, -gK: Generate new application key")
entities := register.BaseEntities()
foundation.StartCommand(os.Args[1:], entities)
}

0 comments on commit c6b95c4

Please sign in to comment.