Repository: google/go-github
File: github/event.go (Go)

Code before:
	Type       *string          `json:"type,omitempty"`
	Public     *bool            `json:"public,omitempty"`
	RawPayload *json.RawMessage `json:"payload,omitempty"`
	Repo       *Repository      `json:"repo,omitempty"`
	Actor      *User            `json:"actor,omitempty"`
	Org        *Organization    `json:"org,omitempty"`
	CreatedAt  *Timestamp       `json:"created_at,omitempty"`
	ID         *string          `json:"id,omitempty"`
}

func (e Event) String() string {
	return Stringify(e)
}

// ParsePayload parses the event payload. For recognized event types,
// a value of the corresponding struct type will be returned.
func (e *Event) ParsePayload() (payload interface{}, err error) {
	// It would be nice if e.Type were the snake_case name of the event,
	// but the existing interface uses the struct name instead.
	typed := EventForType(typeToMessageMapping[e.GetType()])
	if typed != nil {
		payload = typed
	}
	err = json.Unmarshal(e.GetRawPayload(), &payload)

	return
}

// Payload returns the parsed event payload. For recognized event types,
// a value of the corresponding struct type will be returned.
//
// Deprecated: Use ParsePayload instead, which returns an error
// rather than panics if JSON unmarshaling raw payload fails.
func (e *Event) Payload() (payload interface{}) {
	var err error
	payload, err = e.ParsePayload()
	if err != nil {
		panic(err)
	}
	return payload
}


Review comment (suggestion):
Please explicitly return named return values, as that is idiomatic Go.
Also, in this repo, we try to have the last line be the "happy path", so let's get the error out of the way post haste:

```suggestion
	if err := json.Unmarshal(e.GetRawPayload(), &payload); err != nil {
		return nil, err
	}

	return payload, nil
```

Code after:
	Type       *string          `json:"type,omitempty"`
	Public     *bool            `json:"public,omitempty"`
	RawPayload *json.RawMessage `json:"payload,omitempty"`
	Repo       *Repository      `json:"repo,omitempty"`
	Actor      *User            `json:"actor,omitempty"`
	Org        *Organization    `json:"org,omitempty"`
	CreatedAt  *Timestamp       `json:"created_at,omitempty"`
	ID         *string          `json:"id,omitempty"`
}

func (e Event) String() string {
	return Stringify(e)
}

// ParsePayload parses the event payload. For recognized event types,
// a value of the corresponding struct type will be returned.
func (e *Event) ParsePayload() (interface{}, error) {
	// It would be nice if e.Type were the snake_case name of the event,
	// but the existing interface uses the struct name instead.
	payload := EventForType(typeToMessageMapping[e.GetType()])

	if err := json.Unmarshal(e.GetRawPayload(), &payload); err != nil {
		return nil, err
	}

	return payload, nil
}

// Payload returns the parsed event payload. For recognized event types,
// a value of the corresponding struct type will be returned.
//
// Deprecated: Use ParsePayload instead, which returns an error
// rather than panics if JSON unmarshaling raw payload fails.
func (e *Event) Payload() (payload interface{}) {
	var err error
	payload, err = e.ParsePayload()
	if err != nil {
		panic(err)
	}
	return payload
}