The image service written by golang. Use to handle the images from cloud storage. Display the different size image based on the request parameters.
- Download image from url;
- Crop the image;
- Compress the image size;
- Upload to the cloud service;
- Copy and set environment values
cp .env.dist .env
- Build image in your local
docker compose build
- Install required NodeJS libraries
docker compose run --rm app bash -c "npm --prefix /go/src/image-functions/.node install"
- If you want to install some NodeJS packages
docker compose run --rm app bash -c "npm --prefix /go/src/image-functions/.node install serverless --save-dev"
- Install required Golang libraries
docker compose run --rm app make install
- Run the binary file build and watch
docker compose up -d
- Build the production file
docker compose run --rm app make build
- Run the unit test
docker compose run --rm app make test
- Run the benchmark
docker compose run --rm app make benchmark
- Start the serverless offline, there no runner for runtime go1.x in the serverless offline, so use the docker to run it
.node/node_modules/.bin/serverless offline start --useDocker --stage=dev
-
Run or Debug it by IDE We can use the GoLand to build and run the main.go It will start a http server by using the port 8080
-
Use Goland old version (<2020.1.4) to load new Go SDK (1.17+)? Error: unpacked SDK is corrupted
vim <GO_SDK_PATH>/src/runtime/internal/sys/zversion.go
# ADD the const TheVersion
const TheVersion = `go1.17.*`
Local S3 service based on LocalS3
- Create and use local S3 bucket
aws --endpoint-url http://localhost:4566 s3api create-bucket --bucket test
# List buckets
aws --endpoint-url http://localhost:4566 s3api list-buckets
# Copy one file into S3
aws --endpoint-url http://localhost:4566 s3 cp README.md s3://test/
# List the copied file
aws --endpoint-url http://localhost:4566 s3 ls s3://test/
- Load this pre-request script in the postman, or import this collection
const jwtHeader = btoa(JSON.stringify(
{
alg: 'HS256',
typ: 'JWT'
}
)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
const jwtBody = btoa(JSON.stringify(
{
app: 'image-functions',
data: {
host: 'lmg.jj20.com'
},
exp: Math.floor(Date.now() / 1000) + 7200
}
)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
const hmac = CryptoJS.HmacSHA256(jwtHeader + '.' + jwtBody, pm.environment.get('AUTH_KEY'));
const hmacBase64 = CryptoJS.enc.Base64.stringify(hmac).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
pm.request.headers.add({
key: 'Authorization',
value: 'Bearer ' + jwtHeader + '.' + jwtBody + '.' + hmacBase64
});
pm.request.headers.add({
key: 'Auth-User',
value: pm.environment.get('AUTH_USER')
});