Skip to content

Instantly share code, notes, and snippets.

@cn007b
cn007b / Makefile
Last active Apr 10, 2019
Deploy AWS Fargate Service - deploy
View Makefile
deploy:
aws ecs update-service --cluster=$(YourCluster) --service=$(YourSrvc) --task-definition=`\
aws ecs register-task-definition --cli-input-json file://AWSTaskDefinition.json \
| grep -Eo $(YourSrvc)':[0-9]+' \
`
@cn007b
cn007b / Makefile
Created Apr 9, 2019
Deploy AWS Fargate Service - build_and_push_image
View Makefile
build_and_push_image:
docker build \
-t $(YourUserID).dkr.ecr.us-east-1.amazonaws.com/$(YourImage):$(YourTag) \
-f deploy/Dockerfile .
eval $(shell aws ecr get-login --no-include-email)
docker push $(YourUserID).dkr.ecr.us-east-1.amazonaws.com/$(YourImage):$(YourTag)
@cn007b
cn007b / td.json
Last active Apr 9, 2019
AWS TaskDefinition JSON example
View td.json
{
"containerDefinitions": [
{
"name": "$(YourServiceName)",
"image": "$(YourUserID).dkr.ecr.us-east-1.amazonaws.com/$(YourImage):$(YourTag)",
"portMappings": [
{
"protocol": "tcp",
"hostPort": 8080,
"containerPort": 8080
@cn007b
cn007b / DRYinGO.errorHandling.go
Last active Jan 30, 2019
DRY in GO - error handling
View DRYinGO.errorHandling.go
if err != nil {
httpErrorCode := 500
switch err {
case ErrorInvalidID:
httpErrorCode = 400
case ErrorUnauthorized:
httpErrorCode = 401
case ErrorEmployeeNotFound:
httpErrorCode = 404
// other errors
@cn007b
cn007b / DRYinGO.3.go
Last active Jan 30, 2019
DRY in GO #3
View DRYinGO.3.go
func withEmployee(id string, cb func(Employee) (string, int)) (string, int) {
e, err := db.GetEmployeeByID(id)
if err != nil {
// error handling provided earlier
}
return cb(e)
}
func GetEmployeeName(id string) (string, int) {
@cn007b
cn007b / DRYinGO.2.go
Last active Jan 30, 2019
DRY in GO #2
View DRYinGO.2.go
func getEmployee(id string) (Employee, int) {
e, err := db.GetEmployeeByID(id)
if err != nil {
// error handling provided earlier
}
return e, 200
}
func GetEmployeeName(id string) (string, int) {
@cn007b
cn007b / DRYinGO.1.go
Last active Jan 30, 2019
DRY in GO #1
View DRYinGO.1.go
func GetEmployeeName(id string) (string, int) {
e, err := db.GetEmployeeByID(id)
if err != nil {
httpErrorCode := 500
switch err {
case ErrorInvalidID:
httpErrorCode = 400
case ErrorUnauthorized:
httpErrorCode = 401
case ErrorEmployeeNotFound:
@cn007b
cn007b / youtube 500
Created Jan 8, 2019
youtube error 500
View youtube 500
APkpgMVe78Uwfds9i0eAaRtUZ1qoTfYpRShXjGjauvHtQBL_vAoXQH0b
q_2I29eK_8lxoiCauYd0JtgvSgmeGPz4HSkEHH418f0Ysl9txY-3WCcw
EZJsLUJXRvYjqLjd8tqWXtsfE45HrNN6akVsZwN3Rvil0UVGyCqq6dCP
QtGWOvZ4ka6zxb_rFvb4C0J5iY1tCgdQhAXD-sWyjQSU_prXgPSDOz7B
CSvBfsANNWtvqCxaQMnu3wFv2LgmbF0pu1Cam58XZjPH_m8rlhFbvXPV
gZ-iOmZFSJyTfb93boQGJ8fdQ6G0k7Z6hJLmyma4r7f6Y8kUwILiJ2he
S3jHXjdzO6e6b5L5buI6hnYcNEIPkxAwkEa7UktPeZI49X-PSBf2KY9R
0zjcdpQRYDbRLaNpKoyqjaKVkRn4O2DJimzskFS3S_IfQKlkRQEPxcux
HXcXH6Z-RqicpSfL-glePfLwSYAITzt1eo5Ls2lrBwkJuB8nXSj9uhNw
xHK7g6uXrTC3oPm5nAqGuzohZnkOqDgY5b0O_lPf6vu88InEpfgEtYeu
@cn007b
cn007b / gin.go
Created Dec 4, 2018
Plain Go vs Gin - gin
View gin.go
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/v1/id/:id", func(c *gin.Context) {
c.JSON(200, gin.H{
@cn007b
cn007b / plain.go
Created Dec 4, 2018
Plain Go vs Gin - plain go
View plain.go
package main
import (
"encoding/json"
"net/http"
"strings"
)
func main() {
http.HandleFunc("/v1/id/", func(w http.ResponseWriter, r *http.Request) {