-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.go
More file actions
50 lines (41 loc) · 874 Bytes
/
app.go
File metadata and controls
50 lines (41 loc) · 874 Bytes
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
package main
import (
"context"
"fmt"
"net/http"
"code-mind/internal/server"
"code-mind/internal/store"
)
const desktopAPIAddress = "127.0.0.1:34117"
type App struct {
ctx context.Context
apiServer *http.Server
store *store.FileStore
startError error
}
func NewApp(fileStore *store.FileStore) *App {
return &App{
store: fileStore,
}
}
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
apiHandler := server.New(a.store).APIHandler()
a.apiServer = &http.Server{
Addr: desktopAPIAddress,
Handler: apiHandler,
}
go func() {
err := a.apiServer.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
a.startError = err
fmt.Println("desktop api server error:", err)
}
}()
}
func (a *App) shutdown(_ context.Context) {
if a.apiServer == nil {
return
}
_ = a.apiServer.Shutdown(context.Background())
}