-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
628 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/lsowen/hoover-dam/pkg/config" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "hoover-dam", | ||
Short: "hoover-dam is an open source authorization server for lakefs", | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
var initOnce sync.Once | ||
|
||
func newConfig() (*config.Config, error) { | ||
cfg, err := config.NewConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
func loadConfig() *config.Config { | ||
initOnce.Do(initConfig) | ||
cfg, err := newConfig() | ||
if err != nil { | ||
fmt.Println("Failed to load config file", err) | ||
os.Exit(1) | ||
} | ||
return cfg | ||
} | ||
|
||
func initConfig() { | ||
|
||
viper.SetEnvPrefix("LAKEFS") | ||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config | ||
// read in environment variables | ||
viper.AutomaticEnv() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/lsowen/hoover-dam/pkg/api" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var runCmd = &cobra.Command{ | ||
Use: "run", | ||
Short: "Run hoover-dam", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg := loadConfig() | ||
|
||
r, err := api.Serve(cmd.Context(), *cfg) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
http.ListenAndServe(":8080", r) | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(runCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
// import ( | ||
// "context" | ||
// "fmt" | ||
// "net/http" | ||
// "os" | ||
|
||
"github.com/lsowen/hoover-dam/pkg/api" | ||
) | ||
// "github.com/lsowen/hoover-dam/pkg/api" | ||
// ) | ||
|
||
func main() { | ||
ctx := context.Background() | ||
r, err := api.Serve(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
// func main() { | ||
// ctx := context.Background() | ||
// r, err := api.Serve(ctx) | ||
// if err != nil { | ||
// fmt.Println(err) | ||
// os.Exit(1) | ||
// } | ||
|
||
// http.ListenAndServe(":8080", r) | ||
// } | ||
|
||
http.ListenAndServe(":8080", r) | ||
import "github.com/lsowen/hoover-dam/cmd/hooverdam/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.