mirror of
https://github.com/foomo/contentfulvalidation.git
synced 2025-10-16 12:25:37 +00:00
feat: add http request and response
This commit is contained in:
parent
c725ba0602
commit
0fef0ec16c
@ -56,12 +56,15 @@ func (p *ValidationGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
|||||||
rets []interface{}
|
rets []interface{}
|
||||||
)
|
)
|
||||||
executionStart := time.Now()
|
executionStart := time.Now()
|
||||||
listModelTypesAvailableModelTypes := p.service.ListModelTypes()
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
||||||
|
listModelTypesAvailableModelTypes := p.service.ListModelTypes(&rw, r)
|
||||||
callStats.Execution = time.Since(executionStart)
|
callStats.Execution = time.Since(executionStart)
|
||||||
rets = []interface{}{listModelTypesAvailableModelTypes}
|
if rw.Status() == http.StatusOK {
|
||||||
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
rets = []interface{}{listModelTypesAvailableModelTypes}
|
||||||
gotsrpc.ErrorCouldNotReply(w)
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
||||||
return
|
gotsrpc.ErrorCouldNotReply(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gotsrpc.Monitor(w, r, args, rets, callStats)
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
||||||
return
|
return
|
||||||
@ -81,12 +84,15 @@ func (p *ValidationGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
executionStart := time.Now()
|
executionStart := time.Now()
|
||||||
validateEntityValidationResult, validateEntityValidationError := p.service.ValidateEntity(arg_modelType, arg_modelID, arg_commit)
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
||||||
|
validateEntityValidationResult, validateEntityValidationError := p.service.ValidateEntity(&rw, r, arg_modelType, arg_modelID, arg_commit)
|
||||||
callStats.Execution = time.Since(executionStart)
|
callStats.Execution = time.Since(executionStart)
|
||||||
rets = []interface{}{validateEntityValidationResult, validateEntityValidationError}
|
if rw.Status() == http.StatusOK {
|
||||||
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
rets = []interface{}{validateEntityValidationResult, validateEntityValidationError}
|
||||||
gotsrpc.ErrorCouldNotReply(w)
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
||||||
return
|
gotsrpc.ErrorCouldNotReply(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gotsrpc.Monitor(w, r, args, rets, callStats)
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
||||||
return
|
return
|
||||||
@ -105,12 +111,15 @@ func (p *ValidationGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
executionStart := time.Now()
|
executionStart := time.Now()
|
||||||
validationResultValidationResult, validationResultValidationError := p.service.ValidationResult(arg_modelType, arg_modelID)
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
||||||
|
validationResultValidationResult, validationResultValidationError := p.service.ValidationResult(&rw, r, arg_modelType, arg_modelID)
|
||||||
callStats.Execution = time.Since(executionStart)
|
callStats.Execution = time.Since(executionStart)
|
||||||
rets = []interface{}{validationResultValidationResult, validationResultValidationError}
|
if rw.Status() == http.StatusOK {
|
||||||
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
rets = []interface{}{validationResultValidationResult, validationResultValidationError}
|
||||||
gotsrpc.ErrorCouldNotReply(w)
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
||||||
return
|
gotsrpc.ErrorCouldNotReply(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gotsrpc.Monitor(w, r, args, rets, callStats)
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
||||||
return
|
return
|
||||||
@ -128,12 +137,15 @@ func (p *ValidationGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
executionStart := time.Now()
|
executionStart := time.Now()
|
||||||
validationResultsValidationResults, validationResultsValidationError := p.service.ValidationResults(arg_modelType)
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
||||||
|
validationResultsValidationResults, validationResultsValidationError := p.service.ValidationResults(&rw, r, arg_modelType)
|
||||||
callStats.Execution = time.Since(executionStart)
|
callStats.Execution = time.Since(executionStart)
|
||||||
rets = []interface{}{validationResultsValidationResults, validationResultsValidationError}
|
if rw.Status() == http.StatusOK {
|
||||||
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
rets = []interface{}{validationResultsValidationResults, validationResultsValidationError}
|
||||||
gotsrpc.ErrorCouldNotReply(w)
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
||||||
return
|
gotsrpc.ErrorCouldNotReply(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gotsrpc.Monitor(w, r, args, rets, callStats)
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
package validation
|
package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/foomo/contentfulvalidation/errors"
|
"github.com/foomo/contentfulvalidation/errors"
|
||||||
"github.com/foomo/contentfulvalidation/validator"
|
"github.com/foomo/contentfulvalidation/validator"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Validation interface {
|
type Validation interface {
|
||||||
ValidationResult(modelType validator.ModelType, modelID validator.ModelID) (validationResult *validator.ValidationResult, validationError *errors.ValidationError)
|
ValidationResult(w http.ResponseWriter, r *http.Request, modelType validator.ModelType, modelID validator.ModelID) (validationResult *validator.ValidationResult, validationError *errors.ValidationError)
|
||||||
ValidationResults(modelType validator.ModelType) (validationResults map[validator.ModelID]*validator.ValidationResult, validationError *errors.ValidationError)
|
ValidationResults(w http.ResponseWriter, r *http.Request, modelType validator.ModelType) (validationResults map[validator.ModelID]*validator.ValidationResult, validationError *errors.ValidationError)
|
||||||
ValidateEntity(modelType validator.ModelType, modelID validator.ModelID, commit bool) (validationResult *validator.ValidationResult, validationError *errors.ValidationError)
|
ValidateEntity(w http.ResponseWriter, r *http.Request, modelType validator.ModelType, modelID validator.ModelID, commit bool) (validationResult *validator.ValidationResult, validationError *errors.ValidationError)
|
||||||
ListModelTypes() (availableModelTypes []*validator.ModelTypeInfo)
|
ListModelTypes(w http.ResponseWriter, r *http.Request) (availableModelTypes []*validator.ModelTypeInfo)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,12 +63,15 @@ func (p *WebhookGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
executionStart := time.Now()
|
executionStart := time.Now()
|
||||||
p.service.UpdateCache(arg_sysType, arg_modelType, arg_modelID)
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
||||||
|
p.service.UpdateCache(&rw, r, arg_sysType, arg_modelType, arg_modelID)
|
||||||
callStats.Execution = time.Since(executionStart)
|
callStats.Execution = time.Since(executionStart)
|
||||||
rets = []interface{}{}
|
if rw.Status() == http.StatusOK {
|
||||||
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
rets = []interface{}{}
|
||||||
gotsrpc.ErrorCouldNotReply(w)
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
||||||
return
|
gotsrpc.ErrorCouldNotReply(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
gotsrpc.Monitor(w, r, args, rets, callStats)
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package webhook
|
package webhook
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/foomo/contentfulvalidation/validator"
|
"github.com/foomo/contentfulvalidation/validator"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Webhook interface {
|
type Webhook interface {
|
||||||
UpdateCache(sysType validator.SysType, modelType validator.ModelType, modelID validator.ModelID)
|
UpdateCache(w http.ResponseWriter, r *http.Request, sysType validator.SysType, modelType validator.ModelType, modelID validator.ModelID)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user