func UpdatePatchTrafficInfluenceSubscription(w http.ResponseWriter,
	r *http.Request) {
	nefCtx := r.Context().Value(nefCtxKey("nefCtx")).(*nefContext)
	nef := &nefCtx.nef
	vars := mux.Vars(r)
	log.Infof(" AFID  : %s", vars["afId"])
	log.Infof(" SUBSCRIPTION ID  : %s", vars["subscriptionId"])
	af, ok := nef.nefGetAf(vars["afId"])
	if ok == nil {
		b, err := ioutil.ReadAll(r.Body)
		defer closeReqBody(r)
		if err != nil {
			log.Err(err)
			sendCustomeErrorRspToAF(w, 400, "Failed to read HTTP PATCH Body")
			return
		}
		TrInSPBody := TrafficInfluSubPatch{}
		err1 := json.Unmarshal(b, &TrInSPBody)
		if err1 != nil {
			log.Err(err1)
			sendCustomeErrorRspToAF(w, 400, "Failed UnMarshal PATCH data")
			return
		}
		rsp, ti, err := af.afPartialUpdateSubscription(nefCtx,
			vars["subscriptionId"], TrInSPBody)
		if err != nil {
			sendErrorResponseToAF(w, rsp)
			return
		}
		mdata, err2 := json.Marshal(ti)
		if err2 != nil {
			log.Err(err2)
			sendCustomeErrorRspToAF(w, 400,
				"Failed to Marshal PATCH response data")
			return
		}
		w.WriteHeader(http.StatusOK)
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		_, err = w.Write(mdata)
		if err != nil {
			log.Errf("Write Failed: %v", err)
		}
		return
	}
	log.Infoln(ok)
	sendCustomeErrorRspToAF(w, 404, "Failed to find AF records")
}
UpdatePatchTrafficInfluenceSubscription : Updates a traffic influence created
earlier (PATCH Req)
package ngcnef
import (
	"context"
	"encoding/json"
	"errors"
	"io/ioutil"
	"net/http"
	"strconv"
	"strings"
	"github.com/gorilla/mux"
)
func createNewSub(nefCtx *nefContext, afID string,
	ti TrafficInfluSub) (loc string, rsp nefSBRspData, err error) {
	var af *afData
	nef := &nefCtx.nef
	af, err = nef.nefGetAf(afID)
	if err != nil {
		log.Err("NO AF PRESENT CREATE AF")
		af, err = nef.nefAddAf(nefCtx, afID)
		if err != nil {
			return loc, rsp, err
		}
	} else {
		log.Infoln("AF PRESENT")
	}
	loc, rsp, err = af.afAddSubscription(nefCtx, ti)
	if err != nil {
		return loc, rsp, err
	}
	return loc, rsp, nil
}
func ReadAllTrafficInfluenceSubscription(w http.ResponseWriter,
	r *http.Request) {
	var subslist []TrafficInfluSub
	var rsp nefSBRspData
	var err error
	nefCtx := r.Context().Value(nefCtxKey("nefCtx")).(*nefContext)
	nef := &nefCtx.nef
	vars := mux.Vars(r)
	log.Infof(" AFID : %s", vars["afId"])
	af, err := nef.nefGetAf(vars["afId"])
	if err != nil {
		log.Infoln(err)
	} else {
		rsp, subslist, err = af.afGetSubscriptionList(nefCtx)
		if err != nil {
			log.Err(err)
			sendErrorResponseToAF(w, rsp)
			return
		}
	}
	mdata, err2 := json.Marshal(subslist)
	if err2 != nil {
		sendCustomeErrorRspToAF(w, 400, "Failed to MARSHAL Subscription data ")
		return
	}
	w.WriteHeader(http.StatusOK)
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	_, err = w.Write(mdata)
	if err != nil {
		log.Errf("Write Failed: %v", err)
		return
	}
	log.Infof("HTTP Response sent: %d", http.StatusOK)
}
func CreateTrafficInfluenceSubscription(w http.ResponseWriter,
	r *http.Request) {
	nefCtx := r.Context().Value(nefCtxKey("nefCtx")).(*nefContext)
	vars := mux.Vars(r)
	log.Infof(" AFID  : %s", vars["afId"])
	b, err := ioutil.ReadAll(r.Body)
	defer closeReqBody(r)
	if err != nil {
		sendCustomeErrorRspToAF(w, 400, "Failed to read HTTP POST Body")
		return
	}
	trInBody := TrafficInfluSub{}
	err1 := json.Unmarshal(b, &trInBody)
	if err1 != nil {
		log.Err(err1)
		sendCustomeErrorRspToAF(w, 400, "Failed UnMarshal POST data")
		return
	}
	resRsp, status := validateAFTrafficInfluenceData(trInBody)
	if !status {
		log.Err(resRsp.pd.Title)
		sendErrorResponseToAF(w, resRsp)
		return
	}
	loc, rsp, err3 := createNewSub(nefCtx, vars["afId"], trInBody)
	if err3 != nil {
		log.Err(err3)
		rsp.errorCode = 400
		sendErrorResponseToAF(w, rsp)
		return
	}
	log.Infoln(loc)
	trInBody.Self = Link(loc)
	mdata, err2 := json.Marshal(trInBody)
	if err2 != nil {
		log.Err(err2)
		sendCustomeErrorRspToAF(w, 400, "Failed to Marshal GET response data")
		return
	}
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.Header().Set("Location", loc)
	w.WriteHeader(http.StatusCreated)
	log.Infof("CreateTrafficInfluenceSubscription responses => %d",
		http.StatusCreated)
	_, err = w.Write(mdata)
	if err != nil {
		log.Errf("Write Failed: %v", err)
		return
	}
	nef := &nefCtx.nef
	logNef(nef)
}
func ReadTrafficInfluenceSubscription(w http.ResponseWriter, r *http.Request) {
	nefCtx := r.Context().Value(nefCtxKey("nefCtx")).(*nefContext)
	nef := &nefCtx.nef
	vars := mux.Vars(r)
	log.Infof(" AFID  : %s", vars["afId"])
	log.Infof(" SUBSCRIPTION ID  : %s", vars["subscriptionId"])
	af, ok := nef.nefGetAf(vars["afId"])
	if ok != nil {
		sendCustomeErrorRspToAF(w, 404, "Failed to find AF records")
		return
	}
	rsp, sub, err := af.afGetSubscription(nefCtx, vars["subscriptionId"])
	if err != nil {
		log.Err(err)
		sendErrorResponseToAF(w, rsp)
		return
	}
	mdata, err2 := json.Marshal(sub)
	if err2 != nil {
		log.Err(err2)
		sendCustomeErrorRspToAF(w, 400, "Failed to Marshal GET response data")
	}
	w.WriteHeader(http.StatusOK)
	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	_, err = w.Write(mdata)
	if err != nil {
		log.Errf("Write Failed: %v", err)
		return
	}
	log.Infof("HTTP Response sent: %d", http.StatusOK)
}
func UpdatePutTrafficInfluenceSubscription(w http.ResponseWriter,
	r *http.Request) {
	nefCtx := r.Context().Value(nefCtxKey("nefCtx")).(*nefContext)
	nef := &nefCtx.nef
	vars := mux.Vars(r)
	log.Infof(" AFID  : %s", vars["afId"])
	log.Infof(" SUBSCRIPTION ID  : %s", vars["subscriptionId"])
	af, ok := nef.nefGetAf(vars["afId"])
	if ok == nil {
		b, err := ioutil.ReadAll(r.Body)
		defer closeReqBody(r)
		if err != nil {
			log.Err(err)
			sendCustomeErrorRspToAF(w, 400, "Failed to read HTTP PUT Body")
			return
		}
		trInBody := TrafficInfluSub{}
		err1 := json.Unmarshal(b, &trInBody)
		if err1 != nil {
			log.Err(err1)
			sendCustomeErrorRspToAF(w, 400, "Failed UnMarshal PUT data")
			return
		}
		rsp, newTI, err := af.afUpdateSubscription(nefCtx,
			vars["subscriptionId"], trInBody)
		if err != nil {
			sendErrorResponseToAF(w, rsp)
			return
		}
		mdata, err2 := json.Marshal(newTI)
		if err2 != nil {
			log.Err(err2)
			sendCustomeErrorRspToAF(w, 400, "Failed to Marshal PUT"+
				"response data")
			return
		}
		w.WriteHeader(http.StatusOK)
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		_, err = w.Write(mdata)
		if err != nil {
			log.Errf("Write Failed: %v", err)
		}
		return
	}
	log.Infoln(ok)
	sendCustomeErrorRspToAF(w, 404, "Failed to find AF records")
}