本文整理汇总了Golang中code/google/com/p/rsc/qr.Encode函数的典型用法代码示例。如果您正苦于以下问题:Golang Encode函数的具体用法?Golang Encode怎么用?Golang Encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Encode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: BarcodeImage
// BarcodeImage creates a QR code for use with Google Authenticator (GA).
// label is the string that GA uses in the UI. secretkey should be this user's
// secret key. opt should be the configured Options for this TOTP. If a nil
// options is passed, then DefaultOptions is used.
func BarcodeImage(label string, secretkey []byte, opt *Options) ([]byte, error) {
if opt == nil {
opt = DefaultOptions
}
u := &url.URL{
Scheme: "otpauth",
Host: "totp",
Path: fmt.Sprintf("/%s", label),
}
params := url.Values{
"secret": {base32.StdEncoding.EncodeToString(secretkey)},
"digits": {strconv.Itoa(int(opt.Digits))},
"period": {strconv.Itoa(int(opt.TimeStep / time.Second))},
}
u.RawQuery = params.Encode()
c, err := qr.Encode(u.String(), qr.M)
if err != nil {
return nil, err
}
return c.PNG(), nil
}
开发者ID:nzlov,项目名称:totp,代码行数:31,代码来源:totp.go
示例2: registerMFA
func registerMFA(c *gobot.Context) {
log.Debugf("registering mfa")
c.Respond(fmt.Sprintf("registering a %s mfa", c.Match(1)))
data := make([]byte, 10)
if n, err := rand.Read(data); err != nil {
c.Fail(err)
return
} else if n != len(data) {
c.Fail(fmt.Errorf("read %d random bytes, wanted %d", n, len(data)))
return
}
secret := base32.StdEncoding.EncodeToString(data)
saveOtp(c.User, secret)
code, err := qr.Encode("otpauth://totp/Gobot?secret="+secret, qr.Q)
if err != nil {
c.Fail(err)
return
}
c.Upload(gobot.Attachment{
Title: "QR Code",
Filename: "QR.png",
Content: bytes.NewReader(code.PNG()),
ContentType: "image/png",
})
}
开发者ID:leifmadsen,项目名称:gobot,代码行数:29,代码来源:mfa.go
示例3: QRHandler
func (s *Server) QRHandler(path string) http.Handler {
handler := func(w http.ResponseWriter, r *http.Request) {
url := ""
if r.TLS == nil {
url += "qrl://"
} else {
url += "sqrl://"
}
url += r.Host
url += "/" + path + "?"
url += r.URL.RawQuery
url += "&nut="
url += s.nonce.Generate(r.RemoteAddr)
// w.Header().Add("Content-Type", "text/html")
// io.WriteString(w, fmt.Sprintf("%#v<br/><br/>", url))
// io.WriteString(w, fmt.Sprintf("%#v<br/><br/>", *r.URL))
// io.WriteString(w, fmt.Sprintf("%#v<br/><br/>", *r))
w.Header().Add("Content-Type", "image/png")
qrcode, err := qr.Encode(url, qr.M)
if err != nil {
return
}
w.Write(qrcode.PNG())
}
return http.HandlerFunc(handler)
}
开发者ID:sedalu,项目名称:sqrl,代码行数:33,代码来源:server.go
示例4: main
func main() {
var src, dst string
switch len(os.Args) {
case 1:
log.Fatal("Source string must be given!")
case 2:
src = os.Args[1]
dst = "qr.png"
case 3:
src = os.Args[1]
dst = os.Args[2]
default:
log.Fatal("Invalid arguments!")
}
code, err := qr.Encode(src, qr.M)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(dst, code.PNG(), 0644)
if err != nil {
log.Fatal(err)
}
}
开发者ID:minoritea,项目名称:qrgen,代码行数:25,代码来源:main.go
示例5: GenTicket
// GenTicket - Sign the ticket number provided through the URL and Generate a QR Code
func GenTicket(w http.ResponseWriter, r *http.Request) {
var buffer bytes.Buffer
// Load the variables from the path using mux
vars := mux.Vars(r)
// Setup the Ticket and sign it
var ticketnum = TicketNumber{ID: []byte(vars["hash"])}
ticketnum.sign()
// Generate the text string to encode
buffer.WriteString(ticketnum.Sig1.String())
buffer.WriteString("/")
buffer.WriteString(ticketnum.Sig2.String())
buffer.WriteString("/")
buffer.WriteString(vars["hash"])
// Generate the QR code for the hash and two signatures
code, err := qr.Encode(buffer.String(), qr.H)
if err != nil {
panic(err)
}
imgByte := code.PNG()
w.Header().Set("Content-Type", "image/png")
w.WriteHeader(http.StatusOK)
w.Write(imgByte)
// fmt.Fprintf(w, "sig1: %#v \n sig2: %#v \n message: %#v",ticketnum.Sig1,ticketnum.Sig2,vars["hash"])
}
开发者ID:capnfuzz,项目名称:qrtickets,代码行数:32,代码来源:tickets.go
示例6: createQR
// PixelRelay://scan?host=HOSTURL&album=ALBUMNAME&privatekey=PRIVATEKEY
func createQR(album, key string) (qrname string) {
qrname = strings.Join([]string{genQRName(album, key), "png"}, ".")
qrpath := utils.ImageCfg.QR()
qrtemp := strings.Join([]string{qrpath, qrname}, "")
if Exists(qrtemp) {
return
}
host := strings.Join([]string{utils.AppCfg.Url(), "up"}, "/")
qrstr := fmt.Sprintf("PixelRelay://scan?host=%s&album=%s&privatekey=%s", host, album, key)
c, err := qr.Encode(qrstr, qr.M)
if err != nil {
log.Println("qr err: ", err)
}
out, err := os.Create(qrtemp)
if err != nil {
log.Fatal(err)
}
defer out.Close()
_, err = out.Write(c.PNG())
if err != nil {
panic(err)
}
return
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:33,代码来源:qr.go
示例7: qrHandler
func qrHandler(w http.ResponseWriter, r *http.Request) {
uri := r.RequestURI
// TODO(dgryski): handle /qr/ssid for an html page that renders the QR code with also instructions
if !strings.HasPrefix(uri, "/qr/") || !strings.HasSuffix(uri, ".png") {
http.NotFound(w, r)
return
}
ssid := uri[len("/qr/") : len(uri)-len(".png")]
dbmu.RLock()
wifi, ok := db[ssid]
dbmu.RUnlock()
if !ok {
http.NotFound(w, r)
return
}
text := wifi.QRText()
code, err := qr.Encode(text, qr.Q)
if err != nil {
log.Printf("error encoding: %q: %v", text, err)
http.Error(w, "bad request", http.StatusBadRequest)
return
}
w.Header().Set("Content-type", "image/png")
w.Write(code.PNG())
}
开发者ID:postfix,项目名称:qrifidb,代码行数:34,代码来源:main.go
示例8: QR
// QR generates a byte slice containing the a QR code encoded as a
// PNG with level Q error correction.
func (otp *HOTP) QR(label string) ([]byte, error) {
u := otp.URL(label)
code, err := qr.Encode(u, qr.Q)
if err != nil {
return nil, err
}
return code.PNG(), nil
}
开发者ID:carriercomm,项目名称:api-1,代码行数:10,代码来源:hotp.go
示例9: generateQr
func generateQr(headers []string, row []string, pool chan bool, wg *sync.WaitGroup) {
filename := row[*label]
var text string
//build the output string
for index, value := range row {
text += headers[index] + ": " + value + "\n"
}
// Encode string to QR codes
code, err := qr.Encode(text, qr.M)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// convert code to rgba
b := code.Size
img := image.NewRGBA(image.Rect(0, 0, b*scale, b*scale))
for x := 0; x < b; x++ {
for y := 0; y < b; y++ {
if code.Black(x, y) {
draw.Draw(img, image.Rect(x*scale, y*scale, (x+1)*scale, (y+1)*scale), black, black.Bounds().Min, draw.Src)
} else {
draw.Draw(img, image.Rect(x*scale, y*scale, (x+1)*scale, (y+1)*scale), white, white.Bounds().Min, draw.Src)
}
}
}
// verify output dir
if _, err := os.Stat(*outdir); err != nil {
os.Mkdir(*outdir, 0666)
}
//save the imgByte to file
filename = *outdir + "/" + filename + ".png"
out, err := os.Create(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = png.Encode(out, img)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// everything ok
fmt.Println("QR code generated and saved to " + filename)
<-pool
(*wg).Done()
}
开发者ID:StormGoth,项目名称:GenerateQR,代码行数:56,代码来源:GenerateQR.go
示例10: Generate
// Generate a text string to a QR code, which you can write to a terminal or file.
func (c *Config) Generate(text string) (string, error) {
code, err := qr.Encode(text, qr.Level(c.Level))
if err != nil {
return "", err
}
// calculate size in blocks
// two bits per block
// add one block for remaining singlebit (if existing)
// add two blocks for border left and right
size := code.Size/2 + (code.Size % 2) + 2
// rune slice
//++ TODO: precalculate size
qrRunes := make([]rune, 0)
// upper border
c.addWhiteRow(&qrRunes, size)
// content
for y := 0; y < code.Size; y += 2 {
if c.UseSGR {
qrRunes = append(qrRunes, []rune(sgr.FgWhite+sgr.BgBlack)...)
}
qrRunes = append(qrRunes, '█')
for x := 0; x < code.Size; x += 2 {
var num int8
if !code.Black(x, y) {
num += 1
}
if !code.Black(x+1, y) {
num += 2
}
if !code.Black(x, y+1) {
num += 4
}
if !code.Black(x+1, y+1) {
num += 8
}
qrRunes = append(qrRunes, blocks[num])
}
qrRunes = append(qrRunes, '█')
if c.UseSGR {
qrRunes = append(qrRunes, []rune(sgr.Reset)...)
}
qrRunes = append(qrRunes, '\n')
}
// add lower border when required (only required when QR size is odd)
if code.Size%2 == 0 {
c.addWhiteRow(&qrRunes, size)
}
return string(qrRunes), nil
}
开发者ID:GeertJohan,项目名称:go.qrt,代码行数:56,代码来源:qrt.go
示例11: encode
func encode(message string) {
c, err := qr.Encode(message, qr.L)
if err != nil {
fmt.Println(err)
} else {
pngdat := c.PNG()
s := []string{"images/", message, ".png"}
ioutil.WriteFile(strings.Join(s, ""), pngdat, 0666)
}
}
开发者ID:Ticketbud,项目名称:qrservice,代码行数:12,代码来源:web.go
示例12: AddTicket
// AddTicket - Adds a valid ticket for the event and stores it in the datastore
func AddTicket(w http.ResponseWriter, r *http.Request) {
var buffer bytes.Buffer
vars := mux.Vars(r)
// Load the event datastore key
event, err := datastore.DecodeKey(vars["eventId"])
if err != nil {
panic(err)
}
// Create an appengine context
ctx := appengine.NewContext(r)
// fmt.Fprintf("%#v",ctx)
// Build the ticket entry
t := Ticket{
OrderID: r.FormValue("order_id"),
EventKey: event,
Valid: true,
}
// Store the ticket
k, err := t.Store(ctx)
if err != nil {
panic(err)
}
// Create the Ticket Num
var ticketnum = TicketNumber{ID: []byte(k.Encode())}
ticketnum.sign()
// Generate the text string to encode
buffer.WriteString(ticketnum.Sig1.String())
buffer.WriteString("/")
buffer.WriteString(ticketnum.Sig2.String())
buffer.WriteString("/")
buffer.WriteString(string(k.Encode()))
// Generate the QR code for the hash and two signatures
code, err := qr.Encode(buffer.String(), qr.L)
code.Scale = 2
if err != nil {
panic(err)
}
imgByte := code.PNG()
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Content-Disposition", `inline; filename="`+k.Encode()+`"`)
w.WriteHeader(http.StatusOK)
w.Write(imgByte)
}
开发者ID:capnfuzz,项目名称:qrtickets,代码行数:53,代码来源:tickets.go
示例13: viewHandler
func viewHandler(w http.ResponseWriter, r *http.Request) {
c, err := qr.Encode(r.FormValue("t"), qr.L)
if err != nil {
}
pngdat := c.Image()
//fmt.Println(pngdat.Bounds());
//fmt.Println(c.Size);
//fmt.Println(c.Scale);
//to do resize
newImage := resize.Resample(pngdat, image.Rect(0, 0, c.Size, c.Size), 120, 120)
png.Encode(w, newImage)
//png.Encode(w,pngdat);
}
开发者ID:redage,项目名称:apps,代码行数:13,代码来源:test.go
示例14: Encode
// Encode makes a QR code out of data and encodes it into three
// different representations.
func Encode(data []byte) (*Encodings, error) {
code, err := qr.Encode(string(data), qr.L)
if err != nil {
return nil, err
}
var result Encodings
result.PNG = code.PNG()
result.Terminal = terminal(code)
result.ASCII = ascii(code)
return &result, nil
}
开发者ID:mark-adams,项目名称:client,代码行数:15,代码来源:qrcode.go
示例15: getNewUserSession_API
func getNewUserSession_API(w http.ResponseWriter, req *http.Request) {
data := req.FormValue("callbackdata")
if data == "" {
cod, err := qr.Encode(fmt.Sprintf("http://%s/api/v1/openTok3n/getIntegrationError", TOK3N_DOMAIN), qr.M)
if err != nil {
fmt.Fprintf(w, "Something went very wrong, verify OpenTok3n integration instalation")
return
}
img := cod.PNG()
w.Write(img)
return
}
resp, err := http.PostForm(fmt.Sprintf("http://%s/api/v1/openTok3n/getNewUserSession", TOK3N_DOMAIN), url.Values{"kind": {"OTaccess"}, "secretKey": {configData.Tok3nAPISecret}})
if err != nil {
cod, err := qr.Encode(fmt.Sprintf("http://%s/api/v1/openTok3n/getIntegrationError", TOK3N_DOMAIN), qr.M)
if err != nil {
fmt.Fprintf(w, "Something went very wrong, verify OpenTok3n integration instalation")
return
}
img := cod.PNG()
w.Write(img)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
addTok3nAuthenticationSeccion(string(body), data)
cod, err := qr.Encode(fmt.Sprintf("http://%s/api/v1/openTok3n/validateNewUserSession?session=%s&key=%s", TOK3N_DOMAIN, body, configData.Tok3nAPIKey), qr.H)
if err != nil {
fmt.Fprintf(w, "Something whent very wrong, verify OpenTok3n integration instalation")
return
}
img := cod.PNG()
w.Header().Add("Content-Type", "image/png")
w.Write(img)
}
开发者ID:Tok3n,项目名称:OpenTok3n,代码行数:38,代码来源:apiv1.go
示例16: Execute
// Execute write qrcode image to response
func (qrcode *QrCodeResult) Execute(ctx *wk.HttpContext) error {
c, err := qr.Encode(qrcode.Text, qr.M)
if err != nil {
log.Println("QrCodeResult Execute Error", err)
return err
}
png := c.PNG()
//ioutil.WriteFile(qrcode.Text+"_demo.png", png, 0666)
ctx.ContentType("image/png")
ctx.Write(png)
return nil
}
开发者ID:jango2015,项目名称:wk,代码行数:15,代码来源:qr.go
示例17: serveQR
func (ui *UIHandler) serveQR(rw http.ResponseWriter, req *http.Request) {
url := req.URL.Query().Get("url")
if url == "" {
http.Error(rw, "Missing url parameter.", http.StatusBadRequest)
return
}
code, err := qr.Encode(url, qr.L)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
rw.Header().Set("Content-Type", "image/png")
rw.Write(code.PNG())
}
开发者ID:camlistore,项目名称:camlistore,代码行数:14,代码来源:ui.go
示例18: main
func main() {
v := flag.Bool("v", false, "show version")
flag.Parse()
if *v {
fmt.Println("version:0.1.1.dev")
os.Exit(0)
}
text := uuid.New()
data, _ := qr.Encode(text, qr.H)
content := data.PNG()
fmt.Println(text)
ioutil.WriteFile(text+".png", content, 0644)
}
开发者ID:steko,项目名称:go-uuid-qrcode,代码行数:15,代码来源:main.go
示例19: qenerate
func qenerate(text string) (png []byte, err error) {
res := <-storage.Call("read", cacheNamepspace, text)
if res.Err() == nil {
err = res.Extract(&png)
return
}
c, err := qr.Encode(text, qr.L)
if err != nil {
return
}
png = c.PNG()
<-storage.Call("write", cacheNamepspace, text, string(png), []string{cacheTag})
return
}
开发者ID:sguzwf,项目名称:cocaine-paper-sources,代码行数:16,代码来源:qr.go
示例20: get_qr
//func get_qr(t string) image.Image {
func get_qr(t string) string {
var q *qr.Code
var e error
q, e = qr.Encode(t, qr.L)
if e != nil {
fmt.Println(e)
}
fmt.Println(t)
fmt.Print("QR Code Size (Pixels) = ")
fmt.Println(q.Size)
q.Scale = *mult
// return q.Image()
return string(q.PNG())
}
开发者ID:uhu99,项目名称:kurzware,代码行数:18,代码来源:iqr.go
注:本文中的code/google/com/p/rsc/qr.Encode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论