Replace sql.Null* with null.*

This commit is contained in:
Andreas Mieke 2021-03-07 22:33:23 +01:00
parent 49c17d0995
commit c0be366ed5
4 changed files with 15 additions and 12 deletions

1
go.mod
View file

@ -7,4 +7,5 @@ require (
github.com/jinzhu/gorm v1.9.16
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/viper v1.7.1
gopkg.in/guregu/null.v4 v4.0.0
)

2
go.sum
View file

@ -347,6 +347,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg=
gopkg.in/guregu/null.v4 v4.0.0/go.mod h1:YoQhUrADuG3i9WqesrCmpNRwm1ypAgSHYqoOcTu/JrI=
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=

View file

@ -1,7 +1,6 @@
package database
import (
"database/sql"
"log"
"os"
"path"
@ -10,6 +9,7 @@ import (
"github.com/jinzhu/gorm"
"github.com/robfig/cron/v3"
"github.com/spf13/viper"
"gopkg.in/guregu/null.v4"
// Dialects for gorm
_ "github.com/jinzhu/gorm/dialects/postgres"
@ -24,14 +24,14 @@ type URL struct {
CreatedAt time.Time
UpdatedAt time.Time
Short sql.NullString `gorm:"primary_key;unique_index:short_url;not null"`
Long sql.NullString `gorm:"unique"`
Hits sql.NullInt64
Short null.String `gorm:"primary_key;unique_index:short_url;not null"`
Long null.String `gorm:"unique"`
Hits null.Int
FileName sql.NullString `gorm:"default:NULL"`
FileSize sql.NullInt64 `gorm:"default:NULL"`
FileHash sql.NullString `gorm:"default:NULL"`
FileDelete *time.Time `gorm:"default:NULL"`
FileName null.String `gorm:"default:NULL"`
FileSize null.Int `gorm:"default:NULL"`
FileHash null.String `gorm:"default:NULL"`
FileDelete null.Time `gorm:"default:NULL"`
}
// InitDb opens a database connection and runs the auto migration

View file

@ -96,12 +96,12 @@ func encode(c *gin.Context) {
URL.Long.Valid = false
retention := time.Duration(float64(viper.GetInt("MinAge")) + float64(-viper.GetInt("MaxAge")+viper.GetInt("MinAge"))*math.Pow(float64(URL.FileSize.Int64/viper.GetInt64("MaxSize")-1), 3.0)*24)
delTime := time.Now().Add(retention * time.Hour)
URL.FileDelete = &delTime
URL.FileDelete.Time = time.Now().Add(retention * time.Hour)
URL.FileDelete.Valid = true
} else {
retention := time.Duration(float64(viper.GetInt("MinAge")) + float64(-viper.GetInt("MaxAge")+viper.GetInt("MinAge"))*math.Pow(float64(URL.FileSize.Int64/viper.GetInt64("MaxSize")-1), 3.0)*24)
delTime := time.Now().Add(retention * time.Hour)
URL.FileDelete = &delTime
URL.FileDelete.Time = time.Now().Add(retention * time.Hour)
URL.FileDelete.Valid = true
}
} else {