Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ws-proxy/cmd/root.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"fmt"
9
"os"
10
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/gitpod-io/gitpod/common-go/tracing"
15
)
16
17
var (
18
// ServiceName is the name we use for tracing/logging.
19
ServiceName = "ws-proxy"
20
// Version of this service - set during build.
21
Version = ""
22
)
23
24
// rootCmd represents the base command when called without any subcommands.
25
var rootCmd = &cobra.Command{
26
Use: "ws-proxy",
27
Short: "This acts as reverse-proxy for all workspace-bound requests",
28
Args: cobra.MinimumNArgs(1),
29
PersistentPreRun: func(cmd *cobra.Command, args []string) {
30
log.Init(ServiceName, Version, jsonLog, verbose)
31
},
32
}
33
34
// Execute adds all child commands to the root command and sets flags appropriately.
35
// This is called by main.main(). It only needs to happen once to the rootCmd.
36
func Execute() {
37
closer := tracing.Init("ws-proxy")
38
if closer != nil {
39
defer closer.Close()
40
}
41
if err := rootCmd.Execute(); err != nil {
42
fmt.Println(err)
43
os.Exit(1)
44
}
45
}
46
47
func init() {
48
rootCmd.PersistentFlags().BoolVarP(&jsonLog, "json-log", "j", true, "produce JSON log output on verbose level")
49
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose JSON logging")
50
}
51
52