add ability to generate vue componenets based on swagger

This commit is contained in:
2025-03-12 23:53:25 -06:00
parent a8f2b832b4
commit d749a32abd
5 changed files with 530 additions and 42 deletions

View File

@ -0,0 +1,3 @@
local.db
gen/
webapp/src/generated/

View File

@ -1,7 +1,7 @@
package main
import (
"context"
"context"
"log"
"net"
"net/http"
@ -9,40 +9,63 @@ import (
"time"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/payne8/go-libsql-dual-driver"
"github.com/rs/cors"
sqlite "github.com/ytsruh/gorm-libsql"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/reflection"
"gorm.io/gorm"
pb "{{ .AppName }}/gen/go"
pb "{{ .AppName }}/gen/go"
// the following line is used for the local database
"gorm.io/driver/sqlite"
// uncomment the following lines to switch to a production ready remote database
//libsqldb "github.com/payne8/go-libsql-dual-driver"
//sqlite "github.com/ytsruh/gorm-libsql"
)
func main() {
logger := log.New(os.Stdout, "{{ .AppName }} ", log.LstdFlags)
primaryUrl := os.Getenv("LIBSQL_DATABASE_URL")
authToken := os.Getenv("LIBSQL_AUTH_TOKEN")
tdb, err := libsqldb.NewLibSqlDB(
primaryUrl,
// libsqldb.WithMigrationFiles(migrationFiles),
libsqldb.WithAuthToken(authToken),
libsqldb.WithLocalDBName("local.db"), // will not be used for remote-only
)
// instantiate the grom ORM
/*
uncomment the following code to switch to a production ready remote database
you will need to set the environment variables
*/
// --------------------- start of remote database code ---------------------
//primaryUrl := os.Getenv("LIBSQL_DATABASE_URL")
//authToken := os.Getenv("LIBSQL_AUTH_TOKEN")
//tdb, err := libsqldb.NewLibSqlDB(
// primaryUrl,
// //libsqldb.WithMigrationFiles(migrationFiles),
// libsqldb.WithAuthToken(authToken),
// libsqldb.WithLocalDBName("local.db"), // will not be used for remote-only
//)
//if err != nil {
// logger.Printf("failed to open db %s: %s", primaryUrl, err)
// log.Fatalln(err)
// return
//}
//gormDB, err := gorm.Open(sqlite.New(sqlite.Config{Conn: tdb.DB}), &gorm.Config{})
//if err != nil {
// logger.Printf("failed to open gorm db %s: %s", primaryUrl, err)
// log.Fatalln(err)
// return
//}
// --------------------- end of remote database code ---------------------
// -- start of local database code --
gormDB, err := gorm.Open(sqlite.Open("local.db"), &gorm.Config{})
if err != nil {
logger.Printf("failed to open db %s: %s", primaryUrl, err)
log.Fatalln(err)
return
}
// Instantiate the gorm ORM
gormDB, err := gorm.Open(sqlite.New(sqlite.Config{Conn: tdb.DB}), &gorm.Config{})
if err != nil {
logger.Printf("failed to open gorm db %s: %s", primaryUrl, err)
logger.Printf("failed to open gorm db: %s", err)
log.Fatalln(err)
return
}
// -- end of local database code --
// Uncomment these lines if you need automatic migration
// err = gormDB.AutoMigrate(&pb.UserORM{})