Repository: nukosuke/go-zendesk (go)
Issue: Change Via field to pointer
note:
- `omitempty` doesn't emit empty `Via{}` object. It should be `nil` to work correctly.
- It would cause problem only when request create/update Ticket or TicketComment
Pull request description: Make Via field to pointer type
close #191 

Patch:
diff --git a/zendesk/ticket.go b/zendesk/ticket.go
index 92adb14..df77a44 100644
--- a/zendesk/ticket.go
+++ b/zendesk/ticket.go
@@ -73,14 +73,7 @@ type Ticket struct {
 	Tags            []string      `json:"tags,omitempty"`
 	CustomFields    []CustomField `json:"custom_fields,omitempty"`
 
-	Via struct {
-		Channel string `json:"channel"`
-		Source  struct {
-			From map[string]interface{} `json:"from"`
-			To   map[string]interface{} `json:"to"`
-			Rel  string                 `json:"rel"`
-		} `json:"source"`
-	} `json:"via,omitempty"`
+	Via *Via `json:"via,omitempty"`
 
 	SatisfactionRating struct {
 		ID      int64  `json:"id"`
@@ -109,6 +102,16 @@ type Ticket struct {
 	// TODO: TicketAudit (POST only) #126
 }
 
+// Via is information about source of Ticket or TicketComment
+type Via struct {
+	Channel string `json:"channel"`
+	Source  struct {
+		From map[string]interface{} `json:"from"`
+		To   map[string]interface{} `json:"to"`
+		Rel  string                 `json:"rel"`
+	} `json:"source"`
+}
+
 type TicketListOptions struct {
 	PageOptions
 
diff --git a/zendesk/ticket_comment.go b/zendesk/ticket_comment.go
index 4b02bc9..d9606f3 100644
--- a/zendesk/ticket_comment.go
+++ b/zendesk/ticket_comment.go
@@ -29,14 +29,7 @@ type TicketComment struct {
 	Uploads     []string               `json:"uploads,omitempty"`
 	Metadata    map[string]interface{} `json:"metadata,omitempty"`
 
-	Via struct {
-		Channel string `json:"channel"`
-		Source  struct {
-			From map[string]interface{} `json:"from"`
-			To   map[string]interface{} `json:"to"`
-			Rel  string                 `json:"rel"`
-		} `json:"source"`
-	} `json:"via,omitempty"`
+	Via *Via `json:"via,omitempty"`
 }
 
 // NewPublicTicketComment generates and returns a new TicketComment


Test patch:
diff --git a/zendesk/attachment_test.go b/zendesk/attachment_test.go
index 812d8f4..ddd60a0 100644
--- a/zendesk/attachment_test.go
+++ b/zendesk/attachment_test.go
@@ -51,7 +51,7 @@ func TestWrite(t *testing.T) {
 }
 
 func TestWriteCancelledContext(t *testing.T) {
-	mockAPI := newMockAPIWithStatus(http.MethodPost, "ticket.json",  201)
+	mockAPI := newMockAPIWithStatus(http.MethodPost, "ticket.json", 201)
 	defer mockAPI.Close()
 
 	client := newTestClient(mockAPI)
diff --git a/zendesk/ticket_audit_test.go b/zendesk/ticket_audit_test.go
index 320b8a6..8e97322 100644
--- a/zendesk/ticket_audit_test.go
+++ b/zendesk/ticket_audit_test.go
@@ -50,5 +50,3 @@ func TestGetTicketAudit(t *testing.T) {
 		t.Fatalf("Returned ticket audit does not have the expected ID %d. Ticket audit id is %d", expectedID, ticketAudit.ID)
 	}
 }
-
-
diff --git a/zendesk/ticket_test.go b/zendesk/ticket_test.go
index ad5246d..6663d82 100644
--- a/zendesk/ticket_test.go
+++ b/zendesk/ticket_test.go
@@ -49,14 +49,7 @@ func TestGetTicket(t *testing.T) {
 		t.Fatalf("Returned ticket does not have the expected ID %d. Ticket id is %d", expectedID, ticket.ID)
 	}
 
-	expectedVia := struct {
-		Channel string `json:"channel"`
-		Source  struct {
-			From map[string]interface{} `json:"from"`
-			To   map[string]interface{} `json:"to"`
-			Rel  string                 `json:"rel"`
-		} `json:"source"`
-	}{
+	expectedVia := &Via{
 		Channel: "email",
 		Source: struct {
 			From map[string]interface{} `json:"from"`