This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
api_sm_contexts_collection.go
74 lines (64 loc) · 1.81 KB
/
api_sm_contexts_collection.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Nsmf_PDUSession
*
* SMF PDU Session Service
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package PDUSession
import (
"github.com/gin-gonic/gin"
"free5gc/lib/http_wrapper"
"free5gc/lib/openapi"
"free5gc/lib/openapi/models"
"free5gc/src/smf/logger"
"free5gc/src/smf/smf_handler/smf_message"
"net/http"
"strings"
)
// PostSmContexts - Create SM Context
func PostSmContexts(c *gin.Context) {
logger.PduSessLog.Info("Recieve Create SM Context Request")
var request models.PostSmContextsRequest
request.JsonData = new(models.SmContextCreateData)
s := strings.Split(c.GetHeader("Content-Type"), ";")
var err error
switch s[0] {
case "application/json":
err = c.ShouldBindJSON(request.JsonData)
case "multipart/related":
err = c.ShouldBindWith(&request, openapi.MultipartRelatedBinding{})
}
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.PduSessLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}
req := http_wrapper.NewRequest(c.Request, request)
message := smf_message.NewHandlerMessage(smf_message.PDUSessionSMContextCreate, req)
smf_message.SendMessage(message)
rsp := <-message.ResponseChan
HTTPResponse := rsp.HTTPResponse
for key, val := range HTTPResponse.Header {
c.Header(key, val[0])
}
switch HTTPResponse.Status {
case http.StatusCreated,
http.StatusBadRequest,
http.StatusForbidden,
http.StatusNotFound,
http.StatusInternalServerError,
http.StatusServiceUnavailable,
http.StatusGatewayTimeout:
c.Render(HTTPResponse.Status, openapi.MultipartRelatedRender{Data: HTTPResponse.Body})
default:
c.JSON(HTTPResponse.Status, HTTPResponse.Body)
}
}