menus & fixing
This commit is contained in:
parent
c6c649abf6
commit
2e8ed6654f
27
cmd/app.go
27
cmd/app.go
@ -1,5 +1,32 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
helper "git.espin.casa/albert/TC2-BBS-Mesh/internal/helpers"
|
||||
"git.espin.casa/albert/TC2-BBS-Mesh/internal/menus"
|
||||
"git.espin.casa/albert/TC2-BBS-Mesh/internal/storage"
|
||||
"git.espin.casa/albert/logger"
|
||||
)
|
||||
|
||||
func Run() error {
|
||||
// log trace level
|
||||
logLevel := flag.String("level", "debug", "Log level")
|
||||
// parse flags
|
||||
flag.Parse()
|
||||
// setup logger
|
||||
log := logger.New(os.Stdout, *logLevel)
|
||||
// create new storage
|
||||
storage, err := storage.NewStorage("./go-bbs.db", log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer storage.Close()
|
||||
// info banner
|
||||
helper.PrintBanner()
|
||||
// show menu
|
||||
menus.MeshMenu()
|
||||
// done
|
||||
return nil
|
||||
}
|
||||
|
23
go.mod
23
go.mod
@ -2,29 +2,18 @@ module git.espin.casa/albert/TC2-BBS-Mesh
|
||||
|
||||
go 1.24.0
|
||||
|
||||
require git.espin.casa/albert/logger v1.0.0
|
||||
require (
|
||||
git.espin.casa/albert/logger v1.0.0
|
||||
gorm.io/driver/sqlite v1.5.7
|
||||
gorm.io/gorm v1.25.12
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.9.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/lmatte7/gomesh v0.2.0 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.24 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
golang.org/x/mod v0.24.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
github.com/turret-io/go-menu v1.0.2
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
golang.org/x/tools v0.31.0 // indirect
|
||||
google.golang.org/protobuf v1.26.0 // indirect
|
||||
gorm.io/datatypes v1.2.5 // indirect
|
||||
gorm.io/driver/mysql v1.5.7 // indirect
|
||||
gorm.io/driver/sqlite v1.5.7 // indirect
|
||||
gorm.io/gen v0.3.26 // indirect
|
||||
gorm.io/gorm v1.25.12 // indirect
|
||||
gorm.io/hints v1.1.2 // indirect
|
||||
gorm.io/plugin/dbresolver v1.5.3 // indirect
|
||||
)
|
||||
|
78
go.sum
78
go.sum
@ -1,98 +1,32 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
git.espin.casa/albert/logger v1.0.0 h1:DF+SwwkptiZBiB1HUIPcKRRoLuUC7fVUfnF/I9p5Cj4=
|
||||
git.espin.casa/albert/logger v1.0.0/go.mod h1:TXbZ7mayDtJvcs+DucVbs2klio9jq5k1eWFZ2wxgRGM=
|
||||
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/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/go-sql-driver/mysql v1.9.0 h1:Y0zIbQXhQKmQgTp44Y1dp3wTXcn804QoTptLZT1vtvo=
|
||||
github.com/go-sql-driver/mysql v1.9.0/go.mod h1:pDetrLJeA3oMujJuvXc8RJoasr589B6A9fwzD3QMrqw=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4 h1:G2ztCwXov8mRvP0ZfjE6nAlaCX2XbykaeHdbT6KwDz0=
|
||||
github.com/jacobsa/go-serial v0.0.0-20180131005756-15cf729a72d4/go.mod h1:2RvX5ZjVtsznNZPEt4xwJXNJrM3VTZoQf7V6gk0ysvs=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/lmatte7/gomesh v0.2.0 h1:7oSKizmWIf0U5/BDkG6dpEOjjzwhf6kmRcMxqSvpFR4=
|
||||
github.com/lmatte7/gomesh v0.2.0/go.mod h1:1NV2b6GetWWliM7CKVF6+VaC+pfz4G+igCtmu76s4kg=
|
||||
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
||||
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
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=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
|
||||
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
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/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/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-20210525143221-35b2ab0089ea h1:+WiDlPBBaO+h9vPNZi8uJ3k4BkKQB7Iow3aqwHVA5hI=
|
||||
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/turret-io/go-menu v1.0.2 h1:wnxh52FwySBKHgASpJq/x5fQLYwcZwroJVFf4uJ8v/g=
|
||||
github.com/turret-io/go-menu v1.0.2/go.mod h1:k7e/ziL/JqwImhubSklas2BjL8Co9zzIrv68Qsmufsk=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
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.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
|
||||
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gorm.io/datatypes v1.2.5 h1:9UogU3jkydFVW1bIVVeoYsTpLRgwDVW3rHfJG6/Ek9I=
|
||||
gorm.io/datatypes v1.2.5/go.mod h1:I5FUdlKpLb5PMqeMQhm30CQ6jXP8Rj89xkTeCSAaAD4=
|
||||
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
|
||||
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
|
||||
gorm.io/driver/sqlite v1.5.0/go.mod h1:kDMDfntV9u/vuMmz8APHtHF0b4nyBB7sfCieC6G8k8I=
|
||||
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
|
||||
gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
|
||||
gorm.io/gen v0.3.26 h1:sFf1j7vNStimPRRAtH4zz5NiHM+1dr6eA9aaRdplyhY=
|
||||
gorm.io/gen v0.3.26/go.mod h1:a5lq5y3w4g5LMxBcw0wnO6tYUCdNutWODq5LrIt75LE=
|
||||
gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
|
||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
||||
gorm.io/hints v1.1.2 h1:b5j0kwk5p4+3BtDtYqqfY+ATSxjj+6ptPgVveuynn9o=
|
||||
gorm.io/hints v1.1.2/go.mod h1:/ARdpUHAtyEMCh5NNi3tI7FsGh+Cj/MIUlvNxCNCFWg=
|
||||
gorm.io/plugin/dbresolver v1.5.3 h1:wFwINGZZmttuu9h7XpvbDHd8Lf9bb8GNzp/NpAMV2wU=
|
||||
gorm.io/plugin/dbresolver v1.5.3/go.mod h1:TSrVhaUg2DZAWP3PrHlDlITEJmNOkL0tFTjvTEsQ4XE=
|
||||
|
@ -1 +1,22 @@
|
||||
package helper
|
||||
|
||||
import "fmt"
|
||||
|
||||
func PrintBanner() {
|
||||
banner := `
|
||||
██████╗ ██████╗ ██████╗ ██████╗ ███████╗
|
||||
██╔════╝ ██╔═══██╗ ██╔══██╗██╔══██╗██╔════╝
|
||||
██║ ███╗██║ ██║ ██████╔╝██████╔╝███████╗
|
||||
██║ ██║██║ ██║ ██╔══██╗██╔══██╗╚════██║
|
||||
╚██████╔╝╚██████╔╝ ██████╔╝██████╔╝███████║
|
||||
╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝
|
||||
|
||||
███╗ ███╗███████╗███████╗██╗ ██╗████████╗ █████╗ ███████╗████████╗██╗ ██████╗
|
||||
████╗ ████║██╔════╝██╔════╝██║ ██║╚══██╔══╝██╔══██╗██╔════╝╚══██╔══╝██║██╔════╝
|
||||
██╔████╔██║█████╗ ███████╗███████║ ██║ ███████║███████╗ ██║ ██║██║
|
||||
██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ██║ ██╔══██║╚════██║ ██║ ██║██║
|
||||
██║ ╚═╝ ██║███████╗███████║██║ ██║ ██║ ██║ ██║███████║ ██║ ██║╚██████╗
|
||||
╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝
|
||||
`
|
||||
fmt.Println(banner)
|
||||
}
|
||||
|
37
internal/menus/menus.go
Normal file
37
internal/menus/menus.go
Normal file
@ -0,0 +1,37 @@
|
||||
package menus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/turret-io/go-menu/menu"
|
||||
)
|
||||
|
||||
func cmd1(args ...string) error {
|
||||
// Do something
|
||||
fmt.Println("Output of cmd1")
|
||||
return nil
|
||||
}
|
||||
|
||||
func MeshMenu() {
|
||||
|
||||
commandOptions := []menu.CommandOption{
|
||||
{Command: "1", Description: "List Bulletins", Function: cmd1},
|
||||
{Command: "2", Description: "List Mail", Function: cmd1},
|
||||
{Command: "3", Description: "List Channels", Function: cmd1},
|
||||
{Command: "4", Description: "Delete Bulletins", Function: cmd1},
|
||||
{Command: "5", Description: "Delete Mails", Function: cmd1},
|
||||
{Command: "6", Description: "Delete Channels", Function: cmd1},
|
||||
}
|
||||
|
||||
// print("Menu:")
|
||||
// print("1. List Bulletins")
|
||||
// print("2. List Mail")
|
||||
// print("3. List Channels")
|
||||
// print("4. Delete Bulletins")
|
||||
// print("5. Delete Mail")
|
||||
// print("6. Delete Channels")
|
||||
// print("7. Exit")
|
||||
menuOptions := menu.NewMenuOptions("'menu' for help > ", 0)
|
||||
mainMenu := menu.NewMenu(commandOptions, menuOptions)
|
||||
mainMenu.Start()
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"git.espin.casa/albert/TC2-BBS-Mesh/internal/types"
|
||||
"git.espin.casa/albert/logger"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
@ -11,41 +12,37 @@ type Storage struct {
|
||||
log logger.LoggerAdapter
|
||||
}
|
||||
|
||||
type Bulletin struct {
|
||||
gorm.Model
|
||||
Board string `json:"board"`
|
||||
SenderShortName string `json:"sender_short_name"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
UniqueID string `json:"unique_id"`
|
||||
}
|
||||
|
||||
type Mail struct {
|
||||
gorm.Model
|
||||
Sender string `json:"sender"`
|
||||
SenderShortName string `json:"sender_short_name"`
|
||||
Recipient string `json:"recipient"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
UniqueID string `json:"unique_id"`
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
gorm.Model
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
// ListBulletins list all bulletins in database
|
||||
func (s *Storage) ListBulletins() (bulletins []Bulletin, err error) {
|
||||
s.db.
|
||||
|
||||
func (s *Storage) ListBulletins() (bulletins []types.Bulletin, err error) {
|
||||
// get all list bulletins
|
||||
if err := s.db.Find(&bulletins).Error; err != nil {
|
||||
s.log.Error("list all bulletins failed", err, logger.LogFields{})
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Storage) ListMail() ([]Mail, error) {
|
||||
|
||||
// ListMails list all mails in database
|
||||
func (s *Storage) ListMails() (mails []types.Mail, err error) {
|
||||
// get all list mails
|
||||
if err := s.db.Find(&mails).Error; err != nil {
|
||||
s.log.Error("list all mails failed", err, logger.LogFields{})
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ListChannels list all channels in database
|
||||
func (s *Storage) ListChannels() (channels []types.Channel, err error) {
|
||||
// get all list channels
|
||||
if err := s.db.Find(&channels).Error; err != nil {
|
||||
s.log.Error("list all channels failed", err, logger.LogFields{})
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NewStorage create a new storage instance with database connection and logger
|
||||
func NewStorage(path string, log logger.LoggerAdapter) (*Storage, error) {
|
||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
|
||||
if err != nil {
|
||||
@ -53,7 +50,7 @@ func NewStorage(path string, log logger.LoggerAdapter) (*Storage, error) {
|
||||
}
|
||||
|
||||
// AutoMigrate will create the tables and necessary constraints for your models
|
||||
err = db.AutoMigrate(&Bulletin{}, &Mail{}, &Channel{})
|
||||
err = db.AutoMigrate(&types.Bulletin{}, &types.Mail{}, &types.Channel{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
28
internal/types/types.go
Normal file
28
internal/types/types.go
Normal file
@ -0,0 +1,28 @@
|
||||
package types
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Bulletin struct {
|
||||
gorm.Model
|
||||
Board string `json:"board"`
|
||||
SenderShortName string `json:"sender_short_name"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
UniqueID string `json:"unique_id"`
|
||||
}
|
||||
|
||||
type Mail struct {
|
||||
gorm.Model
|
||||
Sender string `json:"sender"`
|
||||
SenderShortName string `json:"sender_short_name"`
|
||||
Recipient string `json:"recipient"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
UniqueID string `json:"unique_id"`
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
gorm.Model
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user