[GH-33] fixes nil pointer panic if SiteURL is not set (#35)

master
Ashim Sedhain 2020-09-22 04:58:49 -05:00 committed by GitHub
parent 0f6783ceb6
commit 495ac389e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -111,6 +111,9 @@ type Plugin struct {
}
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.HandleFunc("/templates/{name}.jpg", serveTemplateJPEG).Methods("GET")
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) {
siteURL := *p.API.GetConfig().ServiceSettings.SiteURL
siteURL := p.GetSiteURL()
input := strings.TrimSpace(strings.TrimPrefix(args.Command, "/meme"))
@ -200,6 +203,15 @@ Available memes: ` + strings.Join(availableMemes, ", "),
return resp, nil
}
func (p *Plugin) GetSiteURL() string {
siteURL := ""
ptr := p.API.GetConfig().ServiceSettings.SiteURL
if ptr != nil {
siteURL = *ptr
}
return siteURL
}
func main() {
if len(os.Args) > 1 {
if err := demo(os.Args[1:]); err != nil {