Compare commits
4 Commits
2293780131
...
975d604e2f
Author | SHA1 | Date | |
---|---|---|---|
975d604e2f | |||
48e8c2d4f0 | |||
64fb80734d | |||
a377995a5b |
@ -209,8 +209,10 @@ func main () {
|
|||||||
|
|
||||||
// set up the HTTP server
|
// set up the HTTP server
|
||||||
httpServer := httpServerRoutine {
|
httpServer := httpServerRoutine {
|
||||||
Addr: config.Get("http.address"),
|
Server: &http.Server {
|
||||||
Handler: &handler,
|
Addr: config.Get("http.address"),
|
||||||
|
Handler: &handler,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up the trimming routine
|
// 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 {
|
func (this *httpServerRoutine) Run (ctx context.Context) error {
|
||||||
ctx, done := context.WithCancel(ctx)
|
ctx, done := context.WithCancel(ctx)
|
||||||
defer done()
|
defer done()
|
||||||
server := http.Server(*this)
|
|
||||||
go func () {
|
go func () {
|
||||||
<- ctx.Done()
|
<- ctx.Done()
|
||||||
shutdownCtx, done := context.WithTimeout (
|
shutdownCtx, done := context.WithTimeout (
|
||||||
context.Background(),
|
context.Background(),
|
||||||
16 * time.Second)
|
16 * time.Second)
|
||||||
defer done()
|
defer done()
|
||||||
server.Shutdown(shutdownCtx)
|
this.Server.Shutdown(shutdownCtx)
|
||||||
} ()
|
} ()
|
||||||
err := server.ListenAndServe()
|
err := this.Server.ListenAndServe()
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
import "log"
|
import "log"
|
||||||
import "time"
|
import "time"
|
||||||
import "net/url"
|
import "net/url"
|
||||||
|
@ -148,12 +148,12 @@ func (this *state) funcWriteFile (name, content string) error {
|
|||||||
|
|
||||||
func (this *state) countFiles(name string) (int, error) {
|
func (this *state) countFiles(name string) (int, error) {
|
||||||
name, err := this.document.Rel(name)
|
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
|
// 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
|
// read their names and everything, all that work just to know how many
|
||||||
// files there are, its slightly upsetting
|
// files there are, its slightly upsetting
|
||||||
files, err := os.ReadDir(name)
|
files, err := os.ReadDir(name)
|
||||||
if err != nil { return err }
|
if err != nil { return 0, err }
|
||||||
return len(files), nil
|
return len(files), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ import "git.tebibyte.media/sashakoshka/go-util/sync"
|
|||||||
func TestSession (test *testing.T) {
|
func TestSession (test *testing.T) {
|
||||||
future := time.Now().Add(5 * time.Minute)
|
future := time.Now().Add(5 * time.Minute)
|
||||||
sessions := make(sessionMap)
|
sessions := make(sessionMap)
|
||||||
sessionLocker := usync.NewRWLocker(sessions)
|
sessionMonitor := usync.NewRWMonitor(sessions)
|
||||||
state := state { sessions: &sessionLocker }
|
state := state { sessions: &sessionMonitor }
|
||||||
session, err := state.newSession(uuid.New(), future)
|
session, err := state.newSession(uuid.New(), future)
|
||||||
if err != nil { test.Fatal(err) }
|
if err != nil { test.Fatal(err) }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user