0001 // 0002 // Controller.swift 0003 // Kunugi 0004 // 0005 // Created by ito on 1/3/16. 0006 // Copyright © 2016 Yusuke Ito. All rights reserved. 0007 // 0008 0009 public protocol ControllerMiddleware: MiddlewareType { 0010 func get
Controller.swift:18 public extension ControllerMiddleware {(ctx: ContextBox) throws -> MiddlewareResult 0011 func post
Controller.swift:31 result = try get(ctx)(ctx: ContextBox) throws -> MiddlewareResult 0012 func put
Controller.swift:33 result = try post(ctx)(ctx: ContextBox) throws -> MiddlewareResult 0013 func delete
Controller.swift:35 result = try put(ctx)(ctx: ContextBox) throws -> MiddlewareResult 0014 func before
Controller.swift:37 result = try delete(ctx)(ctx: ContextBox) throws -> MiddlewareResult 0015 func after
Controller.swift:26 switch try before(ctx) {(ctx: ContextBox, result: MiddlewareResult) throws -> MiddlewareResult 0016 } 0017 0018 public extension ControllerMiddleware { 0019 func before(ctx: ContextBox) throws -> MiddlewareResult { 0020 return .Next 0021 } 0022 func after(ctx: ContextBox, result: MiddlewareResult) throws -> MiddlewareResult { 0023 return result 0024 } 0025 func handle(ctx: ContextBox) throws -> MiddlewareResult { 0026 switch try before(ctx) { 0027 case .Next: 0028 let result: MiddlewareResult 0029 switch ctx.method { 0030 case .GET: 0031 result = try get(ctx) 0032 case .POST: 0033 result = try post(ctx) 0034 case .PUT: 0035 result = try put(ctx) 0036 case .DELETE: 0037 result = try delete(ctx) 0038 default: 0039 result = .Next 0040 } 0041 return try after(ctx, result: result) 0042 0043 case .Respond(let res): 0044 return .Respond(res) 0045 } 0046 } 0047 func get(ctx: ContextBox) throws -> MiddlewareResult { return .Next } 0048 func post(ctx: ContextBox) throws -> MiddlewareResult { return .Next } 0049 func put(ctx: ContextBox) throws -> MiddlewareResult { return .Next } 0050 func delete(ctx: ContextBox) throws -> MiddlewareResult { return .Next } 0051 }
Controller.swift:41 return try after(ctx, result: result)