contentfulvalidation/validation/gotsrpc_gen.go
2023-10-11 12:48:12 +02:00

145 lines
4.6 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()
listModelTypesAvailableModelTypes := p.service.ListModelTypes()
callStats.Execution = time.Since(executionStart)
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()
validateEntityValidationResult, validateEntityValidationError := p.service.ValidateEntity(arg_modelType, arg_modelID, arg_commit)
callStats.Execution = time.Since(executionStart)
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()
validationResultValidationResult, validationResultValidationError := p.service.ValidationResult(arg_modelType, arg_modelID)
callStats.Execution = time.Since(executionStart)
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()
validationResultsValidationResults, validationResultsValidationError := p.service.ValidationResults(arg_modelType)
callStats.Execution = time.Since(executionStart)
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)
}
}