Skip to content

Commit

Permalink
🎨 require the struct but allow it to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
acidjazz committed Aug 18, 2022
1 parent 5926e28 commit f84b111
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,31 @@ import (
var ginLambda *ginadapter.GinLambdaV2

type Options struct {
Port int // port to run on (default 8080)
// optional - hostname to listen on (default: localhost)
Hostname string
// optional - port to run on (default: 8080)
Port int
}

func Start(routes *gin.Engine, options *Options) {
func Start(routes *gin.Engine, options Options) {

defaults := &Options{
Hostname: "localhost",
Port: 8080,
}

if options.Port != 0 {
defaults.Port = options.Port
}
if options.Port != 0 { defaults.Port = options.Port }
if options.Hostname != "" { defaults.Hostname = options.Hostname }

if os.Getenv("_HANDLER") != "" {
ginLambda = ginadapter.NewV2(routes)
lambda.Start(Handler)
} else {
server := &http.Server{
Addr: fmt.Sprintf(":%d", defaults.Port),
Addr: fmt.Sprintf("%s:%d", defaults.Hostname, defaults.Port),
Handler: routes,
}
server.ListenAndServe()
} else {
ginLambda = ginadapter.NewV2(routes)
lambda.Start(Handler)
}
}

Expand Down

0 comments on commit f84b111

Please sign in to comment.