Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
EricZhou committed Oct 24, 2023
1 parent 2624251 commit 88f0921
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions captcha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestCaptcha_GenerateB64s(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewCaptcha(tt.fields.Driver, tt.fields.Store)
gotId, b64s,_, err := c.Generate()
gotId, b64s, _, err := c.Generate()
if (err != nil) != tt.wantErr {
t.Errorf("Captcha.Generate() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestCaptcha_Generate(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotId, gotB64s,_, err := tt.c.Generate()
gotId, gotB64s, _, err := tt.c.Generate()
if (err != nil) != tt.wantErr {
t.Errorf("Captcha.Generate() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
10 changes: 5 additions & 5 deletions driver_audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

package base64Captcha

//DriverAudio captcha config for captcha-engine-audio.
// DriverAudio captcha config for captcha-engine-audio.
type DriverAudio struct {
// Length Default number of digits in captcha solution.
Length int
// Language possible values for lang are "en", "ja", "ru", "zh".
Language string
}

//DefaultDriverAudio is a default audio driver
// DefaultDriverAudio is a default audio driver
var DefaultDriverAudio = NewDriverAudio(6, "en")

//NewDriverAudio creates a driver of audio
// NewDriverAudio creates a driver of audio
func NewDriverAudio(length int, language string) *DriverAudio {
return &DriverAudio{Length: length, Language: language}
}

//DrawCaptcha creates audio captcha item
// DrawCaptcha creates audio captcha item
func (d *DriverAudio) DrawCaptcha(content string) (item Item, err error) {
digits := stringToFakeByte(content)
audio := newAudio("", digits, d.Language)
return audio, nil
}

//GenerateIdQuestionAnswer creates id,captcha content and answer
// GenerateIdQuestionAnswer creates id,captcha content and answer
func (d *DriverAudio) GenerateIdQuestionAnswer() (id, q, a string) {
id = RandomId()
digits := randomDigits(d.Length)
Expand Down
10 changes: 5 additions & 5 deletions driver_chinese.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/golang/freetype/truetype"
)

//DriverChinese is a driver of unicode Chinese characters.
// DriverChinese is a driver of unicode Chinese characters.
type DriverChinese struct {
//Height png height in pixel.
Height int
Expand Down Expand Up @@ -38,7 +38,7 @@ type DriverChinese struct {
fontsArray []*truetype.Font
}

//NewDriverChinese creates a driver of Chinese characters
// NewDriverChinese creates a driver of Chinese characters
func NewDriverChinese(height int, width int, noiseCount int, showLineOptions int, length int, source string, bgColor *color.RGBA, fontsStorage FontsStorage, fonts []string) *DriverChinese {
if fontsStorage == nil {
fontsStorage = DefaultEmbeddedFonts
Expand All @@ -57,7 +57,7 @@ func NewDriverChinese(height int, width int, noiseCount int, showLineOptions int
return &DriverChinese{Height: height, Width: width, NoiseCount: noiseCount, ShowLineOptions: showLineOptions, Length: length, Source: source, BgColor: bgColor, fontsStorage: fontsStorage, fontsArray: tfs}
}

//ConvertFonts loads fonts by names
// ConvertFonts loads fonts by names
func (d *DriverChinese) ConvertFonts() *DriverChinese {
if d.fontsStorage == nil {
d.fontsStorage = DefaultEmbeddedFonts
Expand All @@ -76,7 +76,7 @@ func (d *DriverChinese) ConvertFonts() *DriverChinese {
return d
}

//GenerateIdQuestionAnswer generates captcha content and its answer
// GenerateIdQuestionAnswer generates captcha content and its answer
func (d *DriverChinese) GenerateIdQuestionAnswer() (id, content, answer string) {
id = RandomId()

Expand All @@ -100,7 +100,7 @@ func (d *DriverChinese) GenerateIdQuestionAnswer() (id, content, answer string)
return id, content, content
}

//DrawCaptcha generates captcha item(image)
// DrawCaptcha generates captcha item(image)
func (d *DriverChinese) DrawCaptcha(content string) (item Item, err error) {

var bgc color.RGBA
Expand Down
10 changes: 5 additions & 5 deletions driver_language.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/golang/freetype/truetype"
)

//https://en.wikipedia.org/wiki/Unicode_block
// https://en.wikipedia.org/wiki/Unicode_block
var langMap = map[string][]int{
//"zh-CN": []int{19968, 40869},
"latin": {0x0000, 0x007f},
Expand Down Expand Up @@ -39,7 +39,7 @@ func generateRandomRune(size int, code string) string {
return string(randRune)
}

//DriverLanguage generates language unicode by lanuage
// DriverLanguage generates language unicode by lanuage
type DriverLanguage struct {
// Height png height in pixel.
Height int
Expand All @@ -66,19 +66,19 @@ type DriverLanguage struct {
LanguageCode string
}

//NewDriverLanguage creates a driver
// NewDriverLanguage creates a driver
func NewDriverLanguage(height int, width int, noiseCount int, showLineOptions int, length int, bgColor *color.RGBA, fontsStorage FontsStorage, fonts []*truetype.Font, languageCode string) *DriverLanguage {
return &DriverLanguage{Height: height, Width: width, NoiseCount: noiseCount, ShowLineOptions: showLineOptions, Length: length, BgColor: bgColor, fontsStorage: fontsStorage, Fonts: fonts, LanguageCode: languageCode}
}

//GenerateIdQuestionAnswer creates content and answer
// GenerateIdQuestionAnswer creates content and answer
func (d *DriverLanguage) GenerateIdQuestionAnswer() (id, content, answer string) {
id = RandomId()
content = generateRandomRune(d.Length, d.LanguageCode)
return id, content, content
}

//DrawCaptcha creates item
// DrawCaptcha creates item
func (d *DriverLanguage) DrawCaptcha(content string) (item Item, err error) {
var bgc color.RGBA
if d.BgColor != nil {
Expand Down
10 changes: 5 additions & 5 deletions driver_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/golang/freetype/truetype"
)

//DriverMath captcha config for captcha math
// DriverMath captcha config for captcha math
type DriverMath struct {
//Height png height in pixel.
Height int
Expand All @@ -34,7 +34,7 @@ type DriverMath struct {
fontsArray []*truetype.Font
}

//NewDriverMath creates a driver of math
// NewDriverMath creates a driver of math
func NewDriverMath(height int, width int, noiseCount int, showLineOptions int, bgColor *color.RGBA, fontsStorage FontsStorage, fonts []string) *DriverMath {
if fontsStorage == nil {
fontsStorage = DefaultEmbeddedFonts
Expand All @@ -53,7 +53,7 @@ func NewDriverMath(height int, width int, noiseCount int, showLineOptions int, b
return &DriverMath{Height: height, Width: width, NoiseCount: noiseCount, ShowLineOptions: showLineOptions, fontsArray: tfs, BgColor: bgColor, Fonts: fonts}
}

//ConvertFonts loads fonts from names
// ConvertFonts loads fonts from names
func (d *DriverMath) ConvertFonts() *DriverMath {
if d.fontsStorage == nil {
d.fontsStorage = DefaultEmbeddedFonts
Expand All @@ -72,7 +72,7 @@ func (d *DriverMath) ConvertFonts() *DriverMath {
return d
}

//GenerateIdQuestionAnswer creates id,captcha content and answer
// GenerateIdQuestionAnswer creates id,captcha content and answer
func (d *DriverMath) GenerateIdQuestionAnswer() (id, question, answer string) {
id = RandomId()
operators := []string{"+", "-", "x"}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (d *DriverMath) GenerateIdQuestionAnswer() (id, question, answer string) {
return
}

//DrawCaptcha creates math captcha item
// DrawCaptcha creates math captcha item
func (d *DriverMath) DrawCaptcha(question string) (item Item, err error) {
var bgc color.RGBA
if d.BgColor != nil {
Expand Down
2 changes: 1 addition & 1 deletion faq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestHandlerCaptchaGenerate(t *testing.T) {

c := NewCaptcha(driver, s)

id, _,_, err := c.Generate()
id, _, _, err := c.Generate()
if err != nil {
t.Fatalf("some error: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ var fontsSimple = DefaultEmbeddedFonts.LoadFontsByNames([]string{
"fonts/chromohv.ttf",
})

//var fontemoji = loadFontByName("fonts/seguiemj.ttf")
// var fontemoji = loadFontByName("fonts/seguiemj.ttf")
var fontsAll = append(fontsSimple, fontChinese)
var fontChinese = DefaultEmbeddedFonts.LoadFontByName("fonts/wqy-microhei.ttc")

//randFontFrom choose random font family.选择随机的字体
// randFontFrom choose random font family.选择随机的字体
func randFontFrom(fonts []*truetype.Font) *truetype.Font {
fontCount := len(fonts)

Expand Down
3 changes: 2 additions & 1 deletion fonts_embedded_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package base64Captcha

import "embed"

// defaultEmbeddedFontsFS Built-in font storage.
//
//go:embed fonts/*.ttf
//go:embed fonts/*.ttc
// defaultEmbeddedFontsFS Built-in font storage.
var defaultEmbeddedFontsFS embed.FS

var DefaultEmbeddedFonts = NewEmbeddedFontsStorage(defaultEmbeddedFontsFS)
2 changes: 1 addition & 1 deletion interface_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package base64Captcha

import "io"

//Item is captcha item interface
// Item is captcha item interface
type Item interface {
//WriteTo writes to a writer
WriteTo(w io.Writer) (n int64, err error)
Expand Down
2 changes: 1 addition & 1 deletion item_audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"math/rand"
)

//ItemAudio captcha-audio-engine return type.
// ItemAudio captcha-audio-engine return type.
type ItemAudio struct {
answer string
body *bytes.Buffer
Expand Down
12 changes: 6 additions & 6 deletions item_char.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
"math/rand"
)

//ItemChar captcha item of unicode characters
// ItemChar captcha item of unicode characters
type ItemChar struct {
bgColor color.Color
width int
height int
nrgba *image.NRGBA
}

//NewItemChar creates a captcha item of characters
// NewItemChar creates a captcha item of characters
func NewItemChar(w int, h int, bgColor color.RGBA) *ItemChar {
d := ItemChar{width: w, height: h}
m := image.NewNRGBA(image.Rect(0, 0, w, h))
Expand All @@ -35,7 +35,7 @@ func NewItemChar(w int, h int, bgColor color.RGBA) *ItemChar {
return &d
}

//drawHollowLine draw strong and bold white line.
// drawHollowLine draw strong and bold white line.
func (item *ItemChar) drawHollowLine() *ItemChar {

first := item.width / 20
Expand Down Expand Up @@ -72,7 +72,7 @@ func (item *ItemChar) drawHollowLine() *ItemChar {
return item
}

//drawSineLine draw a sine line.
// drawSineLine draw a sine line.
func (item *ItemChar) drawSineLine() *ItemChar {
var py float64

Expand Down Expand Up @@ -116,7 +116,7 @@ func (item *ItemChar) drawSineLine() *ItemChar {
return item
}

//drawSlimLine draw n slim-random-color lines.
// drawSlimLine draw n slim-random-color lines.
func (item *ItemChar) drawSlimLine(num int) *ItemChar {

first := item.width / 10
Expand Down Expand Up @@ -231,7 +231,7 @@ func (item *ItemChar) drawText(text string, fonts []*truetype.Font) error {
return nil
}

//BinaryEncoding encodes an image to PNG and returns a byte slice.
// BinaryEncoding encodes an image to PNG and returns a byte slice.
func (item *ItemChar) BinaryEncoding() []byte {
var buf bytes.Buffer
if err := png.Encode(&buf, item.nrgba); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions item_digit.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ItemDigit struct {
//rng siprng
}

//NewItemDigit create a instance of item-digit
// NewItemDigit create a instance of item-digit
func NewItemDigit(width int, height int, dotCount int, maxSkew float64) *ItemDigit {
itemDigit := &ItemDigit{width: width, height: height, dotCount: dotCount, maxSkew: maxSkew}
//init image.Paletted
Expand Down Expand Up @@ -163,7 +163,7 @@ func (m *ItemDigit) strikeThrough() {
}
}

//draw digit
// draw digit
func (m *ItemDigit) drawDigit(digit []byte, x, y int) {
skf := randFloat64Range(-m.maxSkew, m.maxSkew)
xs := float64(x)
Expand Down
10 changes: 5 additions & 5 deletions random_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
rand.Seed(time.Now().UnixNano())
}

//RandText creates random text of given size.
// RandText creates random text of given size.
func RandText(size int, sourceChars string) string {
if sourceChars == "" || size == 0 {
return ""
Expand All @@ -34,12 +34,12 @@ func RandText(size int, sourceChars string) string {
return string(text)
}

//Random get random number between min and max. 生成指定大小的随机数.
// Random get random number between min and max. 生成指定大小的随机数.
func random(min int64, max int64) float64 {
return float64(min) + rand.Float64()*float64(max-min)
}

//RandDeepColor get random deep color. 随机生成深色系.
// RandDeepColor get random deep color. 随机生成深色系.
func RandDeepColor() color.RGBA {

randColor := RandColor()
Expand All @@ -54,15 +54,15 @@ func RandDeepColor() color.RGBA {
return color.RGBA{R: uint8(red), G: uint8(green), B: uint8(blue), A: uint8(255)}
}

//RandLightColor get random ligth color. 随机生成浅色.
// RandLightColor get random ligth color. 随机生成浅色.
func RandLightColor() color.RGBA {
red := rand.Intn(55) + 200
green := rand.Intn(55) + 200
blue := rand.Intn(55) + 200
return color.RGBA{R: uint8(red), G: uint8(green), B: uint8(blue), A: uint8(255)}
}

//RandColor get random color. 生成随机颜色.
// RandColor get random color. 生成随机颜色.
func RandColor() color.RGBA {
red := rand.Intn(255)
green := rand.Intn(255)
Expand Down
Loading

0 comments on commit 88f0921

Please sign in to comment.