Add env.cr for HTTP::Server::Context. Support HTTP::Server::Context.sched and HTTP::Server::Context.log.
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/lib/env.cr | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/lib/env.cr
diff --git a/src/lib/env.cr b/src/lib/env.cr new file mode 100644 index 0000000..d33b4c0 --- /dev/null +++ b/src/lib/env.cr @@ -0,0 +1,26 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +require "./sched" +require "./json_logger" + +class HTTP::Server + # Instances of this class are passed to an `HTTP::Server` handler. + class Context + def create_sched + @sched = Sched.new(self) + end + + def sched + @sched ||= create_sched + end + + def create_log + @log = JSONLogger.new(env: self) + end + + def log + @log ||= create_log + end + end +end