Skip to content

Commit

Permalink
[GH-33] fixes nil pointer panic if SiteURL is not set (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
asimsedhain authored Sep 22, 2020
1 parent 0f6783c commit 495ac38
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 495ac38

Please sign in to comment.