Added serverless folder and files in it
This commit is contained in:
5
backend/serverless/GO_API_service/.gitignore
vendored
Normal file
5
backend/serverless/GO_API_service/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Serverless directories
|
||||||
|
.serverless
|
||||||
|
|
||||||
|
# golang output binary directory
|
||||||
|
bin
|
||||||
87
backend/serverless/GO_API_service/GO_API/server.go
Normal file
87
backend/serverless/GO_API_service/GO_API/server.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"fmt"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/labstack/echo"
|
||||||
|
"github.com/labstack/echo/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
Username string
|
||||||
|
FirstName string
|
||||||
|
LastName string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Task struct {
|
||||||
|
Title string
|
||||||
|
Description string
|
||||||
|
UserOfTask User
|
||||||
|
Date string
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
e := echo.New()
|
||||||
|
|
||||||
|
// Middleware
|
||||||
|
e.Use(middleware.Logger())
|
||||||
|
e.Use(middleware.Recover())
|
||||||
|
|
||||||
|
// CORS
|
||||||
|
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||||
|
AllowOrigins: []string{"*"},
|
||||||
|
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
|
||||||
|
}))
|
||||||
|
|
||||||
|
// Getting JSON as []byte
|
||||||
|
b, err := Handler()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("error:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Route => handler
|
||||||
|
e.GET("/", func(c echo.Context) error {
|
||||||
|
return c.String(http.StatusOK, string(b[:]))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Server
|
||||||
|
e.Start(":1500")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u User) String() string {
|
||||||
|
return fmt.Sprintf("Username: %v\nFirst name: %v\nLast name: %v", u.Username, u.FirstName, u.LastName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t Task) String() string {
|
||||||
|
return fmt.Sprintf("Title: %v\nDescription: %v\nUser: %v\nDate: %v", t.Title, t.Description, t.UserOfTask, t.Date)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Handler() ([]byte, error) {
|
||||||
|
user := User {
|
||||||
|
Username: "emirbarucija",
|
||||||
|
FirstName: "Emir",
|
||||||
|
LastName: "Baručija",
|
||||||
|
}
|
||||||
|
|
||||||
|
task1 := Task {
|
||||||
|
Title: "First task",
|
||||||
|
Description: "This is my first task in GO language",
|
||||||
|
UserOfTask: user,
|
||||||
|
Date: "10.04.2018.",
|
||||||
|
}
|
||||||
|
|
||||||
|
task2 := Task {
|
||||||
|
Title: "Second task",
|
||||||
|
Description: "This is my second task in GO language",
|
||||||
|
UserOfTask: user,
|
||||||
|
Date: "14.04.2018.",
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks := []Task{task1, task2}
|
||||||
|
|
||||||
|
b, err := json.Marshal(tasks)
|
||||||
|
|
||||||
|
return b, err
|
||||||
|
}
|
||||||
3
backend/serverless/GO_API_service/Makefile
Normal file
3
backend/serverless/GO_API_service/Makefile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
build:
|
||||||
|
go get github.com/aws/aws-lambda-go/lambda
|
||||||
|
env GOOS=windows go build -ldflags="-s -w" -o bin/GO_API GO_API/server.go
|
||||||
106
backend/serverless/GO_API_service/serverless.yml
Normal file
106
backend/serverless/GO_API_service/serverless.yml
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
# Welcome to Serverless!
|
||||||
|
#
|
||||||
|
# This file is the main config file for your service.
|
||||||
|
# It's very minimal at this point and uses default values.
|
||||||
|
# You can always add more config options for more control.
|
||||||
|
# We've included some commented out config examples here.
|
||||||
|
# Just uncomment any of them to get that config option.
|
||||||
|
#
|
||||||
|
# For full config options, check the docs:
|
||||||
|
# docs.serverless.com
|
||||||
|
#
|
||||||
|
# Happy Coding!
|
||||||
|
|
||||||
|
service: GO_API_service
|
||||||
|
|
||||||
|
# You can pin your service to only deploy with a specific Serverless version
|
||||||
|
# Check out our docs for more details
|
||||||
|
# frameworkVersion: "=X.X.X"
|
||||||
|
|
||||||
|
provider:
|
||||||
|
name: aws
|
||||||
|
runtime: go1.x
|
||||||
|
|
||||||
|
# you can overwrite defaults here
|
||||||
|
# stage: dev
|
||||||
|
# region: us-east-1
|
||||||
|
|
||||||
|
# you can add statements to the Lambda function's IAM Role here
|
||||||
|
# iamRoleStatements:
|
||||||
|
# - Effect: "Allow"
|
||||||
|
# Action:
|
||||||
|
# - "s3:ListBucket"
|
||||||
|
# Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
|
||||||
|
# - Effect: "Allow"
|
||||||
|
# Action:
|
||||||
|
# - "s3:PutObject"
|
||||||
|
# Resource:
|
||||||
|
# Fn::Join:
|
||||||
|
# - ""
|
||||||
|
# - - "arn:aws:s3:::"
|
||||||
|
# - "Ref" : "ServerlessDeploymentBucket"
|
||||||
|
# - "/*"
|
||||||
|
|
||||||
|
# you can define service wide environment variables here
|
||||||
|
# environment:
|
||||||
|
# variable1: value1
|
||||||
|
|
||||||
|
package:
|
||||||
|
exclude:
|
||||||
|
- ./**
|
||||||
|
include:
|
||||||
|
- ./bin/**
|
||||||
|
|
||||||
|
functions:
|
||||||
|
GO_API:
|
||||||
|
handler: bin/GO_API
|
||||||
|
events:
|
||||||
|
- http:
|
||||||
|
path: all
|
||||||
|
method: get
|
||||||
|
|
||||||
|
# The following are a few example events you can configure
|
||||||
|
# NOTE: Please make sure to change your handler code to work with those events
|
||||||
|
# Check the event documentation for details
|
||||||
|
# events:
|
||||||
|
# events:
|
||||||
|
# - http:
|
||||||
|
# path: users/create
|
||||||
|
# method: get
|
||||||
|
# - s3: ${env:BUCKET}
|
||||||
|
# - schedule: rate(10 minutes)
|
||||||
|
# - sns: greeter-topic
|
||||||
|
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
|
||||||
|
# - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
|
||||||
|
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
|
||||||
|
# - iot:
|
||||||
|
# sql: "SELECT * FROM 'some_topic'"
|
||||||
|
# - cloudwatchEvent:
|
||||||
|
# event:
|
||||||
|
# source:
|
||||||
|
# - "aws.ec2"
|
||||||
|
# detail-type:
|
||||||
|
# - "EC2 Instance State-change Notification"
|
||||||
|
# detail:
|
||||||
|
# state:
|
||||||
|
# - pending
|
||||||
|
# - cloudwatchLog: '/aws/lambda/hello'
|
||||||
|
# - cognitoUserPool:
|
||||||
|
# pool: MyUserPool
|
||||||
|
# trigger: PreSignUp
|
||||||
|
|
||||||
|
# Define function environment variables here
|
||||||
|
# environment:
|
||||||
|
# variable2: value2
|
||||||
|
|
||||||
|
# you can add CloudFormation resource templates here
|
||||||
|
#resources:
|
||||||
|
# Resources:
|
||||||
|
# NewResource:
|
||||||
|
# Type: AWS::S3::Bucket
|
||||||
|
# Properties:
|
||||||
|
# BucketName: my-new-bucket
|
||||||
|
# Outputs:
|
||||||
|
# NewOutput:
|
||||||
|
# Description: "Description for the output"
|
||||||
|
# Value: "Some output value"
|
||||||
Reference in New Issue
Block a user