本文整理汇总了Golang中github.com/cloudsecurityalliance/ctpd/server/ctp.NewHttpError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHttpError函数的具体用法?Golang NewHttpError怎么用?Golang NewHttpError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHttpError函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Create
func (asset *Asset) Create(context *ctp.ApiContext) *ctp.HttpError {
asset.BuildLinks(context)
if !ctp.CreateResource(context, "assets", asset) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save asset")
}
return nil
}
开发者ID:ehengzh,项目名称:ctpd,代码行数:7,代码来源:assets.go
示例2: Create
func (attribute *Attribute) Create(context *ctp.ApiContext) *ctp.HttpError {
attribute.BuildLinks(context)
if !ctp.CreateResource(context, "attributes", attribute) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:7,代码来源:attributes.go
示例3: Load
func (res *TaggedResource) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, context.Params[0], ctp.Base64Id(context.Params[1]), res) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
res.BuildLinks(context)
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:7,代码来源:tags.go
示例4: Load
func (attribute *Attribute) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "attributes", ctp.Base64Id(context.Params[1]), attribute) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
attribute.BuildLinks(context)
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:7,代码来源:attributes.go
示例5: Create
func (account *Account) Create(context *ctp.ApiContext) *ctp.HttpError {
var key [24]byte
account.BuildLinks(context)
if account.Token == "" {
_, err := rand.Read(key[:])
if err != nil {
return ctp.NewInternalServerError("Error generating key")
}
account.Token = base64.StdEncoding.EncodeToString(key[:])
}
if len(account.AccountTags.WithPrefix("account:")) == 0 {
account.AccountTags.Append(ctp.NewTags("account:" + string(account.Id)))
}
if len(account.AccountTags.WithPrefix("role:")) == 0 {
account.AccountTags.Append(ctp.UserRoleTag)
}
if !ctp.CreateResource(context, "accounts", account) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save account")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:26,代码来源:accounts.go
示例6: Load
func (serviceview *ServiceView) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "serviceViews", ctp.Base64Id(context.Params[1]), serviceview) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
serviceview.BuildLinks(context)
return nil
}
开发者ID:ehengzh,项目名称:ctpd,代码行数:7,代码来源:serviceviews.go
示例7: Load
func (log *LogEntry) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "logs", ctp.Base64Id(context.Params[1]), log) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
log.BuildLinks(context)
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:7,代码来源:logs.go
示例8: Load
func (metric *Metric) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "metrics", ctp.Base64Id(context.Params[1]), metric) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
metric.BuildLinks(context)
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:7,代码来源:metrics.go
示例9: Load
func (asset *Asset) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "assets", ctp.Base64Id(context.Params[1]), asset) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
asset.BuildLinks(context)
return nil
}
开发者ID:ehengzh,项目名称:ctpd,代码行数:7,代码来源:assets.go
示例10: Load
func (access *Access) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "access", ctp.Base64Id(context.Params[1]), access) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
access.BuildLinks(context)
return nil
}
开发者ID:ehengzh,项目名称:ctpd,代码行数:7,代码来源:access.go
示例11: Load
func (trigger *Trigger) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "triggers", ctp.Base64Id(context.Params[1]), trigger) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
trigger.Measurement = ctp.ExpandLink(context.CtpBase, trigger.Measurement)
trigger.BuildLinks(context)
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:8,代码来源:triggers.go
示例12: Create
func (log *LogEntry) Create(context *ctp.ApiContext) *ctp.HttpError {
log.BuildLinks(context)
//log.CreationTime = ctp.Now()
if !ctp.CreateResource(context, "logs", log) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:8,代码来源:logs.go
示例13: Create
func (serviceview *ServiceView) Create(context *ctp.ApiContext) *ctp.HttpError {
serviceview.BuildLinks(context)
if !ctp.CreateResource(context, "serviceViews", serviceview) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:8,代码来源:serviceviews.go
示例14: Load
func (measurement *Measurement) Load(context *ctp.ApiContext) *ctp.HttpError {
if !ctp.LoadResource(context, "measurements", ctp.Base64Id(context.Params[1]), measurement) {
return ctp.NewHttpError(http.StatusNotFound, "Not Found")
}
measurement.Metric = ctp.ExpandLink(context.CtpBase, measurement.Metric)
measurement.BuildLinks(context)
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:8,代码来源:measurements.go
示例15: Create
func (metric *Metric) Create(context *ctp.ApiContext) *ctp.HttpError {
metric.BuildLinks(context)
if !ctp.CreateResource(context, "metrics", metric) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:8,代码来源:metrics.go
示例16: Update
func (res *TaggedResource) Update(context *ctp.ApiContext, update ctp.ResourceUpdater) *ctp.HttpError {
res.BuildLinks(context)
if !ctp.UpdateResourcePart(context, context.Params[0], ctp.Base64Id(context.Params[1]), "accessTags", update.Super().AccessTags) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not update object")
}
res.AccessTags = update.Super().AccessTags
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:8,代码来源:tags.go
示例17: ServeHTTP
func (mux *CtpApiHandlerMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
context, err := ctp.NewApiContext(r, mux.Configuration)
if err != nil {
ctp.RenderErrorResponse(w, context, ctp.NewHttpError(500, "Context creation failure"))
return
}
defer context.Close()
if handlerfunc, ok := ctpUrlMap[context.Signature]; ok {
ctp.Log(context, ctp.INFO, "Serving request '%s' with signature '%s'", r.RequestURI, context.Signature)
handlerfunc(w, r, context)
} else {
ctp.Log(nil, ctp.WARNING, "Not found: %s\n", context.Signature)
http.NotFound(w, r)
}
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:16,代码来源:serve.go
示例18: Delete
func (metric *Metric) Delete(context *ctp.ApiContext) *ctp.HttpError {
metricUrl := ctp.NewLink(context.CtpBase, "@/metrics/$", metric.Id) // just to create a clean URL
query := context.Session.DB("ctp").C("measurements").Find(bson.M{"metric": metricUrl})
count, err := query.Count()
if err != nil {
return ctp.NewInternalServerError(err)
}
if count > 0 {
return ctp.NewHttpError(http.StatusConflict, "Metric cannot be deleted because it is still in use by some measurements.")
}
if !ctp.DeleteResource(context, "metrics", metric.Id) {
return ctp.NewInternalServerError("Metric deletion failed")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:17,代码来源:metrics.go
示例19: Create
func (trigger *Trigger) Create(context *ctp.ApiContext) *ctp.HttpError {
trigger.BuildLinks(context)
trigger.Measurement = ctp.ShortenLink(context.CtpBase, trigger.Measurement)
if !ctp.IsShortLink(trigger.Measurement) {
return ctp.NewBadRequestError("Invalid measurement URL")
}
ok, err := triggerCheckCondition(context, trigger, nil)
if err != nil {
return ctp.NewBadRequestErrorf("%s", err.Error())
}
if ok {
triggerLogAndNotify(context, trigger, nil)
}
if !ctp.CreateResource(context, "triggers", trigger) {
return ctp.NewHttpError(http.StatusInternalServerError, "Could not save object")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:21,代码来源:triggers.go
示例20: Update
func (measurement *Measurement) Update(context *ctp.ApiContext, update ctp.ResourceUpdater) *ctp.HttpError {
measurement.BuildLinks(context)
up, ok := update.(*Measurement)
if !ok {
return ctp.NewInternalServerError("Updated object is not a measurement") // should never happen
}
switch context.QueryParam {
case "userActivated":
switch up.State {
case "activated":
if measurement.State == "deactivated" {
measurement.State = "pending" // FIXME: add backoffice logic for notification of state change?
}
case "deactivated":
measurement.State = "deactivated"
measurement.Result = nil
default:
return ctp.NewBadRequestError("state can only be 'activated' or 'deactivated'")
}
case "objective":
measurement.Objective = up.Objective
if err := measurementObjectiveEvaluate(context, measurement); err != nil {
return err
}
case "result":
if measurement.State == "deactivated" {
return ctp.NewHttpError(http.StatusConflict, "Measurement is not in activated state.")
}
if measurement.State == "pending" {
measurement.State = "activated"
}
if up.Result == nil {
return ctp.NewBadRequestError("No result provided in request")
}
measurement.Result = up.Result
if measurement.Result.UpdateTime.IsZero() {
measurement.Result.UpdateTime = ctp.Now()
}
if err := measurementCheckMetric(context, measurement); err != nil {
return err
}
if measurement.Objective != nil {
if err := measurementObjectiveEvaluate(context, measurement); err != nil {
return err
}
}
measurementTriggersEvaluate(context, measurement)
default:
return ctp.NewBadRequestError("invalid query string") // should never happen, because already filtered in serve.go
}
if !ctp.UpdateResource(context, "measurements", measurement.Id, measurement) {
return ctp.NewInternalServerError("Could not update measurement object")
}
return nil
}
开发者ID:cloudsecurityalliance,项目名称:ctpd,代码行数:64,代码来源:measurements.go
注:本文中的github.com/cloudsecurityalliance/ctpd/server/ctp.NewHttpError函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论