mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 23:24:09 +00:00
zig 0.12.0-dev.3561+f45ba7d0c: remove type argument from fieldParentPtr
This commit is contained in:
parent
028574f3ed
commit
3f7492260d
7 changed files with 18 additions and 19 deletions
|
@ -54,7 +54,7 @@ fn userIdFromPath(self: *Self, path: []const u8) ?usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getUser(e: *zap.Endpoint, r: zap.Request) void {
|
fn getUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
const self = @fieldParentPtr(Self, "ep", e);
|
const self: Self = @fieldParentPtr("ep", e);
|
||||||
if (r.path) |path| {
|
if (r.path) |path| {
|
||||||
// /users
|
// /users
|
||||||
if (path.len == e.settings.path.len) {
|
if (path.len == e.settings.path.len) {
|
||||||
|
@ -81,7 +81,7 @@ fn listUsers(self: *Self, r: zap.Request) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn postUser(e: *zap.Endpoint, r: zap.Request) void {
|
fn postUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
const self = @fieldParentPtr(Self, "ep", e);
|
const self: Self = @fieldParentPtr("ep", e);
|
||||||
if (r.body) |body| {
|
if (r.body) |body| {
|
||||||
const maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
const maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||||
if (maybe_user) |u| {
|
if (maybe_user) |u| {
|
||||||
|
@ -100,7 +100,7 @@ fn postUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn putUser(e: *zap.Endpoint, r: zap.Request) void {
|
fn putUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
const self = @fieldParentPtr(Self, "ep", e);
|
const self: Self = @fieldParentPtr("ep", e);
|
||||||
if (r.path) |path| {
|
if (r.path) |path| {
|
||||||
if (self.userIdFromPath(path)) |id| {
|
if (self.userIdFromPath(path)) |id| {
|
||||||
if (self._users.get(id)) |_| {
|
if (self._users.get(id)) |_| {
|
||||||
|
@ -126,7 +126,7 @@ fn putUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deleteUser(e: *zap.Endpoint, r: zap.Request) void {
|
fn deleteUser(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
const self = @fieldParentPtr(Self, "ep", e);
|
const self: Self = @fieldParentPtr("ep", e);
|
||||||
if (r.path) |path| {
|
if (r.path) |path| {
|
||||||
if (self.userIdFromPath(path)) |id| {
|
if (self.userIdFromPath(path)) |id| {
|
||||||
var jsonbuf: [128]u8 = undefined;
|
var jsonbuf: [128]u8 = undefined;
|
||||||
|
|
|
@ -72,7 +72,7 @@ const UserMiddleWare = struct {
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
|
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
const self = @fieldParentPtr(Self, "handler", handler);
|
const self: Self = @fieldParentPtr("handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
// do our work: fill in the user field of the context
|
// do our work: fill in the user field of the context
|
||||||
|
@ -115,7 +115,7 @@ const SessionMiddleWare = struct {
|
||||||
// note that the first parameter is of type *Handler, not *Self !!!
|
// note that the first parameter is of type *Handler, not *Self !!!
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
const self = @fieldParentPtr(Self, "handler", handler);
|
const self: Self = @fieldParentPtr("handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
context.session = Session{
|
context.session = Session{
|
||||||
|
@ -151,7 +151,7 @@ const HtmlMiddleWare = struct {
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
|
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
const self = @fieldParentPtr(Self, "handler", handler);
|
const self: Self = @fieldParentPtr("handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
std.debug.print("\n\nHtmlMiddleware: handling request with context: {any}\n\n", .{context});
|
std.debug.print("\n\nHtmlMiddleware: handling request with context: {any}\n\n", .{context});
|
||||||
|
|
|
@ -60,7 +60,7 @@ const UserMiddleWare = struct {
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
|
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
const self = @fieldParentPtr(Self, "handler", handler);
|
const self: Self = @fieldParentPtr("handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
// do our work: fill in the user field of the context
|
// do our work: fill in the user field of the context
|
||||||
|
@ -105,7 +105,7 @@ const SessionMiddleWare = struct {
|
||||||
// note that the first parameter is of type *Handler, not *Self !!!
|
// note that the first parameter is of type *Handler, not *Self !!!
|
||||||
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
pub fn onRequest(handler: *Handler, r: zap.Request, context: *Context) bool {
|
||||||
// this is how we would get our self pointer
|
// this is how we would get our self pointer
|
||||||
const self = @fieldParentPtr(Self, "handler", handler);
|
const self: Self = @fieldParentPtr("handler", handler);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
context.session = Session{
|
context.session = Session{
|
||||||
|
@ -155,7 +155,7 @@ const HtmlEndpoint = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(ep: *zap.Endpoint, r: zap.Request) void {
|
pub fn get(ep: *zap.Endpoint, r: zap.Request) void {
|
||||||
const self = @fieldParentPtr(Self, "ep", ep);
|
const self: Self = @fieldParentPtr("ep", ep);
|
||||||
_ = self;
|
_ = self;
|
||||||
|
|
||||||
var buf: [1024]u8 = undefined;
|
var buf: [1024]u8 = undefined;
|
||||||
|
|
|
@ -2,4 +2,3 @@
|
||||||
.name = "facil.io",
|
.name = "facil.io",
|
||||||
.version = "0.0.12",
|
.version = "0.0.12",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
|
||||||
/// GET: here, the auth_endpoint will be passed in as endpoint.
|
/// GET: here, the auth_endpoint will be passed in as endpoint.
|
||||||
/// Authenticates GET requests using the Authenticator.
|
/// Authenticates GET requests using the Authenticator.
|
||||||
pub fn get(e: *Endpoint, r: zap.Request) void {
|
pub fn get(e: *Endpoint, r: zap.Request) void {
|
||||||
const authEp: *Self = @fieldParentPtr(Self, "auth_endpoint", e);
|
const authEp: *Self = @fieldParentPtr("auth_endpoint", e);
|
||||||
switch (authEp.authenticator.authenticateRequest(&r)) {
|
switch (authEp.authenticator.authenticateRequest(&r)) {
|
||||||
.AuthFailed => {
|
.AuthFailed => {
|
||||||
if (e.settings.unauthorized) |unauthorized| {
|
if (e.settings.unauthorized) |unauthorized| {
|
||||||
|
@ -132,7 +132,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
|
||||||
/// POST: here, the auth_endpoint will be passed in as endpoint.
|
/// POST: here, the auth_endpoint will be passed in as endpoint.
|
||||||
/// Authenticates POST requests using the Authenticator.
|
/// Authenticates POST requests using the Authenticator.
|
||||||
pub fn post(e: *Endpoint, r: zap.Request) void {
|
pub fn post(e: *Endpoint, r: zap.Request) void {
|
||||||
const authEp: *Self = @fieldParentPtr(Self, "auth_endpoint", e);
|
const authEp: *Self = @fieldParentPtr("auth_endpoint", e);
|
||||||
switch (authEp.authenticator.authenticateRequest(&r)) {
|
switch (authEp.authenticator.authenticateRequest(&r)) {
|
||||||
.AuthFailed => {
|
.AuthFailed => {
|
||||||
if (e.settings.unauthorized) |unauthorized| {
|
if (e.settings.unauthorized) |unauthorized| {
|
||||||
|
@ -152,7 +152,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
|
||||||
/// PUT: here, the auth_endpoint will be passed in as endpoint.
|
/// PUT: here, the auth_endpoint will be passed in as endpoint.
|
||||||
/// Authenticates PUT requests using the Authenticator.
|
/// Authenticates PUT requests using the Authenticator.
|
||||||
pub fn put(e: *Endpoint, r: zap.Request) void {
|
pub fn put(e: *Endpoint, r: zap.Request) void {
|
||||||
const authEp: *Self = @fieldParentPtr(Self, "auth_endpoint", e);
|
const authEp: *Self = @fieldParentPtr("auth_endpoint", e);
|
||||||
switch (authEp.authenticator.authenticateRequest(&r)) {
|
switch (authEp.authenticator.authenticateRequest(&r)) {
|
||||||
.AuthFailed => {
|
.AuthFailed => {
|
||||||
if (e.settings.unauthorized) |unauthorized| {
|
if (e.settings.unauthorized) |unauthorized| {
|
||||||
|
@ -172,7 +172,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
|
||||||
/// DELETE: here, the auth_endpoint will be passed in as endpoint.
|
/// DELETE: here, the auth_endpoint will be passed in as endpoint.
|
||||||
/// Authenticates DELETE requests using the Authenticator.
|
/// Authenticates DELETE requests using the Authenticator.
|
||||||
pub fn delete(e: *Endpoint, r: zap.Request) void {
|
pub fn delete(e: *Endpoint, r: zap.Request) void {
|
||||||
const authEp: *Self = @fieldParentPtr(Self, "auth_endpoint", e);
|
const authEp: *Self = @fieldParentPtr("auth_endpoint", e);
|
||||||
switch (authEp.authenticator.authenticateRequest(&r)) {
|
switch (authEp.authenticator.authenticateRequest(&r)) {
|
||||||
.AuthFailed => {
|
.AuthFailed => {
|
||||||
if (e.settings.unauthorized) |unauthorized| {
|
if (e.settings.unauthorized) |unauthorized| {
|
||||||
|
@ -192,7 +192,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
|
||||||
/// PATCH: here, the auth_endpoint will be passed in as endpoint.
|
/// PATCH: here, the auth_endpoint will be passed in as endpoint.
|
||||||
/// Authenticates PATCH requests using the Authenticator.
|
/// Authenticates PATCH requests using the Authenticator.
|
||||||
pub fn patch(e: *Endpoint, r: zap.Request) void {
|
pub fn patch(e: *Endpoint, r: zap.Request) void {
|
||||||
const authEp: *Self = @fieldParentPtr(Self, "auth_endpoint", e);
|
const authEp: *Self = @fieldParentPtr("auth_endpoint", e);
|
||||||
switch (authEp.authenticator.authenticateRequest(&r)) {
|
switch (authEp.authenticator.authenticateRequest(&r)) {
|
||||||
.AuthFailed => {
|
.AuthFailed => {
|
||||||
if (e.settings.unauthorized) |unauthorized| {
|
if (e.settings.unauthorized) |unauthorized| {
|
||||||
|
@ -212,7 +212,7 @@ pub fn Authenticating(comptime Authenticator: type) type {
|
||||||
/// OPTIONS: here, the auth_endpoint will be passed in as endpoint.
|
/// OPTIONS: here, the auth_endpoint will be passed in as endpoint.
|
||||||
/// Authenticates OPTIONS requests using the Authenticator.
|
/// Authenticates OPTIONS requests using the Authenticator.
|
||||||
pub fn options(e: *Endpoint, r: zap.Request) void {
|
pub fn options(e: *Endpoint, r: zap.Request) void {
|
||||||
const authEp: *Self = @fieldParentPtr(Self, "auth_endpoint", e);
|
const authEp: *Self = @fieldParentPtr("auth_endpoint", e);
|
||||||
switch (authEp.authenticator.authenticateRequest(&r)) {
|
switch (authEp.authenticator.authenticateRequest(&r)) {
|
||||||
.AuthFailed => {
|
.AuthFailed => {
|
||||||
if (e.settings.unauthorized) |unauthorized| {
|
if (e.settings.unauthorized) |unauthorized| {
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub fn EndpointHandler(comptime HandlerType: anytype, comptime ContextType: anyt
|
||||||
/// If `breakOnFinish` is `true`, the handler will stop handing requests down the chain if
|
/// If `breakOnFinish` is `true`, the handler will stop handing requests down the chain if
|
||||||
/// the endpoint processed the request.
|
/// the endpoint processed the request.
|
||||||
pub fn onRequest(handler: *HandlerType, r: zap.Request, context: *ContextType) bool {
|
pub fn onRequest(handler: *HandlerType, r: zap.Request, context: *ContextType) bool {
|
||||||
var self = @fieldParentPtr(Self, "handler", handler);
|
var self: Self = @fieldParentPtr("handler", handler);
|
||||||
r.setUserContext(context);
|
r.setUserContext(context);
|
||||||
self.endpoint.onRequest(r);
|
self.endpoint.onRequest(r);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub const Tls = @import("tls.zig");
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn get(e: *zap.Endpoint, r: zap.Request) void {
|
/// fn get(e: *zap.Endpoint, r: zap.Request) void {
|
||||||
/// const self: *StopEndpoint = @fieldParentPtr(StopEndpoint, "ep", e);
|
/// const self: *StopEndpoint = @fieldParentPtr("ep", e);
|
||||||
/// _ = self;
|
/// _ = self;
|
||||||
/// _ = r;
|
/// _ = r;
|
||||||
/// zap.stop();
|
/// zap.stop();
|
||||||
|
|
Loading…
Add table
Reference in a new issue