Skip to content

Commit 9bbbb87

Browse files
committed
Initial commit
0 parents  commit 9bbbb87

File tree

9 files changed

+153
-0
lines changed

9 files changed

+153
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.9rc2-alpine as BUILDER
2+
3+
4+
RUN apk --no-cache add make
5+
WORKDIR /go/src/github.com/faas-and-furious/qrcode
6+
COPY . /go/src/github.com/faas-and-furious/qrcode
7+
8+
RUN make
9+
10+
FROM alpine
11+
12+
COPY --from=builder /go/bin/qrcode /usr/bin
13+
ADD https://github.com/alexellis/faas/releases/download/0.6.0/fwatchdog /usr/bin
14+
RUN chmod +x /usr/bin/fwatchdog
15+
COPY --from=builder /go/bin/qrcode /usr/bin
16+
RUN chmod +x /usr/bin/qrcode
17+
18+
ENV fprocess "/usr/bin/qrcode"
19+
20+
CMD [ "/usr/bin/fwatchdog"]

Gopkg.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Gopkg.toml example
3+
#
4+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
5+
# for detailed Gopkg.toml documentation.
6+
#
7+
# required = ["github.com/user/thing/cmd/thing"]
8+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
9+
#
10+
# [[constraint]]
11+
# name = "github.com/user/project"
12+
# version = "1.0.0"
13+
#
14+
# [[constraint]]
15+
# name = "github.com/user/project2"
16+
# branch = "dev"
17+
# source = "github.com/myfork/project2"
18+
#
19+
# [[override]]
20+
# name = "github.com/x/y"
21+
# version = "2.4.0"
22+
23+
24+
[[constraint]]
25+
branch = "master"
26+
name = "github.com/skip2/go-qrcode"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.PHONY: install image dependencies
2+
3+
build: dependencies
4+
@go install .
5+
6+
image:
7+
@docker build -t faasandfurious/qrcode .
8+
9+
dependencies:
10+
@apk update
11+
@apk add git
12+
@rm -rf /var/cache/apk/*
13+
@go get -u github.com/golang/dep/cmd/dep
14+
@dep ensure

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# FaaS qrcode
2+
3+
[![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")
4+
5+
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.
6+
7+
## Deploying the Function
8+
9+
Make sure you have deployed a FaaS stack to your cluster using the instructions on the [FaaS repo](https://github.com/alexellis/faas).
10+
11+
### Use the CLI (`faas-cli`)
12+
13+
**Get the CLI**
14+
15+
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`.
16+
17+
Now deploy the function as follows:
18+
19+
```
20+
# faas-cli -action deploy -image=faasandfurious/qrcode -name=qrcode -fprocess="/usr/bin/qrcode"
21+
200 OK
22+
URL: http://localhost:8080/function/qrcode
23+
```
24+
25+
### Testing the Function
26+
Now that the function is running in your FaaS environment you can test it from the command line by running:
27+
28+
```
29+
$ curl localhost:8080/function/qrcode --data "https://github.com/alexellis/faas" > qrcode.png
30+
```
31+
32+
![](images/qrcode.png)
33+
34+
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)

function.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"encoding/binary"
5+
"io/ioutil"
6+
"log"
7+
"os"
8+
9+
qrcode "github.com/skip2/go-qrcode"
10+
)
11+
12+
func main() {
13+
input, err := ioutil.ReadAll(os.Stdin)
14+
if err != nil {
15+
log.Fatalf("Unable to read standard input: %s", err.Error())
16+
}
17+
png, err := qrcode.Encode(string(input), qrcode.Medium, 256)
18+
if err != nil {
19+
log.Fatalf("Unable to read standard input: %s", err.Error())
20+
}
21+
binary.Write(os.Stdout, binary.LittleEndian, png)
22+
}

images/qrcode.png

641 Bytes
Loading

0 commit comments

Comments
 (0)