Skip to content

Commit

Permalink
Merge pull request #15 from hardcore-os/logic_dev
Browse files Browse the repository at this point in the history
feat: 用户领域服务框架开发
  • Loading branch information
logikoisto authored Feb 16, 2024
2 parents 3cb4a91 + 3c937f2 commit 1a5bc00
Show file tree
Hide file tree
Showing 31 changed files with 2,372 additions and 3 deletions.
25 changes: 25 additions & 0 deletions cmd/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/hardcore-os/plato/domain/user"
"github.com/spf13/cobra"
)

func init() {
userCmd.AddCommand(domainCMD)
rootCmd.AddCommand(userCmd)
}

var userCmd = &cobra.Command{
Use: "user",
Short: "这是用户模块的命令,通常有api和domain两个子命令",
}

var domainCMD = &cobra.Command{
Use: "domain",
Run: DomainHandle,
}

func DomainHandle(cmd *cobra.Command, args []string) {
user.RunMain(ConfigPath)
}
1 change: 1 addition & 0 deletions common/bizflow/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (g *Graph) Run(ctx context.Context) error {
g.tryStop(it)
case RetryableError:
if it.retryNum > 0 {
it.retryNum -= 1
g.e.workPool.Submit(func() { g.work(it) })
}
case NonRetryable:
Expand Down
7 changes: 7 additions & 0 deletions common/bus/event/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package event

type Channel string

const (
UserEvent Channel = "user_event"
)
1 change: 1 addition & 0 deletions common/bus/event/kafka.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package event
23 changes: 23 additions & 0 deletions common/bus/event/mq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package event

type Manager struct {
channelsConf map[Channel]*Options
channels map[Channel]mq
}

type mq interface {
Send(event interface{})
Receive() <-chan interface{}
}

func NewManager(opts map[Channel]*Options) *Manager {
return &Manager{channelsConf: opts}
}

func (m *Manager) Send(c Channel, data interface{}) {

}

func (m *Manager) Receive(c Channel) interface{} {
return nil
}
4 changes: 4 additions & 0 deletions common/bus/event/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package event

type Options struct {
}
19 changes: 19 additions & 0 deletions common/cache/local.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cache

type localCache struct{}

func newLocalCache(opt *Options) *localCache {
return &localCache{}
}

func (r *localCache) MSet(keys map[string]interface{}) {

}

func (r *localCache) MGet(key []string) map[string]interface{} {
return nil
}

func (r *localCache) MDel(key []string) {

}
47 changes: 47 additions & 0 deletions common/cache/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cache

type mode = string

const (
Local mode = "local"
Remote mode = "remote"
)

type Options struct {
Mode mode
}

type cache interface {
MSet(keys map[string]interface{})
MGet(key []string) map[string]interface{}
MDel(key []string)
}

type Manager struct {
opts []*Options
cacheList []cache
}

func NewManager(opts []*Options) *Manager {
m := &Manager{opts: opts, cacheList: make([]cache, 0)}
for _, opt := range opts {
switch opt.Mode {
case Local:
m.cacheList = append(m.cacheList, newLocalCache(opt))
case Remote:
m.cacheList = append(m.cacheList, newRedisCache(opt))
}
}
return m
}

func (m *Manager) MSet(keys map[string]interface{}) {

}

func (m *Manager) MGet(key []string) map[string]interface{} {
return nil
}

func (m *Manager) MDel(key []string) {
}
20 changes: 20 additions & 0 deletions common/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,23 @@ func RunLuaInt(ctx context.Context, name string, keys []string, args ...interfac
func GetKeys(ctx context.Context, key string) ([]string, error) {
return rdb.Keys(ctx, key).Result()
}

// redis cache
type redisCache struct {
}

func newRedisCache(opt *Options) *redisCache {
return &redisCache{}
}

func (r *redisCache) MSet(keys map[string]interface{}) {

}

func (r *redisCache) MGet(key []string) map[string]interface{} {
return nil
}

func (r *redisCache) MDel(key []string) {

}
2 changes: 1 addition & 1 deletion common/config/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func GetSateCmdChannelNum() int {
return viper.GetInt("state.cmd_channel_num")
}
func GetSateServiceAddr() string {
return viper.GetString("state.servide_addr")
return viper.GetString("state.service_addr")
}
func GetStateServiceName() string {
return viper.GetString("state.service_name")
Expand Down
21 changes: 21 additions & 0 deletions common/config/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package config

import "github.com/spf13/viper"

func GetDomainUserServerName() string {
return viper.GetString("user_domain.service_name")
}

func GetDomainUserServerAddr() string {
return viper.GetString("user_domain.service_addr")
}

func GetDomainUserServerPoint() int {
return viper.GetInt("user_dimain.service_port")
}
func GetDomainUserRPCWeight() int {
return viper.GetInt("user_dimain.weight")
}
func GetDomainUserDBDNS() string {
return viper.GetString("user_dimain.db_dns")
}
1 change: 1 addition & 0 deletions common/idl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
idl目录存储全项目通用的可复用的标准化结构体定义
163 changes: 163 additions & 0 deletions common/idl/base/base.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions common/idl/base/base.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

option go_package = "common/idl/base";
//protoc --go-grpc_out=. --go_out=. ./common/idl/base/base.proto
package base;


message BaseResp {
uint32 Code = 1;
string Msg = 2;
string LogID = 3;
}
Loading

0 comments on commit 1a5bc00

Please sign in to comment.