This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 971
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,581 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Build stage | ||
FROM golang:1.9.4 as builder | ||
|
||
# Set the working directory to the app directory | ||
WORKDIR /go/src/captureorderfd | ||
|
||
# Install godeps | ||
RUN go get -u -v github.com/astaxie/beego | ||
RUN go get -u -v github.com/beego/bee | ||
RUN go get -d github.com/Microsoft/ApplicationInsights-Go/appinsights | ||
RUN go get -u -v gopkg.in/mgo.v2 | ||
RUN go get -u -v github.com/Azure/go-autorest/autorest/utils | ||
RUN go get -u -v github.com/streadway/amqp | ||
RUN go get -u -v pack.ag/amqp | ||
RUN go get gopkg.in/matryer/try.v1 | ||
|
||
# Copy the application files | ||
COPY . . | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o captureorderfd . | ||
|
||
## App stage | ||
FROM alpine:latest | ||
RUN apk --no-cache add ca-certificates | ||
WORKDIR /root/ | ||
COPY --from=builder /go/src/captureorderfd . | ||
|
||
# Define environment variables | ||
# Application Insights | ||
ENV APPINSIGHTS_KEY= | ||
ENV CHALLENGEAPPINSIGHTS_KEY=23c6b1ec-ca92-4083-86b6-eba851af9032 | ||
|
||
# Challenge Logging | ||
ENV TEAMNAME= | ||
|
||
# AMQP | ||
ENV AMQPURL= | ||
|
||
# Mongo/Cosmos | ||
ENV MONGOURL= | ||
|
||
# Expose the application on port 8080 | ||
EXPOSE 8080 | ||
|
||
# Set the entry point of the container to the bee command that runs the | ||
# application and watches for changes | ||
CMD ["./captureorderfd", "run"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
MIT License | ||
MIT License | ||
|
||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Copyright (c) 2017 Shane Peckham | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
, | ||
"more than","one row" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
zzz, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
appname = captureorderfd | ||
httpport = 8080 | ||
runmode = dev | ||
autorender = false | ||
copyrequestbody = true | ||
EnableDocs = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package controllers | ||
|
||
import ( | ||
"captureorderfd/models" | ||
"encoding/json" | ||
|
||
"github.com/astaxie/beego" | ||
) | ||
|
||
// Operations about object | ||
type OrderController struct { | ||
beego.Controller | ||
} | ||
|
||
// @Title Capture Order | ||
// @Description Capture order POST | ||
// @Param body body models.Order true "body for order content" | ||
// @Success 200 {string} models.Order.ID | ||
// @Failure 403 body is empty | ||
// @router / [post] | ||
func (this *OrderController) Post() { | ||
|
||
var ob models.Order | ||
json.Unmarshal(this.Ctx.Input.RequestBody, &ob) | ||
|
||
|
||
// Add the order to MongoDB | ||
addedOrder, err := models.AddOrderToMongoDB(ob) | ||
|
||
if err == nil { | ||
// Add the order to AMQP | ||
models.AddOrderToAMQP(addedOrder) | ||
|
||
// return | ||
this.Data["json"] = map[string]string{"orderId": addedOrder.OrderID} | ||
} else { | ||
this.Data["json"] = map[string]string{"error": "order not added to MongoDB. Check logs: " + err.Error()} | ||
this.Ctx.Output.SetStatus(500) | ||
} | ||
|
||
this.ServeJSON() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
_ "captureorderfd/routers" | ||
|
||
"github.com/astaxie/beego" | ||
) | ||
|
||
func main() { | ||
if beego.BConfig.RunMode == "dev" { | ||
beego.BConfig.WebConfig.DirectoryIndex = true | ||
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" | ||
} | ||
beego.Run() | ||
} |
Oops, something went wrong.