Minimal working template for creating and deploying a go micro-service in both local and lambda http / json
- cmd
- commands which run the micro-service using either local http or lambda http networking
- networking
- transport layer which receives a request and write an appropriate response, as specified by the business logic in the service; this request is treated as either a http request or a generic apit gateway request, depending on whether or not the http or lambda transport layer is used; in both cases the response is marshalled via an json encoder
- service
- mock service which returns an appropriate message given a name string in the url query params
Install both go and dep
(Example: brew install golang, dep
)
- Remember to properly set you GOPATH variable (e.g. add
export GOPATH="$HOME/go"
to ~/.bashrc) - Clone this repo using go get:
go get go get github.com/uncmath25/go-microservice-template
- Import and develop this repo under your gopath $GOPATH/src/github.com/uncmath25/go-microservice-template
- Run
make build
to build the binary from the go project - Start the server:
./bin/run_http_server
and test with a local client GET request - Test the server using curl (or just the browser I suppose...) with the provided stub script ./testing.sh
- Install serverless if necessary:
npm install serverless -g
- Login to serverless:
sls login
- Add an application through the serverless website
- Remember to add your app and tenant name to ./serverless.yml: https://serverless.com/framework/docs/providers/aws/guide/deploying/
- Setup an appropriate AWS profile: https://serverless.com/framework/docs/providers/aws/guide/credentials/
- Set "PROFILE_NAME" in "./Makefile"
- Run
make deploy
- (Bonus: Print logging to console:
sls logs -f lambdahttpserver
) - (Bonus: Remove serverless deployment:
make remove
)