mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 10:54:28 +00:00
replace users with user (#113)
This commit is contained in:
@@ -8,15 +8,15 @@ init:
|
||||
go get github.com/micro/micro/v3/cmd/protoc-gen-openapi
|
||||
.PHONY: proto
|
||||
proto:
|
||||
protoc --proto_path=. --micro_out=. --go_out=:. proto/users.proto
|
||||
protoc --proto_path=. --micro_out=. --go_out=:. proto/user.proto
|
||||
|
||||
.PHONY: api
|
||||
api:
|
||||
protoc --openapi_out=. --proto_path=. proto/users.proto
|
||||
protoc --openapi_out=. --proto_path=. proto/user.proto
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
go build -o users *.go
|
||||
go build -o user *.go
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
@@ -24,4 +24,4 @@ test:
|
||||
|
||||
.PHONY: docker
|
||||
docker:
|
||||
docker build . -t users:latest
|
||||
docker build . -t user:latest
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
user "github.com/micro/services/users/proto"
|
||||
"github.com/micro/micro/v3/service/model"
|
||||
user "github.com/micro/services/user/proto"
|
||||
)
|
||||
|
||||
type pw struct {
|
||||
@@ -15,7 +15,7 @@ type pw struct {
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
users model.Model
|
||||
user model.Model
|
||||
sessions model.Model
|
||||
passwords model.Model
|
||||
|
||||
@@ -39,7 +39,7 @@ func New() *Domain {
|
||||
idIndex.Order.Type = model.OrderTypeUnordered
|
||||
|
||||
return &Domain{
|
||||
users: model.New(user.User{}, &model.Options{
|
||||
user: model.New(user.Account{}, &model.Options{
|
||||
Indexes: []model.Index{nameIndex, emailIndex},
|
||||
}),
|
||||
sessions: model.New(user.Session{}, nil),
|
||||
@@ -72,10 +72,10 @@ func (domain *Domain) ReadSession(id string) (*user.Session, error) {
|
||||
return sess, domain.sessions.Read(domain.idIndex.ToQuery(id), &sess)
|
||||
}
|
||||
|
||||
func (domain *Domain) Create(user *user.User, salt string, password string) error {
|
||||
func (domain *Domain) Create(user *user.Account, salt string, password string) error {
|
||||
user.Created = time.Now().Unix()
|
||||
user.Updated = time.Now().Unix()
|
||||
err := domain.users.Create(user)
|
||||
err := domain.user.Create(user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -87,20 +87,20 @@ func (domain *Domain) Create(user *user.User, salt string, password string) erro
|
||||
}
|
||||
|
||||
func (domain *Domain) Delete(id string) error {
|
||||
return domain.users.Delete(domain.idIndex.ToQuery(id))
|
||||
return domain.user.Delete(domain.idIndex.ToQuery(id))
|
||||
}
|
||||
|
||||
func (domain *Domain) Update(user *user.User) error {
|
||||
func (domain *Domain) Update(user *user.Account) error {
|
||||
user.Updated = time.Now().Unix()
|
||||
return domain.users.Create(user)
|
||||
return domain.user.Create(user)
|
||||
}
|
||||
|
||||
func (domain *Domain) Read(id string) (*user.User, error) {
|
||||
user := &user.User{}
|
||||
return user, domain.users.Read(domain.idIndex.ToQuery(id), user)
|
||||
func (domain *Domain) Read(id string) (*user.Account, error) {
|
||||
user := &user.Account{}
|
||||
return user, domain.user.Read(domain.idIndex.ToQuery(id), user)
|
||||
}
|
||||
|
||||
func (domain *Domain) Search(username, email string, limit, offset int64) ([]*user.User, error) {
|
||||
func (domain *Domain) Search(username, email string, limit, offset int64) ([]*user.Account, error) {
|
||||
var query model.Query
|
||||
if len(username) > 0 {
|
||||
query = domain.nameIndex.ToQuery(username)
|
||||
@@ -110,8 +110,8 @@ func (domain *Domain) Search(username, email string, limit, offset int64) ([]*us
|
||||
return nil, errors.New("username and email cannot be blank")
|
||||
}
|
||||
|
||||
users := []*user.User{}
|
||||
return users, domain.users.Read(query, &users)
|
||||
user := []*user.Account{}
|
||||
return user, domain.user.Read(query, &user)
|
||||
}
|
||||
|
||||
func (domain *Domain) UpdatePassword(id string, salt string, password string) error {
|
||||
@@ -132,8 +132,8 @@ func (domain *Domain) SaltAndPassword(username, email string) (string, string, e
|
||||
return "", "", errors.New("username and email cannot be blank")
|
||||
}
|
||||
|
||||
user := &user.User{}
|
||||
err := domain.users.Read(query, &user)
|
||||
user := &user.Account{}
|
||||
err := domain.user.Read(query, &user)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/micro/services/users/domain"
|
||||
pb "github.com/micro/services/users/proto"
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/services/user/domain"
|
||||
pb "github.com/micro/services/user/proto"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@@ -33,101 +33,101 @@ func random(i int) string {
|
||||
return "ughwhy?!!!"
|
||||
}
|
||||
|
||||
type Users struct {
|
||||
type User struct {
|
||||
domain *domain.Domain
|
||||
}
|
||||
|
||||
func NewUsers() *Users {
|
||||
return &Users{
|
||||
func NewUser() *User {
|
||||
return &User{
|
||||
domain: domain.New(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Users) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error {
|
||||
func (s *User) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error {
|
||||
if len(req.Password) < 8 {
|
||||
return errors.InternalServerError("users.Create.Check", "Password is less than 8 characters")
|
||||
return errors.InternalServerError("user.Create.Check", "Password is less than 8 characters")
|
||||
}
|
||||
salt := random(16)
|
||||
h, err := bcrypt.GenerateFromPassword([]byte(x+salt+req.Password), 10)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("users.Create", err.Error())
|
||||
return errors.InternalServerError("user.Create", err.Error())
|
||||
}
|
||||
pp := base64.StdEncoding.EncodeToString(h)
|
||||
|
||||
return s.domain.Create(&pb.User{
|
||||
return s.domain.Create(&pb.Account{
|
||||
Id: req.Id,
|
||||
Username: strings.ToLower(req.Username),
|
||||
Email: strings.ToLower(req.Email),
|
||||
}, salt, pp)
|
||||
}
|
||||
|
||||
func (s *Users) Read(ctx context.Context, req *pb.ReadRequest, rsp *pb.ReadResponse) error {
|
||||
user, err := s.domain.Read(req.Id)
|
||||
func (s *User) Read(ctx context.Context, req *pb.ReadRequest, rsp *pb.ReadResponse) error {
|
||||
account, err := s.domain.Read(req.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rsp.User = user
|
||||
rsp.Account = account
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Users) Update(ctx context.Context, req *pb.UpdateRequest, rsp *pb.UpdateResponse) error {
|
||||
return s.domain.Update(&pb.User{
|
||||
func (s *User) Update(ctx context.Context, req *pb.UpdateRequest, rsp *pb.UpdateResponse) error {
|
||||
return s.domain.Update(&pb.Account{
|
||||
Id: req.Id,
|
||||
Username: strings.ToLower(req.Username),
|
||||
Email: strings.ToLower(req.Email),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Users) Delete(ctx context.Context, req *pb.DeleteRequest, rsp *pb.DeleteResponse) error {
|
||||
func (s *User) Delete(ctx context.Context, req *pb.DeleteRequest, rsp *pb.DeleteResponse) error {
|
||||
return s.domain.Delete(req.Id)
|
||||
}
|
||||
|
||||
func (s *Users) Search(ctx context.Context, req *pb.SearchRequest, rsp *pb.SearchResponse) error {
|
||||
users, err := s.domain.Search(req.Username, req.Email, req.Limit, req.Offset)
|
||||
func (s *User) Search(ctx context.Context, req *pb.SearchRequest, rsp *pb.SearchResponse) error {
|
||||
accounts, err := s.domain.Search(req.Username, req.Email, req.Limit, req.Offset)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rsp.Users = users
|
||||
rsp.Accounts = accounts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Users) UpdatePassword(ctx context.Context, req *pb.UpdatePasswordRequest, rsp *pb.UpdatePasswordResponse) error {
|
||||
func (s *User) UpdatePassword(ctx context.Context, req *pb.UpdatePasswordRequest, rsp *pb.UpdatePasswordResponse) error {
|
||||
usr, err := s.domain.Read(req.UserId)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("users.updatepassword", err.Error())
|
||||
return errors.InternalServerError("user.updatepassword", err.Error())
|
||||
}
|
||||
if req.NewPassword != req.ConfirmPassword {
|
||||
return errors.InternalServerError("users.updatepassword", "Passwords don't math")
|
||||
return errors.InternalServerError("user.updatepassword", "Passwords don't math")
|
||||
}
|
||||
|
||||
salt, hashed, err := s.domain.SaltAndPassword(usr.Username, usr.Email)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("users.updatepassword", err.Error())
|
||||
return errors.InternalServerError("user.updatepassword", err.Error())
|
||||
}
|
||||
|
||||
hh, err := base64.StdEncoding.DecodeString(hashed)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("users.updatepassword", err.Error())
|
||||
return errors.InternalServerError("user.updatepassword", err.Error())
|
||||
}
|
||||
|
||||
if err := bcrypt.CompareHashAndPassword(hh, []byte(x+salt+req.OldPassword)); err != nil {
|
||||
return errors.Unauthorized("users.updatepassword", err.Error())
|
||||
return errors.Unauthorized("user.updatepassword", err.Error())
|
||||
}
|
||||
|
||||
salt = random(16)
|
||||
h, err := bcrypt.GenerateFromPassword([]byte(x+salt+req.NewPassword), 10)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("users.updatepassword", err.Error())
|
||||
return errors.InternalServerError("user.updatepassword", err.Error())
|
||||
}
|
||||
pp := base64.StdEncoding.EncodeToString(h)
|
||||
|
||||
if err := s.domain.UpdatePassword(req.UserId, salt, pp); err != nil {
|
||||
return errors.InternalServerError("users.updatepassword", err.Error())
|
||||
return errors.InternalServerError("user.updatepassword", err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Users) Login(ctx context.Context, req *pb.LoginRequest, rsp *pb.LoginResponse) error {
|
||||
func (s *User) Login(ctx context.Context, req *pb.LoginRequest, rsp *pb.LoginResponse) error {
|
||||
username := strings.ToLower(req.Username)
|
||||
email := strings.ToLower(req.Email)
|
||||
|
||||
@@ -138,11 +138,11 @@ func (s *Users) Login(ctx context.Context, req *pb.LoginRequest, rsp *pb.LoginRe
|
||||
|
||||
hh, err := base64.StdEncoding.DecodeString(hashed)
|
||||
if err != nil {
|
||||
return errors.InternalServerError("users.Login", err.Error())
|
||||
return errors.InternalServerError("user.Login", err.Error())
|
||||
}
|
||||
|
||||
if err := bcrypt.CompareHashAndPassword(hh, []byte(x+salt+req.Password)); err != nil {
|
||||
return errors.Unauthorized("users.login", err.Error())
|
||||
return errors.Unauthorized("user.login", err.Error())
|
||||
}
|
||||
// save session
|
||||
sess := &pb.Session{
|
||||
@@ -154,17 +154,17 @@ func (s *Users) Login(ctx context.Context, req *pb.LoginRequest, rsp *pb.LoginRe
|
||||
}
|
||||
|
||||
if err := s.domain.CreateSession(sess); err != nil {
|
||||
return errors.InternalServerError("users.Login", err.Error())
|
||||
return errors.InternalServerError("user.Login", err.Error())
|
||||
}
|
||||
rsp.Session = sess
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Users) Logout(ctx context.Context, req *pb.LogoutRequest, rsp *pb.LogoutResponse) error {
|
||||
func (s *User) Logout(ctx context.Context, req *pb.LogoutRequest, rsp *pb.LogoutResponse) error {
|
||||
return s.domain.DeleteSession(req.SessionId)
|
||||
}
|
||||
|
||||
func (s *Users) ReadSession(ctx context.Context, req *pb.ReadSessionRequest, rsp *pb.ReadSessionResponse) error {
|
||||
func (s *User) ReadSession(ctx context.Context, req *pb.ReadSessionRequest, rsp *pb.ReadSessionResponse) error {
|
||||
sess, err := s.domain.ReadSession(req.SessionId)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1,20 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/micro/services/users/handler"
|
||||
proto "github.com/micro/services/users/proto"
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
"github.com/micro/services/user/handler"
|
||||
proto "github.com/micro/services/user/proto"
|
||||
)
|
||||
|
||||
func main() {
|
||||
service := service.New(
|
||||
service.Name("users"),
|
||||
service.Name("user"),
|
||||
)
|
||||
|
||||
service.Init()
|
||||
|
||||
proto.RegisterUsersHandler(service.Server(), handler.NewUsers())
|
||||
proto.RegisterUserHandler(service.Server(), handler.NewUser())
|
||||
|
||||
if err := service.Run(); err != nil {
|
||||
logger.Fatal(err)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-micro. DO NOT EDIT.
|
||||
// source: proto/users.proto
|
||||
// source: proto/user.proto
|
||||
|
||||
package users
|
||||
package user
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
@@ -33,15 +33,15 @@ var _ context.Context
|
||||
var _ client.Option
|
||||
var _ server.Option
|
||||
|
||||
// Api Endpoints for Users service
|
||||
// Api Endpoints for User service
|
||||
|
||||
func NewUsersEndpoints() []*api.Endpoint {
|
||||
func NewUserEndpoints() []*api.Endpoint {
|
||||
return []*api.Endpoint{}
|
||||
}
|
||||
|
||||
// Client API for Users service
|
||||
// Client API for User service
|
||||
|
||||
type UsersService interface {
|
||||
type UserService interface {
|
||||
Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error)
|
||||
Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error)
|
||||
Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error)
|
||||
@@ -53,20 +53,20 @@ type UsersService interface {
|
||||
ReadSession(ctx context.Context, in *ReadSessionRequest, opts ...client.CallOption) (*ReadSessionResponse, error)
|
||||
}
|
||||
|
||||
type usersService struct {
|
||||
type userService struct {
|
||||
c client.Client
|
||||
name string
|
||||
}
|
||||
|
||||
func NewUsersService(name string, c client.Client) UsersService {
|
||||
return &usersService{
|
||||
func NewUserService(name string, c client.Client) UserService {
|
||||
return &userService{
|
||||
c: c,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *usersService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Create", in)
|
||||
func (c *userService) Create(ctx context.Context, in *CreateRequest, opts ...client.CallOption) (*CreateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Create", in)
|
||||
out := new(CreateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -75,8 +75,8 @@ func (c *usersService) Create(ctx context.Context, in *CreateRequest, opts ...cl
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Read", in)
|
||||
func (c *userService) Read(ctx context.Context, in *ReadRequest, opts ...client.CallOption) (*ReadResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Read", in)
|
||||
out := new(ReadResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -85,8 +85,8 @@ func (c *usersService) Read(ctx context.Context, in *ReadRequest, opts ...client
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Update", in)
|
||||
func (c *userService) Update(ctx context.Context, in *UpdateRequest, opts ...client.CallOption) (*UpdateResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Update", in)
|
||||
out := new(UpdateResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -95,8 +95,8 @@ func (c *usersService) Update(ctx context.Context, in *UpdateRequest, opts ...cl
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Delete", in)
|
||||
func (c *userService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Delete", in)
|
||||
out := new(DeleteResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -105,8 +105,8 @@ func (c *usersService) Delete(ctx context.Context, in *DeleteRequest, opts ...cl
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Search", in)
|
||||
func (c *userService) Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Search", in)
|
||||
out := new(SearchResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -115,8 +115,8 @@ func (c *usersService) Search(ctx context.Context, in *SearchRequest, opts ...cl
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) UpdatePassword(ctx context.Context, in *UpdatePasswordRequest, opts ...client.CallOption) (*UpdatePasswordResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.UpdatePassword", in)
|
||||
func (c *userService) UpdatePassword(ctx context.Context, in *UpdatePasswordRequest, opts ...client.CallOption) (*UpdatePasswordResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.UpdatePassword", in)
|
||||
out := new(UpdatePasswordResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -125,8 +125,8 @@ func (c *usersService) UpdatePassword(ctx context.Context, in *UpdatePasswordReq
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Login", in)
|
||||
func (c *userService) Login(ctx context.Context, in *LoginRequest, opts ...client.CallOption) (*LoginResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Login", in)
|
||||
out := new(LoginResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -135,8 +135,8 @@ func (c *usersService) Login(ctx context.Context, in *LoginRequest, opts ...clie
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) Logout(ctx context.Context, in *LogoutRequest, opts ...client.CallOption) (*LogoutResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.Logout", in)
|
||||
func (c *userService) Logout(ctx context.Context, in *LogoutRequest, opts ...client.CallOption) (*LogoutResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.Logout", in)
|
||||
out := new(LogoutResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -145,8 +145,8 @@ func (c *usersService) Logout(ctx context.Context, in *LogoutRequest, opts ...cl
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *usersService) ReadSession(ctx context.Context, in *ReadSessionRequest, opts ...client.CallOption) (*ReadSessionResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "Users.ReadSession", in)
|
||||
func (c *userService) ReadSession(ctx context.Context, in *ReadSessionRequest, opts ...client.CallOption) (*ReadSessionResponse, error) {
|
||||
req := c.c.NewRequest(c.name, "User.ReadSession", in)
|
||||
out := new(ReadSessionResponse)
|
||||
err := c.c.Call(ctx, req, out, opts...)
|
||||
if err != nil {
|
||||
@@ -155,9 +155,9 @@ func (c *usersService) ReadSession(ctx context.Context, in *ReadSessionRequest,
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Server API for Users service
|
||||
// Server API for User service
|
||||
|
||||
type UsersHandler interface {
|
||||
type UserHandler interface {
|
||||
Create(context.Context, *CreateRequest, *CreateResponse) error
|
||||
Read(context.Context, *ReadRequest, *ReadResponse) error
|
||||
Update(context.Context, *UpdateRequest, *UpdateResponse) error
|
||||
@@ -169,8 +169,8 @@ type UsersHandler interface {
|
||||
ReadSession(context.Context, *ReadSessionRequest, *ReadSessionResponse) error
|
||||
}
|
||||
|
||||
func RegisterUsersHandler(s server.Server, hdlr UsersHandler, opts ...server.HandlerOption) error {
|
||||
type users interface {
|
||||
func RegisterUserHandler(s server.Server, hdlr UserHandler, opts ...server.HandlerOption) error {
|
||||
type user interface {
|
||||
Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error
|
||||
Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error
|
||||
Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error
|
||||
@@ -181,49 +181,49 @@ func RegisterUsersHandler(s server.Server, hdlr UsersHandler, opts ...server.Han
|
||||
Logout(ctx context.Context, in *LogoutRequest, out *LogoutResponse) error
|
||||
ReadSession(ctx context.Context, in *ReadSessionRequest, out *ReadSessionResponse) error
|
||||
}
|
||||
type Users struct {
|
||||
users
|
||||
type User struct {
|
||||
user
|
||||
}
|
||||
h := &usersHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&Users{h}, opts...))
|
||||
h := &userHandler{hdlr}
|
||||
return s.Handle(s.NewHandler(&User{h}, opts...))
|
||||
}
|
||||
|
||||
type usersHandler struct {
|
||||
UsersHandler
|
||||
type userHandler struct {
|
||||
UserHandler
|
||||
}
|
||||
|
||||
func (h *usersHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error {
|
||||
return h.UsersHandler.Create(ctx, in, out)
|
||||
func (h *userHandler) Create(ctx context.Context, in *CreateRequest, out *CreateResponse) error {
|
||||
return h.UserHandler.Create(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error {
|
||||
return h.UsersHandler.Read(ctx, in, out)
|
||||
func (h *userHandler) Read(ctx context.Context, in *ReadRequest, out *ReadResponse) error {
|
||||
return h.UserHandler.Read(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error {
|
||||
return h.UsersHandler.Update(ctx, in, out)
|
||||
func (h *userHandler) Update(ctx context.Context, in *UpdateRequest, out *UpdateResponse) error {
|
||||
return h.UserHandler.Update(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
|
||||
return h.UsersHandler.Delete(ctx, in, out)
|
||||
func (h *userHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error {
|
||||
return h.UserHandler.Delete(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error {
|
||||
return h.UsersHandler.Search(ctx, in, out)
|
||||
func (h *userHandler) Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error {
|
||||
return h.UserHandler.Search(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) UpdatePassword(ctx context.Context, in *UpdatePasswordRequest, out *UpdatePasswordResponse) error {
|
||||
return h.UsersHandler.UpdatePassword(ctx, in, out)
|
||||
func (h *userHandler) UpdatePassword(ctx context.Context, in *UpdatePasswordRequest, out *UpdatePasswordResponse) error {
|
||||
return h.UserHandler.UpdatePassword(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) Login(ctx context.Context, in *LoginRequest, out *LoginResponse) error {
|
||||
return h.UsersHandler.Login(ctx, in, out)
|
||||
func (h *userHandler) Login(ctx context.Context, in *LoginRequest, out *LoginResponse) error {
|
||||
return h.UserHandler.Login(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) Logout(ctx context.Context, in *LogoutRequest, out *LogoutResponse) error {
|
||||
return h.UsersHandler.Logout(ctx, in, out)
|
||||
func (h *userHandler) Logout(ctx context.Context, in *LogoutRequest, out *LogoutResponse) error {
|
||||
return h.UserHandler.Logout(ctx, in, out)
|
||||
}
|
||||
|
||||
func (h *usersHandler) ReadSession(ctx context.Context, in *ReadSessionRequest, out *ReadSessionResponse) error {
|
||||
return h.UsersHandler.ReadSession(ctx, in, out)
|
||||
func (h *userHandler) ReadSession(ctx context.Context, in *ReadSessionRequest, out *ReadSessionResponse) error {
|
||||
return h.UserHandler.ReadSession(ctx, in, out)
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package users;
|
||||
package user;
|
||||
|
||||
option go_package = "./proto;users";
|
||||
option go_package = "./proto;user";
|
||||
|
||||
service Users {
|
||||
service User {
|
||||
rpc Create(CreateRequest) returns (CreateResponse) {}
|
||||
rpc Read(ReadRequest) returns (ReadResponse) {}
|
||||
rpc Update(UpdateRequest) returns (UpdateResponse) {}
|
||||
@@ -16,66 +16,95 @@ service Users {
|
||||
rpc ReadSession(ReadSessionRequest) returns(ReadSessionResponse) {}
|
||||
}
|
||||
|
||||
message User {
|
||||
string id = 1; // uuid
|
||||
string username = 2; // alphanumeric user or org
|
||||
message Account {
|
||||
// unique account id
|
||||
string id = 1;
|
||||
// alphanumeric username
|
||||
string username = 2;
|
||||
// an email address
|
||||
string email = 3;
|
||||
int64 created = 4; // unix
|
||||
int64 updated = 5; // unix
|
||||
// unix timestamp
|
||||
int64 created = 4;
|
||||
// unix timestamp
|
||||
int64 updated = 5;
|
||||
}
|
||||
|
||||
message Session {
|
||||
string id = 1;
|
||||
string username = 2;
|
||||
// the session id
|
||||
string id = 1;
|
||||
// account username
|
||||
string username = 2;
|
||||
// account email
|
||||
string email = 3;
|
||||
int64 created = 4; // unix
|
||||
int64 expires = 5; // unix
|
||||
// unix timestamp
|
||||
int64 created = 4;
|
||||
// unix timestamp
|
||||
int64 expires = 5;
|
||||
}
|
||||
|
||||
// Create a new user account
|
||||
message CreateRequest {
|
||||
string id = 1; // uuid
|
||||
string username = 2; // alphanumeric user or org
|
||||
// the acccount id
|
||||
string id = 1;
|
||||
// the username
|
||||
string username = 2;
|
||||
// the email address
|
||||
string email = 3;
|
||||
string password = 4;
|
||||
// the user password
|
||||
string password = 4;
|
||||
}
|
||||
|
||||
message CreateResponse {
|
||||
}
|
||||
|
||||
// Delete an account by id
|
||||
message DeleteRequest {
|
||||
// the account id
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message DeleteResponse {
|
||||
}
|
||||
|
||||
// Read an account by id
|
||||
message ReadRequest {
|
||||
// the account id
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message ReadResponse {
|
||||
User user = 1;
|
||||
Account account = 1;
|
||||
}
|
||||
|
||||
// Update the account username or email
|
||||
message UpdateRequest {
|
||||
string id = 1; // uuid
|
||||
string username = 2; // alphanumeric user or org
|
||||
// the account id
|
||||
string id = 1;
|
||||
// the new username
|
||||
string username = 2;
|
||||
// the new email address
|
||||
string email = 3;
|
||||
}
|
||||
|
||||
message UpdateResponse {
|
||||
}
|
||||
|
||||
// Update the account password
|
||||
message UpdatePasswordRequest {
|
||||
string userId = 1;
|
||||
string oldPassword = 2;
|
||||
string newPassword = 3;
|
||||
string confirm_password = 4;
|
||||
// the account id
|
||||
string userId = 1;
|
||||
// the old password
|
||||
string oldPassword = 2;
|
||||
// the new password
|
||||
string newPassword = 3;
|
||||
// confirm new password
|
||||
string confirm_password = 4;
|
||||
}
|
||||
|
||||
message UpdatePasswordResponse {
|
||||
}
|
||||
|
||||
// Search for an account
|
||||
message SearchRequest {
|
||||
string username = 1;
|
||||
string email = 2;
|
||||
@@ -84,9 +113,10 @@ message SearchRequest {
|
||||
}
|
||||
|
||||
message SearchResponse {
|
||||
repeated User users = 1;
|
||||
repeated Account accounts = 1;
|
||||
}
|
||||
|
||||
// Read a session by id
|
||||
message ReadSessionRequest {
|
||||
string sessionId = 1;
|
||||
}
|
||||
@@ -95,6 +125,8 @@ message ReadSessionResponse {
|
||||
Session session = 1;
|
||||
}
|
||||
|
||||
|
||||
// Login a user account
|
||||
message LoginRequest {
|
||||
string username = 1;
|
||||
string email = 2;
|
||||
@@ -105,6 +137,7 @@ message LoginResponse {
|
||||
Session session = 1;
|
||||
}
|
||||
|
||||
// Logout a user account
|
||||
message LogoutRequest {
|
||||
string sessionId = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user