From 9bbbb873fe6f662a93d5108e6cc7e2fd889fc6e3 Mon Sep 17 00:00:00 2001 From: John McCabe Date: Fri, 18 Aug 2017 16:51:45 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + Dockerfile | 20 ++++++++++++++++++++ Gopkg.lock | 15 +++++++++++++++ Gopkg.toml | 26 ++++++++++++++++++++++++++ LICENSE | 21 +++++++++++++++++++++ Makefile | 14 ++++++++++++++ README.md | 34 ++++++++++++++++++++++++++++++++++ function.go | 22 ++++++++++++++++++++++ images/qrcode.png | Bin 0 -> 641 bytes 9 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 function.go create mode 100644 images/qrcode.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5657f6e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4917698 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.9rc2-alpine as BUILDER +MAINTAINER john@johnmccabe.net + +RUN apk --no-cache add make +WORKDIR /go/src/github.com/faas-and-furious/qrcode +COPY . /go/src/github.com/faas-and-furious/qrcode + +RUN make + +FROM alpine + +COPY --from=builder /go/bin/qrcode /usr/bin +ADD https://github.com/alexellis/faas/releases/download/0.6.0/fwatchdog /usr/bin +RUN chmod +x /usr/bin/fwatchdog +COPY --from=builder /go/bin/qrcode /usr/bin +RUN chmod +x /usr/bin/qrcode + +ENV fprocess "/usr/bin/qrcode" + +CMD [ "/usr/bin/fwatchdog"] \ No newline at end of file diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..49a49f7 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,15 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/skip2/go-qrcode" + packages = [".","bitset","reedsolomon"] + revision = "695fc75a09738f9be56aaa3aecfd7dac28e66b63" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "9094a24c5d5f0ca0993e22a6e3af8cc6a50b6d87628ae6f69f433da34c8721ae" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..5e7dea5 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,26 @@ + +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + + +[[constraint]] + branch = "master" + name = "github.com/skip2/go-qrcode" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8864d4a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e952b61 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +.PHONY: install image dependencies + +build: dependencies + @go install . + +image: + @docker build -t faasandfurious/qrcode . + +dependencies: + @apk update + @apk add git + @rm -rf /var/cache/apk/* + @go get -u github.com/golang/dep/cmd/dep + @dep ensure \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fa58b95 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# FaaS qrcode + +[![Go Report Card](https://goreportcard.com/badge/github.com/faas-and-furious/qrcode)](https://goreportcard.com/report/github.com/faas-and-furious/qrcode) [![](https://images.microbadger.com/badges/image/faasandfurious/qrcode.svg)](https://microbadger.com/images/faasandfurious/qrcode "Get your own image badge on microbadger.com") + +This repo contains an example [FaaS](https://github.com/alexellis/faas) function which uses the [skip2/go-qrcode](https://github.com/skip2/go-qrcode) Go library to generate a QR Code for a string. + +## Deploying the Function + +Make sure you have deployed a FaaS stack to your cluster using the instructions on the [FaaS repo](https://github.com/alexellis/faas). + +### Use the CLI (`faas-cli`) + +**Get the CLI** + +The [faas-cli](https://github.com/alexellis/faas-cli/) can be installed via `brew install faas-cli` or `curl -sSL https://get.openfaas.com | sudo sh`. + +Now deploy the function as follows: + +``` +# faas-cli -action deploy -image=faasandfurious/qrcode -name=qrcode -fprocess="/usr/bin/qrcode" +200 OK +URL: http://localhost:8080/function/qrcode +``` + +### Testing the Function +Now that the function is running in your FaaS environment you can test it from the command line by running: + +``` +$ curl localhost:8080/function/qrcode --data "https://github.com/alexellis/faas" > qrcode.png +``` + +![](images/qrcode.png) + +You can check the QR code works using your phone, or an online QR Code decoder ([ZXing Decoder Online](https://zxing.org/w/decode.jspx) for example) diff --git a/function.go b/function.go new file mode 100644 index 0000000..65a5102 --- /dev/null +++ b/function.go @@ -0,0 +1,22 @@ +package main + +import ( + "encoding/binary" + "io/ioutil" + "log" + "os" + + qrcode "github.com/skip2/go-qrcode" +) + +func main() { + input, err := ioutil.ReadAll(os.Stdin) + if err != nil { + log.Fatalf("Unable to read standard input: %s", err.Error()) + } + png, err := qrcode.Encode(string(input), qrcode.Medium, 256) + if err != nil { + log.Fatalf("Unable to read standard input: %s", err.Error()) + } + binary.Write(os.Stdout, binary.LittleEndian, png) +} diff --git a/images/qrcode.png b/images/qrcode.png new file mode 100644 index 0000000000000000000000000000000000000000..66a7ce0ac69ee2cfb0a3c5e3f5e220293edd28d7 GIT binary patch literal 641 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5Fo`C;1lBd|Nnm=GxX5qItB(N zGfx-CkcwMx?phb!HV|nG%=|yQ>~-6m|4fIPkNjNK^Vs81rh<*dPmf6|o=E7Wbotl( z$@BmJKY8{3wpuozaSRL>_$U1LGn(>5^j-Y&x5Z2#p$55z)tS%hBEm0+*!zoef`k~( zu&nUw;S>e4Z%8W46au-D;eaq>-R|6J@`W~8{sJI@IF1SRPYUbnPW%P&7%D^$%sE;7 zn-Qe=z(R(rn%ee4J8!YAj@vKm!wOcx6+UN`_foSxojf3Jfr-PXHd|+Zy@;>-`M~lL z=3llsPfh8_6*hwK_o`0I$q4P={r=-5PYJM4&ut;^Wox#n`hD6b{e~0dg9C*Op>2ZU z^Cuk@2CJCC8E|)>m)hQWM=zx3fJA`y6q#Jy?6A_W93@tRsKT_Uf0bU_COt7rxzyDV_B;UIiSY z4WSG_1y;A~UR@mlR-e$GxuJ@2Th+m=-|xW+J_t3unif%7v|4U0znm3VO~#-1-#`0q us_ESPWhdA(79tKvu?|cDFBAU)gBzHFgsdaQ{`^P;Y4ddTb6Mw<&;$S+Y2%#$ literal 0 HcmV?d00001