forked from p53841790/wheat-cache
commit
2a69f393e5
|
@ -2,6 +2,7 @@ package conf
|
|||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
@ -10,18 +11,23 @@ const (
|
|||
linuxPath = "/etc/wheat-cache/"
|
||||
)
|
||||
|
||||
func init() {
|
||||
setDefaultConfValue()
|
||||
err := LoadConf("")
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
case viper.ConfigFileNotFoundError:
|
||||
formatPath := []string{linuxPath}
|
||||
log.Fatalf("the profile could not be read, read path:%v", formatPath)
|
||||
default:
|
||||
log.Fatalf("the resolution of the profile failed, err: %v", err)
|
||||
var confLock sync.Once
|
||||
|
||||
}
|
||||
func init() {
|
||||
confLock.Do(func() {
|
||||
setDefaultConfValue()
|
||||
err := LoadConf("")
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
case viper.ConfigFileNotFoundError:
|
||||
formatPath := []string{linuxPath}
|
||||
log.Fatalf("the profile could not be read, read path:%v", formatPath)
|
||||
default:
|
||||
log.Fatalf("the resolution of the profile failed, err: %v", err)
|
||||
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func setDefaultConfValue() {
|
||||
|
|
|
@ -48,4 +48,6 @@ gateway:
|
|||
host: '127.0.0.1'
|
||||
port: 5891
|
||||
target: ["127.0.0.1:5890"]
|
||||
|
||||
|
||||
mock-plugin:
|
||||
pprof-addr: "127.0.0.1:8000"
|
|
@ -12,8 +12,9 @@ import (
|
|||
func GetMiddlewareMap() map[string]plugins.PluginInterface {
|
||||
|
||||
mockPlugin := mockPlugin.NewPlugin()
|
||||
return map[string]plugins.PluginInterface{
|
||||
mockPlugin.Init()
|
||||
|
||||
return map[string]plugins.PluginInterface{
|
||||
mockPlugin.Name(): mockPlugin,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,10 @@ import (
|
|||
func GetMiddlewareMap() map[string]plugins.PluginInterface {
|
||||
{%for dir in dirs %}
|
||||
{{dir[0]}}:={{dir[0]}}.NewPlugin()
|
||||
{%- endfor%}
|
||||
{{dir[0]}}.Init()
|
||||
{% endfor%}
|
||||
return map[string]plugins.PluginInterface{
|
||||
{%for dir in dirs %}
|
||||
{%for dir in dirs -%}
|
||||
{{dir[0]}}.Name():{{dir[0]}},
|
||||
{%- endfor%}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
package mockplugin
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
||||
_ "gitee.com/timedb/wheatCache/conf"
|
||||
"gitee.com/timedb/wheatCache/pkg/logx"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type MockPlugin struct {
|
||||
}
|
||||
|
||||
func (m *MockPlugin) Init() {
|
||||
addr := viper.GetString("mock-plugin.pprof-addr")
|
||||
if addr != "" {
|
||||
go func() {
|
||||
logx.Debugln(http.ListenAndServe(addr, nil))
|
||||
}()
|
||||
}
|
||||
|
||||
logx.Debug("mock-plugins status: start")
|
||||
}
|
||||
|
||||
func (m *MockPlugin) Exec(msg interface{}) (interface{}, error) {
|
||||
|
|
Loading…
Reference in New Issue