Skip to content

Commit

Permalink
fix: engine 脸是调用
Browse files Browse the repository at this point in the history
  • Loading branch information
tangx committed Dec 5, 2021
1 parent 9884db3 commit ce0a008
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 1 addition & 2 deletions internal/example/apis/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package index

import (
"context"
"fmt"

"github.com/gin-gonic/gin"
"github.com/tangx/rum-gonic/internal/example/injector/redis"
Expand All @@ -24,7 +23,7 @@ func logic(ctx context.Context, index *Index) map[string]string {
ra := redis.FromRedisAgentOnline(ctx)

return map[string]string{
"redis-agent": fmt.Sprintf("%s:%d", ra.Addr, ra.Port),
"redis-agent": ra.ServerAddr(),
"code": "200",
"message": "index.html",
"name": index.Name,
Expand Down
17 changes: 12 additions & 5 deletions internal/example/injector/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ package redis

import (
"context"
"fmt"

"github.com/tangx/rum-gonic/rum"
)

/* 定义 */
type RedisAgent struct {
Addr string
Port int
}

func (r *RedisAgent) ServerAddr() string {
return fmt.Sprintf("%s:%d", r.Addr, r.Port)
}

/* 初始化与注入 */
type RedisKey string

const (
redisOnlineKey RedisKey = "online"
)

type RedisAgent struct {
Addr string
Port int
}

var RedisOnlineAgent = &RedisAgent{
Addr: "Online-agent",
Port: 6379,
Expand Down
4 changes: 3 additions & 1 deletion rum/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ func (e *Engine) register() {
}

// WithContextCompose 添加注入控制器
func (e *Engine) WithContextCompose(injectors ...ContextInjectorFunc) {
func (e *Engine) WithContextCompose(injectors ...ContextInjectorFunc) *Engine {
if contextInjectors == nil {
contextInjectors = make([]ContextInjectorFunc, 0)
}
contextInjectors = append(contextInjectors, injectors...)

return e
}

0 comments on commit ce0a008

Please sign in to comment.