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/host/apidomain.go

50 lines
1.3 KiB
Go

package host
import (
"net/http"
"golang.org/x/net/context"
libapi "dev.sum7.eu/sum7/warehost/lib/api"
)
func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
profil := ctx.Value("profil").(*Profil)
returndata = false
logger := log.GetLog(r, "domainlist")
var domain []*Domain
dbconnection.Where("profil = ?", profil.ID).Find(&domain)
logger.Info("done")
returndata = domain
return
}
func domainAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
profil := ctx.Value("profil").(*Profil)
returndata = false
logger := log.GetLog(r, "domainadd")
var domainRequest Domain
returnerr = libapi.JSONDecoder(r.Body, &domainRequest, w, logger)
if returnerr != nil {
return
}
domain := &Domain{
ProfilID: profil.ID,
FQDN: domainRequest.FQDN,
Mail: domainRequest.Mail,
Web: domainRequest.Web,
}
if err := dbconnection.Create(domain).Error; err != nil {
logger.Error("database: during create host domain: ", err)
w.WriteHeader(http.StatusInternalServerError)
returnerr = &libapi.ErrorResult{Message: "Internal Database Error with Database"}
return
}
returndata = true
logger.Info("done")
return
}