1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

remove usingnamespace

This commit is contained in:
renerocksai 2025-03-16 16:17:42 +01:00
parent 3856fceb9f
commit ab42f971a0
No known key found for this signature in database
7 changed files with 17 additions and 59 deletions

View file

@ -41,7 +41,7 @@ fn on_request_verbose(r: zap.Request) void {
},
.JSON => {
var buffer: [128]u8 = undefined;
const json = zap.stringifyBuf(&buffer, .{ .message = "Hello from ZAP!!!" }, .{}) orelse return;
const json = zap.util.stringifyBuf(&buffer, .{ .message = "Hello from ZAP!!!" }, .{}) orelse return;
r.sendJson(json) catch return;
},
.XHTML => {

View file

@ -52,7 +52,7 @@ pub fn get(self: *Self, r: zap.Request) void {
var jsonbuf: [256]u8 = undefined;
if (self.userIdFromPath(path)) |id| {
if (self._users.get(id)) |user| {
if (zap.stringifyBuf(&jsonbuf, user, .{})) |json| {
if (zap.util.stringifyBuf(&jsonbuf, user, .{})) |json| {
r.sendJson(json) catch return;
}
}
@ -76,7 +76,7 @@ pub fn post(self: *Self, r: zap.Request) void {
defer u.deinit();
if (self._users.addByName(u.value.first_name, u.value.last_name)) |id| {
var jsonbuf: [128]u8 = undefined;
if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
if (zap.util.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
r.sendJson(json) catch return;
}
} else |err| {
@ -97,11 +97,11 @@ pub fn patch(self: *Self, r: zap.Request) void {
defer u.deinit();
var jsonbuf: [128]u8 = undefined;
if (self._users.update(id, u.value.first_name, u.value.last_name)) {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
if (zap.util.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
r.sendJson(json) catch return;
}
} else {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
if (zap.util.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
r.sendJson(json) catch return;
}
}
@ -117,11 +117,11 @@ pub fn delete(self: *Self, r: zap.Request) void {
if (self.userIdFromPath(path)) |id| {
var jsonbuf: [128]u8 = undefined;
if (self._users.delete(id)) {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
if (zap.util.stringifyBuf(&jsonbuf, .{ .status = "OK", .id = id }, .{})) |json| {
r.sendJson(json) catch return;
}
} else {
if (zap.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
if (zap.util.stringifyBuf(&jsonbuf, .{ .status = "ERROR", .id = id }, .{})) |json| {
r.sendJson(json) catch return;
}
}
@ -132,6 +132,6 @@ pub fn delete(self: *Self, r: zap.Request) void {
pub fn options(_: *Self, r: zap.Request) void {
r.setHeader("Access-Control-Allow-Origin", "*") catch return;
r.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS") catch return;
r.setStatus(zap.StatusCode.no_content);
r.setStatus(zap.http.StatusCode.no_content);
r.markAsFinished(true);
}

View file

@ -19,7 +19,7 @@ fn on_request(r: zap.Request) void {
var buf: [100]u8 = undefined;
var json_to_send: []const u8 = undefined;
if (zap.stringifyBuf(&buf, user, .{})) |json| {
if (zap.util.stringifyBuf(&buf, user, .{})) |json| {
json_to_send = json;
} else {
json_to_send = "null";

View file

@ -61,8 +61,9 @@ pub const AuthResult = enum {
/// The authenticator handled the request that didn't pass authentication /
/// authorization.
/// This is used to implement authenticators that redirect to a login
/// page. An Authenticating endpoint will not do the default, which is trying
/// to call the `unauthorized` callback if one exists orelse ignore the request.
/// page. An Authenticating endpoint will not do the default, which is
/// trying to call the `unauthorized` callback. `unauthorized()` must be
/// implemented in the endpoint.
Handled,
};
@ -338,7 +339,7 @@ pub const UserPassSessionArgs = struct {
/// cookie max age in seconds; 0 -> session cookie
cookieMaxAge: u8 = 0,
/// redirect status code, defaults to 302 found
redirectCode: zap.StatusCode = .found,
redirectCode: zap.http.StatusCode = .found,
};
/// UserPassSession supports the following use case:

View file

@ -495,7 +495,7 @@ pub fn getHeaderCommon(self: *const Self, which: HttpHeaderCommon) ?[]const u8 {
.upgrade => fio.HTTP_HEADER_UPGRADE,
};
const fiobj = zap.fio.fiobj_hash_get(self.h.*.headers, field);
return zap.fio2str(fiobj);
return zap.util.fio2str(fiobj);
}
/// Set header.

View file

@ -26,7 +26,7 @@ test "http parameters" {
var strParams: ?zap.Request.HttpParamStrKVList = null;
var params: ?zap.Request.HttpParamKVList = null;
var paramOneStr: ?zap.FreeOrNot = null;
var paramOneStr: ?zap.util.FreeOrNot = null;
var paramOneSlice: ?[]const u8 = null;
var paramSlices: zap.Request.ParamSliceIterator = undefined;

View file

@ -9,52 +9,10 @@ pub const fio = @import("fio.zig");
/// Server-Side TLS function wrapper
pub const Tls = @import("tls.zig");
/// Endpoint and supporting types.
/// Create one and define all callbacks. Then, pass it to a HttpListener's
/// `register()` function to register with the listener.
///
/// **NOTE**: Endpoints must define the following:
///
/// ```zig
/// path: []const u8,
/// pub fn get(_: *Self, _: zap.Request) void {}
/// pub fn post(_: *Self, _: zap.Request) void {}
/// pub fn put(_: *Self, _: zap.Request) void {}
/// pub fn delete(_: *Self, _: zap.Request) void {}
/// pub fn patch(_: *Self, _: zap.Request) void {}
/// pub fn options(_: *Self, _: zap.Request) void {}
/// // optional, if auth stuff is used:
/// pub fn unauthorized(_: *Self, _: zap.Request) void {}
/// ```
///
/// Example:
/// A simple endpoint listening on the /stop route that shuts down zap. The
/// main thread usually continues at the instructions after the call to
/// zap.start().
///
/// ```zig
/// const StopEndpoint = struct {
///
/// pub fn init( path: []const u8,) StopEndpoint {
/// return .{
/// .path = path,
/// };
/// }
///
/// pub fn get(self: *StopEndpoint, r: zap.Request) void {
/// _ = self;
/// _ = r;
/// zap.stop();
/// }
/// };
/// ```
pub const Endpoint = @import("endpoint.zig");
pub const Router = @import("router.zig");
pub usingnamespace @import("util.zig");
pub usingnamespace @import("http.zig");
/// A struct to handle Mustache templating.
///
/// This is a wrapper around fiobj's mustache template handling.
@ -78,9 +36,8 @@ pub const Middleware = @import("middleware.zig");
pub const WebSockets = @import("websockets.zig");
pub const Log = @import("log.zig");
const http = @import("http.zig");
const util = @import("util.zig");
pub const http = @import("http.zig");
pub const util = @import("util.zig");
// TODO: replace with comptime debug logger like in log.zig
var _debug: bool = false;