Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
EricZhou committed Dec 19, 2019
1 parent 5f5254b commit da84ccf
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 771 deletions.
10 changes: 0 additions & 10 deletions captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
// base64Captcha is used for fast development of RESTful APIs, web apps and backend services in Go. give a string identifier to the package and it returns with a base64-encoding-png-string
package base64Captcha

import (
"math/rand"
"time"
)

func init() {
//init rand seed
rand.Seed(time.Now().UnixNano())
}

// Captcha captcha basic information.
type Captcha struct {
Driver Driver
Expand Down
5 changes: 5 additions & 0 deletions const.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package base64Captcha

const idLen = 20

// idChars are characters allowed in captcha id.
var idChars = []byte(TxtNumbers + TxtAlphabet)

const (
imageStringDpi = 72.0
//TxtNumbers chacters for numbers.
Expand Down
7 changes: 3 additions & 4 deletions item_digit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ type ItemDigit struct {
//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}

itemDigit.Paletted = image.NewPaletted(image.Rect(0, 0, width, height), randomPalette(dotCount))

//init image.Paletted
itemDigit.Paletted = image.NewPaletted(image.Rect(0, 0, width, height), createRandPaletteColors(dotCount))
return itemDigit
}

func randomPalette(dotCount int) color.Palette {
func createRandPaletteColors(dotCount int) color.Palette {
p := make([]color.Color, dotCount+1)
// Transparent color.
p[0] = color.RGBA{0xFF, 0xFF, 0xFF, 0x00}
Expand Down
73 changes: 0 additions & 73 deletions random_crypto.go

This file was deleted.

58 changes: 0 additions & 58 deletions random_crypto_test.go

This file was deleted.

15 changes: 15 additions & 0 deletions random_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import (
"math"
"math/rand"
"strings"
"time"
)

func init() {
//init rand seed
rand.Seed(time.Now().UnixNano())
}

//RandText create random text.
func RandText(size int, sourceChars string) string {
if size >= len(sourceChars) {
Expand Down Expand Up @@ -90,3 +96,12 @@ func randBytes(n int) []byte {
}
return b[:n]
}

// RandomId returns a new random id key string.
func RandomId() string {
b := randomBytesMod(idLen, byte(len(idChars)))
for i, c := range b {
b[i] = idChars[c]
}
return string(b)
}
Loading

0 comments on commit da84ccf

Please sign in to comment.