forked from lgblaumeiser/UserManager.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (64 loc) · 1.95 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* User Manager API
*
* Description of a user manager API
*
* API version: 1.0.0
* Contact: [email protected]
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
// SPDX-FileCopyrightText: 2022 Lars Geyer-Blaumeiser <[email protected]>
// SPDX-License-Identifier: MIT
package main
import (
"flag"
"fmt"
"log"
"net/http"
_ "github.com/lgblaumeiser/usermanager/statik"
"github.com/lgblaumeiser/usermanager/util"
"github.com/rakyll/statik/fs"
"github.com/lgblaumeiser/usermanager/rest"
"github.com/lgblaumeiser/usermanager/service"
"github.com/lgblaumeiser/usermanager/store"
)
func main() {
log.Printf("Server started")
var srvport int
var dbhost string
var dbport int
var dbuser string
var dbpawd string
var dbname string
flag.IntVar(&srvport, "srvport", 8080, "service port")
flag.StringVar(&dbhost, "dbhost", "", "database hostname")
flag.IntVar(&dbport, "dbport", -1, "database port")
flag.StringVar(&dbuser, "dbuser", "", "database username")
flag.StringVar(&dbpawd, "dbpwd", "", "database user password")
flag.StringVar(&dbname, "dbname", "", "database name")
flag.Parse()
var database service.UserStore
var rerr *util.RestError
if dbport > -1 {
database = store.ConnectPostgresStore(dbhost, dbport, dbuser, dbpawd, dbname)
} else {
database = store.CreateMemoryStore()
}
defer database.CloseStore()
userService, rerr := service.NewUserService(database)
if rerr != nil {
panic(rerr)
}
InfrastructureApiController := rest.NewInfrastructureApiController(&userService)
UsersApiController := rest.NewUsersApiController(&userService)
router := rest.NewRouter(InfrastructureApiController, UsersApiController)
statikFS, err := fs.New()
if err != nil {
panic(err)
}
staticServer := http.FileServer(statikFS)
sh := http.StripPrefix("/openapi/", staticServer)
router.PathPrefix("/openapi/").Handler(sh)
portstring := fmt.Sprintf(":%d", srvport)
log.Fatal(http.ListenAndServe(portstring, router))
}