Пример #1
0
func (model ServicesModel) Create(item Service) {
	_, err := model.db.Exec(
		"INSERT INTO services (title, addr) VALUES (?, ?)",
		item.title,
		item.addr,
	)
	webapp.Panic(err)
}
Пример #2
0
func (model DomainsModel) Create(item Domain) {
	_, err := model.db.Exec(
		"INSERT INTO domains (domain, comment) VALUES (?, ?)",
		item.domain,
		item.comment,
	)
	webapp.Panic(err)
}
Пример #3
0
func (model DomainsModel) Update(item Domain) {
	_, err := model.db.Exec(
		"UPDATE domains SET domain=?,comment=? WHERE domain_id = ?",
		item.domain,
		item.comment,
		item.domain_id,
	)
	webapp.Panic(err)
}
Пример #4
0
func (model DomainsModel) fetchAll(query db.Select, scanFunc db.ScanFunction) []Domain {

	sql, bind := query.Build()
	rows, err := model.db.Query(sql, bind...)
	webapp.Panic(err)

	defer rows.Close()

	items := []Domain{}

	for rows.Next() {
		item, err := scanFunc(rows)
		webapp.Panic(err)
		items = append(items, item.(Domain))
	}

	return items
}
Пример #5
0
func (model ServicesModel) Update(item Service) {
	_, err := model.db.Exec(
		"UPDATE services SET title=?, addr=? WHERE service_id = ?",
		item.title,
		item.addr,
		item.service_id,
	)
	webapp.Panic(err)
}
Пример #6
0
func (model DomainsModel) fetchRow(query db.Select, scanFunc db.ScanFunction) *Domain {

	sql, bind := query.Build()
	item, err := scanFunc(model.db.QueryRow(sql, bind...))
	webapp.Panic(err)

	result := Domain{}
	result = item.(Domain)

	return &result
}
Пример #7
0
func (model ServicesModel) fetchRow(query db.Select, scanFunc db.ScanFunction) *Service {

	sql, bind := query.Build()
	item, err := scanFunc(model.db.QueryRow(sql, bind...))
	webapp.Panic(err)

	result := Service{}
	result = item.(Service)

	return &result
}
Пример #8
0
func main() {
	db, err = sql.Open(config.ContainerConfig.Db.Driver, config.ContainerConfig.Db.DataSource)
	webapp.Panic(err)
	webapp.Panic(db.Ping())
	defer db.Close()
	db.SetMaxOpenConns(config.ContainerConfig.Db.MaxOpenConns)

	router := httprouter.New()

	domains := controller.DomainsController{}
	domains.SetDb(db)
	domains.SetConfig(config.ContainerConfig)
	domains.BindActions(router)

	services := controller.ServicesController{}
	services.SetDb(db)
	services.SetConfig(config.ContainerConfig)
	services.BindActions(router)

	router.ServeFiles("/static/*filepath", http.Dir(config.ContainerConfig.Paths.Static))

	webapp.Panic(http.ListenAndServe(config.ContainerConfig.Http.Host+":"+config.ContainerConfig.Http.Port, router))
}
Пример #9
0
func (model DomainsModel) Delete(id interface{}) {
	_, err := model.db.Exec("DELETE FROM domains WHERE domain_id = ?", id)
	webapp.Panic(err)
}
Пример #10
0
func (model ServicesModel) Delete(id interface{}) {
	_, err := model.db.Exec("DELETE FROM services WHERE service_id = ?", id)
	webapp.Panic(err)
}