kratos + react + admin
Go to file
Yvan b63a296144 任务三 2026-01-07 11:04:29 +08:00
api/kratos/admin/v1 init 2026-01-06 12:20:42 +08:00
cmd/gen 任务三 2026-01-07 11:03:52 +08:00
configs 任务一完成 2026-01-07 10:20:55 +08:00
internal 任务三 2026-01-07 11:04:29 +08:00
pkg 任务二完成 2026-01-07 10:35:49 +08:00
third_party init 2026-01-06 12:20:42 +08:00
web init 2026-01-06 12:20:42 +08:00
.gitignore init 2026-01-06 12:25:15 +08:00
Dockerfile init 2026-01-06 12:20:42 +08:00
LICENSE init 2026-01-06 12:20:42 +08:00
Makefile init 2026-01-06 12:20:42 +08:00
README.md init 2026-01-06 12:20:42 +08:00
go.mod 任务一完成 2026-01-07 10:13:35 +08:00
go.sum 任务一完成 2026-01-07 10:13:35 +08:00
openapi.yaml init 2026-01-06 12:20:42 +08:00

README.md

Kratos Admin Template

Best Practice

Google AIP(https://google.aip.dev/general):

  1. Resource-oriented design
  2. Filtering
  3. Pagination
  4. Field masks
  5. Field behavior

Generate API files

# Download and update dependencies
make init
# Generate API files (include: pb.go, http, grpc, validate, swagger, index.ts) by proto file
make api

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);
  }
};