Skip to main content

Service Interfaces

Gotsrpc services are defined in Go.

Interface definitions and value objects

All gotsrpc service definitions should be in a central place separated from their respective implementations.

Definition of a service interface

Service interfaces for gotsrpc services are plain Go interfaces.

type Service interface {
    HelloWorld(name string) string
}

Special handling of http request arguments

Despite the fact, that gostrpc is not RESTful it is possible and encouraged to access the underlying incoming w http.ResponseWriter and r *http.Request arguments like in a http.HandlerFunc for use cases like:

  • http request headers eg to implement access tokens
  • http request and response headers for cookie handling
  • accessing r.Context() for proper handling of context handling in the given request context
  • ...

Service interface with http.HandlerFunc arguments

type Service interface {
    HelloWorld(w http.ResponseWriter, r *http.Request, name string) string
}

In the generated client code the interface will not change. Accessing headers, cookies etc is handled in your projects client and transport

arguments and return values have to be serializable

All arguments and return values will be marshalled typically as JSON

Also see protocol