feat: initial commit - kratos admin service
This commit is contained in:
Generated
+390
@@ -0,0 +1,390 @@
|
||||
// Code generated by protoc-gen-go-http. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-http v2.9.2
|
||||
// - protoc (unknown)
|
||||
// source: kratos/admin/v1/admin.proto
|
||||
|
||||
package v1
|
||||
|
||||
import (
|
||||
context "context"
|
||||
http "github.com/go-kratos/kratos/v3/transport/http"
|
||||
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the kratos package it is being compiled against.
|
||||
var _ = new(context.Context)
|
||||
|
||||
const _ = http.SupportPackageIsVersion3
|
||||
|
||||
const OperationAdminServiceCreateAdmin = "/kratos.admin.v1.AdminService/CreateAdmin"
|
||||
const OperationAdminServiceCurrent = "/kratos.admin.v1.AdminService/Current"
|
||||
const OperationAdminServiceDeleteAdmin = "/kratos.admin.v1.AdminService/DeleteAdmin"
|
||||
const OperationAdminServiceGetAdmin = "/kratos.admin.v1.AdminService/GetAdmin"
|
||||
const OperationAdminServiceListAdmins = "/kratos.admin.v1.AdminService/ListAdmins"
|
||||
const OperationAdminServiceLogin = "/kratos.admin.v1.AdminService/Login"
|
||||
const OperationAdminServiceLogout = "/kratos.admin.v1.AdminService/Logout"
|
||||
const OperationAdminServiceUpdateAdmin = "/kratos.admin.v1.AdminService/UpdateAdmin"
|
||||
|
||||
type AdminServiceHTTPServer interface {
|
||||
// CreateAdmin CreateAdmin creates a new admin.
|
||||
CreateAdmin(context.Context, *CreateAdminRequest) (*Admin, error)
|
||||
// Current Current returns the currently logged-in user.
|
||||
Current(context.Context, *emptypb.Empty) (*Admin, error)
|
||||
// DeleteAdmin DeleteAdmin deletes an admin by ID.
|
||||
DeleteAdmin(context.Context, *DeleteAdminRequest) (*emptypb.Empty, error)
|
||||
// GetAdmin GetAdmin retrieves an admin by ID.
|
||||
GetAdmin(context.Context, *GetAdminRequest) (*Admin, error)
|
||||
// ListAdmins ListAdmins returns a list of admins.
|
||||
ListAdmins(context.Context, *ListAdminsRequest) (*AdminSet, error)
|
||||
// Login Login a user and return the username.
|
||||
Login(context.Context, *LoginRequest) (*Admin, error)
|
||||
// Logout Logout the currently logged-in user.
|
||||
Logout(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
|
||||
// UpdateAdmin UpdateAdmin updates an existing admin.
|
||||
UpdateAdmin(context.Context, *UpdateAdminRequest) (*Admin, error)
|
||||
}
|
||||
|
||||
func RegisterAdminServiceHTTPServer(s *http.Server, srv AdminServiceHTTPServer) {
|
||||
r := s.Route("/")
|
||||
r.Handle("POST", "/v1/admins/login", _AdminService_Login0_HTTP_Handler(srv))
|
||||
r.Handle("POST", "/v1/admins/logout", _AdminService_Logout0_HTTP_Handler(srv))
|
||||
r.Handle("GET", "/v1/admins/current", _AdminService_Current0_HTTP_Handler(srv))
|
||||
r.Handle("GET", "/v1/admins/list", _AdminService_ListAdmins0_HTTP_Handler(srv))
|
||||
r.Handle("POST", "/v1/admins/create", _AdminService_CreateAdmin0_HTTP_Handler(srv))
|
||||
r.Handle("PUT", "/v1/admins/update", _AdminService_UpdateAdmin0_HTTP_Handler(srv))
|
||||
r.Handle("DELETE", "/v1/admins/{id}", _AdminService_DeleteAdmin0_HTTP_Handler(srv))
|
||||
r.Handle("GET", "/v1/admins/{id}", _AdminService_GetAdmin0_HTTP_Handler(srv))
|
||||
}
|
||||
|
||||
func _AdminService_Login0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in LoginRequest
|
||||
if err := ctx.Bind(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceLogin)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.Login(ctx, req.(*LoginRequest))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*Admin)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_Logout0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in emptypb.Empty
|
||||
if err := ctx.Bind(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceLogout)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.Logout(ctx, req.(*emptypb.Empty))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*emptypb.Empty)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_Current0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in emptypb.Empty
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceCurrent)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.Current(ctx, req.(*emptypb.Empty))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*Admin)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_ListAdmins0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in ListAdminsRequest
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceListAdmins)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.ListAdmins(ctx, req.(*ListAdminsRequest))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*AdminSet)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_CreateAdmin0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in CreateAdminRequest
|
||||
if err := ctx.Bind(&in.Admin); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceCreateAdmin)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.CreateAdmin(ctx, req.(*CreateAdminRequest))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*Admin)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_UpdateAdmin0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in UpdateAdminRequest
|
||||
if err := ctx.Bind(&in.Admin); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceUpdateAdmin)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.UpdateAdmin(ctx, req.(*UpdateAdminRequest))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*Admin)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_DeleteAdmin0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in DeleteAdminRequest
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.BindVars(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceDeleteAdmin)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.DeleteAdmin(ctx, req.(*DeleteAdminRequest))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*emptypb.Empty)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func _AdminService_GetAdmin0_HTTP_Handler(srv AdminServiceHTTPServer) func(ctx http.Context) error {
|
||||
return func(ctx http.Context) error {
|
||||
var in GetAdminRequest
|
||||
if err := ctx.BindQuery(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.BindVars(&in); err != nil {
|
||||
return err
|
||||
}
|
||||
http.SetOperation(ctx, OperationAdminServiceGetAdmin)
|
||||
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.GetAdmin(ctx, req.(*GetAdminRequest))
|
||||
})
|
||||
out, err := h(ctx, &in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
reply := out.(*Admin)
|
||||
return ctx.Result(200, reply)
|
||||
}
|
||||
}
|
||||
|
||||
type AdminServiceHTTPClient interface {
|
||||
// CreateAdmin CreateAdmin creates a new admin.
|
||||
CreateAdmin(ctx context.Context, req *CreateAdminRequest, opts ...http.CallOption) (rsp *Admin, err error)
|
||||
// Current Current returns the currently logged-in user.
|
||||
Current(ctx context.Context, req *emptypb.Empty, opts ...http.CallOption) (rsp *Admin, err error)
|
||||
// DeleteAdmin DeleteAdmin deletes an admin by ID.
|
||||
DeleteAdmin(ctx context.Context, req *DeleteAdminRequest, opts ...http.CallOption) (rsp *emptypb.Empty, err error)
|
||||
// GetAdmin GetAdmin retrieves an admin by ID.
|
||||
GetAdmin(ctx context.Context, req *GetAdminRequest, opts ...http.CallOption) (rsp *Admin, err error)
|
||||
// ListAdmins ListAdmins returns a list of admins.
|
||||
ListAdmins(ctx context.Context, req *ListAdminsRequest, opts ...http.CallOption) (rsp *AdminSet, err error)
|
||||
// Login Login a user and return the username.
|
||||
Login(ctx context.Context, req *LoginRequest, opts ...http.CallOption) (rsp *Admin, err error)
|
||||
// Logout Logout the currently logged-in user.
|
||||
Logout(ctx context.Context, req *emptypb.Empty, opts ...http.CallOption) (rsp *emptypb.Empty, err error)
|
||||
// UpdateAdmin UpdateAdmin updates an existing admin.
|
||||
UpdateAdmin(ctx context.Context, req *UpdateAdminRequest, opts ...http.CallOption) (rsp *Admin, err error)
|
||||
}
|
||||
|
||||
type AdminServiceHTTPClientImpl struct {
|
||||
cc *http.Client
|
||||
}
|
||||
|
||||
func NewAdminServiceHTTPClient(client *http.Client) AdminServiceHTTPClient {
|
||||
return &AdminServiceHTTPClientImpl{client}
|
||||
}
|
||||
|
||||
// CreateAdmin CreateAdmin creates a new admin.
|
||||
func (c *AdminServiceHTTPClientImpl) CreateAdmin(ctx context.Context, in *CreateAdminRequest, opts ...http.CallOption) (*Admin, error) {
|
||||
var out Admin
|
||||
pattern := "/v1/admins/create"
|
||||
path := http.BuildPath(pattern, in, http.WithQueryParams(), http.WithOmitFields("admin"))
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.ContentType("application/protojson"),
|
||||
http.Operation(OperationAdminServiceCreateAdmin),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "POST", path, in.Admin, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// Current Current returns the currently logged-in user.
|
||||
func (c *AdminServiceHTTPClientImpl) Current(ctx context.Context, in *emptypb.Empty, opts ...http.CallOption) (*Admin, error) {
|
||||
var out Admin
|
||||
pattern := "/v1/admins/current"
|
||||
path := http.BuildPath(pattern, in, http.WithQueryParams())
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.Operation(OperationAdminServiceCurrent),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// DeleteAdmin DeleteAdmin deletes an admin by ID.
|
||||
func (c *AdminServiceHTTPClientImpl) DeleteAdmin(ctx context.Context, in *DeleteAdminRequest, opts ...http.CallOption) (*emptypb.Empty, error) {
|
||||
var out emptypb.Empty
|
||||
pattern := "/v1/admins/{id}"
|
||||
path := http.BuildPath(pattern, in, http.WithQueryParams())
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.Operation(OperationAdminServiceDeleteAdmin),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// GetAdmin GetAdmin retrieves an admin by ID.
|
||||
func (c *AdminServiceHTTPClientImpl) GetAdmin(ctx context.Context, in *GetAdminRequest, opts ...http.CallOption) (*Admin, error) {
|
||||
var out Admin
|
||||
pattern := "/v1/admins/{id}"
|
||||
path := http.BuildPath(pattern, in, http.WithQueryParams())
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.Operation(OperationAdminServiceGetAdmin),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// ListAdmins ListAdmins returns a list of admins.
|
||||
func (c *AdminServiceHTTPClientImpl) ListAdmins(ctx context.Context, in *ListAdminsRequest, opts ...http.CallOption) (*AdminSet, error) {
|
||||
var out AdminSet
|
||||
pattern := "/v1/admins/list"
|
||||
path := http.BuildPath(pattern, in, http.WithQueryParams())
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.Operation(OperationAdminServiceListAdmins),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// Login Login a user and return the username.
|
||||
func (c *AdminServiceHTTPClientImpl) Login(ctx context.Context, in *LoginRequest, opts ...http.CallOption) (*Admin, error) {
|
||||
var out Admin
|
||||
pattern := "/v1/admins/login"
|
||||
path := http.BuildPath(pattern, in)
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.ContentType("application/protojson"),
|
||||
http.Operation(OperationAdminServiceLogin),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// Logout Logout the currently logged-in user.
|
||||
func (c *AdminServiceHTTPClientImpl) Logout(ctx context.Context, in *emptypb.Empty, opts ...http.CallOption) (*emptypb.Empty, error) {
|
||||
var out emptypb.Empty
|
||||
pattern := "/v1/admins/logout"
|
||||
path := http.BuildPath(pattern, in)
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.ContentType("application/protojson"),
|
||||
http.Operation(OperationAdminServiceLogout),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "POST", path, in, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
// UpdateAdmin UpdateAdmin updates an existing admin.
|
||||
func (c *AdminServiceHTTPClientImpl) UpdateAdmin(ctx context.Context, in *UpdateAdminRequest, opts ...http.CallOption) (*Admin, error) {
|
||||
var out Admin
|
||||
pattern := "/v1/admins/update"
|
||||
path := http.BuildPath(pattern, in, http.WithQueryParams(), http.WithOmitFields("admin"))
|
||||
opts = append([]http.CallOption{
|
||||
http.Accept("application/protojson"),
|
||||
http.ContentType("application/protojson"),
|
||||
http.Operation(OperationAdminServiceUpdateAdmin),
|
||||
http.PathTemplate(pattern),
|
||||
}, opts...)
|
||||
err := c.cc.Invoke(ctx, "PUT", path, in.Admin, &out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user