Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Imported code from old repository
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbour committed Oct 31, 2018
1 parent 9d21697 commit 5039f6f
Show file tree
Hide file tree
Showing 30 changed files with 1,581 additions and 17 deletions.
48 changes: 48 additions & 0 deletions Dockerfile
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"]
34 changes: 17 additions & 17 deletions LICENSE
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.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@

# CaptureOrder

A containerised Go swagger API to capture orders, write them to MongoDb and an AMQP message queue.

## Usage
### Swagger

Access the Swagger UI at [http://[host]/swagger]()

### Submitting an order

```
POST /v1/Order HTTP/1.1
Host: [host]:[port]
Content-Type: application/json
{
"EmailAddress": "test@domain.com",
"PreferredLanguage": "en"
}
```

## Environment Variables

The following environment variables need to be passed to the container:

### Logging

```
ENV TEAMNAME=[YourTeamName]
ENV APPINSIGHTS_KEY=[YourCustomApplicationInsightsKey] # Optional, create your own App Insights resource
```

### For MongoDB

```
ENV MONGOURL=mongodb://[mongoinstance].[namespace]
```

### For CosmosDB

```
ENV MONGOURL=mongodb://[CosmosDBInstanceName]:[CosmosDBPrimaryPassword]=@[CosmosDBInstanceName].documents.azure.com:10255/?ssl=true&replicaSet=globaldb
```

### For RabbitMQ

```
ENV AMQPURL=amqp://[url]:5672
```

### For Event Hubs

```
ENV AMQPURL=amqps://[policy name]:[policy key]@[youreventhub].servicebus.windows.net/[eventhubname]
```

Make sure your _policy key_ is URL Encoded. Use a tool like: <https://www.url-encode-decode.com/>

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
1 change: 1 addition & 0 deletions assets/main_receiver_offsets.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
1 change: 1 addition & 0 deletions assets/partition_offsets.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
2 changes: 2 additions & 0 deletions assets/test_invalid_format.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
,
"more than","one row"
1 change: 1 addition & 0 deletions assets/test_offsets_lifecycle.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zzz,
6 changes: 6 additions & 0 deletions conf/app.conf
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
42 changes: 42 additions & 0 deletions controllers/order.go
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()
}
15 changes: 15 additions & 0 deletions main.go
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()
}
Loading

0 comments on commit 5039f6f

Please sign in to comment.