Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyaoMa committed Sep 15, 2022
1 parent a6d3184 commit eda6b64
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ Prepare and install environment for development in Window 10/11?
- Go v1.19+, https://go.dev/
- Node.js v16+, https://nodejs.org/
- PNPM v7+, https://pnpm.io/
- VS Code v1.71+, https://code.visualstudio.com/
- VS Code v1.71+ with GCC, https://code.visualstudio.com/docs/cpp/config-mingw
- WebView2 v104+, https://developer.microsoft.com/en-us/microsoft-edge/webview2/

> Run command `pnpm install` at project root directory to setup.
## Technologies

| Technology | Role | Sources |
| :---------- | :---------------------------------------------------- | :------------------------------------ |
| Go | Backend programming language | https://pkg.go.dev/std |
| TypeScript | Frontend programming language | https://typescriptlang.org |
| Vite | Next Generation Frontend Tooling | https://vitejs.dev/ |
| Vue 3 | Progressive JavaScript Framework | https://vuejs.org/ |
| Wails | Build cross-platform desktop applications using Go | https://wails.io/ |
| UPX | Ultimate packer for executables | https://upx.github.io/ |
| Systray | A cross platfrom system tray using Go | https://github.com/getlantern/systray |
| Gin | A HTTP web framework using Go | https://gin-gonic.com/ |
| Gin Swagger | Gin middleware for API documentation with Swagger 2.0 | https://github.com/swaggo/gin-swagger |
| Swaggo | Converts Go annotations to Swagger Documentation 2.0 | https://github.com/swaggo/swag |
| Air | Live reload and test for API service | https://github.com/cosmtrek/air |
| Technology | Role | Sources |
| :---------- | :------------------------------------------------------- | :------------------------------------ |
| Go | Backend programming language | https://pkg.go.dev/std |
| TypeScript | Frontend programming language | https://typescriptlang.org/ |
| Vite | Next Generation Frontend Tooling | https://vitejs.dev/ |
| Vue 3 | Progressive JavaScript Framework | https://vuejs.org/ |
| Wails | Build cross-platform desktop applications using Go | https://wails.io/ |
| UPX | Ultimate packer for executables | https://upx.github.io/ |
| Systray | A cross platfrom system tray using Go | https://github.com/getlantern/systray |
| Gin | A HTTP web framework using Go | https://gin-gonic.com/ |
| Gin Swagger | Gin middleware for API documentation with Swagger 2.0 | https://github.com/swaggo/gin-swagger |
| Swaggo | Converts Go annotations to Swagger Documentation 2.0 | https://github.com/swaggo/swag |
| Air | Live reload and test for API service | https://github.com/cosmtrek/air |
| Gorm | ORM library for Go | https://gorm.io/ |
| SQLite | C-language library that implements a SQL database engine | https://www.sqlite.org/ |
29 changes: 29 additions & 0 deletions backend/model/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package model

import (
"log"
"my-app/backend/utils"

"gorm.io/driver/sqlite"
"gorm.io/gorm"
)

var (
db *gorm.DB
)

func init() {
var err error
db, err = gorm.Open(
sqlite.Open(utils.GetExecutablePath("my-app.db")),
&gorm.Config{
FullSaveAssociations: false,
PrepareStmt: true,
},
)
if err != nil {
log.Fatalf("failed to connect database: %+v\n", err)
}

db.AutoMigrate()
}
24 changes: 24 additions & 0 deletions backend/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
package utils

import (
"log"
"os"
"path/filepath"
)

var (
executablePath string
)

func init() {
var err error

executablePath, err = os.Executable()
if err != nil {
log.Fatalf("fail to get executable path: %+v\n", err)
}
executablePath = filepath.Dir(executablePath)
}

func GetExecutablePath(elem ...string) string {
return filepath.Join(append([]string{executablePath}, elem...)...)
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ require (
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
Expand Down Expand Up @@ -77,4 +80,6 @@ require (
golang.org/x/sync v0.0.0-20220907140024-f12130a52804
golang.org/x/sys v0.0.0-20220913175220-63ea55921009 // indirect
golang.org/x/text v0.3.7 // indirect
gorm.io/driver/sqlite v1.3.6
gorm.io/gorm v1.23.8
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
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.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down Expand Up @@ -129,6 +134,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -299,3 +306,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.3.6 h1:Fi8xNYCUplOqWiPa3/GuCeowRNBRGTf62DEmhMDHeQQ=
gorm.io/driver/sqlite v1.3.6/go.mod h1:Sg1/pvnKtbQ7jLXxfZa+jSHvoX8hoZA8cn4xllOMTgE=
gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=

0 comments on commit eda6b64

Please sign in to comment.