Compare commits
7 Commits
2293780131
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 998110000a | |||
| 439e90357d | |||
| 6c18c1c922 | |||
| 975d604e2f | |||
| 48e8c2d4f0 | |||
| 64fb80734d | |||
| a377995a5b |
@@ -209,8 +209,10 @@ func main () {
|
||||
|
||||
// set up the HTTP server
|
||||
httpServer := httpServerRoutine {
|
||||
Addr: config.Get("http.address"),
|
||||
Handler: &handler,
|
||||
Server: &http.Server {
|
||||
Addr: config.Get("http.address"),
|
||||
Handler: &handler,
|
||||
},
|
||||
}
|
||||
|
||||
// set up the trimming routine
|
||||
@@ -241,21 +243,22 @@ func main () {
|
||||
}
|
||||
}
|
||||
|
||||
type httpServerRoutine http.Server
|
||||
type httpServerRoutine struct {
|
||||
*http.Server
|
||||
}
|
||||
|
||||
func (this *httpServerRoutine) Run (ctx context.Context) error {
|
||||
ctx, done := context.WithCancel(ctx)
|
||||
defer done()
|
||||
server := http.Server(*this)
|
||||
go func () {
|
||||
<- ctx.Done()
|
||||
shutdownCtx, done := context.WithTimeout (
|
||||
context.Background(),
|
||||
16 * time.Second)
|
||||
defer done()
|
||||
server.Shutdown(shutdownCtx)
|
||||
this.Server.Shutdown(shutdownCtx)
|
||||
} ()
|
||||
err := server.ListenAndServe()
|
||||
err := this.Server.ListenAndServe()
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package http
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "time"
|
||||
import "net/url"
|
||||
|
||||
@@ -148,12 +148,12 @@ func (this *state) funcWriteFile (name, content string) error {
|
||||
|
||||
func (this *state) countFiles(name string) (int, error) {
|
||||
name, err := this.document.Rel(name)
|
||||
if err != nil { return err }
|
||||
if err != nil { return 0, err }
|
||||
// genuinely can't believe this is the only way to do it, we have to
|
||||
// read their names and everything, all that work just to know how many
|
||||
// files there are, its slightly upsetting
|
||||
files, err := os.ReadDir(name)
|
||||
if err != nil { return err }
|
||||
if err != nil { return 0, err }
|
||||
return len(files), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import "git.tebibyte.media/sashakoshka/go-util/sync"
|
||||
func TestSession (test *testing.T) {
|
||||
future := time.Now().Add(5 * time.Minute)
|
||||
sessions := make(sessionMap)
|
||||
sessionLocker := usync.NewRWLocker(sessions)
|
||||
state := state { sessions: &sessionLocker }
|
||||
sessionMonitor := usync.NewRWMonitor(sessions)
|
||||
state := state { sessions: &sessionMonitor }
|
||||
session, err := state.newSession(uuid.New(), future)
|
||||
if err != nil { test.Fatal(err) }
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ func (this *Provider) FuncMap () template.FuncMap {
|
||||
"inRange": this.funcInRange,
|
||||
"strInRange": this.funcStrInRange,
|
||||
"hasWords": this.funcHasWords,
|
||||
"hasXML": this.funcHasXML,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +70,11 @@ func (this *Provider) funcIsEnglish(value string) bool {
|
||||
score := 0
|
||||
total := 0
|
||||
for _, char := range value {
|
||||
if char >= 'a' && char <= 'z' || char >= 'A' && char <= 'Z' || char >= '0' || char <= '9' {
|
||||
ok :=
|
||||
char >= 'a' && char <= 'z' ||
|
||||
char >= 'A' && char <= 'Z' ||
|
||||
char >= '0' && char <= '9'
|
||||
if ok {
|
||||
score += 1
|
||||
}
|
||||
total += 1
|
||||
|
||||
38
providers/validate/validate_test.go
Normal file
38
providers/validate/validate_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package validate
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFuncIsEnglish(test *testing.T) {
|
||||
russian :=
|
||||
"Качество изделия будет напрямую зависеть от точности " +
|
||||
"соблюдения всех правил технологии выполнения " +
|
||||
"https://some-random-scam-link-they-sent-me.com"
|
||||
symbols :=
|
||||
")(*#&$(*89347928374)(*/./,./,/,./.,) half is english but it " +
|
||||
"will still be over the threshold"
|
||||
english :=
|
||||
"A limousine service offers luxurious, chauffeur-driven " +
|
||||
"vehicles for various occasions. For Seattle residents and " +
|
||||
"visitors, <a href=https://scam.com/> ScamTac airport limo " +
|
||||
"service </a> is a popular choice. This service provides " +
|
||||
"professional chauffeurs who ensure a smooth, comfortable " +
|
||||
"ride to and from ScamTac airport. The fleet typically " +
|
||||
"includes sedans, SUVs, and stretch limousines, catering to " +
|
||||
"different group sizes and preferences. Key features include " +
|
||||
"timely pick-ups, meet-and-greet services, and luggage " +
|
||||
"assistance. Whether for business travel, special events, or " +
|
||||
"simply a stress-free airport transfer, ScamTac airport limo " +
|
||||
"service ensures a high-end travel experience. - " +
|
||||
"https://scam.com/"
|
||||
provider := new(Provider)
|
||||
|
||||
if got, correct := provider.funcIsEnglish(russian), false; got != correct {
|
||||
test.Fatal("incorrect:", correct)
|
||||
}
|
||||
if got, correct := provider.funcIsEnglish(symbols), false; got != correct {
|
||||
test.Fatal("incorrect:", correct)
|
||||
}
|
||||
if got, correct := provider.funcIsEnglish(english), true; got != correct {
|
||||
test.Fatal("incorrect:", correct)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user