forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restorenext.go
40 lines (34 loc) · 1.29 KB
/
restorenext.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
39
40
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package handler
import (
"net/http"
log "github.com/sirupsen/logrus"
"github.com/rymurr/aws-lambda-runtime-interface-emulator/lambda/core"
"github.com/rymurr/aws-lambda-runtime-interface-emulator/lambda/rapi/rendering"
)
type restoreNextHandler struct {
registrationService core.RegistrationService
renderingService *rendering.EventRenderingService
}
func (h *restoreNextHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
runtime := h.registrationService.GetRuntime()
err := runtime.RestoreReady()
if err != nil {
log.Warn(err)
rendering.RenderForbiddenWithTypeMsg(writer, request, rendering.ErrorTypeInvalidStateTransition, StateTransitionFailedForRuntimeMessageFormat, runtime.GetState().Name(), core.RuntimeReadyStateName, err)
return
}
err = h.renderingService.RenderRuntimeEvent(writer, request)
if err != nil {
log.Error(err)
rendering.RenderInternalServerError(writer, request)
return
}
}
func NewRestoreNextHandler(registrationService core.RegistrationService, renderingService *rendering.EventRenderingService) http.Handler {
return &restoreNextHandler{
registrationService: registrationService,
renderingService: renderingService,
}
}