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 }