Compare commits
4 Commits
2293780131
...
975d604e2f
Author | SHA1 | Date | |
---|---|---|---|
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) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user