Compare commits

..

2 Commits

Author SHA1 Message Date
Andrea Spacca
c5664b433d better logic 2023-06-06 19:35:45 +09:00
Andrea Spacca
fc6f897eaa fix basic auth 2023-06-06 19:30:32 +09:00
2 changed files with 15 additions and 16 deletions

View File

@@ -26,9 +26,12 @@ package server
import (
"context"
cryptoRand "crypto/rand"
"crypto/tls"
"encoding/binary"
"errors"
"log"
"math/rand"
"mime"
"net/http"
_ "net/http/pprof"
@@ -271,8 +274,9 @@ func UseLetsEncrypt(hosts []string) OptionFn {
},
}
srvr.tlsConfig = m.TLSConfig()
srvr.tlsConfig.GetCertificate = m.GetCertificate
srvr.tlsConfig = &tls.Config{
GetCertificate: m.GetCertificate,
}
}
}
@@ -399,6 +403,14 @@ func New(options ...OptionFn) (*Server, error) {
return s, nil
}
func init() {
var seedBytes [8]byte
if _, err := cryptoRand.Read(seedBytes[:]); err != nil {
panic("cannot obtain cryptographically secure seed")
}
rand.Seed(int64(binary.LittleEndian.Uint64(seedBytes[:])))
}
// Run starts Server
func (s *Server) Run() {
listening := false

View File

@@ -25,22 +25,9 @@ THE SOFTWARE.
package server
import (
cryptoRand "crypto/rand"
"encoding/binary"
"math/rand"
)
var seed *rand.Rand
func init() {
var seedBytes [8]byte
if _, err := cryptoRand.Read(seedBytes[:]); err != nil {
panic("cannot obtain cryptographically secure seed")
}
seed = rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(seedBytes[:]))))
}
const (
// SYMBOLS characters used for short-urls
SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -50,7 +37,7 @@ const (
func token(length int) string {
result := ""
for i := 0; i < length; i++ {
x := seed.Intn(len(SYMBOLS) - 1)
x := rand.Intn(len(SYMBOLS) - 1)
result = string(SYMBOLS[x]) + result
}