Permalink
Browse files

cache setting

  • Loading branch information...
icchy committed Oct 20, 2018
1 parent 684d0c9 commit 020010e6a336af3465c47ec7b64fce8d3aae4416
Showing with 20 additions and 7 deletions.
  1. +20 −7 src/isucon8/isucoin/model/setting.go
@@ -21,37 +21,50 @@ type Setting struct {
Val string
}

func SetSetting(d QueryExecutor, k, v string) error {
_, err := d.Exec(`INSERT INTO setting (name, val) VALUES (?, ?) ON DUPLICATE KEY UPDATE val = VALUES(val)`, k, v)
var bankEndpoint string
var bankAppId string
var logEndpoint string
var logAppId string

func SetSetting(d QueryExecutor) error {
bankEndpoint = ""
bankAppId = ""
logEndpoint = ""
logAppId = ""
return err
}

func GetSetting(d QueryExecutor, k string) (string, error) {
func GetSetting(d QueryExecutor, k string, memo *string) (string, error) {
if memo != "" {
return memo, nil
}

s, err := scanSetting(d.Query(`SELECT * FROM setting WHERE name = ?`, k))
if err != nil {
return "", err
}
memo = s.Val
return s.Val, nil
}

func Isubank(d QueryExecutor) (*isubank.Isubank, error) {
ep, err := GetSetting(d, BankEndpoint)
ep, err := GetSetting(d, BankEndpoint, &bankEndpoint)
if err != nil {
return nil, errors.Wrapf(err, "getSetting failed. %s", BankEndpoint)
}
id, err := GetSetting(d, BankAppid)
id, err := GetSetting(d, BankAppid, &bankAppId)
if err != nil {
return nil, errors.Wrapf(err, "getSetting failed. %s", BankAppid)
}
return isubank.NewIsubank(ep, id)
}

func Logger(d QueryExecutor) (*isulogger.Isulogger, error) {
ep, err := GetSetting(d, LogEndpoint)
ep, err := GetSetting(d, LogEndpoint, &logEndpoint)
if err != nil {
return nil, errors.Wrapf(err, "getSetting failed. %s", LogEndpoint)
}
id, err := GetSetting(d, LogAppid)
id, err := GetSetting(d, LogAppid, &logAppId)
if err != nil {
return nil, errors.Wrapf(err, "getSetting failed. %s", LogAppid)
}

0 comments on commit 020010e

Please sign in to comment.