Closed bruceyan303 closed 1 year ago
06-08T22:18:29.636+0800 INFO server/server.go:1147 init plugin {"name": "auth"} 2023-06-08T22:18:29.637+0800 INFO server/server.go:1147 init plugin {"name": "prometheus"} 2023-06-08T22:18:29.637+0800 INFO server/server.go:1147 init plugin {"name": "admin"} 2023-06-08T22:18:29.637+0800 INFO server/server.go:1147 init plugin {"name": "federation"} 2023-06-08T22:18:29.638+0800 INFO log/log.go:204 2023/06/08 22:18:29 [INFO] serf: EventMemberJoin: bruceyan 192.168.5.145 {"plugin": "federation"} 2023-06-08T22:18:29.638+0800 INFO server/server.go:1147 init plugin {"name": "testplugin"} panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x77c6e1]
goroutine 1 [running]: hmqtt/server.(server).initPluginHooks(0xc00002d880) C:/code/mqtt/server/server.go:1148 +0x221 hmqtt/server.(server).init(0xc00002d880, {0x0, 0x0, 0x9c1480?}) C:/code/mqtt/server/server.go:864 +0x8a hmqtt/server.(server).Init.func1() C:/code/mqtt/server/server.go:972 +0x32 sync.(Once).doSlow(0x1?, 0x1?) C:/Program Files/Go/src/sync/once.go:74 +0xc2 sync.(Once).Do(...) C:/Program Files/Go/src/sync/once.go:65 hmqtt/server.(server).Init(0xc0000cd8a8?, {0x0?, 0x2?, 0xc000112788?}) C:/code/mqtt/server/server.go:971 +0x76 hmqtt/cmd/gmqttd/command.NewStartCmd.func1(0xc000356000?, {0xa8c472?, 0x2?, 0x2?}) C:/code/mqtt/cmd/gmqttd/command/start.go:131 +0x4e5 github.com/spf13/cobra.(Command).execute(0xc000356000, {0xc000110a00, 0x2, 0x2}) C:/Users/longt/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944 +0x847 github.com/spf13/cobra.(Command).ExecuteC(0x10b82a0) C:/Users/longt/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd github.com/spf13/cobra.(*Command).Execute(...) C:/Users/longt/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992 main.main() C:/code/mqtt/cmd/gmqttd/main.go:56 +0x3a exit status 2
package testplugin import ( "hmqtt/config" "hmqtt/server" "go.uber.org/zap" ) var _ server.Plugin = (*Testplugin)(nil) const Name = "testplugin" func init() { server.RegisterPlugin(Name, New) config.RegisterDefaultPluginConfig(Name, &DefaultConfig) } func New(config config.Config) (server.Plugin, error) { c := &Testplugin{ config: config.Plugins[Name].(*Config), } return c, nil } var log *zap.Logger type Testplugin struct { config *Config } var registerAPI = func(service server.Server, c *Testplugin) error { apiRegistrar := service.APIRegistrar() RegisterCtrlCenterServer(apiRegistrar, c) return nil // err := apiRegistrar.RegisterHTTPHandler(RegisterAccountServiceHandlerFromEndpoint) // return err } func (c *Testplugin) Load(service server.Server) error { err := registerAPI(service, c) if err != nil { return err } log = server.LoggerWithField(zap.String("plugin", Name)) return nil } func (c *Testplugin) Unload() error { return nil } func (c *Testplugin) Name() string { return Name }
请教一下 试着自己添加插件是哪里返回空啊
06-08T22:18:29.636+0800 INFO server/server.go:1147 init plugin {"name": "auth"} 2023-06-08T22:18:29.637+0800 INFO server/server.go:1147 init plugin {"name": "prometheus"} 2023-06-08T22:18:29.637+0800 INFO server/server.go:1147 init plugin {"name": "admin"} 2023-06-08T22:18:29.637+0800 INFO server/server.go:1147 init plugin {"name": "federation"} 2023-06-08T22:18:29.638+0800 INFO log/log.go:204 2023/06/08 22:18:29 [INFO] serf: EventMemberJoin: bruceyan 192.168.5.145 {"plugin": "federation"} 2023-06-08T22:18:29.638+0800 INFO server/server.go:1147 init plugin {"name": "testplugin"} panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x0 pc=0x77c6e1]
goroutine 1 [running]: hmqtt/server.(server).initPluginHooks(0xc00002d880) C:/code/mqtt/server/server.go:1148 +0x221 hmqtt/server.(server).init(0xc00002d880, {0x0, 0x0, 0x9c1480?}) C:/code/mqtt/server/server.go:864 +0x8a hmqtt/server.(server).Init.func1() C:/code/mqtt/server/server.go:972 +0x32 sync.(Once).doSlow(0x1?, 0x1?) C:/Program Files/Go/src/sync/once.go:74 +0xc2 sync.(Once).Do(...) C:/Program Files/Go/src/sync/once.go:65 hmqtt/server.(server).Init(0xc0000cd8a8?, {0x0?, 0x2?, 0xc000112788?}) C:/code/mqtt/server/server.go:971 +0x76 hmqtt/cmd/gmqttd/command.NewStartCmd.func1(0xc000356000?, {0xa8c472?, 0x2?, 0x2?}) C:/code/mqtt/cmd/gmqttd/command/start.go:131 +0x4e5 github.com/spf13/cobra.(Command).execute(0xc000356000, {0xc000110a00, 0x2, 0x2}) C:/Users/longt/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:944 +0x847 github.com/spf13/cobra.(Command).ExecuteC(0x10b82a0) C:/Users/longt/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bd github.com/spf13/cobra.(*Command).Execute(...) C:/Users/longt/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992 main.main() C:/code/mqtt/cmd/gmqttd/main.go:56 +0x3a exit status 2
请教一下 试着自己添加插件是哪里返回空啊