add db parameter
This commit is contained in:
parent
4206dcf433
commit
e82e51af2d
@ -7,8 +7,8 @@ import (
|
||||
|
||||
var DB *gorm.DB
|
||||
|
||||
func ConnectDatabase() {
|
||||
database, err := gorm.Open("sqlite3", "../test.db")
|
||||
func ConnectDatabase(filename *string) {
|
||||
database, err := gorm.Open("sqlite3", *filename)
|
||||
|
||||
if err != nil {
|
||||
panic("Failed to connect to database!")
|
||||
|
@ -1,15 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gitlab.celogeek.com/photos/api/src/controllers"
|
||||
"gitlab.celogeek.com/photos/api/src/controllers/models"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dbFilename := flag.String("db", "test.db", "database filename")
|
||||
flag.Parse()
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
models.ConnectDatabase()
|
||||
models.ConnectDatabase(dbFilename)
|
||||
|
||||
r.GET("/", controllers.DefaultRoot)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user