Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a config struct instead of a raw global in main.go #18

Open
flbn opened this issue Sep 27, 2023 · 0 comments
Open

use a config struct instead of a raw global in main.go #18

flbn opened this issue Sep 27, 2023 · 0 comments

Comments

@flbn
Copy link

flbn commented Sep 27, 2023

          also, this is separate but how do we feel about using a struct instead of this global variable?

like, instead of this:

var (
	runtimeAPI        = os.Getenv("AWS_LAMBDA_RUNTIME_API")
	extensionName     = filepath.Base(os.Args[0])
	isFirstInvocation = true
	runtimeDone       = make(chan struct{})

	// API Port
	logsPort = "8080"

	// Buffering Config
	defaultMaxItems  = 1000
	defaultMaxBytes  = 262144
	defaultTimeoutMS = 1000

	developmentMode = false
	logger          *zap.Logger
)

something more like:

type Config struct {
    RuntimeAPI        string
    ExtensionName     string
    IsFirstInvocation bool
    LogsPort          string
    MaxItems          int
    MaxBytes          int
    TimeoutMS         int
    DevelopmentMode   bool
    Logger            *zap.Logger
    RuntimeDone       chan struct{}
}

var cfg = Config{
    RuntimeAPI:        os.Getenv("AWS_LAMBDA_RUNTIME_API"),
    ExtensionName:     filepath.Base(os.Args[0]),
    IsFirstInvocation: true,
    LogsPort:          "8080",
    MaxItems:          1000,
    MaxBytes:          262144,
    TimeoutMS:         1000,
    DevelopmentMode:   false,
    RuntimeDone:       make(chan struct{}),
}

and then used like

cfg.Logger.Error('ex')

Originally posted by @flbn in #17 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant