Giter Site home page Giter Site logo

imgresize's Introduction

Image Resize Service

Instruction

Prerequisite: Make sure you have Docker Also make sure you have docker-compose. It should come with Docker Mac/Windows version but might need to be installed separately with package managers with different version of Unix.

  • If you have go installed, you can download this by go get github.com/funfoolsuzi/imgresize. Or just clone it.

To build the Docker image:

make build

To start the entire service via docker-compose:

make up

To tear down the entire service via docker-compose:

make down

Once the docker-compose is up, try a few url in your browser: "http://127.0.0.1:8080/originals/gophers/fancygopher.jpg" "http://127.0.0.1:8080/resized/gophers/fancygopher_h100_w100.jpg"

Description

This app relies on another go repo: github.com/h2non/imaginary

The app uses imaginary as a service in docker-compose to resize image. The service itself is pre-loaded with a few images. The original images can be accessed at "http://127.0.0.1:8080/originals/". It is built with go's default http file server. The resized images can be accessed from "http://127.0.0.1:8080/resized/". The file path should be the same with the originals. But the image name is different. It follows a convention. For example, if the original is saved at "/originals/this/image.jpg", then you can access the resized image at "/resized/this/image_h100_w100.jpg". So to sum up, for resized image /resized/{path_to_image}/{image_name}_h{height}_w{width}.{file_extention}.

If a resized image doesn't exist at first, the main service will contact an instance of of imaginary for a resized image and then store it at certain location for future access.

log for the main service is persisted at ./log/app.log. Once you run the service, you can get most updated log entries withouth docker exec -it container_name /bin/sh.

The service is built with Dependency Injection/IoC(Inversion of Control) pattern. This will let components being able to be mocked, thus forming better testibility. I have introduced this pattern to my current job. Everything is organized within IoC Container.

Developer Notes

  1. Whenever interfaces are updated, remember to call make mockgen to update the mock files. This requires your OS with mockgen installed(go install github.com/golang/mock/mockgen).

TODO

  1. add config file to the service.
  2. More unit tests.

imgresize's People

Contributors

funfoolsuzi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.