-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserver.go
62 lines (54 loc) · 1.59 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"log"
"net/http"
"time"
"github.com/dgruber/drmaa2os/pkg/jobtracker"
"github.com/dgruber/drmaa2os/pkg/jobtracker/remote/server"
genserver "github.com/dgruber/drmaa2os/pkg/jobtracker/remote/server/generated"
"github.com/dgruber/drmaa2os/pkg/jobtracker/simpletracker"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)
func main() {
// run jobs behind server as simple OS processes
jobStore, err := simpletracker.NewPersistentJobStore("job.db")
if err != nil {
panic(err)
}
processTracker, err := simpletracker.NewWithJobStore(
"testsession", jobStore, true)
if err != nil {
panic(err)
}
RunServer(processTracker)
}
func RunServer(jobTracker jobtracker.JobTracker) {
// connect the OpenAPI spec with the job tracker
// interface implementation - could be anything
impl, _ := server.NewJobTrackerImpl(jobTracker)
// using chi router and logging + basic auth middleware
router := chi.NewRouter()
router.Use(middleware.Logger)
router.Use(middleware.BasicAuth(
"remotetracker",
map[string]string{
"user": "testpassword",
}))
// using the multiplexer for the case we want to serve
// different implemenations at the same server
m := http.NewServeMux()
m.Handle("/jobserver/jobmanagement/",
genserver.HandlerFromMuxWithBaseURL(
impl, router, "/jobserver/jobmanagement"))
// using standard http - this should be https with
// certificates
s := &http.Server{
Addr: ":8088",
Handler: m,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}