|
|
||
|---|---|---|
| .codegraph | ||
| api/kratos/admin/v1 | ||
| configs | ||
| docs | ||
| gva@02f3783325 | ||
| internal | ||
| pkg | ||
| web | ||
| .gitattributes | ||
| .gitignore | ||
| AGENTS.md | ||
| CLAUDE.md | ||
| Dockerfile | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
| buf.gen.config.yaml | ||
| buf.gen.yaml | ||
| buf.lock | ||
| buf.yaml | ||
| go.mod | ||
| go.sum | ||
| openapi.yaml | ||
README.md
Kratos Admin Template
Best Practice
Google AIP(https://google.aip.dev/general):
- Resource-oriented design
- Filtering
- Pagination
- Field masks
- Field behavior
Generate API files
Proto generation is driven by buf. Dependencies such as
googleapis are resolved from the Buf Schema Registry (buf.build/googleapis/googleapis),
so there is no vendored third_party/ directory.
# Install tooling (buf + wire)
make init
# Generate API files (pb.go, grpc, kratos http, openapi.yaml, web TS clients) from api/*.proto
make api
# Generate internal config (internal/conf/conf.pb.go) from internal/*.proto
make config
Run Web Application
# Enter web directory, install dependencies and start development server
cd web
npm install
npm run dev
The generated clients work with any Promise-based HTTP client that returns JSON.
Services are defined and re-exported from this file: web/src/services/index.ts.
import { createAdminServiceClient } from "@/services/kratos/admin/v1/index";
type Request = {
path: string;
method: string;
body: string | null;
};
function requestHandler({ path, method, body }: Request) { ... }
export function createAdminService() {
return createAdminServiceClient(requestHandler);
}
Example using the generated client:
import { createAdminService } from "@/services/index";
const adminService = createAdminService();
const handleLogin = async (username: string, password: string) => {
try {
const response = await adminService.Login({
username: username,
password: password,
});
console.log("Login successful:", response);
} catch (error) {
console.error("Login failed:", error);
}
};