Let we have a simple problem to demonstare the way of thinking.
getting image stub (for instance, white noise) with the given sizes.
Let's define some requirements which seem make a program more flexible to use:
- we should have a package to use the module inside another solid go program
- it could be used via http api if we have a microservice architecture
- it could be used via cli if we have a pipeline
Architecture could be like this:
- we have a lorempixum package
- we have a microservice in go which uses the lorempixum
- we have a standalone program which uses the same package and could be a part of pipeline
Unix way! :)
Try within Internet:
$ curl lorempixum.herokuapp.com/jpeg/200/200 > white-noise-200x200.jpg
If we need it via cli, let's write a tiny program uses the lorempixum:
package main
import (
"flag"
"github.com/vitkarpov/lorempixum"
"os"
)
func main() {
w := flag.Int("width", 0);
h := flag.Int("height", 0);
flag.Parse();
// get the pointer to the image
img := lorempixum.GetImage(*w, *h)
// stream it to the standart output
lorempixum.StreamImage(os.Stdout, img, "jpeg")
}
now we can use it inside pipelines:
$ lorempixum -width=100 -height=100 > white-noise-100x100.jpg
If you need a junior golang developer — drop me a line: [email protected]