-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
54 lines (36 loc) · 1.13 KB
/
index.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
package deploy
import (
"encoding/json"
"github.com/roger-russel/deploy-calendar/pkg/api"
"github.com/roger-russel/deploy-calendar/pkg/logger"
"github.com/valyala/fasthttp"
)
type createRequest struct {
ProjectHash string `json:"project_hash,omitempty"`
Context string `json:"context,omitempty"`
Version string `json:"version,omitempty"`
PullRequestURL string `json:"pull_request_url,omitempty"`
}
func Create(ctx *fasthttp.RequestCtx) {
status, message, err := createHandler(ctx.PostBody())
response := api.SimpleResponse{
Message: message,
Error: err,
}
ctx.SetStatusCode(status)
if status != fasthttp.StatusAccepted {
api.JsonOut(ctx, response)
}
}
func createHandler(data []byte) (int, string, error) {
var request = &createRequest{}
err := json.Unmarshal(data, request)
if err != nil {
logger.Error("error unmarshal create deploy request", err)
return fasthttp.StatusBadRequest, "body data could not be parsed as json", err
}
//ToDO Validar request
// jsonRequest, _ := json.Marshal(request)
//nc := nats.Pub(nats.SubEventDeploy, *jsonRequest)
return fasthttp.StatusAccepted, "", nil
}