func (h *Handler) APIV1RequestServicePost(w http.ResponseWriter, r *http.Request) {
	log.Printf("[%s] APIV1RequestServicePost", logPrefix)
	if !h.isSetAPI {
		log.Printf("[%s] does not set api", logPrefix)
		h.helper.Response(w, nil, http.StatusServiceUnavailable)
		return
	} else if !h.IsSetKey {
		log.Printf("[%s] does not set key", logPrefix)
		h.helper.Response(w, nil, http.StatusServiceUnavailable)
		return
	}
	reqAddr := strings.Split(r.RemoteAddr, ":")
	var addr string
	var portStr string
	if strings.Contains(r.RemoteAddr, "::1") {
		addr = "localhost"
		portStr = reqAddr[len(reqAddr)-1]
	} else {
		addr = reqAddr[0]
		portStr = reqAddr[1]
	}
	ips, err := h.netHelper.GetIPs()
	if err != nil {
		h.helper.Response(w, nil, http.StatusServiceUnavailable)
		return
	} else if addr != "localhost" && addr != "127.0.0.1" && !common.HasElem(ips, addr) {
		h.helper.Response(w, nil, http.StatusNotAcceptable)
		return
	}
	var (
		responseMsg  string
		responseName string
		resp         orchestrationapi.ResponseService
		name               string
		executeEnvs        []interface{}
		responseTargetInfo map[string]interface{}
	)
	encryptBytes, _ := ioutil.ReadAll(r.Body)
	appCommand, err := h.Key.DecryptByteToJSON(encryptBytes)
	if err != nil {
		log.Printf("[%s] can not decryption", logPrefix)
		h.helper.Response(w, nil, http.StatusServiceUnavailable)
		return
	}
	serviceInfos := orchestrationapi.ReqeustService{}
	selfSelection, ok := appCommand["SelfSelection"].(string)
	if !ok {
		selfSelection = "true"
	}
	if selfSelection == "true" {
		serviceInfos.SelfSelection = true
	} else {
		serviceInfos.SelfSelection = false
	}
	isParseRequesterFromPort := true
	port, err := strconv.Atoi(portStr)
	log.Println("port: ", port)
	if err != nil {
		isParseRequesterFromPort = false
	} else {
		requester, err := senderresolver.GetNameByPort(int64(port))
		log.Println("requester: ", requester)
		if err != nil {
			isParseRequesterFromPort = false
		} else {
			serviceInfos.ServiceRequester = requester
		}
	}
	if !isParseRequesterFromPort {
		serviceRequester, ok := appCommand["ServiceRequester"].(string)
		if !ok {
			responseMsg = orchestrationapi.InvalidParameter
			responseName = ""
			goto SEND_RESP
		}
		serviceInfos.ServiceRequester = serviceRequester
	}
	name, ok = appCommand["ServiceName"].(string)
	if !ok {
		responseMsg = orchestrationapi.InvalidParameter
		responseName = ""
		goto SEND_RESP
	}
	serviceInfos.ServiceName = name
	executeEnvs, ok = appCommand["ServiceInfo"].([]interface{})
	if !ok {
		responseMsg = orchestrationapi.InvalidParameter
		responseName = name
		goto SEND_RESP
	}
	serviceInfos.ServiceInfo = make([]orchestrationapi.RequestServiceInfo, len(executeEnvs))
	for idx, executeEnv := range executeEnvs {
		tmp := executeEnv.(map[string]interface{})
		exeType, ok := tmp["ExecutionType"].(string)
		if !ok {
			responseMsg = orchestrationapi.InvalidParameter
			responseName = name
			goto SEND_RESP
		}
		serviceInfos.ServiceInfo[idx].ExecutionType = exeType
		exeCmd, ok := tmp["ExecCmd"].([]interface{})
		if ok {
			serviceInfos.ServiceInfo[idx].ExeCmd = make([]string, len(exeCmd))
			for idy, cmd := range exeCmd {
				serviceInfos.ServiceInfo[idx].ExeCmd[idy] = cmd.(string)
			}
		}
		exeOption, ok := tmp["ExecOption"].(interface{})
		if ok {
			serviceInfos.ServiceInfo[idx].ExeOption = exeOption.(map[string]interface{})
		}
	}
	resp = h.api.RequestService(serviceInfos)
	responseMsg = resp.Message
	responseName = resp.ServiceName
	responseTargetInfo = make(map[string]interface{})
	responseTargetInfo["ExecutionType"] = resp.RemoteTargetInfo.ExecutionType
	responseTargetInfo["Target"] = resp.RemoteTargetInfo.Target
SEND_RESP:
	respJSONMsg := make(map[string]interface{})
	respJSONMsg["Message"] = responseMsg
	respJSONMsg["ServiceName"] = responseName
	respJSONMsg["RemoteTargetInfo"] = responseTargetInfo
	respEncryptBytes, err := h.Key.EncryptJSONToByte(respJSONMsg)
	if err != nil {
		log.Printf("[%s] can not encryption", logPrefix)
		h.helper.Response(w, nil, http.StatusServiceUnavailable)
		return
	}
	h.helper.Response(w, respEncryptBytes, http.StatusOK)
}
APIV1RequestServicePost handles service request from service application
package externalhandler
import (
	"io/ioutil"
	"net/http"
	"strconv"
	"strings"
	"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
	"github.com/lf-edge/edge-home-orchestration-go/internal/common/networkhelper"
	"github.com/lf-edge/edge-home-orchestration-go/internal/controller/securemgr/verifier"
	"github.com/lf-edge/edge-home-orchestration-go/internal/db/bolt/common"
	"github.com/lf-edge/edge-home-orchestration-go/internal/orchestrationapi"
	"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface"
	"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/cipher"
	"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/externalhandler/senderresolver"
	"github.com/lf-edge/edge-home-orchestration-go/internal/restinterface/resthelper"
)
const logPrefix = "RestExternalInterface"
type Handler struct {
	isSetAPI bool
	api      orchestrationapi.OrcheExternalAPI
	helper resthelper.RestHelper
	restinterface.HasRoutes
	cipher.HasCipher
	netHelper networkhelper.Network
}
var (
	handler *Handler
	log     = logmgr.GetInstance()
)
func init() {
	handler = new(Handler)
	handler.helper = resthelper.GetHelper()
	handler.Routes = restinterface.Routes{
		restinterface.Route{
			Name:        "APIV1RequestServicePost",
			Method:      strings.ToUpper("Post"),
			Pattern:     "/api/v1/orchestration/services",
			HandlerFunc: handler.APIV1RequestServicePost,
		},
		restinterface.Route{
			Name:        "APIV1RequestSecuremgrPost",
			Method:      strings.ToUpper("Post"),
			Pattern:     "/api/v1/orchestration/securemgr",
			HandlerFunc: handler.APIV1RequestSecuremgrPost,
		},
	}
	handler.netHelper = networkhelper.GetInstance()
}
func GetHandler() *Handler {
	return handler
}
func (h *Handler) SetOrchestrationAPI(o orchestrationapi.OrcheExternalAPI) {
	h.api = o
	h.isSetAPI = true
}