srctree

Gregory Mullen parent fc5f8c89 660a5846
divide Sever option scope

src/http.zig added: 20, removed: 19, total 1
@@ -18,10 +18,15 @@ listen_addr: std.net.Address,
router: Router,
max_request_size: usize = 0xffff,
 
pub fn init(a: Allocator, host: []const u8, port: u16, router: Router) !HTTP {
pub const Options = struct {
host: []const u8 = "127.0.0.1",
port: u16 = 80,
};
 
pub fn init(a: Allocator, opts: Options, router: Router) !HTTP {
return .{
.alloc = a,
.listen_addr = try std.net.Address.parseIp(host, port),
.listen_addr = try std.net.Address.parseIp(opts.host, opts.port),
.router = router,
};
}
 
src/server.zig added: 20, removed: 19, total 1
@@ -4,7 +4,6 @@ const Allocator = std.mem.Allocator;
const Verse = @import("verse.zig");
const Router = @import("router.zig");
 
/// Thin wrapper for zWSGI
pub const Server = @This();
 
pub const zWSGI = @import("zwsgi.zig");
@@ -12,7 +11,6 @@ pub const Http = @import("http.zig");
 
alloc: Allocator,
router: Router,
//runmode: RunMode,
interface: union(RunMode) {
unix: zWSGI,
http: Http,
@@ -26,19 +24,17 @@ pub const RunMode = enum {
};
 
pub const Options = struct {
file: []const u8 = "./zwsgi_file.sock",
host: []const u8 = "127.0.0.1",
port: u16 = 80,
zwsgi: zWSGI.Options = .{},
http: Http.Options = .{},
};
 
pub fn init(a: Allocator, runmode: RunMode, router: Router, opts: Options) !Server {
return .{
.alloc = a,
//.config = config,
.router = router,
.interface = switch (runmode) {
.unix => .{ .unix = zWSGI.init(a, opts.file, router) },
.http => .{ .http = try Http.init(a, opts.host, opts.port, router) },
.unix => .{ .unix = zWSGI.init(a, opts.zwsgi, router) },
.http => .{ .http = try Http.init(a, opts.http, router) },
.other => unreachable,
},
};
 
src/zwsgi.zig added: 20, removed: 19, total 1
@@ -15,14 +15,14 @@ alloc: Allocator,
unix_file: []const u8,
router: Router,
 
pub fn init(
a: Allocator,
file: []const u8,
router: Router,
) zWSGI {
pub const Options = struct {
file: []const u8 = "./zwsgi_file.sock",
};
 
pub fn init(a: Allocator, opts: Options, router: Router) zWSGI {
return .{
.alloc = a,
.unix_file = file,
.unix_file = opts.file,
.router = router,
};
}