Skip to content

feat: Add authentication example demonstrating gotsrpc Context function#79

Open
quwe66 wants to merge 2 commits intomainfrom
feature/example-auth
Open

feat: Add authentication example demonstrating gotsrpc Context function#79
quwe66 wants to merge 2 commits intomainfrom
feature/example-auth

Conversation

@quwe66
Copy link
Member

@quwe66 quwe66 commented Oct 22, 2025

Overview

This PR adds a comprehensive authentication example that demonstrates gotsrpc's special Context function for centralized authentication.

Key Principle

The Context function handles all authentication logic, keeping service methods clean and focused on business logic:

  • Context function validates Authorization header once
  • Service methods remain clean without auth boilerplate
  • Single point of authentication for entire service

What's Included

  • 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 Added

  • example/auth/ - Complete authentication example
  • example/auth/README.md - Comprehensive documentation
  • example/auth/Makefile - Build automation
  • example/auth/main_test.go - Tests for Context function

How to Test

cd example/auth
make dev

Open http://localhost:8080 and test with accounts:

  • alice/password123
  • bob/secret456
  • admin/admin789

Benefits

This example showcases the core architectural pattern of using gotsrpc's Context function to centralize authentication while keeping service methods clean - a key value proposition of the framework.

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)
@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 2.55%. Comparing base (7e1298b) to head (5d68c02).

Additional details and impacted files
@@          Coverage Diff          @@
##            main     #79   +/-   ##
=====================================
  Coverage   2.55%   2.55%           
=====================================
  Files         23      23           
  Lines       2816    2816           
=====================================
  Hits          72      72           
  Misses      2734    2734           
  Partials      10      10           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants