Skip to content

Commit

Permalink
🔨 make some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 9, 2020
1 parent a009224 commit c301f55
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
upload
*.exe
*.db
build
build
data.db
Binary file removed data.db
Binary file not shown.
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"flag"
"fmt"
"github.com/gin-gonic/gin"
"lan-share/model"
"log"
"os"
"strconv"
)
Expand All @@ -15,12 +15,14 @@ var (
)

func main() {
gin.SetMode(gin.ReleaseMode)
if os.Getenv("GIN_MODE") != "debug" {
gin.SetMode(gin.ReleaseMode)
}
flag.Parse()

db, err := model.InitDB()
if err != nil {
fmt.Errorf("failed to init database")
log.Fatal(err)
}
defer db.Close()
server := gin.Default()
Expand All @@ -31,5 +33,8 @@ func main() {
if realPort == "" {
realPort = strconv.Itoa(*port)
}
_ = server.Run(":" + realPort)
err = server.Run(":" + realPort)
if err != nil {
log.Println(err)
}
}
16 changes: 10 additions & 6 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package model
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"log"
"os"
"strings"
)

type File struct {
Id int `json:"id"`
Filename string `json:"filename"`
Description string `json:"description"`
Uploader string `json:"uploader"`
Link string `json:"link"`
Time string `json:"time"`
DownloadCounter int `json:"download_counter"`
Filename string `json:"filename" gorm:"type:string"`
Description string `json:"description" gorm:"type:string"`
Uploader string `json:"uploader" gorm:"type:string"`
Link string `json:"link" gorm:"type:string"`
Time string `json:"time" gorm:"type:string"`
DownloadCounter int `json:"download_counter" gorm:"type:int"`
}

var DB *gorm.DB
Expand All @@ -23,7 +24,10 @@ func InitDB() (*gorm.DB, error) {
db, err := gorm.Open("sqlite3", "./data.db")
if err == nil {
DB = db
db.AutoMigrate(&File{})
return DB, err
} else {
log.Fatal(err)
}
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions static/template.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@
<div class="mdui-textfield mdui-textfield-floating-label">
<i class="mdui-icon material-icons">account_circle</i>
<label class="mdui-textfield-label">Your name</label>
<textarea class="mdui-textfield-input" required name="uploader" id="fileUploader"></textarea>
<textarea class="mdui-textfield-input" name="uploader" id="fileUploader"></textarea>
</div>
<div class="mdui-textfield mdui-textfield-floating-label">
<i class="mdui-icon material-icons">textsms</i>
<label class="mdui-textfield-label">Description</label>
<textarea class="mdui-textfield-input" required name="description" id="fileDescription"></textarea>
<textarea class="mdui-textfield-input" name="description" id="fileDescription"></textarea>
</div>
</div>
<div class="mdui-dialog-actions">
Expand Down

0 comments on commit c301f55

Please sign in to comment.