mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
// this file was auto generated by gotsrpc https://github.com/foomo/gotsrpc
|
|
package demo
|
|
|
|
import (
|
|
gotsrpc "github.com/foomo/gotsrpc"
|
|
demo "github.com/foomo/gotsrpc/demo"
|
|
http "net/http"
|
|
)
|
|
|
|
type ServiceGoTSRPCProxy struct {
|
|
EndPoint string
|
|
allowOrigin []string
|
|
service *Service
|
|
}
|
|
|
|
func NewServiceGoTSRPCProxy(service *Service, endpoint string, allowOrigin []string) *ServiceGoTSRPCProxy {
|
|
return &ServiceGoTSRPCProxy{
|
|
EndPoint: endpoint,
|
|
allowOrigin: allowOrigin,
|
|
service: service,
|
|
}
|
|
}
|
|
|
|
// ServeHTTP exposes your service
|
|
func (p *ServiceGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
for _, origin := range p.allowOrigin {
|
|
w.Header().Add("Access-Control-Allow-Origin", origin)
|
|
}
|
|
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
|
if r.Method != "POST" {
|
|
gotsrpc.ErrorMethodNotAllowed(w)
|
|
return
|
|
}
|
|
var args []interface{}
|
|
switch gotsrpc.GetCalledFunc(r, p.EndPoint) {
|
|
case "ExtractAddress":
|
|
args = []interface{}{&Person{}}
|
|
err := gotsrpc.LoadArgs(args, r)
|
|
if err != nil {
|
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
|
return
|
|
}
|
|
extractAddressAddr, extractAddressE := p.service.ExtractAddress(args[0].(*demo.Person))
|
|
gotsrpc.Reply([]interface{}{extractAddressAddr, extractAddressE}, w)
|
|
return
|
|
case "Hello":
|
|
args = []interface{}{""}
|
|
err := gotsrpc.LoadArgs(args, r)
|
|
if err != nil {
|
|
gotsrpc.ErrorCouldNotLoadArgs(w)
|
|
return
|
|
}
|
|
helloReply, helloErr := p.service.Hello(args[0].(string))
|
|
gotsrpc.Reply([]interface{}{helloReply, helloErr}, w)
|
|
return
|
|
case "NothingInNothinOut":
|
|
p.service.NothingInNothinOut()
|
|
gotsrpc.Reply([]interface{}{}, w)
|
|
return
|
|
}
|
|
}
|