Martin's changes
This commit is contained in:
parent
0d0d98a1d1
commit
c74e2e1e85
|
@ -1 +1,2 @@
|
||||||
cmd/review/config.conf
|
cmd/review/config.conf
|
||||||
|
.idea/
|
||||||
|
|
|
@ -2,6 +2,7 @@ webserver_bind = ":8080"
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
type = "sqlite3"
|
type = "sqlite3"
|
||||||
|
# logging = true
|
||||||
connection = "file::memory:?mode=memory&cache=shared"
|
connection = "file::memory:?mode=memory&cache=shared"
|
||||||
# For Master-Slave cluster
|
# For Master-Slave cluster
|
||||||
# read_connection = ""
|
# read_connection = ""
|
||||||
|
|
|
@ -20,7 +20,7 @@ func listReview(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, "wrong productid", http.StatusNotAcceptable)
|
http.Error(w, "wrong productid", http.StatusNotAcceptable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.WithField("productid", id)
|
log = log.WithField("productid", id)
|
||||||
var list []*models.Review
|
var list []*models.Review
|
||||||
result := database.Read.Where("product_id = ?", id).Find(&list)
|
result := database.Read.Where("product_id = ?", id).Find(&list)
|
||||||
if result.RowsAffected == 0 {
|
if result.RowsAffected == 0 {
|
||||||
|
|
|
@ -17,12 +17,14 @@ type Config struct {
|
||||||
Type string
|
Type string
|
||||||
Connection string
|
Connection string
|
||||||
ReadConnection string
|
ReadConnection string
|
||||||
|
Logging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(c Config) (err error) {
|
func Open(c Config) (err error) {
|
||||||
config = &c
|
config = &c
|
||||||
Write, err = gorm.Open(config.Type, config.Connection)
|
Write, err = gorm.Open(config.Type, config.Connection)
|
||||||
Write.SingularTable(true)
|
Write.SingularTable(true)
|
||||||
|
Write.LogMode(c.Logging)
|
||||||
Write.Callback().Create().Remove("gorm:update_time_stamp")
|
Write.Callback().Create().Remove("gorm:update_time_stamp")
|
||||||
Write.Callback().Update().Remove("gorm:update_time_stamp")
|
Write.Callback().Update().Remove("gorm:update_time_stamp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -31,6 +33,7 @@ func Open(c Config) (err error) {
|
||||||
if len(config.ReadConnection) > 0 {
|
if len(config.ReadConnection) > 0 {
|
||||||
Read, err = gorm.Open(config.Type, config.ReadConnection)
|
Read, err = gorm.Open(config.Type, config.ReadConnection)
|
||||||
Read.SingularTable(true)
|
Read.SingularTable(true)
|
||||||
|
Read.LogMode(c.Logging)
|
||||||
Read.Callback().Create().Remove("gorm:update_time_stamp")
|
Read.Callback().Create().Remove("gorm:update_time_stamp")
|
||||||
Read.Callback().Update().Remove("gorm:update_time_stamp")
|
Read.Callback().Update().Remove("gorm:update_time_stamp")
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in New Issue