Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmccabe committed Aug 18, 2017
0 parents commit 9bbbb87
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.9rc2-alpine as BUILDER
MAINTAINER [email protected]

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"]
15 changes: 15 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -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"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
@@ -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)
}
Binary file added images/qrcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9bbbb87

Please sign in to comment.