/
http.go
38 lines (30 loc) · 1.04 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package communications
import (
"context"
"net/http"
"github.com/cloudtrust/keycloak-bridge/internal/constants"
commonhttp "github.com/cloudtrust/common-service/http"
"github.com/cloudtrust/common-service/log"
"github.com/go-kit/kit/endpoint"
http_transport "github.com/go-kit/kit/transport/http"
)
const (
reqBody = "body"
prmRealm = "realm"
)
// MakeCommunicationsHandler make an HTTP handler for a Communications endpoint.
func MakeCommunicationsHandler(e endpoint.Endpoint, logger log.Logger) *http_transport.Server {
return http_transport.NewServer(e,
decodeCommunicationsRequest,
commonhttp.EncodeReply,
http_transport.ServerErrorEncoder(commonhttp.ErrorHandler(logger)),
)
}
// decodeCommunicationsRequest gets the HTTP parameters and body content
func decodeCommunicationsRequest(ctx context.Context, req *http.Request) (interface{}, error) {
var pathParams = map[string]string{
prmRealm: constants.RegExpRealmName,
}
var queryParams = map[string]string{}
return commonhttp.DecodeRequest(ctx, req, pathParams, queryParams)
}