Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Partially Blind Unmarshaling with Golang.
package triggertypes
import "time"
// RequestMade ...
type RequestMade struct {
Requester int `json:"requester"` // sapphire userID
RequestID int `json:"requestID"`
EventID int `json:"eventID"`
CreatedDate *time.Time `json:"createdDate"` // Here just incase its lost or delayed.
const requestMadeType = "RequestMade"
// GetRequestMadeTypeString ...
func GetRequestMadeTypeString() string {
return requestMadeType
// GetTypeString ...
func (trigger *RequestMade) GetTypeString() string {
return requestMadeType
package triggertypes
import (
// Unmarshal ...
func Unmarshal(triggerType string, reader io.ReadCloser) (t interface{}, err error) {
t = nil
decoder := json.NewDecoder(reader)
switch triggerType {
case requestMadeType:
t = &RequestMade{}
if t != nil {
err = decoder.Decode(&t)
if err != nil {
return nil, err
return nil, errors.New("Unknown type")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.