[GH-33] fixes nil pointer panic if SiteURL is not set (#35)
parent
0f6783ceb6
commit
495ac389e0
|
@ -111,6 +111,9 @@ type Plugin struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) OnActivate() error {
|
func (p *Plugin) OnActivate() error {
|
||||||
|
if p.API.GetConfig().ServiceSettings.SiteURL == nil {
|
||||||
|
p.API.LogError("SiteURL must be set. Some features will operate incorrectly if the SiteURL is not set. See documentation for details: http://about.mattermost.com/default-site-url")
|
||||||
|
}
|
||||||
p.router = mux.NewRouter()
|
p.router = mux.NewRouter()
|
||||||
p.router.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
|
p.router.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
|
||||||
if err := p.API.RegisterCommand(createMemesCommand()); err != nil {
|
if err := p.API.RegisterCommand(createMemesCommand()); err != nil {
|
||||||
|
@ -152,7 +155,7 @@ func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||||
siteURL := *p.API.GetConfig().ServiceSettings.SiteURL
|
siteURL := p.GetSiteURL()
|
||||||
|
|
||||||
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))
|
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))
|
||||||
|
|
||||||
|
@ -200,6 +203,15 @@ Available memes: ` + strings.Join(availableMemes, ", "),
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Plugin) GetSiteURL() string {
|
||||||
|
siteURL := ""
|
||||||
|
ptr := p.API.GetConfig().ServiceSettings.SiteURL
|
||||||
|
if ptr != nil {
|
||||||
|
siteURL = *ptr
|
||||||
|
}
|
||||||
|
return siteURL
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
if err := demo(os.Args[1:]); err != nil {
|
if err := demo(os.Args[1:]); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue