Skip to content

Commit 1a5bc00

Browse files
authored
Merge pull request #15 from hardcore-os/logic_dev
feat: 用户领域服务框架开发
2 parents 3cb4a91 + 3c937f2 commit 1a5bc00

31 files changed

+2372
-3
lines changed

cmd/user.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cmd
2+
3+
import (
4+
"github.com/hardcore-os/plato/domain/user"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func init() {
9+
userCmd.AddCommand(domainCMD)
10+
rootCmd.AddCommand(userCmd)
11+
}
12+
13+
var userCmd = &cobra.Command{
14+
Use: "user",
15+
Short: "这是用户模块的命令,通常有api和domain两个子命令",
16+
}
17+
18+
var domainCMD = &cobra.Command{
19+
Use: "domain",
20+
Run: DomainHandle,
21+
}
22+
23+
func DomainHandle(cmd *cobra.Command, args []string) {
24+
user.RunMain(ConfigPath)
25+
}

common/bizflow/graph.go

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func (g *Graph) Run(ctx context.Context) error {
9090
g.tryStop(it)
9191
case RetryableError:
9292
if it.retryNum > 0 {
93+
it.retryNum -= 1
9394
g.e.workPool.Submit(func() { g.work(it) })
9495
}
9596
case NonRetryable:

common/bus/event/channel.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package event
2+
3+
type Channel string
4+
5+
const (
6+
UserEvent Channel = "user_event"
7+
)

common/bus/event/kafka.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package event

common/bus/event/mq.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package event
2+
3+
type Manager struct {
4+
channelsConf map[Channel]*Options
5+
channels map[Channel]mq
6+
}
7+
8+
type mq interface {
9+
Send(event interface{})
10+
Receive() <-chan interface{}
11+
}
12+
13+
func NewManager(opts map[Channel]*Options) *Manager {
14+
return &Manager{channelsConf: opts}
15+
}
16+
17+
func (m *Manager) Send(c Channel, data interface{}) {
18+
19+
}
20+
21+
func (m *Manager) Receive(c Channel) interface{} {
22+
return nil
23+
}

common/bus/event/options.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package event
2+
3+
type Options struct {
4+
}

common/cache/local.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cache
2+
3+
type localCache struct{}
4+
5+
func newLocalCache(opt *Options) *localCache {
6+
return &localCache{}
7+
}
8+
9+
func (r *localCache) MSet(keys map[string]interface{}) {
10+
11+
}
12+
13+
func (r *localCache) MGet(key []string) map[string]interface{} {
14+
return nil
15+
}
16+
17+
func (r *localCache) MDel(key []string) {
18+
19+
}

common/cache/manager.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cache
2+
3+
type mode = string
4+
5+
const (
6+
Local mode = "local"
7+
Remote mode = "remote"
8+
)
9+
10+
type Options struct {
11+
Mode mode
12+
}
13+
14+
type cache interface {
15+
MSet(keys map[string]interface{})
16+
MGet(key []string) map[string]interface{}
17+
MDel(key []string)
18+
}
19+
20+
type Manager struct {
21+
opts []*Options
22+
cacheList []cache
23+
}
24+
25+
func NewManager(opts []*Options) *Manager {
26+
m := &Manager{opts: opts, cacheList: make([]cache, 0)}
27+
for _, opt := range opts {
28+
switch opt.Mode {
29+
case Local:
30+
m.cacheList = append(m.cacheList, newLocalCache(opt))
31+
case Remote:
32+
m.cacheList = append(m.cacheList, newRedisCache(opt))
33+
}
34+
}
35+
return m
36+
}
37+
38+
func (m *Manager) MSet(keys map[string]interface{}) {
39+
40+
}
41+
42+
func (m *Manager) MGet(key []string) map[string]interface{} {
43+
return nil
44+
}
45+
46+
func (m *Manager) MDel(key []string) {
47+
}

common/cache/redis.go

+20
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,23 @@ func RunLuaInt(ctx context.Context, name string, keys []string, args ...interfac
125125
func GetKeys(ctx context.Context, key string) ([]string, error) {
126126
return rdb.Keys(ctx, key).Result()
127127
}
128+
129+
// redis cache
130+
type redisCache struct {
131+
}
132+
133+
func newRedisCache(opt *Options) *redisCache {
134+
return &redisCache{}
135+
}
136+
137+
func (r *redisCache) MSet(keys map[string]interface{}) {
138+
139+
}
140+
141+
func (r *redisCache) MGet(key []string) map[string]interface{} {
142+
return nil
143+
}
144+
145+
func (r *redisCache) MDel(key []string) {
146+
147+
}

common/config/state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func GetSateCmdChannelNum() int {
1111
return viper.GetInt("state.cmd_channel_num")
1212
}
1313
func GetSateServiceAddr() string {
14-
return viper.GetString("state.servide_addr")
14+
return viper.GetString("state.service_addr")
1515
}
1616
func GetStateServiceName() string {
1717
return viper.GetString("state.service_name")

common/config/user.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package config
2+
3+
import "github.com/spf13/viper"
4+
5+
func GetDomainUserServerName() string {
6+
return viper.GetString("user_domain.service_name")
7+
}
8+
9+
func GetDomainUserServerAddr() string {
10+
return viper.GetString("user_domain.service_addr")
11+
}
12+
13+
func GetDomainUserServerPoint() int {
14+
return viper.GetInt("user_dimain.service_port")
15+
}
16+
func GetDomainUserRPCWeight() int {
17+
return viper.GetInt("user_dimain.weight")
18+
}
19+
func GetDomainUserDBDNS() string {
20+
return viper.GetString("user_dimain.db_dns")
21+
}

common/idl/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
idl目录存储全项目通用的可复用的标准化结构体定义

common/idl/base/base.pb.go

+163
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/idl/base/base.proto

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
syntax = "proto3";
2+
3+
option go_package = "common/idl/base";
4+
//protoc --go-grpc_out=. --go_out=. ./common/idl/base/base.proto
5+
package base;
6+
7+
8+
message BaseResp {
9+
uint32 Code = 1;
10+
string Msg = 2;
11+
string LogID = 3;
12+
}

0 commit comments

Comments
 (0)