sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/modul/web/apidomain.go

58 lines
1.7 KiB
Go

package web
import (
"net/http"
"goji.io/pat"
"golang.org/x/net/context"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
)
// DomainList to list domains
func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
returndata = false
logger := log.GetLog(r, "domainlist")
var domain []*Domain
dbconnection.Where("website = ?", ctx.Value("websiteid").(int64)).Preload("Domains").Find(&domain)
logger.Info("done")
returndata = domain
return
}
// DomainAdd to add domain
func domainAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
returndata = false
logger := log.GetLog(r, "domainadd")
domain := &Domain{
WebsiteID: ctx.Value("websiteid").(int64),
Name: pat.Param(ctx, "domain"),
}
if err := dbconnection.Create(domain).Error; err != nil {
logger.Error("database: during create website domain: ", err)
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
return
}
returndata = true
logger.Info("done")
return
}
// DomainDelete to delete domain
func domainDelete(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
returndata = false
logger := log.GetLog(r, "domaindelete")
domain := &Domain{
WebsiteID: ctx.Value("websiteid").(int64),
Name: pat.Param(ctx, "domain"),
}
if err := dbconnection.Unscoped().Delete(domain).Error; err != nil {
logger.Error("database: during delete website Domain")
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
return
}
returndata = true
logger.Info("done")
return
}