mirror of
https://github.com/foomo/contentfulvalidation.git
synced 2025-10-16 12:25:37 +00:00
157 lines
5.0 KiB
Go
157 lines
5.0 KiB
Go
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
|
|
|
package validation
|
|
|
|
import (
|
|
io "io"
|
|
http "net/http"
|
|
time "time"
|
|
|
|
github_com_foomo_contentfulvalidation_validator "github.com/foomo/contentfulvalidation/validator"
|
|
gotsrpc "github.com/foomo/gotsrpc/v2"
|
|
)
|
|
|
|
const (
|
|
ValidationGoTSRPCProxyListModelTypes = "ListModelTypes"
|
|
ValidationGoTSRPCProxyValidateEntity = "ValidateEntity"
|
|
ValidationGoTSRPCProxyValidationResult = "ValidationResult"
|
|
ValidationGoTSRPCProxyValidationResults = "ValidationResults"
|
|
)
|
|
|
|
type ValidationGoTSRPCProxy struct {
|
|
EndPoint string
|
|
service Validation
|
|
}
|
|
|
|
func NewDefaultValidationGoTSRPCProxy(service Validation) *ValidationGoTSRPCProxy {
|
|
return NewValidationGoTSRPCProxy(service, "/services/contentfulvalidation/validation")
|
|
}
|
|
|
|
func NewValidationGoTSRPCProxy(service Validation, endpoint string) *ValidationGoTSRPCProxy {
|
|
return &ValidationGoTSRPCProxy{
|
|
EndPoint: endpoint,
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
// ServeHTTP exposes your service
|
|
func (p *ValidationGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == http.MethodOptions {
|
|
return
|
|
} else if r.Method != http.MethodPost {
|
|
gotsrpc.ErrorMethodNotAllowed(w)
|
|
return
|
|
}
|
|
defer io.Copy(io.Discard, r.Body) // Drain Request Body
|
|
|
|
funcName := gotsrpc.GetCalledFunc(r, p.EndPoint)
|
|
callStats, _ := gotsrpc.GetStatsForRequest(r)
|
|
callStats.Func = funcName
|
|
callStats.Package = "github.com/foomo/contentfulvalidation/validation"
|
|
callStats.Service = "Validation"
|
|
switch funcName {
|
|
case ValidationGoTSRPCProxyListModelTypes:
|
|
var (
|
|
args []interface{}
|
|
rets []interface{}
|
|
)
|
|
executionStart := time.Now()
|
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
|
listModelTypesAvailableModelTypes := p.service.ListModelTypes(&rw, r)
|
|
callStats.Execution = time.Since(executionStart)
|
|
if rw.Status() == http.StatusOK {
|
|
rets = []interface{}{listModelTypesAvailableModelTypes}
|
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
|
gotsrpc.ErrorCouldNotReply(w)
|
|
return
|
|
}
|
|
}
|
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
|
return
|
|
case ValidationGoTSRPCProxyValidateEntity:
|
|
var (
|
|
args []interface{}
|
|
rets []interface{}
|
|
)
|
|
var (
|
|
arg_modelType github_com_foomo_contentfulvalidation_validator.ModelType
|
|
arg_modelID github_com_foomo_contentfulvalidation_validator.ModelID
|
|
arg_commit bool
|
|
)
|
|
args = []interface{}{&arg_modelType, &arg_modelID, &arg_commit}
|
|
if err := gotsrpc.LoadArgs(&args, callStats, r); err != nil {
|
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
|
return
|
|
}
|
|
executionStart := time.Now()
|
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
|
validateEntityValidationResult, validateEntityValidationError := p.service.ValidateEntity(&rw, r, arg_modelType, arg_modelID, arg_commit)
|
|
callStats.Execution = time.Since(executionStart)
|
|
if rw.Status() == http.StatusOK {
|
|
rets = []interface{}{validateEntityValidationResult, validateEntityValidationError}
|
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
|
gotsrpc.ErrorCouldNotReply(w)
|
|
return
|
|
}
|
|
}
|
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
|
return
|
|
case ValidationGoTSRPCProxyValidationResult:
|
|
var (
|
|
args []interface{}
|
|
rets []interface{}
|
|
)
|
|
var (
|
|
arg_modelType github_com_foomo_contentfulvalidation_validator.ModelType
|
|
arg_modelID github_com_foomo_contentfulvalidation_validator.ModelID
|
|
)
|
|
args = []interface{}{&arg_modelType, &arg_modelID}
|
|
if err := gotsrpc.LoadArgs(&args, callStats, r); err != nil {
|
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
|
return
|
|
}
|
|
executionStart := time.Now()
|
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
|
validationResultValidationResult, validationResultValidationError := p.service.ValidationResult(&rw, r, arg_modelType, arg_modelID)
|
|
callStats.Execution = time.Since(executionStart)
|
|
if rw.Status() == http.StatusOK {
|
|
rets = []interface{}{validationResultValidationResult, validationResultValidationError}
|
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
|
gotsrpc.ErrorCouldNotReply(w)
|
|
return
|
|
}
|
|
}
|
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
|
return
|
|
case ValidationGoTSRPCProxyValidationResults:
|
|
var (
|
|
args []interface{}
|
|
rets []interface{}
|
|
)
|
|
var (
|
|
arg_modelType github_com_foomo_contentfulvalidation_validator.ModelType
|
|
)
|
|
args = []interface{}{&arg_modelType}
|
|
if err := gotsrpc.LoadArgs(&args, callStats, r); err != nil {
|
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
|
return
|
|
}
|
|
executionStart := time.Now()
|
|
rw := gotsrpc.ResponseWriter{ResponseWriter: w}
|
|
validationResultsValidationResults, validationResultsValidationError := p.service.ValidationResults(&rw, r, arg_modelType)
|
|
callStats.Execution = time.Since(executionStart)
|
|
if rw.Status() == http.StatusOK {
|
|
rets = []interface{}{validationResultsValidationResults, validationResultsValidationError}
|
|
if err := gotsrpc.Reply(rets, callStats, r, w); err != nil {
|
|
gotsrpc.ErrorCouldNotReply(w)
|
|
return
|
|
}
|
|
}
|
|
gotsrpc.Monitor(w, r, args, rets, callStats)
|
|
return
|
|
default:
|
|
gotsrpc.ClearStats(r)
|
|
gotsrpc.ErrorFuncNotFound(w)
|
|
}
|
|
}
|