// Code generated by protoc-gen-grpc-api-gateway. DO NOT EDIT.
// source: ark/v1/signer_manager.proto

/*
Package arkv1 is a reverse proxy.

It translates gRPC into RESTful JSON APIs.
*/
package arkv1

import (
	"context"
	"io"
	"net/http"

	"github.com/meshapi/grpc-api-gateway/gateway"
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
	"google.golang.org/protobuf/proto"
)

func request_SignerManagerService_LoadSigner_0(ctx context.Context, marshaler gateway.Marshaler, mux *gateway.ServeMux, client SignerManagerServiceClient, req *http.Request, pathParams gateway.Params) (proto.Message, gateway.ServerMetadata, error) {
	var protoReq LoadSignerRequest
	var metadata gateway.ServerMetadata

	if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
		return nil, metadata, gateway.ErrMarshal{Err: err, Inbound: true}
	}

	msg, err := client.LoadSigner(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

// RegisterSignerManagerServiceHandlerFromEndpoint is same as RegisterSignerManagerServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterSignerManagerServiceHandlerFromEndpoint(ctx context.Context, mux *gateway.ServeMux, endpoint string, opts []grpc.DialOption) error {
	conn, err := grpc.DialContext(ctx, endpoint, opts...)
	if err != nil {
		return err
	}
	defer func() {
		if err != nil {
			if cerr := conn.Close(); cerr != nil {
				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
			}
			return
		}
		go func() {
			<-ctx.Done()
			if cerr := conn.Close(); cerr != nil {
				grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
			}
		}()
	}()

	RegisterSignerManagerServiceHandler(ctx, mux, conn)
	return nil
}

// RegisterSignerManagerServiceHandler registers the http handlers for service SignerManagerService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterSignerManagerServiceHandler(ctx context.Context, mux *gateway.ServeMux, conn *grpc.ClientConn) {
	RegisterSignerManagerServiceHandlerClient(ctx, mux, NewSignerManagerServiceClient(conn))
}

// RegisterSignerManagerServiceHandlerClient registers the http handlers for service SignerManagerService
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SignerManagerServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SignerManagerServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "SignerManagerServiceClient" to call the correct interceptors.
func RegisterSignerManagerServiceHandlerClient(ctx context.Context, mux *gateway.ServeMux, client SignerManagerServiceClient) {

	mux.HandleWithParams("POST", "/v1/admin/signer", func(w http.ResponseWriter, req *http.Request, pathParams gateway.Params) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		inboundMarshaler, outboundMarshaler := mux.MarshalerForRequest(req)
		var err error
		var annotatedContext context.Context
		annotatedContext, err = gateway.AnnotateContext(ctx, mux, req, "/ark.v1.SignerManagerService/LoadSigner", gateway.WithHTTPPathPattern("/v1/admin/signer"))
		if err != nil {
			mux.HTTPError(ctx, outboundMarshaler, w, req, err)
			return
		}

		resp, md, err := request_SignerManagerService_LoadSigner_0(annotatedContext, inboundMarshaler, mux, client, req, pathParams)
		annotatedContext = gateway.NewServerMetadataContext(annotatedContext, md)
		if err != nil {
			mux.HTTPError(annotatedContext, outboundMarshaler, w, req, err)
			return
		}

		mux.ForwardResponseMessage(annotatedContext, outboundMarshaler, w, req, resp)
	})

}
