mirror of
https://github.com/foomo/contentfulvalidation.git
synced 2025-10-16 12:25:37 +00:00
feat: add gotsrpc clients and proxy
This commit is contained in:
parent
8660dd38f6
commit
0edbef3173
10
gotsrpc.yml
10
gotsrpc.yml
@ -3,11 +3,15 @@ module:
|
|||||||
path: ./
|
path: ./
|
||||||
|
|
||||||
targets:
|
targets:
|
||||||
services:
|
validation:
|
||||||
services:
|
services:
|
||||||
/services/contenfulvalidation/validation: Validation
|
/services/contenfulvalidation/validation: Validation
|
||||||
/services/contenfulvalidation/webhook: Webhook
|
package: github.com/foomo/contentfulvalidation/validation
|
||||||
package: github.com/foomo/contentfulvalidation/services
|
|
||||||
tsrpc:
|
tsrpc:
|
||||||
- Validation
|
- Validation
|
||||||
|
webhook:
|
||||||
|
services:
|
||||||
|
/services/contenfulvalidation/webhook: Webhook
|
||||||
|
package: github.com/foomo/contentfulvalidation/webhook
|
||||||
|
tsrpc:
|
||||||
- Webhook
|
- Webhook
|
||||||
|
|||||||
144
validation/gotsrpc_gen.go
Normal file
144
validation/gotsrpc_gen.go
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
// 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/contenfulvalidation/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)
|
||||||
|
}
|
||||||
|
}
|
||||||
81
validation/gotsrpcclient_gen.go
Normal file
81
validation/gotsrpcclient_gen.go
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
|
package validation
|
||||||
|
|
||||||
|
import (
|
||||||
|
go_context "context"
|
||||||
|
go_net_http "net/http"
|
||||||
|
|
||||||
|
github_com_foomo_contentfulvalidation_errors "github.com/foomo/contentfulvalidation/errors"
|
||||||
|
github_com_foomo_contentfulvalidation_validator "github.com/foomo/contentfulvalidation/validator"
|
||||||
|
gotsrpc "github.com/foomo/gotsrpc/v2"
|
||||||
|
pkg_errors "github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ValidationGoTSRPCClient interface {
|
||||||
|
ListModelTypes(ctx go_context.Context) (availableModelTypes []*github_com_foomo_contentfulvalidation_validator.ModelTypeInfo, clientErr error)
|
||||||
|
ValidateEntity(ctx go_context.Context, modelType github_com_foomo_contentfulvalidation_validator.ModelType, modelID github_com_foomo_contentfulvalidation_validator.ModelID, commit bool) (validationResult *github_com_foomo_contentfulvalidation_validator.ValidationResult, validationError *github_com_foomo_contentfulvalidation_errors.ValidationError, clientErr error)
|
||||||
|
ValidationResult(ctx go_context.Context, modelType github_com_foomo_contentfulvalidation_validator.ModelType, modelID github_com_foomo_contentfulvalidation_validator.ModelID) (validationResult *github_com_foomo_contentfulvalidation_validator.ValidationResult, validationError *github_com_foomo_contentfulvalidation_errors.ValidationError, clientErr error)
|
||||||
|
ValidationResults(ctx go_context.Context, modelType github_com_foomo_contentfulvalidation_validator.ModelType) (validationResults map[github_com_foomo_contentfulvalidation_validator.ModelID]*github_com_foomo_contentfulvalidation_validator.ValidationResult, validationError *github_com_foomo_contentfulvalidation_errors.ValidationError, clientErr error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type HTTPValidationGoTSRPCClient struct {
|
||||||
|
URL string
|
||||||
|
EndPoint string
|
||||||
|
Client gotsrpc.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDefaultValidationGoTSRPCClient(url string) *HTTPValidationGoTSRPCClient {
|
||||||
|
return NewValidationGoTSRPCClient(url, "/services/contenfulvalidation/validation")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValidationGoTSRPCClient(url string, endpoint string) *HTTPValidationGoTSRPCClient {
|
||||||
|
return NewValidationGoTSRPCClientWithClient(url, endpoint, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewValidationGoTSRPCClientWithClient(url string, endpoint string, client *go_net_http.Client) *HTTPValidationGoTSRPCClient {
|
||||||
|
return &HTTPValidationGoTSRPCClient{
|
||||||
|
URL: url,
|
||||||
|
EndPoint: endpoint,
|
||||||
|
Client: gotsrpc.NewClientWithHttpClient(client),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (tsc *HTTPValidationGoTSRPCClient) ListModelTypes(ctx go_context.Context) (availableModelTypes []*github_com_foomo_contentfulvalidation_validator.ModelTypeInfo, clientErr error) {
|
||||||
|
args := []interface{}{}
|
||||||
|
reply := []interface{}{&availableModelTypes}
|
||||||
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "ListModelTypes", args, reply)
|
||||||
|
if clientErr != nil {
|
||||||
|
clientErr = pkg_errors.WithMessage(clientErr, "failed to call validation.ValidationGoTSRPCProxy ListModelTypes")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tsc *HTTPValidationGoTSRPCClient) ValidateEntity(ctx go_context.Context, modelType github_com_foomo_contentfulvalidation_validator.ModelType, modelID github_com_foomo_contentfulvalidation_validator.ModelID, commit bool) (validationResult *github_com_foomo_contentfulvalidation_validator.ValidationResult, validationError *github_com_foomo_contentfulvalidation_errors.ValidationError, clientErr error) {
|
||||||
|
args := []interface{}{modelType, modelID, commit}
|
||||||
|
reply := []interface{}{&validationResult, &validationError}
|
||||||
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "ValidateEntity", args, reply)
|
||||||
|
if clientErr != nil {
|
||||||
|
clientErr = pkg_errors.WithMessage(clientErr, "failed to call validation.ValidationGoTSRPCProxy ValidateEntity")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tsc *HTTPValidationGoTSRPCClient) ValidationResult(ctx go_context.Context, modelType github_com_foomo_contentfulvalidation_validator.ModelType, modelID github_com_foomo_contentfulvalidation_validator.ModelID) (validationResult *github_com_foomo_contentfulvalidation_validator.ValidationResult, validationError *github_com_foomo_contentfulvalidation_errors.ValidationError, clientErr error) {
|
||||||
|
args := []interface{}{modelType, modelID}
|
||||||
|
reply := []interface{}{&validationResult, &validationError}
|
||||||
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "ValidationResult", args, reply)
|
||||||
|
if clientErr != nil {
|
||||||
|
clientErr = pkg_errors.WithMessage(clientErr, "failed to call validation.ValidationGoTSRPCProxy ValidationResult")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tsc *HTTPValidationGoTSRPCClient) ValidationResults(ctx go_context.Context, modelType github_com_foomo_contentfulvalidation_validator.ModelType) (validationResults map[github_com_foomo_contentfulvalidation_validator.ModelID]*github_com_foomo_contentfulvalidation_validator.ValidationResult, validationError *github_com_foomo_contentfulvalidation_errors.ValidationError, clientErr error) {
|
||||||
|
args := []interface{}{modelType}
|
||||||
|
reply := []interface{}{&validationResults, &validationError}
|
||||||
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "ValidationResults", args, reply)
|
||||||
|
if clientErr != nil {
|
||||||
|
clientErr = pkg_errors.WithMessage(clientErr, "failed to call validation.ValidationGoTSRPCProxy ValidationResults")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
79
webhook/gotsrpc_gen.go
Normal file
79
webhook/gotsrpc_gen.go
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
|
package webhook
|
||||||
|
|
||||||
|
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 (
|
||||||
|
WebhookGoTSRPCProxyUpdateCache = "UpdateCache"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebhookGoTSRPCProxy struct {
|
||||||
|
EndPoint string
|
||||||
|
service Webhook
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDefaultWebhookGoTSRPCProxy(service Webhook) *WebhookGoTSRPCProxy {
|
||||||
|
return NewWebhookGoTSRPCProxy(service, "/services/contenfulvalidation/webhook")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebhookGoTSRPCProxy(service Webhook, endpoint string) *WebhookGoTSRPCProxy {
|
||||||
|
return &WebhookGoTSRPCProxy{
|
||||||
|
EndPoint: endpoint,
|
||||||
|
service: service,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeHTTP exposes your service
|
||||||
|
func (p *WebhookGoTSRPCProxy) 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/webhook"
|
||||||
|
callStats.Service = "Webhook"
|
||||||
|
switch funcName {
|
||||||
|
case WebhookGoTSRPCProxyUpdateCache:
|
||||||
|
var (
|
||||||
|
args []interface{}
|
||||||
|
rets []interface{}
|
||||||
|
)
|
||||||
|
var (
|
||||||
|
arg_sysType github_com_foomo_contentfulvalidation_validator.SysType
|
||||||
|
arg_modelType github_com_foomo_contentfulvalidation_validator.ModelType
|
||||||
|
arg_modelID github_com_foomo_contentfulvalidation_validator.ModelID
|
||||||
|
)
|
||||||
|
args = []interface{}{&arg_sysType, &arg_modelType, &arg_modelID}
|
||||||
|
if err := gotsrpc.LoadArgs(&args, callStats, r); err != nil {
|
||||||
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
executionStart := time.Now()
|
||||||
|
p.service.UpdateCache(arg_sysType, arg_modelType, arg_modelID)
|
||||||
|
callStats.Execution = time.Since(executionStart)
|
||||||
|
rets = []interface{}{}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
47
webhook/gotsrpcclient_gen.go
Normal file
47
webhook/gotsrpcclient_gen.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
|
||||||
|
|
||||||
|
package webhook
|
||||||
|
|
||||||
|
import (
|
||||||
|
go_context "context"
|
||||||
|
go_net_http "net/http"
|
||||||
|
|
||||||
|
github_com_foomo_contentfulvalidation_validator "github.com/foomo/contentfulvalidation/validator"
|
||||||
|
gotsrpc "github.com/foomo/gotsrpc/v2"
|
||||||
|
pkg_errors "github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebhookGoTSRPCClient interface {
|
||||||
|
UpdateCache(ctx go_context.Context, sysType github_com_foomo_contentfulvalidation_validator.SysType, modelType github_com_foomo_contentfulvalidation_validator.ModelType, modelID github_com_foomo_contentfulvalidation_validator.ModelID) (clientErr error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type HTTPWebhookGoTSRPCClient struct {
|
||||||
|
URL string
|
||||||
|
EndPoint string
|
||||||
|
Client gotsrpc.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDefaultWebhookGoTSRPCClient(url string) *HTTPWebhookGoTSRPCClient {
|
||||||
|
return NewWebhookGoTSRPCClient(url, "/services/contenfulvalidation/webhook")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebhookGoTSRPCClient(url string, endpoint string) *HTTPWebhookGoTSRPCClient {
|
||||||
|
return NewWebhookGoTSRPCClientWithClient(url, endpoint, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebhookGoTSRPCClientWithClient(url string, endpoint string, client *go_net_http.Client) *HTTPWebhookGoTSRPCClient {
|
||||||
|
return &HTTPWebhookGoTSRPCClient{
|
||||||
|
URL: url,
|
||||||
|
EndPoint: endpoint,
|
||||||
|
Client: gotsrpc.NewClientWithHttpClient(client),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (tsc *HTTPWebhookGoTSRPCClient) UpdateCache(ctx go_context.Context, sysType github_com_foomo_contentfulvalidation_validator.SysType, modelType github_com_foomo_contentfulvalidation_validator.ModelType, modelID github_com_foomo_contentfulvalidation_validator.ModelID) (clientErr error) {
|
||||||
|
args := []interface{}{sysType, modelType, modelID}
|
||||||
|
reply := []interface{}{}
|
||||||
|
clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "UpdateCache", args, reply)
|
||||||
|
if clientErr != nil {
|
||||||
|
clientErr = pkg_errors.WithMessage(clientErr, "failed to call webhook.WebhookGoTSRPCProxy UpdateCache")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user