forked from bacalhau-project/bacalhau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (80 loc) · 3.2 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/bacalhau-project/bacalhau/cmd/cli"
"github.com/bacalhau-project/bacalhau/cmd/util"
"github.com/bacalhau-project/bacalhau/pkg/config"
_ "github.com/bacalhau-project/bacalhau/pkg/version"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
"github.com/bacalhau-project/bacalhau/pkg/logger"
)
// @title Bacalhau API
// @version v1
// @description The Bacalhau API is a RESTful API that allows you to interact with the Bacalhau network.
// @termsOfService http://bacalhau.org/terms/
// TODO: #3165 Host the terms of service on bacalhau.org/terms
// @contact.name API Support
// @contact.url https://www.expanso.io/contact/
// @contact.email support@bacalhau.org
// TODO: #3166 Host an email address and a contact form on bacalhau.org/support
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:1234
// @BasePath /api/v1
// @externalDocs.description Bacalhau Documentation
// @externalDocs.url https://docs.bacalhau.org
//// @securityDefinitions.basic BasicAuth
//// @securityDefinitions.apikey ApiKeyAuth
//// @in header
//// @name Authorization
//// @description Description for what is this security definition being used
// -- Add authentication to swagger here
//// @securitydefinitions.oauth2.application OAuth2Application
//// @tokenUrl https://example.com/oauth/token
//// @scope.write Grants write access
//// @scope.admin Grants read and write access to administrative information
//
//// @securitydefinitions.oauth2.implicit OAuth2Implicit
//// @authorizationUrl https://example.com/oauth/authorize
//// @scope.write Grants write access
//// @scope.admin Grants read and write access to administrative information
//
//// @securitydefinitions.oauth2.password OAuth2Password
//// @tokenUrl https://example.com/oauth/token
//// @scope.read Grants read access
//// @scope.write Grants write access
//// @scope.admin Grants read and write access to administrative information
//
//// @securitydefinitions.oauth2.accessCode OAuth2AccessCode
//// @tokenUrl https://example.com/oauth/token
//// @authorizationUrl https://example.com/oauth/authorize
//// @scope.admin Grants read and write access to administrative information
func main() {
localCtx, localCancel := context.WithCancel(context.Background())
defer func() {
// Make sure any buffered logs are written if something failed before logging was configured.
logger.LogBufferedLogs(nil)
}()
_ = godotenv.Load()
devstackEnvFile := config.DevstackEnvFile()
if _, err := os.Stat(devstackEnvFile); err == nil {
log.Debug().Msgf("Loading environment from %s", devstackEnvFile)
_ = godotenv.Overload(devstackEnvFile)
}
// Ensure commands are able to stop cleanly if someone presses ctrl+c
ctx, cancel := signal.NotifyContext(context.Background(), util.ShutdownSignals...)
go func() {
cli.Execute(ctx)
cancel()
localCancel()
}()
// Wait for the context to be cancelled
// either by a signal or by the command completing
<-localCtx.Done()
// Print a newline to ensure the next prompt is on a new line
fmt.Println()
}