Compare commits

...

4 Commits

  1. 2
      cmd/commands/create_ticket_keys.go
  2. 29
      cmd/main.go
  3. 9
      go.mod
  4. 29
      go.sum
  5. 4
      internal/init.go
  6. 4
      internal/services/company/controller/company_controller.go
  7. 4
      internal/services/company/controller/company_department_controller.go
  8. 4
      internal/services/company/controller/company_staff_controller.go
  9. 4
      internal/services/company/service.go
  10. 4
      internal/services/config/controller/config_controller.go
  11. 4
      internal/services/config/controller/config_group_controller.go
  12. 4
      internal/services/config/service.go
  13. 4
      internal/services/feature/controller/feature_category_controller.go
  14. 4
      internal/services/feature/controller/feature_config_controller.go
  15. 4
      internal/services/feature/controller/feature_content_chapter_controller.go
  16. 4
      internal/services/feature/controller/feature_content_controller.go
  17. 4
      internal/services/feature/controller/feature_content_detail_controller.go
  18. 4
      internal/services/feature/controller/feature_controller.go
  19. 4
      internal/services/feature/service.go
  20. 4
      internal/services/resource/controller/resource_category_controller.go
  21. 4
      internal/services/resource/controller/resource_controller.go
  22. 4
      internal/services/resource/service.go
  23. 20
      internal/services/service.go
  24. 4
      internal/services/system/controller/system_log_controller.go
  25. 4
      internal/services/system/controller/system_menu_controller.go
  26. 4
      internal/services/system/controller/system_permission_controller.go
  27. 4
      internal/services/system/controller/system_role_controller.go
  28. 4
      internal/services/system/controller/system_role_power_controller.go
  29. 4
      internal/services/system/controller/system_user_controller.go
  30. 4
      internal/services/system/service.go
  31. 179
      pkg/app/pubsub.go
  32. 2
      pkg/crud/context.go
  33. 2
      pkg/crud/controller.go
  34. 2
      pkg/crud/echo_utils.go
  35. 2
      pkg/crud/service.go

