parent
f5e32fac77
commit
25375da284
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
[![GoDoc](https://godoc.org/github.com/steambap/captcha?status.svg)](https://godoc.org/github.com/steambap/captcha)
|
[![GoDoc](https://godoc.org/github.com/steambap/captcha?status.svg)](https://godoc.org/github.com/steambap/captcha)
|
||||||
[![Build Status](https://travis-ci.org/steambap/captcha.svg)](https://travis-ci.org/steambap/captcha)
|
[![Build Status](https://travis-ci.org/steambap/captcha.svg)](https://travis-ci.org/steambap/captcha)
|
||||||
|
[![Go Report Card](https://goreportcard.com/badge/github.com/steambap/captcha)](https://goreportcard.com/report/github.com/steambap/captcha)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (data *Data) WriteTo(w io.Writer) error {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
ttfFont, err = freetype.ParseFont(TTF)
|
ttfFont, err = freetype.ParseFont(ttf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", IndexHandle)
|
http.HandleFunc("/", indexHandle)
|
||||||
http.HandleFunc("/captcha", CaptchaHandle)
|
http.HandleFunc("/captcha", captchaHandle)
|
||||||
fmt.Println("Server start at port 8080")
|
fmt.Println("Server start at port 8080")
|
||||||
err := http.ListenAndServe(":8080", nil)
|
err := http.ListenAndServe(":8080", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IndexHandle(w http.ResponseWriter, _ *http.Request) {
|
func indexHandle(w http.ResponseWriter, _ *http.Request) {
|
||||||
doc, err := template.ParseFiles("index.html")
|
doc, err := template.ParseFiles("index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint(w, err.Error())
|
fmt.Fprint(w, err.Error())
|
||||||
|
@ -26,7 +26,7 @@ func IndexHandle(w http.ResponseWriter, _ *http.Request) {
|
||||||
doc.Execute(w, nil)
|
doc.Execute(w, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CaptchaHandle(w http.ResponseWriter, _ *http.Request) {
|
func captchaHandle(w http.ResponseWriter, _ *http.Request) {
|
||||||
img, err := captcha.New(150, 50)
|
img, err := captcha.New(150, 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprint(w, nil)
|
fmt.Fprint(w, nil)
|
||||||
|
|
2
font.go
2
font.go
|
@ -3,7 +3,7 @@
|
||||||
package captcha
|
package captcha
|
||||||
|
|
||||||
// The following is Comismsh TrueType font data.
|
// The following is Comismsh TrueType font data.
|
||||||
var TTF = []byte{
|
var ttf = []byte{
|
||||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x04, 0x00, 0xc0, 0x4f, 0x53, 0x2f, 0x32,
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x40, 0x00, 0x04, 0x00, 0xc0, 0x4f, 0x53, 0x2f, 0x32,
|
||||||
0x7f, 0x0c, 0x33, 0xcc, 0x00, 0x01, 0x37, 0xf8, 0x00, 0x00, 0x00, 0x56, 0x50, 0x43, 0x4c, 0x54,
|
0x7f, 0x0c, 0x33, 0xcc, 0x00, 0x01, 0x37, 0xf8, 0x00, 0x00, 0x00, 0x56, 0x50, 0x43, 0x4c, 0x54,
|
||||||
0x61, 0x79, 0x01, 0xab, 0x00, 0x01, 0x38, 0x50, 0x00, 0x00, 0x00, 0x36, 0x63, 0x6d, 0x61, 0x70,
|
0x61, 0x79, 0x01, 0xab, 0x00, 0x01, 0x38, 0x50, 0x00, 0x00, 0x00, 0x36, 0x63, 0x6d, 0x61, 0x70,
|
||||||
|
|
|
@ -21,7 +21,7 @@ func main() {
|
||||||
fmt.Fprint(buf, "// DO NOT EDIT. This file is generated.\n\n")
|
fmt.Fprint(buf, "// DO NOT EDIT. This file is generated.\n\n")
|
||||||
fmt.Fprint(buf, "package captcha\n\n")
|
fmt.Fprint(buf, "package captcha\n\n")
|
||||||
fmt.Fprint(buf, "// The following is Comismsh TrueType font data.\n")
|
fmt.Fprint(buf, "// The following is Comismsh TrueType font data.\n")
|
||||||
fmt.Fprint(buf, "var TTF = []byte{")
|
fmt.Fprint(buf, "var ttf = []byte{")
|
||||||
for i, x := range src {
|
for i, x := range src {
|
||||||
if i&15 == 0 {
|
if i&15 == 0 {
|
||||||
buf.WriteByte('\n')
|
buf.WriteByte('\n')
|
||||||
|
|
Reference in New Issue