minor improvement (see prev commit)

This commit is contained in:
Gerasimos (Makis) Maropoulos 2023-11-15 12:22:34 +02:00
parent e6a12bf776
commit f29d690c5f
No known key found for this signature in database
GPG Key ID: B9839E9CD30B7B6B

View File

@ -271,10 +271,10 @@ type (
// Deferrables registers one or more functions to be ran when the server is terminated. // Deferrables registers one or more functions to be ran when the server is terminated.
Deferrables(closers ...func()) ServiceGuide Deferrables(closers ...func()) ServiceGuide
// Prefix sets the API Party prefix path. // Prefix sets the API Party prefix path.
// Usage: WithPrefix("/api") // Usage: WithPrefix("/api").
WithPrefix(prefixPath string) ServiceGuide WithPrefix(prefixPath string) ServiceGuide
// WithoutPrefix disables the API Party prefix path. // WithoutPrefix disables the API Party prefix path.
// Usage: WithoutPrefix() // Usage: WithoutPrefix(), same as WithPrefix("").
WithoutPrefix() ServiceGuide WithoutPrefix() ServiceGuide
// Services registers one or more dependencies that APIs can use. // Services registers one or more dependencies that APIs can use.
Services(deps ...interface{}) ApplicationBuilder Services(deps ...interface{}) ApplicationBuilder
@ -395,7 +395,8 @@ type step6 struct {
configuratorsAsDeps []Configurator configuratorsAsDeps []Configurator
// API Party optional prefix path. // API Party optional prefix path.
// If this is nil and prefix is empty then it defaults to "/api" in order to keep backwards compatibility. // If this is nil then it defaults to "/api" in order to keep backwards compatibility,
// otherwise can be set to empty or a custom one.
prefix *string prefix *string
} }
@ -413,11 +414,15 @@ func getDefaultAPIPrefix() *string {
// WithPrefix sets the API Party prefix path. // WithPrefix sets the API Party prefix path.
// Usage: WithPrefix("/api"). // Usage: WithPrefix("/api").
func (s *step6) WithPrefix(prefixPath string) ServiceGuide { func (s *step6) WithPrefix(prefixPath string) ServiceGuide {
if prefixPath == "" {
return s.WithoutPrefix()
}
*s.prefix = prefixPath *s.prefix = prefixPath
return s return s
} }
// WithoutPrefix disables the API Party prefix path. // WithoutPrefix disables the API Party prefix path, same as WithPrefix("").
// Usage: WithoutPrefix() // Usage: WithoutPrefix()
func (s *step6) WithoutPrefix() ServiceGuide { func (s *step6) WithoutPrefix() ServiceGuide {
s.prefix = nil s.prefix = nil
@ -430,7 +435,7 @@ func (s *step6) getPrefix() string {
} }
apiPrefix := *s.prefix apiPrefix := *s.prefix
if apiPrefix == "" { // if not nil but empty then it defaults to "/api". if apiPrefix == "" { // if not nil but empty (this shouldn't happen) then it defaults to "/api".
apiPrefix = defaultAPIPrefix apiPrefix = defaultAPIPrefix
} }