Files
gotsrpc/example/auth/client/src/client_gen.ts
Uwe Quitter 5d68c02535 feat: Add authentication example demonstrating gotsrpc Context function
This example showcases gotsrpc's special Context function for centralized
authentication. The Context function handles all authentication logic,
keeping service methods clean and focused on business logic.

Key principle: Centralized authentication via Context function
- Context function validates Authorization header once
- Service methods remain clean without auth boilerplate
- Single point of authentication for entire service

Example includes:
- AuthService: Login/logout operations
- HelloService: Demonstrates Context function pattern
- Complete build system with Makefile
- TypeScript client with proper ES6 modules
- Comprehensive tests and documentation

Files: example/auth/ (complete authentication example)
2025-10-22 16:07:17 +02:00

38 lines
2.0 KiB
TypeScript

/* eslint:disable */
// Code generated by gotsrpc https://github.com/foomo/gotsrpc/v2 - DO NOT EDIT.
import * as github_com_foomo_gotsrpc_v2_example_auth_service from './vo_gen'; // ./client/src/client_gen.ts to ./client/src/vo_gen.ts
export class HelloServiceClient {
public static defaultEndpoint = "/hello";
constructor(
public transport:<T>(method: string, data?: any[]) => Promise<T>
) {}
async context():Promise<void> {
await this.transport<void>("Context", [])
}
async getUserInfo():Promise<{ret:github_com_foomo_gotsrpc_v2_example_auth_service.User; ret_1:error}> {
const response = await this.transport<{0:github_com_foomo_gotsrpc_v2_example_auth_service.User; 1:error}>("GetUserInfo", [])
return {ret : response[0], ret_1 : response[1]};
}
async sayHello(req:github_com_foomo_gotsrpc_v2_example_auth_service.HelloRequest):Promise<{ret:github_com_foomo_gotsrpc_v2_example_auth_service.HelloResponse; ret_1:error}> {
const response = await this.transport<{0:github_com_foomo_gotsrpc_v2_example_auth_service.HelloResponse; 1:error}>("SayHello", [req])
return {ret : response[0], ret_1 : response[1]};
}
}
export class AuthServiceClient {
public static defaultEndpoint = "/auth";
constructor(
public transport:<T>(method: string, data?: any[]) => Promise<T>
) {}
async login(req:github_com_foomo_gotsrpc_v2_example_auth_service.LoginRequest):Promise<{ret:github_com_foomo_gotsrpc_v2_example_auth_service.LoginResponse; ret_1:error}> {
const response = await this.transport<{0:github_com_foomo_gotsrpc_v2_example_auth_service.LoginResponse; 1:error}>("Login", [req])
return {ret : response[0], ret_1 : response[1]};
}
async logout(token:string):Promise<error> {
return (await this.transport<{0:error}>("Logout", [token]))[0]
}
async validateToken(token:string):Promise<{ret:github_com_foomo_gotsrpc_v2_example_auth_service.User; ret_1:error}> {
const response = await this.transport<{0:github_com_foomo_gotsrpc_v2_example_auth_service.User; 1:error}>("ValidateToken", [token])
return {ret : response[0], ret_1 : response[1]};
}
}