@ -1,4 +1,4 @@
package main
package commands
import (
"crypto/rand"

@ -1 +1,30 @@
package main
import (
"log"
"os"
"sorbet/cmd/commands"
"github.com/urfave/cli/v2"
)
var app = &cli.App{
Name: "sorbet",
Usage: "sorbet scaffold",
Commands: []*cli.Command{
{
Name: "secret",
Usage: "Builds a ticket private/public keys",
Action: func(c *cli.Context) error {
g := new(commands.TicketKeysGenerator)
return g.Generate()
},
},
},
}
func main() {
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

@ -3,7 +3,6 @@ module sorbet
go 1.21
require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/go-resty/resty/v2 v2.7.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/joho/godotenv v1.5.1
@ -11,7 +10,7 @@ require (
github.com/labstack/gommon v0.4.0
github.com/mattn/go-isatty v0.0.19
github.com/rs/xid v1.5.0
github.com/stoewer/go-strcase v1.3.0
github.com/urfave/cli/v2 v2.25.7
golang.org/x/time v0.3.0
gorm.io/driver/mysql v1.5.1
gorm.io/driver/postgres v1.5.2
@ -22,6 +21,7 @@ require (
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
@ -31,17 +31,16 @@ require (
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/microsoft/go-mssqldb v1.1.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
)

@ -1,13 +1,9 @@
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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=
@ -33,8 +29,6 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
@ -53,26 +47,20 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/labstack/echo/v4 v4.11.1 h1:dEpLU2FLg4UVmvCGPuk/APjlH6GDpbEPti61srUUUs4=
github.com/labstack/echo/v4 v4.11.1/go.mod h1:YuYRTSM3CHs2ybfrL8Px48bO6BAnYIN4l8wSTMP6BDQ=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/microsoft/go-mssqldb v1.1.0 h1:jsV+tpvcPTbNNKW0o3kiCD69kOHICsfjZ2VcVu2lKYc=
github.com/microsoft/go-mssqldb v1.1.0/go.mod h1:LzkFdl4z2Ck+Hi+ycGOTbL56VEfgoyA2DvYejrNGbRk=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
@ -82,25 +70,28 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
@ -126,7 +117,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -147,13 +137,10 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=

@ -31,16 +31,16 @@ func syncEntities() error {
&entities.Company{},
&entities.CompanyDepartment{},
&entities.CompanyStaff{},
&entities.Config{},
&entities.ConfigGroup{},
&entities.Config{},
&entities.Feature{},
&entities.FeatureCategory{},
&entities.FeatureConfig{},
&entities.FeatureContent{},
&entities.FeatureContentChapter{},
&entities.FeatureContentDetail{},
&entities.Resource{},
&entities.ResourceCategory{},
&entities.Resource{},
&entities.SystemLog{},
&entities.SystemMenu{},
&entities.SystemPermission{},

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/company/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type CompanyController struct {
app.Controller[entities.Company, request.CompanyUpsertRequest]
crud.Controller[entities.Company, request.CompanyUpsertRequest]
}
func (ctr *CompanyController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/company/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type CompanyDepartmentController struct {
app.Controller[entities.CompanyDepartment, request.CompanyDepartmentUpsertRequest]
crud.Controller[entities.CompanyDepartment, request.CompanyDepartmentUpsertRequest]
}
func (c *CompanyDepartmentController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/company/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type CompanyStaffController struct {
app.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest]
crud.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest]
}
func (c *CompanyStaffController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package company
import (
"sorbet/internal/services/company/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 1
}
func (*Service) Init(ctx *app.Context) error {
func (*Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.CompanyController{})
ctx.Routes(&controller.CompanyDepartmentController{})
ctx.Routes(&controller.CompanyStaffController{})

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/config/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type ConfigController struct {
app.Controller[entities.Config, request.ConfigUpsertRequest]
crud.Controller[entities.Config, request.ConfigUpsertRequest]
}
func (ctr *ConfigController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/config/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type ConfigGroupController struct {
app.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest]
crud.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest]
}
// InitRoutes 实现路由注册接口

@ -2,7 +2,7 @@ package config
import (
"sorbet/internal/services/config/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 0
}
func (*Service) Init(ctx *app.Context) error {
func (*Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.ConfigGroupController{})
ctx.Routes(&controller.ConfigController{})
return nil

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/feature/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type FeatureCategoryController struct {
app.Controller[entities.FeatureCategory, request.FeatureCategoryUpsertRequest]
crud.Controller[entities.FeatureCategory, request.FeatureCategoryUpsertRequest]
}
func (f *FeatureCategoryController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/feature/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type FeatureConfigController struct {
app.Controller[entities.FeatureConfig, request.FeatureConfigUpsertRequest]
crud.Controller[entities.FeatureConfig, request.FeatureConfigUpsertRequest]
}
func (f *FeatureConfigController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/feature/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type FeatureContentChapterController struct {
app.Controller[entities.FeatureContentChapter, request.FeatureContentChapterUpsertRequest]
crud.Controller[entities.FeatureContentChapter, request.FeatureContentChapterUpsertRequest]
}
func (f *FeatureContentChapterController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/feature/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type FeatureContentController struct {
app.Controller[entities.FeatureContent, request.FeatureContentUpsertRequest]
crud.Controller[entities.FeatureContent, request.FeatureContentUpsertRequest]
}
func (f *FeatureContentController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/feature/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type FeatureContentDetailController struct {
app.Controller[entities.FeatureContentDetail, request.FeatureContentDetailUpsertRequest]
crud.Controller[entities.FeatureContentDetail, request.FeatureContentDetailUpsertRequest]
}
func (f *FeatureContentDetailController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/feature/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type FeatureController struct {
app.Controller[entities.Feature, request.FeatureUpsertRequest]
crud.Controller[entities.Feature, request.FeatureUpsertRequest]
}
func (f *FeatureController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package feature
import (
"sorbet/internal/services/feature/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 3
}
func (s *Service) Init(ctx *app.Context) error {
func (s *Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.FeatureCategoryController{})
ctx.Routes(&controller.FeatureConfigController{})
ctx.Routes(&controller.FeatureContentChapterController{})

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/resource/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type ResourceCategoryController struct {
app.Controller[entities.Resource, request.ResourceCategoryUpsertRequest]
crud.Controller[entities.Resource, request.ResourceCategoryUpsertRequest]
}
func (ctr *ResourceCategoryController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/resource/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type ResourceController struct {
app.Controller[entities.Resource, request.ResourceUpsertRequest]
crud.Controller[entities.Resource, request.ResourceUpsertRequest]
}
func (ctr *ResourceController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package resource
import (
"sorbet/internal/services/resource/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 2
}
func (*Service) Init(ctx *app.Context) error {
func (*Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.ResourceController{})
ctx.Routes(&controller.ResourceCategoryController{})
return nil

@ -10,12 +10,14 @@ import (
"sorbet/internal/services/feature"
"sorbet/internal/services/resource"
"sorbet/internal/services/system"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
var services []app.Service
var services []crud.Service
func Register(service app.Service) error {
const ContextEchoKey = "echo_framework"
func Register(service crud.Service) error {
for _, applet := range services {
if applet.Name() == service.Name() {
return errors.New("service already registered")
@ -25,8 +27,8 @@ func Register(service app.Service) error {
return nil
}
func Init() {
services = []app.Service{
func Init(ctx context.Context) error {
services = []crud.Service{
&config.Service{},
&company.Service{},
&resource.Service{},
@ -35,15 +37,17 @@ func Init() {
}
// 按优先级排序
slices.SortFunc(services, func(a, b app.Service) int {
slices.SortFunc(services, func(a, b crud.Service) int {
return b.Priority() - a.Priority()
})
return nil
}
func Bootstrap(ctx context.Context) error {
e := ctx.Value("echo_framework").(*echo.Echo)
e := ctx.Value(ContextEchoKey).(*echo.Echo)
for _, service := range services {
err := service.Init(app.NewContext(ctx, e.Group("")))
err := service.Init(crud.NewContext(ctx, e.Group("")))
if err != nil {
return err
}

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/system/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type SystemLogController struct {
app.Controller[entities.SystemLog, request.SystemLogUpsertRequest]
crud.Controller[entities.SystemLog, request.SystemLogUpsertRequest]
}
func (s *SystemLogController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/system/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type SystemMenuController struct {
app.Controller[entities.SystemMenu, request.SystemMenuUpsertRequest]
crud.Controller[entities.SystemMenu, request.SystemMenuUpsertRequest]
}
func (s *SystemMenuController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/system/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type SystemPermissionController struct {
app.Controller[entities.SystemPermission, request.SystemPermissionUpsertRequest]
crud.Controller[entities.SystemPermission, request.SystemPermissionUpsertRequest]
}
func (s *SystemPermissionController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/system/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type SystemRoleController struct {
app.Controller[entities.SystemRole, request.SystemRoleUpsertRequest]
crud.Controller[entities.SystemRole, request.SystemRoleUpsertRequest]
}
func (s *SystemRoleController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/system/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type SystemRolePowerController struct {
app.Controller[entities.SystemRolePower, request.SystemRolePowerUpsertRequest]
crud.Controller[entities.SystemRolePower, request.SystemRolePowerUpsertRequest]
}
func (s *SystemRolePowerController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4"
"sorbet/internal/entities"
"sorbet/internal/services/system/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type SystemUserController struct {
app.Controller[entities.SystemUser, request.SystemUserUpsertRequest]
crud.Controller[entities.SystemUser, request.SystemUserUpsertRequest]
}
func (s *SystemUserController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package system
import (
"sorbet/internal/services/system/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 3
}
func (s *Service) Init(ctx *app.Context) error {
func (s *Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.SystemLogController{})
ctx.Routes(&controller.SystemMenuController{})
ctx.Routes(&controller.SystemPermissionController{})

@ -0,0 +1,179 @@
package app
import (
"bytes"
"context"
"encoding/binary"
"fmt"
"io"
"os"
"sync"
)
// Callback 订阅回调
type Callback func(payload []byte)
// Runnable 子协程运行
type Runnable func(ctx context.Context)
var wg sync.WaitGroup
var resChan chan []byte
var doneChan chan struct{}
var channels = make(map[string][]Callback)
var runtime = context.Background()
var stats struct {
send int
respond int
receive int
}
func Async(callback func()) {
wg.Add(1)
go func() {
defer wg.Done()
callback()
}()
}
func process(buf []byte) (response []byte, err error) {
stats.receive++
var n int
var channel []byte
n, channel, err = decode(buf)
if err != nil {
return
}
var payload []byte
_, payload, err = decode(buf[n:])
if err != nil {
return
}
subscribers, ok := channels[string(channel)]
if !ok {
err = fmt.Errorf("no subscribers for channel %s", string(channel))
return
}
for _, subscriber := range subscribers[:] {
// fixme: 是否需要使用 payload 的副本?
recovery(payload, subscriber)
}
if response != nil {
stats.respond++
}
return
}
func recovery(payload []byte, callback Callback) {
defer func() {
err := recover()
if err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
}
}()
callback(payload)
}
func Sub(channel string, callback Callback) {
subscribers, ok := channels[channel]
if !ok {
subscribers = make([]Callback, 0)
}
subscribers = append(subscribers, callback)
channels[channel] = subscribers
}
// 定义写数据的格式
func encode(data []byte) []byte {
// 4字节头部 + 可变体的长度
buf := make([]byte, 4+len(data))
// 写入头部,记录数据长度
binary.BigEndian.PutUint32(buf[:4], uint32(len(data)))
// 将整个数据,放到4后边
copy(buf[4:], data)
// 返回结果
return buf
}
func decode(buf []byte) (int, []byte, error) {
r := bytes.NewBuffer(buf)
// 读取头部记录的长度
header := make([]byte, 4)
// 按长度读取消息
_, err := io.ReadFull(r, header)
if err != nil {
return 0, nil, err
}
// 读取数据
dataLen := binary.BigEndian.Uint32(header)
data := make([]byte, dataLen)
_, err = io.ReadFull(r, data)
if err != nil {
return 0, nil, err
}
return 4 + int(dataLen), data, nil
}
func Pub(channel string, payload []byte) {
// fixme: 在时间和空间上,是否有比 append 性能更好的操作
buf := append(encode([]byte(channel)), encode(payload)...)
wg.Add(1)
resChan <- buf
}
func Run(runner Runnable) {
Async(func() {
runner(runtime)
})
}
func Loop() {
wg.Add(1)
first := true
var cancel context.CancelFunc
runtime, cancel = context.WithCancel(context.Background())
go func() {
wg.Wait()
cancel()
doneChan <- struct{}{}
}()
for {
select {
case msg := <-resChan:
process(msg)
wg.Done() // Corresponds to the wg.Add(1) in Pub().
case <-doneChan:
// All goroutines have completed. Now we can exit main().
checkChanEmpty()
return
}
// We don't want to exit until we've received at least one message.
// This is so the program doesn't exit after sending the "start"
// message.
if first {
wg.Done()
first = false
}
}
// todo 清理工作
}
func checkChanEmpty() {
// We've received a done event. As a sanity check, make sure that resChan is
// empty.
select {
case _, ok := <-resChan:
if ok {
panic("Read a message from resChan after doneChan closed.")
} else {
panic("resChan closed. Unexpected.")
}
default:
// No value ready, moving on.
}
}

@ -1,4 +1,4 @@
package app
package crud
import (
"context"

@ -1,4 +1,4 @@
package app
package crud
import (
"github.com/labstack/echo/v4"

@ -1,4 +1,4 @@
package app
package crud
import (
"github.com/labstack/echo/v4"

@ -1,4 +1,4 @@
package app
package crud
import "github.com/labstack/echo/v4"
Loading…
Cancel
Save