Browse Source

Removed useless dependency, simplified key id format

main
Artemis 2 years ago
parent
commit
6b7b137ccb
  1. 19
      generator.go
  2. 1
      go.mod
  3. 2
      go.sum
  4. 8
      handlers.go

19
generator.go

@ -1,16 +1,19 @@
package main
import (
"fmt"
"github.com/elgs/gostrgen"
"math/rand"
)
func GetNewKey() (error, string) {
key, err := gostrgen.RandGen(6, gostrgen.LowerUpper, "", "")
if err != nil {
fmt.Print(err)
return err, ""
const KeyID = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789-_+$~"
func RandomString(length int) string {
b := make([]uint8, length)
for i := range b {
b[i] = KeyID[rand.Intn(len(KeyID))]
}
return string(b)
}
return nil, key
func GetNewKey() string {
return RandomString(6)
}

1
go.mod

@ -2,7 +2,6 @@ module gitlab.com/Artemix/paste
require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/elgs/gostrgen v0.0.0-20161222160715-9d61ae07eeae
github.com/go-redis/redis v6.15.2+incompatible
github.com/gorilla/mux v1.7.3
github.com/onsi/ginkgo v1.10.3 // indirect

2
go.sum

@ -6,8 +6,6 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elgs/gostrgen v0.0.0-20161222160715-9d61ae07eeae h1:3KvK2DmA7TxQ6PZ2f0rWbdqjgJhRcqgbY70bBeE4clI=
github.com/elgs/gostrgen v0.0.0-20161222160715-9d61ae07eeae/go.mod h1:wruC5r2gHdr/JIUs5Rr1V45YtsAzKXZxAnn/5rPC97g=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4=

8
handlers.go

@ -128,13 +128,7 @@ func (h Handlers) HandleNewPaste(w http.ResponseWriter, req *http.Request) {
return
}
err, key := GetNewKey()
if err != nil {
w.WriteHeader(500)
fmt.Println(err)
return
}
key := GetNewKey()
err = h.BackendService.
Persist(key, pasteValue, keepaliveTime)

Loading…
Cancel
Save