forked from fossul/fossul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
96 lines (78 loc) · 2.57 KB
/
storage.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Copyright 2019 The Fossul Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"context"
_ "fossul/src/engine/storage/docs"
"fossul/src/engine/util"
"github.com/swaggo/http-swagger"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
const version = "1.0.0"
var port string = os.Getenv("FOSSUL_STORAGE_SERVICE_PORT")
var pluginDir string = os.Getenv("FOSSUL_STORAGE_PLUGIN_DIR")
var myUser string = os.Getenv("FOSSUL_USERNAME")
var myPass string = os.Getenv("FOSSUL_PASSWORD")
var debug string = os.Getenv("FOSSUL_STORAGE_DEBUG")
// @title Fossul Framework Storage API
// @version 1.0
// @description APIs for managing Fossul storage plugins
// @description JSON API definition can be retrieved at <a href="/api/v1/swagger/doc.json">/api/v1/swagger/doc.json</a>
// @termsOfService http://swagger.io/terms/
// @contact.name Keith Tenzer
// @contact.url http://www.keithtenzer.com
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {
log.Println("Plugin directory [" + pluginDir + "]")
err := util.CreateDir(pluginDir, 0755)
if err != nil {
log.Fatal(err)
}
os.Setenv("MyUser", myUser)
os.Setenv("MyPass", myPass)
router := NewRouter()
router.PathPrefix("/api/v1").Handler(httpSwagger.WrapHandler)
srv := &http.Server{
Addr: ":" + port,
Handler: router,
}
idleConnsClosed := make(chan struct{})
go func() {
sigint := make(chan os.Signal, 1)
// Catch Terminal (ctr-c) and SigTerm
signal.Notify(sigint, os.Interrupt)
signal.Notify(sigint, syscall.SIGTERM)
<-sigint
// Signal recieved, shutdown
if err := srv.Shutdown(context.Background()); err != nil {
log.Println("Storage service shutdown failed! %v", err)
}
log.Println("Stopping storage service on port [" + port + "]")
close(idleConnsClosed)
}()
log.Println("Starting storage service on port [" + port + "]")
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Println("App service start failed! %v", err)
}
<-idleConnsClosed
}
func printConfigDebug(config util.Config) {
if debug == "true" {
log.Println("[DEBUG]", config)
}
}