qrcode

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2018 License: MIT Imports: 7 Imported by: 0

README

QR Code API

Go Report Card GoDoc Docker Image

A simple API service for QR Code generation/recognition.

This project provide Bearychat integration.

API Doc

Encoding

Request:

GET /encode?content=helloWorld&size=400&type=png

Params:

  • content required
  • size QR Code size in pixel, may not be honored
  • type png(default) or string

Response:

  • HTTP status 200 OK

A image/png or plain text(type=string).

  • HTTP status 400 Bad Request

Check your params.

  • HTTP status 500

Something unexpected happened.

Decoding

Request:

POST /decode

Params: image as binary body

Response:

  • HTTP status 200 OK

Good decoding:

{
    "ok": true,
    "desc": "",
    "content": [
        "你好"
    ]
}

Everything is ok, but nothing recognized:

{
    "ok": true,
    "desc": "",
    "content": null
}

Something is wrong:

{
    "ok": false,
    "desc": "file decoding error: image: unknown format",
    "content": null
}
  • HTTP status 413 Request Entity Too Large

Request Body is too large.

  • HTTP status 500

Something unexpected happened.

Docker Image

There is a pre-compiled Docker image alone with C++ dependencies(ZBar), you may pull the image like following:

docker pull nanmu42/qrcode-api

See Docker directory for docker-compose.yaml and more detail.

Build and Run

If you'd like to get you hands dirty, you can build this project as following:

Download and compile ZBar for shared dependencies:

wget https://downloads.sourceforge.net/project/zbar/zbar/0.10/zbar-0.10.tar.bz2
# or, if you are suffering decoding troubles on UTF-8, try this modified version:
# wget https://github.com/nanmu42/zbar-utf8/archive/master.zip
tar -xf zbar-0.10.tar.bz2
cd zbar-0.10
export CFLAGS=""
./configure --disable-video --without-imagemagick --without-qt --without-python --without-gtk --without-x --disable-pthread
make install

Go to cmd/api or cmd/bearychat for further instruction, more details are in README.md there.

License

Copyright (c) 2018 LI Zhennan

Use of this work is governed by an MIT License. You may find a license copy in project root.

Documentation

Index

Constants

View Source
const (
	// TypePNG file as png
	TypePNG = "png"
	// TypeString QRCode
	TypeString = "string"

	// DefaultType default file type
	DefaultType = TypePNG
)

Variables

This section is empty.

Functions

func DecodeQRCode

func DecodeQRCode(img image.Image) (content []string, err error)

DecodeQRCode decodes QR Code content from image

content contains multiple string if there are more than one QR Code got decoded. content and err are both nil when no QR Code found.

Types

type QREncoder

type QREncoder struct {
	// content to encode
	Content string
	// desired encoding type
	Type string
	// desired image size in pixel, may not be honored
	Size int
}

QREncoder holds info for QR code encoding

func (*QREncoder) Encode

func (q *QREncoder) Encode(dest io.Writer) (gotType string, err error)

Encode produces a QR code

Directories

Path Synopsis
cmd
api
bearychat
QRCode API integration on Bearychat, a Slack-like working group.
QRCode API integration on Bearychat, a Slack-like working group.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL