-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
343 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Name: user_center-api | ||
Host: 0.0.0.0 | ||
Port: 8888 | ||
|
||
user_center: | ||
Etcd: | ||
Hosts: | ||
- localhost:2379 | ||
Key: usercenter.rpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/zeromicro/go-zero/rest" | ||
"github.com/zeromicro/go-zero/zrpc" | ||
) | ||
|
||
type Config struct { | ||
rest.RestConf | ||
UserCenter zrpc.RpcClientConf | ||
} |
28 changes: 28 additions & 0 deletions
28
service/user_center/api/internal/handler/create_user_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/linehk/go-blogger/service/user_center/api/internal/logic" | ||
"github.com/linehk/go-blogger/service/user_center/api/internal/svc" | ||
"github.com/linehk/go-blogger/service/user_center/api/internal/types" | ||
"github.com/zeromicro/go-zero/rest/httpx" | ||
) | ||
|
||
func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.CreateUserRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
return | ||
} | ||
|
||
l := logic.NewCreateUserLogic(r.Context(), svcCtx) | ||
err := l.CreateUser(&req) | ||
if err != nil { | ||
httpx.ErrorCtx(r.Context(), w, err) | ||
} else { | ||
httpx.Ok(w) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
service/user_center/api/internal/logic/create_user_logic.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package logic | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/linehk/go-blogger/service/user_center/api/internal/svc" | ||
"github.com/linehk/go-blogger/service/user_center/api/internal/types" | ||
"github.com/linehk/go-blogger/service/user_center/rpc/user_center" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type CreateUserLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic { | ||
return &CreateUserLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *CreateUserLogic) CreateUser(req *types.CreateUserRequest) error { | ||
_, err := l.svcCtx.UserCenter.CreateUser(l.ctx, &user_center.CreateUserRequest{ | ||
Username: req.Username, | ||
Password: req.Password, | ||
Email: req.Email, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package svc | ||
|
||
import ( | ||
"github.com/linehk/go-blogger/service/user_center/api/internal/config" | ||
"github.com/linehk/go-blogger/service/user_center/rpc/user_center_client" | ||
"github.com/zeromicro/go-zero/zrpc" | ||
) | ||
|
||
type ServiceContext struct { | ||
Config config.Config | ||
UserCenter user_center_client.UserCenter | ||
} | ||
|
||
func NewServiceContext(c config.Config) *ServiceContext { | ||
return &ServiceContext{ | ||
Config: c, | ||
UserCenter: user_center_client.NewUserCenter(zrpc.MustNewClient(c.UserCenter)), | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
syntax = "v1" | ||
|
||
info ( | ||
title: "user_center" | ||
desc: "user_center" | ||
author: "sulinehk" | ||
email: "sulinehk@gmail.com" | ||
) | ||
|
||
type EmptyRequest {} | ||
|
||
type EmptyResponse {} | ||
|
||
type CreateUserRequest { | ||
username string `form:"username"` | ||
password string `form:"password"` | ||
email string `form:"email"` | ||
} | ||
|
||
service user_center-api { | ||
@handler CreateUser | ||
post /users/create (CreateUserRequest) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/linehk/go-blogger/service/user_center/api/internal/config" | ||
"github.com/linehk/go-blogger/service/user_center/api/internal/handler" | ||
"github.com/linehk/go-blogger/service/user_center/api/internal/svc" | ||
|
||
"github.com/zeromicro/go-zero/core/conf" | ||
"github.com/zeromicro/go-zero/rest" | ||
) | ||
|
||
var configFile = flag.String("f", "etc/user_center-api.yaml", "the config file") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
var c config.Config | ||
conf.MustLoad(*configFile, &c) | ||
|
||
server := rest.MustNewServer(c.RestConf) | ||
defer server.Stop() | ||
|
||
ctx := svc.NewServiceContext(c) | ||
handler.RegisterHandlers(server, ctx) | ||
|
||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) | ||
server.Start() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
service/user_center/rpc/internal/server/user_center_server.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.