func InitDatabase(driver, dbPath string) error {
var db gorm.DB
var err error
switch driver {
case "sqlite3":
db, err = gorm.Open("sqlite3", dbPath)
if err != nil {
return err
}
break
case "mysql":
db, err = gorm.Open("mysql", dbPath)
if err != nil {
return err
}
break
case "postgres":
db, err = gorm.Open("postgres", dbPath)
if err != nil {
return err
}
break
default:
return fmt.Errorf("Unknown database driver of %v", driver)
}
type Config struct {
Database struct {
DatabaseName string `json:"database_name"`
DatabasePassword string `json:"database_password"`
DatabaseUser string `json:"database_user"`
DatabasePort int `json:"database_port"`
} `json:"database"`
Accounts struct {
AutoCreate bool `json:"auto_create"`
} `json:"accounts"`
Client struct {
BanTimeForBruteForcing int `json:"ban_time_for_brute_forcing"`
Host string `json:"host"`
LoginTryBeforeBan int `json:"login_try_before_ban"`
Port int `json:"port"`
} `json:"client"`
Server struct {
Pingpong bool `json:"pingpong"`
Host string `json:"host"`
PingpongDelay bool `json:"pingpong_delay"`
PingpongDelayTime int `json:"pingpong_delay_time"`
Port int `json:"port"`
} `json:"server"`
}
curl -X "POST" "http://xn--80aehbq0cfe.xn--p1ai/raschet_stoimosti_rabot/goodsNameWork/" \
--data-urlencode "model_id=1310"
curl -X "POST" "http://xn--80aehbq0cfe.xn--p1ai/raschet_stoimosti_rabot/goodsNameWork/selectd/item/" \
--data-urlencode "part_id=6068" \
--data-urlencode "model_id=1310"
[
{
"sdh_id": "197663",
"work_name": "Замена",
"sdh_comment": "",
"sdh_hour": "4.6",
"part_id": "6068",
"part_name": "Амортизатор задний левый",
"urn": "amortizator_zadniy_leviy",
"as_price": "1100"
}
]
price = sdh_hour(4.6) * as_price(1100) = 5060