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

Add services parameter to Application.init #438

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions Sources/Hummingbird/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ public struct Application<Responder: HTTPResponder>: ApplicationProtocol where R
/// - responder: HTTP responder. Returns a response based off a request and context
/// - server: Server child channel setup (http1, http2, http1WithWebSocketUpgrade etc)
/// - configuration: Application configuration
/// - services: List of Services for Application to add to its internal ServiceGroup
/// - onServerRunning: Function called once the server is running
/// - eventLoopGroupProvider: Where to get our EventLoopGroup
/// - logger: Logger application uses
public init(
responder: Responder,
server: HTTPChannelBuilder = .http1(),
configuration: ApplicationConfiguration = ApplicationConfiguration(),
services: [Service] = [],
onServerRunning: @escaping @Sendable (Channel) async -> Void = { _ in },
eventLoopGroupProvider: EventLoopGroupProvider = .singleton,
logger: Logger? = nil
Expand All @@ -211,7 +213,7 @@ public struct Application<Responder: HTTPResponder>: ApplicationProtocol where R
self._onServerRunning = onServerRunning

self.eventLoopGroup = eventLoopGroupProvider.eventLoopGroup
self.services = []
self.services = services
self.processesRunBeforeServerStart = []
}

Expand All @@ -221,32 +223,28 @@ public struct Application<Responder: HTTPResponder>: ApplicationProtocol where R
/// - router: Router used to generate responses from requests
/// - server: Server child channel setup (http1, http2, http1WithWebSocketUpgrade etc)
/// - configuration: Application configuration
/// - services: List of Services for Application to add to its internal ServiceGroup
/// - onServerRunning: Function called once the server is running
/// - eventLoopGroupProvider: Where to get our EventLoopGroup
/// - logger: Logger application uses
public init<ResponderBuilder: HTTPResponderBuilder>(
router: ResponderBuilder,
server: HTTPChannelBuilder = .http1(),
configuration: ApplicationConfiguration = ApplicationConfiguration(),
services: [Service] = [],
onServerRunning: @escaping @Sendable (Channel) async -> Void = { _ in },
eventLoopGroupProvider: EventLoopGroupProvider = .singleton,
logger: Logger? = nil
) where Responder == ResponderBuilder.Responder {
if let logger {
self.logger = logger
} else {
var logger = Logger(label: configuration.serverName ?? "Hummingbird")
logger.logLevel = Environment().get("LOG_LEVEL").map { Logger.Level(rawValue: $0) ?? .info } ?? .info
self.logger = logger
}
self.responder = router.buildResponder()
self.server = server
self.configuration = configuration
self._onServerRunning = onServerRunning

self.eventLoopGroup = eventLoopGroupProvider.eventLoopGroup
self.services = []
self.processesRunBeforeServerStart = []
self.init(
responder: router.buildResponder(),
server: server,
configuration: configuration,
services: services,
onServerRunning: onServerRunning,
eventLoopGroupProvider: eventLoopGroupProvider,
logger: logger
)
}

// MARK: Methods
Expand Down
Loading