// Package main is the entry point for the GitLab Shell health check … - #277
Open
natnaka268-cloud wants to merge 1 commit into
Open
// Package main is the entry point for the GitLab Shell health check …#277natnaka268-cloud wants to merge 1 commit into
natnaka268-cloud wants to merge 1 commit into
Conversation
…command. package main import ( "fmt" "os" checkCmd "gitlab.com/gitlab-org/gitlab-shell/v14/cmd/gitlab-shell-check/command" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/command" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/config" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/logger" ) var ( // Version is the current version of gitlab-shell Version = "(unknown version)" // Set at build time in the Makefile // BuildTime signifies the time the binary was build BuildTime = "19700101.000000" // Set at build time in the Makefile ) func main() { os.Exit(run()) } func run() int { command.CheckForVersionFlag(os.Args, Version, BuildTime) readWriter := &readwriter.ReadWriter{ Out: &readwriter.CountingWriter{W: os.Stdout}, In: os.Stdin, ErrOut: os.Stderr, } exitOnError := func(err error, message string) int { if err != nil { _, _ = fmt.Fprintf(readWriter.ErrOut, "%s: %v\n", message, err) return 1 } return 0 } executable, err := executable.New(executable.Healthcheck) if code := exitOnError(err, "Failed to determine executable, exiting"); code != 0 { return code } config, err := config.NewFromDirExternal(executable.RootDir) if code := exitOnError(err, "Failed to read config, exiting"); code != 0 { return code } defer config.Close() //nolint:errcheck logCloser := logger.ConfigureLogger(config) if logCloser != nil { defer logCloser.Close() //nolint:errcheck } cmd, err := checkCmd.New(config, readWriter) if code := exitOnError(err, "Failed to create command"); code != 0 { return code } ctx, finished := command.Setup(executable.Name, config) defer finished() if _, err = cmd.Execute(ctx); err != nil { _, _ = fmt.Fprintf(readWriter.ErrOut, "%v\n", err) return 1 } return 0 }
Movelog
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…command. package main import ( "fmt" "os" checkCmd "gitlab.com/gitlab-org/gitlab-shell/v14/cmd/gitlab-shell-check/command" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/command" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/config" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/v14/internal/logger" ) var ( // Version is the current version of gitlab-shell Version = "(unknown version)" // Set at build time in the Makefile // BuildTime signifies the time the binary was build BuildTime = "19700101.000000" // Set at build time in the Makefile ) func main() { os.Exit(run()) } func run() int { command.CheckForVersionFlag(os.Args, Version, BuildTime) readWriter := &readwriter.ReadWriter{ Out: &readwriter.CountingWriter{W: os.Stdout}, In: os.Stdin, ErrOut: os.Stderr, } exitOnError := func(err error, message string) int { if err != nil { _, _ = fmt.Fprintf(readWriter.ErrOut, "%s: %v\n", message, err) return 1 } return 0 } executable, err := executable.New(executable.Healthcheck) if code := exitOnError(err, "Failed to determine executable, exiting"); code != 0 { return code } config, err := config.NewFromDirExternal(executable.RootDir) if code := exitOnError(err, "Failed to read config, exiting"); code != 0 { return code } defer config.Close() //nolint:errcheck logCloser := logger.ConfigureLogger(config) if logCloser != nil { defer logCloser.Close() //nolint:errcheck } cmd, err := checkCmd.New(config, readWriter) if code := exitOnError(err, "Failed to create command"); code != 0 { return code } ctx, finished := command.Setup(executable.Name, config) defer finished() if _, err = cmd.Execute(ctx); err != nil { _, _ = fmt.Fprintf(readWriter.ErrOut, "%v\n", err) return 1 } return 0 }
Movelog