redirects/redirect/gotsrpc_gen.go
2023-09-20 15:51:13 +02:00

69 lines
1.6 KiB
Go

// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
package redirect
import (
io "io"
http "net/http"
time "time"
gotsrpc "github.com/foomo/gotsrpc/v2"
)
const (
RedirectGoTSRPCProxyCreate = "Create"
)
type RedirectGoTSRPCProxy struct {
EndPoint string
service Redirect
}
func NewDefaultRedirectGoTSRPCProxy(service Redirect) *RedirectGoTSRPCProxy {
return NewRedirectGoTSRPCProxy(service, "/services/redirects/redirect")
}
func NewRedirectGoTSRPCProxy(service Redirect, endpoint string) *RedirectGoTSRPCProxy {
return &RedirectGoTSRPCProxy{
EndPoint: endpoint,
service: service,
}
}
// ServeHTTP exposes your service
func (p *RedirectGoTSRPCProxy) 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/redirects/redirect"
callStats.Service = "Redirect"
switch funcName {
case RedirectGoTSRPCProxyCreate:
var (
args []interface{}
rets []interface{}
)
executionStart := time.Now()
p.service.Create()
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)
}
}