func()

in openwhisk/initHandler.go [54:110]


func (ap *ActionProxy) initHandler(w http.ResponseWriter, r *http.Request) {
	// you can do multiple initializations when debugging
	if ap.initialized && !Debugging {
		msg := "Cannot initialize the action more than once."
		sendError(w, http.StatusForbidden, msg)
		log.Println(msg)
		return
	}

	if ap.proxyMode == ProxyModeClient {
		ap.ForwardInitRequest(w, r)
		return
	}

	if ap.compiler != "" {
		Debug("compiler: " + ap.compiler)
	}

	// read body of the request
	body, err := io.ReadAll(r.Body)
	defer r.Body.Close()
	if err != nil {
		sendError(w, http.StatusBadRequest, fmt.Sprintf("%v", err))
		return
	}

	// decode request parameters
	if len(body) < 1000 {
		Debug("init: decoding %s\n", string(body))
	}

	var request initRequest
	err = json.Unmarshal(body, &request)
	if err != nil {
		sendError(w, http.StatusBadRequest, fmt.Sprintf("Error unmarshaling request: %v", err))
		return
	}

	if ap.proxyMode == ProxyModeServer {
		if ap.serverProxyData == nil {
			ap.serverProxyData = &ServerProxyData{actions: make(map[RemoteAPKey]*RemoteAPValue)}
		}
		if ok := doRemoteInit(ap, request, w); !ok {
			return
		}

		sendOK(w)
		return
	}

	if err := ap.doInit(request, w); err != nil {
		Debug("Error initializing action: %v", err)
		return
	}

	sendOK(w)
}