Skip to content

Commit

Permalink
Merge pull request #1 from aismirnov/master
Browse files Browse the repository at this point in the history
setting default path in program arguments
  • Loading branch information
cfi2017 authored Apr 20, 2020
2 parents 6a6ea35 + 92c2000 commit e3ce872
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var cfgFile string

var (
insecure bool
defaultPwd string
)

// rootCmd represents the base command when called without any subcommands
Expand All @@ -48,6 +49,7 @@ to quickly create a Cobra application.`,
shared.OpenBrowser("https://bl3.swiss.dev/")
opts := server.Options{}
opts.Insecure = insecure
opts.DefaultPwd = defaultPwd
if err := server.Start(opts); err != nil {
panic(err)
}
Expand All @@ -74,6 +76,8 @@ func init() {
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolVar(&insecure, "insecure", false, "Run server without cors protection")
var currentPwd, _ = os.Getwd()
rootCmd.Flags().StringVar(&defaultPwd, "path", currentPwd, "Path to save file directory")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
1 change: 1 addition & 0 deletions internal/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package server

type Options struct {
Insecure bool
DefaultPwd string
}
5 changes: 1 addition & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ var (
BuiltBy = ""
)

func init() {
pwd, _ = os.Getwd()
}

func Start(opts Options) error {
gin.SetMode(gin.ReleaseMode)
r := gin.New()
Expand All @@ -38,6 +34,7 @@ func Start(opts Options) error {
} else {
cfg.AllowOrigins = []string{"https://bl3.swiss.dev", "http://localhost:4200"}
}
pwd = opts.DefaultPwd
r.Use(cors.New(cfg))

r.GET("/stats", func(c *gin.Context) {
Expand Down

0 comments on commit e3ce872

Please sign in to comment.