@@ -11,29 +11,32 @@ pub const Http = @import("http.zig");
alloc: Allocator,
router: Router,
interface: union(RunMode) {
unix: zWSGI,
http: Http,
other: void,
},
interface: Interface,
pub const RunMode = enum {
unix,
zwsgi,
http,
other,
};
pub const Options = struct {
zwsgi: zWSGI.Options = .{},
http: Http.Options = .{},
pub const Interface = union(RunMode) {
zwsgi: zWSGI,
http: Http,
other: void,
};
pub fn init(a: Allocator, runmode: RunMode, router: Router, opts: Options) !Server {
pub const Options = union(RunMode) {
zwsgi: zWSGI.Options,
http: Http.Options,
other: void,
};
pub fn init(a: Allocator, opts: Options, router: Router) !Server {
return .{
.alloc = a,
.router = router,
.interface = switch (runmode) {
.unix => .{ .unix = zWSGI.init(a, opts.zwsgi, router) },
.interface = switch (opts) {
.zwsgi => .{ .zwsgi = zWSGI.init(a, opts.zwsgi, router) },
.http => .{ .http = try Http.init(a, opts.http, router) },
.other => unreachable,
},
@@ -42,7 +45,7 @@ pub fn init(a: Allocator, runmode: RunMode, router: Router, opts: Options) !Serv
pub fn serve(srv: *Server) !void {
switch (srv.interface) {
.unix => |*zw| try zw.serve(),
.zwsgi => |*zw| try zw.serve(),
.http => |*ht| try ht.serve(),
else => {},
}